setSalt(); $savePassword = $this->setPassword($password, $salt); $data = [ 'password' => $savePassword, 'salt' => $salt ]; $User = new WechatUser(); return $User->where('id', $id)->save($data); } public static function addUser( int $phone, string $email, string $pucode, string $tax_number, int $type ) { $where = ['phone' => $phone, 'delete_time' => 0]; $query = WechatUser::where($where)->find(); if (!$query) { $save = [ 'nickname' => '导入用户', 'phone' => $phone, 'email' => $email, 'create_time' => time() ]; $id = (new WechatUser())->insertGetId($save); } else { $id = $query['id']; $query->email = $email; $query->save(); } if ($id) { $puCodeQuery = (new WechatPucode())->where('pucode', $pucode)->where('wechat_user_id', $id)->find(); if ($puCodeQuery) { $puCodeQuery->wechat_user_id = $id; $puCodeQuery->create_time = time(); $puCodeQuery->save(); } else { $codeSave = [ 'wechat_user_id' => $id, 'pucode' => $pucode, 'create_time' => time() ]; (new WechatPucode())->save($codeSave); } $headSave = [ 'wechat_user_id' => $id ]; if ($tax_number) { $headQuery = (new InvoiceHead())->where($headSave)->find(); if ($headQuery && ($headQuery['pucode'] == $pucode || empty($headQuery['pucode']))) { $headQuery->type = $type; $headQuery->tax_number = $tax_number; $headQuery->phone = $phone; $headQuery->pucode = $pucode; $headQuery->create_time = time(); $headQuery->save(); } else { $headSave['type'] = $type; $headSave['tax_number'] = $tax_number; $headSave['phone'] = $phone; $headSave['pucode'] = $pucode; $headSave['create_time'] = time(); (new InvoiceHead())->save($headSave); } } return 1; } return 0; } public static function getTaxUser($tax_id, $wechat_user_id) { $where = [ ['tax_number', '=', $tax_id], ['wechat_user_id', '<>', $wechat_user_id], ]; $user_ids = InvoiceHead::where($where)->column('wechat_user_id'); if ($user_ids) { return WechatPucode::whereIn('wechat_user_id', $user_ids)->column('pucode'); } } }