diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/bourse_p1.iml b/.idea/bourse_p1.iml new file mode 100644 index 0000000..8f6197f --- /dev/null +++ b/.idea/bourse_p1.iml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..230561d --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml new file mode 100644 index 0000000..7f9700d --- /dev/null +++ b/.idea/php.xml @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..c8397c9 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/admin/service/AdminService.php b/app/admin/service/AdminService.php index 59065ab..18e0c55 100644 --- a/app/admin/service/AdminService.php +++ b/app/admin/service/AdminService.php @@ -7,6 +7,7 @@ use app\home\service\BaseHomeService; use app\model\AdminLogModel; use app\model\AdminModel; use app\model\AuthRoleModel; +use app\model\UserChatLinkModel; use phpDocumentor\Reflection\Type; use think\exception\ValidateException; use app\utility\UnqId; @@ -102,8 +103,18 @@ class AdminService extends AdminBaseService if (empty($info)) { return $this->toData('100400', 'The user does not exist.', []); } + $infoArr = $info->toArray(); + + // 获取用户的聊天账号信息 + $chatInfo = UserChatLinkModel::where(['user_id'=>$userId, 'user_type'=>UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_ADMIN])->find(); + $chat_uuid = 0; + if (!empty($chatInfo)) { + $chat_uuid = $chatInfo->chat_uuid; + } + $infoArr['chat_uuid'] = $chat_uuid; + // 返回数据 - return $this->toData('0', 'Modification successful.', $info->toArray()); + return $this->toData('0', 'Modification successful.', $infoArr); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy.', [$exception->getMessage(), $exception->getTrace()]); } diff --git a/app/home/service/UserService.php b/app/home/service/UserService.php index fe384ec..e85630c 100644 --- a/app/home/service/UserService.php +++ b/app/home/service/UserService.php @@ -5,6 +5,8 @@ namespace app\home\service; use app\home\validate\UserValidate; use app\model\CountryModel; use app\model\FileModel; +use app\model\UserChatGroupModel; +use app\model\UserChatLinkModel; use app\model\UserContractModel; use app\model\UserDigitalModel; use app\model\UserForexModel; @@ -157,6 +159,31 @@ class UserService extends BaseHomeService } $leverageNum= empty($leverageNum) ? 1: $leverageNum; + // 查询用户的chat信息 + $userChatInfo = UserChatLinkModel::where(['user_id'=>$userId,'user_type'=>UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_PC])->find(); + $userChatUuid = ""; + $userChatName = ""; + if (!empty($userChatInfo)) { + $userChatUuid = $userChatInfo->chat_uuid; + $userChatName = $userChatInfo->chat_name; + } + // 查询用户关联的客服的chat信息 P1项目中客服账号就是admin + $adminId = 1; + $customerChatUuid = ""; + $customerChatName = ""; + $customerChatInfo = UserChatLinkModel::where(['user_id'=>$adminId, 'user_type'=>UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_ADMIN])->find(); + if ($customerChatInfo) { + $customerChatUuid = $customerChatInfo->chat_uuid; + $customerChatName = $customerChatInfo->chat_name; + } + // 获取聊天群组信息 + $chatGroup = UserChatGroupModel::where(['user_id'=>$adminId])->find(); + if (empty($chatGroup)) { + return $this->toData('500', 'chat group is null.'); + } + $group_chat_name = $chatGroup->group_name; + $group_chat_uuid = $chatGroup->group_uuid; + // 返回数据 return $this->toData('0', 'Modification successful.', [ 'logo' => $headPath, @@ -177,7 +204,14 @@ class UserService extends BaseHomeService 'country' => $countryName, 'countryId' => $countryId, 'lever_status' => $info['lever_status'], - 'leverage_num' =>$leverageNum + 'leverage_num' =>$leverageNum, + 'user_chat_uuid' => $userChatUuid, + 'user_chat_name' => $userChatName, + 'customer_chat_uuid' => $customerChatUuid, + 'customer_chat_name' => $customerChatName, + 'customer_chat_avatar' => '/bs/image/default.jpeg', + 'group_chat_name' => $group_chat_name, + 'group_chat_uuid' => $group_chat_uuid, ]); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy.', [$exception->getMessage(), $exception->getTrace()]); diff --git a/app/home/service/UserService.php.backup b/app/home/service/UserService.php.backup deleted file mode 100644 index 979357a..0000000 --- a/app/home/service/UserService.php.backup +++ /dev/null @@ -1,1330 +0,0 @@ -createUserLevel($user_id, $parent_id); - (new TeamService())->regBrokerage($data['parent_id'], $data['grandpa_id'], $data['top_id']); - } - $this->initUserWallet($user_id); - } - - /** - * 处理用户等级关系 - * @param int $user_id - * @param int $parent_id - * @return bool - */ - private function createUserLevel(int $user_id, int $parent_id) - { - //插入用户等级关系 - if ($parent_id > 0) { - $parent_info = UserLevelModel::getUserLevelById($parent_id); - $grandpa_id = $parent_info['parent_id']; - $top_id = $parent_info['grandpa_id']; - } else { - $grandpa_id = 0; - $top_id = 0; - } - $data['user_id'] = $user_id; - $data['parent_id'] = $parent_id; - $data['grandpa_id'] = $grandpa_id; - $data['top_id'] = $top_id; - UserLevelModel::InsertUserLevel($data); - return $data; - } - - public function getUserLevel(int $user_id) - { - $level_info = UserLevelModel::getUserLevelById($user_id); - $this->setUserLevel($user_id, $level_info); - } - - /** - * 初始化各钱包数据 U数据 - * @param int $user_id - * @return void - */ - private function initUserWallet(int $user_id) - { - if (env('FEATURE.HAS_STOCK_US')) { - UserStockModel::InsertUserStock([ - 'user_id' => $user_id, - 'stock_id' => 'USD', - 'usable_num' => 0, - 'frozen_num' => 0, - ]); - } - if (env('FEATURE.HAS_DIGITAL')) { - UserDigitalModel::InsertUserDigital([ - 'user_id' => $user_id, - 'digital_id' => 'USDT', - 'usable_num' => 0, - 'frozen_num' => 0, - ]); - } - if (env('FEATURE.HAS_CONTRACT')) { - UserContractModel::InsertUserContract([ - 'user_id' => $user_id, - 'contract_id' => 'USDT', - 'usable_num' => 0, - 'frozen_num' => 0, - ]); - } - - } - - /** - * @desc 获取用户信息 - * @param $userId - * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public function getUserInfo($userId) - { - try { - if (empty($userId) || $userId <= 0) { - return $this->toData('100403', 'Please log in first', []); - } - - $info = UserModel::getFieldsByUserId('trade_password,lever_status,gender,last_name,first_name,real_status,country_id,user_no,nick_name,email,phone_number,country_code,is_real,head_img_id,invite_code', $userId); - if (empty($info)) { - return $this->toData('100400', 'The user does not exist.', []); - } - - // 获取国家名称 - $countryId = $info['country_id']; - - $countryName = ''; - if ($countryId > 0) { - $countryName = CountryModel::getNameById($countryId); - } - - // 获取头像 - $headPath = env('USER.DEFAULT_HEAD_IMG_PATH'); - if ($info['head_img_id'] > 0) { - $headPath = FileModel::getFilePath($info['head_img_id']); - } - - $key = 'LEVERAGE:' . $userId; - $leverageNum = Cache::store('redis')->get($key); - if (empty($leverageNum)) { - $key = 'LEVERAGE:0'; - $leverageNum = Cache::store('redis')->get($key); - } - $leverageNum= empty($leverageNum) ? 1: $leverageNum; - - // 返回数据 - return $this->toData('0', 'Modification successful.', [ - 'logo' => $headPath, - 'userId' => $userId, - 'userNo' => $info['user_no'], - 'nickName' => $info['nick_name'], - 'nation' => $info['country_code'], - 'phone' => $info['phone_number'], - 'email' => $info['email'], - 'isReal' => $info['is_real'], - 'real_status' => $info['real_status'], - 'inviteCode' => $info['invite_code'], - 'firstName' => $info['first_name'], - 'lastName' => $info['last_name'], - 'gender' => (string)$info['gender'], - 'isSetPayPassword' => $info['trade_password'] ? '1' : '0', - 'country' => $countryName, - 'countryId' => $countryId, - 'lever_status' => $info['lever_status'], - 'leverage_num' =>$leverageNum - ]); - } catch (\Exception $exception) { - return $this->toData('100500', 'The system is busy.', [$exception->getMessage(), $exception->getTrace()]); - } - } - - /** - * @desc 设置用户国家 - * @param $userId - * @param $param - * @return array - */ - public function setCountry($userId, $param): array - { - try { - // 主键 - if (empty($userId) || $userId <= 0) { - return $this->toData('100403', 'Please log in first.', []); - } - // 邮件注册参数校验 - validate(UserValidate::class)->scene('setCountry')->check($param); - $countryId = $param['country_id']; - - // 国家是否存在 - $country = CountryModel::getById($countryId); - if (empty($country)) { - return $this->toData('100400', 'Unsupported country or region.', []); - } - - // 是否是黑名单国家 - if ($this->checkForbidNation($country['code'])) { - return $this->toData('100400', 'Unsupported country or region.', []); - } - - // 设置 - UserModel::updateFieldsByUserId(['country_id' => $country['id']], $userId); - return $this->toData('0', 'Modification successful.'); - } catch (ValidateException $validateException) { - $message = $validateException->getMessage(); - return $this->toData('100400', $message, []); - } catch (\Exception $exception) { - return $this->toData('100500', 'The system is busy.', [$exception->getMessage(), $exception->getTrace()]); - } - } - - /** - * @desc 更新用户头像 - * @param $userId - * @param $param - * @return array - */ - public function updateHeadImg($userId, $param): array - { - try { - // 主键 - if (empty($userId) || $userId <= 0) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 参数校验 - validate(UserValidate::class)->scene('updateHeadImg')->check($param); - $fileId = $param['file_id']; - - // 文件是否存在 - $file = FileModel::getById($fileId); - if (empty($file)) { - return $this->toData('100400', 'The file does not exist.', []); - } - - - // 设置 - UserModel::updateFieldsByUserId(['head_img_id' => $fileId], $userId); - return $this->toData('0', 'Modification successful.'); - } catch (ValidateException $validateException) { - $message = $validateException->getMessage(); - return $this->toData('100400', $message, []); - } catch (\Exception $exception) { - return $this->toData('100500', 'The system is busy.', []); - } - } - - /** - * @desc 设置用户 昵称 性别 名字信息 - * @param $userId - * @param $param - * @return array - */ - public function updateInfo($userId, $param): array - { - try { - // 主键 - if (empty($userId) || $userId <= 0) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 参数校验 - validate(UserValidate::class)->scene('updateInfo')->check($param); - - // 查找用户信息 - $user = UserModel::getFieldsByUserId('user_id,nick_name,first_name,first_name,gender', $userId); - if (empty($user)) { - return $this->toData('100403', 'Please log in first.', []); - } - - $nickName = $param['nick_name']; - $gender = $param['gender']; - $lastName = $param['last_name'] ?? $user['last_name']; - $first_name = $param['first_name'] ?? $user['first_name']; - - UserModel::updateFieldsByUserId([ - 'nick_name' => $nickName, - 'first_name' => $first_name, - 'last_name' => $lastName, - 'gender' => $gender, - ], $userId); - - // 返回 - return $this->toData('0', 'Modification successful.', []); - } catch (ValidateException $validateException) { - $message = $validateException->getError(); - return $this->toData('100400', $message); - } catch (\Exception $exception) { - return $this->toData('100500', 'The system is busy.', [$exception->getMessage()]); - } - - } - - /** - * @desc 登陆状态下发送短信 - * @param $userId - * @param $param - * @return array - * @throws \Psr\SimpleCache\InvalidArgumentException - */ - public function sendEmail($userId, $param) - { - try { - $ip = $this->getClientRealIp(); - - // 主键 - if (empty($userId) || $userId <= 0) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 参数校验 - validate(UserValidate::class)->scene('sendEmail')->check($param); - - // 如果是非交易业务 需要判断验证码获取次数 - $key = 'USER:SEND_CODE_NUM:' . $ip; - if ($param['business'] == '1') { - if ($this->checkGetNoTradeCodeNum($key)) { - return $this->toData('100300', 'No worries. Please feel free to reach out again tomorrow.', []); - } - } - - // 提取参数 - $emailType = $param['email_type']; // 1 给已经绑定的邮箱发 2 给新邮箱发 - $email = $param['email'] ?? ''; - if ($emailType == 1) { - $email = UserModel::getEmailById($userId); - if (empty($email)) { - return $this->toData('100400', '邮箱未绑定', []); - } - } - - // 获取邮件内容 - $content = $this->getEmailContent(); - $content['email'] = $email; - $code = $content['code']; - Queue::push('app\home\job\SendEmail', $content, 'sendEmail'); - - // 设置缓存 - $sendEmailCacheKey = 'USER:sendEmailLoginTrade:' . $email; - if ($param['business'] == '1') { - $sendEmailCacheKey = 'USER:sendEmailLoginNoTrade:' . $email; - // 累加ip获取的次数 - $this->updateHadGetCodeNumCache($key); - } - - $this->insertCodeToCache($sendEmailCacheKey, $code, 300); - - // 返回结果 - return $this->toData('0', 'Modification successful.'); - } catch (ValidateException $validateException) { - // 参数校验失败 异常类 - $message = $validateException->getError(); - return $this->toData('100400', $message); - } catch (\Exception $exception) { - return $this->toData('100500', 'The system is busy.', [$exception->getMessage()]); - } - } - - /** - * @desc 登陆状态下发送短信 - * @param $userId - * @param $param - * @return array - * @throws \Psr\SimpleCache\InvalidArgumentException - */ - public function sendSms($userId, $param): array - { - try { - $ip = $this->getClientRealIp(); - - // 主键 - if (empty($userId) || $userId <= 0) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 参数校验 - validate(UserValidate::class)->scene('sendSms')->check($param); - - // 如果是非交易业务 需要判断验证码获取次数 - $key = 'USER:SEND_CODE_NUM:' . $ip; - if ($param['business'] == '1') { - if ($this->checkGetNoTradeCodeNum($key)) { - return $this->toData('100300', 'No worries. Please feel free to reach out again tomorrow.', []); - } - } - - // 提取参数 - $phoneType = $param['phone_type']; // 1 给已经绑定的手机发 2 给新手机发 - $phone = $param['phone'] ?? ''; - $nation = $param['nation'] ?? ''; - if ($phoneType == 1) { - $user = UserModel::getFieldsByUserId('country_code,phone_number', $userId); - if (empty($user)) { - return $this->toData('100400', 'The phone number is not linked/bound.', []); - } - $phone = $user['phone_number']; - $nation = $user['country_code']; - } else { - // 如果给新手机发 判断国家码是否存在 - $nationCheck = CountryModel::checkCodeExists($nation); - if (!$nationCheck) { - return $this->toData('100400', 'Unsupported country or region.', []); - } - } - - $mobile = $nation . $phone; - - // 获取邮件内容 - $content = $this->getSmsContent(1); - $content['mobile'] = $mobile; - $code = $content['code']; - Queue::push('app\home\job\SendSms', $content, 'sendSms'); - - // 设置缓存 - $sendCodeKey = 'USER:sendSmsLoginTrade:' . $mobile; - - if ($param['business'] == '1') { - $sendCodeKey = 'USER:sendSmsLoginNoTrade:' . $mobile; - // 累加已经获取的次数 - $this->updateHadGetCodeNumCache($key); - } - $this->insertCodeToCache($sendCodeKey, $code, 300); - - - // 返回结果 - return $this->toData('0', 'Modification successful.'); - } catch (ValidateException $validateException) { - // 参数校验失败 异常类 - $message = $validateException->getError(); - return $this->toData('100400', $message); - } catch (\Exception $exception) { - return $this->toData('100500', 'The system is busy.', [$exception->getMessage()]); - } - } - - public function setPayPasswordByEmail($userId, $param) - { - try { - // 主键 - if (empty($userId) || $userId <= 0) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 参数校验 email_code pay_password - validate(UserValidate::class)->scene('setPayPasswordByEmail')->check($param); - - // 获取用户 - $user = UserModel::getFieldsByUserId('email,user_id,trade_password', $userId); - if (empty($user)) { - return $this->toData('100403', 'Please log in first.', []); - } - -// // 校验验证码 -// $key = 'USER:sendEmailLoginNoTrade:'.$user['email']; -// $emailCache = Cache::store('redis')->get($key); -// if(empty($param['email_code']) || $emailCache != $param['email_code']){ -// return $this->toData('100400', 'The verification code is incorrect.', []); -// } - - // 如果已经存在交易密码 则不能设置 - if (!empty($user['trade_password'])) { - return $this->toData('100400', 'The payment password has already been set.', []); - } - - // 加密密码 - $payPassword = $param['pay_password']; - $salt = env('ENCRYPT.SALT'); - $payPassword = (new UnqId())->encryptPassword($payPassword, $salt); - - // 设置密码 - UserModel::setPayPassword($payPassword, $salt, $userId); - - return $this->toData('0', 'Modification successful.', []); - } catch (ValidateException $validateException) { - // 参数校验失败 异常类 - $message = $validateException->getError(); - return $this->toData('100400', $message); - } catch (\Exception $exception) { - return $this->toData('100500', 'The system is busy.', []); - } - } - - /** - * @desc 通过短信设置取款密码 - * @param $userId - * @param $param - * @return array - * @throws \Psr\SimpleCache\InvalidArgumentException - */ - public function setPayPasswordBySms($userId, $param) - { - try { - // 主键 - if (empty($userId) || $userId <= 0) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 参数校验 nation phone pay_password - validate(UserValidate::class)->scene('setPayPasswordBySms')->check($param); - - // 获取用户信息 - $user = UserModel::getFieldsByUserId('country_code,phone_number,user_id,trade_password', $userId); - if (empty($user)) { - return $this->toData('100403', 'Please log in first.', []); - } - - if (!empty($user['trade_password'])) { - return $this->toData('100400', 'The payment password has already been set.', []); - } - -// // 校验验证码 -// $mobile = $user['country_code'].$user['phone_number']; -// $key = 'USER:sendSmsLoginNoTrade:'.$mobile; -// if(Cache::store('redis')->get($key) != $param['sms_code']){ -// return $this->toData('100400', 'The verification code is incorrect.', []); -// } - - // 校验验证码 - $payPassword = $param['pay_password']; - $salt = env('ENCRYPT.SALT'); - $payPassword = (new UnqId())->encryptPassword($payPassword, $salt); - - - // 设置密码 - UserModel::setPayPassword($payPassword, $salt, $userId); - - return $this->toData('0', 'Modification successful.', []); - } catch (ValidateException $validateException) { - // 参数校验失败 异常类 - $message = $validateException->getError(); - return $this->toData('100400', $message); - } catch (\Exception $exception) { - return $this->toData('100500', 'The system is busy.', [$exception->getMessage()]); - } - - } - - /** - * @desc 通过手机号修改交易密码 - * @param $userId - * @param $param - * @return array - * @throws \Psr\SimpleCache\InvalidArgumentException - */ - public function updatePayPasswordBySms($userId, $param) - { - try { - // user_id - if (empty($userId) || $userId <= 0) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 参数校验 email_code email - validate(UserValidate::class)->scene('updatePayPasswordBySms')->check($param); - - // 获取用户信息 - $user = UserModel::getFieldsByUserId('user_id,trade_password,salt,phone_number,country_code', $userId); - if (empty($user)) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 提取参数 -// $nation = $user['country_code']; -// $phone = $user['phone_number']; -// $smsCode = $param['sms_code']; - $payPassword = $param['pay_password']; - $payPasswordNew = $param['pay_password_new']; - - // 校验验证码 -// $mobile = $nation.$phone; -// $cacheSmsKey = 'USER:sendSmsLoginNoTrade:'.$mobile; -// $cacheSmsCode = Cache::store('redis')->get($cacheSmsKey); -// if(empty($smsCode) || $smsCode != $cacheSmsCode){ -// return $this->toData('100400', 'The verification code is incorrect.', []); -// } - - // 校验旧密码 - $checkPasswordBool = (new UnqId())->checkPassword($payPassword, $user['trade_password'], $user['salt']); - if (!$checkPasswordBool) { - return $this->toData('100400', 'Incorrect password.'); - } - - // 设置密码 - $newPassword = (new UnqId())->encryptPassword($payPasswordNew, $user['salt']); - UserModel::updateFieldsByUserId(['trade_password' => $newPassword], $userId); - - // 返回结果 - return $this->toData('0', 'Modification successful.', []); - - } catch (ValidateException $validateException) { - // 参数校验失败 异常类 - $message = $validateException->getError(); - return $this->toData('100400', $message); - } catch (\Exception $exception) { - return $this->toData('100500', 'The system is busy.', [$exception->getMessage()]); - } - - } - - /** - * @desc 根据邮箱修改交易密码 - * @param $userId - * @param $param - * @return array - * @throws \Psr\SimpleCache\InvalidArgumentException - */ - public function updatePayPasswordByEmail($userId, $param) - { - // 通过 邮箱 收款密码 重新设置收款密码 - try { - // user_id - if (empty($userId) || $userId <= 0) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 参数校验 email_code email - validate(UserValidate::class)->scene('updatePayPasswordByEmail')->check($param); - - // 获取用户信息 - $user = UserModel::getFieldsByUserId('user_id,trade_password,salt,email', $userId); - if (empty($user)) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 提取参数 -// $email = $user['email']; -// $emailCode = $param['email_code']; - $payPassword = $param['pay_password']; - $payPasswordNew = $param['pay_password_new']; - - // 校验验证码 -// $cacheEmailKey = 'USER:sendEmailLoginNoTrade:'.$email; -// $cacheEmailCode = Cache::store('redis')->get($cacheEmailKey); -// if(empty($emailCode) || $emailCode != $cacheEmailCode){ -// return $this->toData('100400', 'The verification code is incorrect.', []); -// } - - // 校验旧密码 - $checkPasswordBool = (new UnqId())->checkPassword($payPassword, $user['trade_password'], $user['salt']); - if (!$checkPasswordBool) { - return $this->toData('100400', 'Incorrect password.', []); - } - - // 设置密码 - $newPassword = (new UnqId())->encryptPassword($payPasswordNew, $user['salt']); - UserModel::updateFieldsByUserId(['trade_password' => $newPassword], $userId); - - // 返回结果 - return $this->toData('0', 'Modification successful.', []); - - } catch (ValidateException $validateException) { - // 参数校验失败 异常类 - $message = $validateException->getError(); - return $this->toData('100400', $message); - } catch (\Exception $exception) { - return $this->toData('100500', 'The system is busy.', [$exception->getMessage()]); - } - - } - - /** - * @desc 根据短信重新设置交易密码 - * @param $userId - * @param $param - * @return array - * @throws \Psr\SimpleCache\InvalidArgumentException - */ - public function resetPayPasswordBySms($userId, $param) - { - try { - // user_id - if (empty($userId) || $userId <= 0) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 参数校验 email_code email - validate(UserValidate::class)->scene('resetPayPasswordBySms')->check($param); - - // 获取用户信息 - $user = UserModel::getFieldsByUserId('user_id,salt,phone_number,country_code', $userId); - if (empty($user)) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 提取参数 -// $nation = $user['country_code']; -// $phone = $user['phone_number']; -// $smsCode = $param['sms_code']; - $payPasswordNew = $param['pay_password_new']; - - // 校验验证码 -// $mobile = $nation.$phone; -// $cacheSmsKey = 'USER:sendSmsLoginNoTrade:'.$mobile; -// $cacheSmsCode = Cache::store('redis')->get($cacheSmsKey); -// if(empty($smsCode) || $smsCode != $cacheSmsCode){ -// return $this->toData('100400', 'The verification code is incorrect.', []); -// } - - // 设置密码 - $newPassword = (new UnqId())->encryptPassword($payPasswordNew, $user['salt']); - UserModel::updateFieldsByUserId(['trade_password' => $newPassword], $userId); - - // 返回结果 - return $this->toData('0', 'Modification successful.', []); - - } catch (ValidateException $validateException) { - // 参数校验失败 异常类 - $message = $validateException->getError(); - return $this->toData('100400', $message); - } catch (\Exception $exception) { - return $this->toData('100500', 'The system is busy.', [$exception->getMessage()]); - } - - } - - /** - * @desc 通过邮箱重新设置交易密码 - * @param $userId - * @param $param - * @return array - * @throws \Psr\SimpleCache\InvalidArgumentException - */ - public function resetPayPasswordByEmail($userId, $param) - { - // 通过邮箱验证码 新密码 设置交易密码 - try { - // user_id - if (empty($userId) || $userId <= 0) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 参数校验 email_code email - validate(UserValidate::class)->scene('resetPayPasswordByEmail')->check($param); - - // 获取用户信息 - $user = UserModel::getFieldsByUserId('user_id,salt,email', $userId); - if (empty($user)) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 提取参数 -// $email = $user['email']; -// $emailCode = $param['email_code']; - $payPasswordNew = $param['pay_password_new']; - - // 校验验证码 -// $cacheEmailKey = 'USER:sendEmailLoginNoTrade:'.$email; -// $cacheEmailCode = Cache::store('redis')->get($cacheEmailKey); -// if(empty($emailCode) || $emailCode != $cacheEmailCode){ -// return $this->toData('100400', 'The verification code is incorrect.', []); -// } - - // 设置密码 - $newPassword = (new UnqId())->encryptPassword($payPasswordNew, $user['salt']); - UserModel::updateFieldsByUserId(['trade_password' => $newPassword], $userId); - - // 返回结果 - return $this->toData('0', 'Modification successful.', []); - - } catch (ValidateException $validateException) { - // 参数校验失败 异常类 - $message = $validateException->getError(); - return $this->toData('100400', $message); - } catch (\Exception $exception) { - return $this->toData('100500', 'The system is busy.', [$exception->getMessage()]); - } - } - - public function updatePasswordBySms($userId, $param) - { - try { - if (empty($userId) || $userId <= 0) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 参数校验 email_code email - validate(UserValidate::class)->scene('updatePasswordBySms')->check($param); - - // 获取用户信息 - $user = UserModel::getFieldsByUserId('user_id,login_password,salt,phone_number,country_code', $userId); - if (empty($user)) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 提取参数 -// $nation = $user['country_code']; -// $phone = $user['phone_number']; -// $smsCode = $param['sms_code']; - $password = $param['password']; - $passwordNew = $param['password_new']; - - // 校验验证码 -// $mobile = $nation.$phone; -// $cacheSmsKey = 'USER:sendSmsLoginNoTrade:'.$mobile; -// $cacheSmsCode = Cache::store('redis')->get($cacheSmsKey); -// if(empty($smsCode) || $smsCode != $cacheSmsCode){ -// return $this->toData('100400', 'The verification code is incorrect.', []); -// } - - // 校验旧密码 - $checkPasswordBool = (new UnqId())->checkPassword($password, $user['login_password'], $user['salt']); - if (!$checkPasswordBool) { - return $this->toData('100400', 'Incorrect password.', []); - } - - // 设置密码 - $newPassword = (new UnqId())->encryptPassword($passwordNew, $user['salt']); - UserModel::updateFieldsByUserId(['login_password' => $newPassword], $userId); - - // 返回结果 - return $this->toData('0', 'Modification successful.', []); - - } catch (ValidateException $validateException) { - // 参数校验失败 异常类 - $message = $validateException->getError(); - return $this->toData('100400', $message); - } catch (\Exception $exception) { - return $this->toData('100500', 'The system is busy.', [$exception->getMessage()]); - } - - } - - /** - * @desc 邮箱修改登陆密码 - * @param $userId - * @param $param - * @return array - * @throws \Psr\SimpleCache\InvalidArgumentException - */ - public function updatePasswordByEmail($userId, $param) - { - try { - // user_id - if (empty($userId) || $userId <= 0) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 参数校验 - validate(UserValidate::class)->scene('updatePasswordByEmail')->check($param); - - // 获取用户信息 - $user = UserModel::getFieldsByUserId('user_id,login_password,salt,email', $userId); - if (empty($user)) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 提取参数 -// $email = $user['email']; -// $emailCode = $param['email_code']; - $password = $param['password']; - $passwordNew = $param['password_new']; - - // 校验验证码 -// $cacheEmailKey = 'USER:sendEmailLoginNoTrade:'.$email; -// $cacheEmailCode = Cache::store('redis')->get($cacheEmailKey); -// if(empty($emailCode) || $emailCode != $cacheEmailCode){ -// return $this->toData('100400', 'The verification code is incorrect.', []); -// } - - // 校验旧密码 - $checkPasswordBool = (new UnqId())->checkPassword($password, $user['login_password'], $user['salt']); - if (!$checkPasswordBool) { - return $this->toData('100400', 'Incorrect password.', []); - } - - // 设置密码 - $newPassword = (new UnqId())->encryptPassword($passwordNew, $user['salt']); - UserModel::updateFieldsByUserId(['login_password' => $newPassword], $userId); - - // 返回结果 - return $this->toData('0', 'Modification successful.', []); - - } catch (ValidateException $validateException) { - // 参数校验失败 异常类 - $message = $validateException->getError(); - return $this->toData('100400', $message); - } catch (\Exception $exception) { - return $this->toData('100500', 'The system is busy.', [$exception->getMessage()]); - } - - } - - /** - * @desc 短信重新设置登陆密码 - * @param $userId - * @param $param - * @return array - * @throws \Psr\SimpleCache\InvalidArgumentException - */ - public function resetPasswordBySms($userId, $param) - { - try { - if (empty($userId) || $userId <= 0) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 参数校验 email_code email - validate(UserValidate::class)->scene('resetPasswordBySms')->check($param); - - // 获取用户信息 - $user = UserModel::getFieldsByUserId('user_id,salt,phone_number,country_code', $userId); - if (empty($user)) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 提取参数 -// $nation = $user['country_code']; -// $phone = $user['phone_number']; -// $smsCode = $param['sms_code']; - $passwordNew = $param['password_new']; - - // 校验验证码 -// $mobile = $nation.$phone; -// $cacheSmsKey = 'USER:sendSmsLoginNoTrade:'.$mobile; -// $cacheSmsCode = Cache::store('redis')->get($cacheSmsKey); -// if(empty($smsCode) || $smsCode != $cacheSmsCode){ -// return $this->toData('100400', 'The verification code is incorrect.', []); -// } - - // 设置密码 - $newPassword = (new UnqId())->encryptPassword($passwordNew, $user['salt']); - UserModel::updateFieldsByUserId(['login_password' => $newPassword], $userId); - - // 返回结果 - return $this->toData('0', 'Modification successful.', []); - - } catch (ValidateException $validateException) { - // 参数校验失败 异常类 - $message = $validateException->getError(); - return $this->toData('100400', $message); - } catch (\Exception $exception) { - return $this->toData('100500', 'The system is busy.', [$exception->getMessage()]); - } - - } - - /** - * @desc 邮箱重新设置登陆密码 - * @param $userId - * @param $param - * @return array - * @throws \Psr\SimpleCache\InvalidArgumentException - */ - public function resetPasswordByEmail($userId, $param) - { - try { - // user_id - if (empty($userId) || $userId <= 0) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 参数校验 email_code email - validate(UserValidate::class)->scene('resetPasswordByEmail')->check($param); - - // 获取用户信息 - $user = UserModel::getFieldsByUserId('user_id,salt,email', $userId); - if (empty($user)) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 提取参数 -// $email = $user['email']; -// $emailCode = $param['email_code']; - $passwordNew = $param['password_new']; - - // 校验验证码 -// $cacheEmailKey = 'USER:sendEmailLoginNoTrade:'.$email; -// $cacheEmailCode = Cache::store('redis')->get($cacheEmailKey); -// if(empty($emailCode) || $emailCode != $cacheEmailCode){ -// return $this->toData('100400', 'The verification code is incorrect.', []); -// } - - // 设置密码 - $newPassword = (new UnqId())->encryptPassword($passwordNew, $user['salt']); - UserModel::updateFieldsByUserId(['login_password' => $newPassword], $userId); - - // 返回结果 - return $this->toData('0', 'Modification successful.', []); - - } catch (ValidateException $validateException) { - // 参数校验失败 异常类 - $message = $validateException->getError(); - return $this->toData('100400', $message); - } catch (\Exception $exception) { - return $this->toData('100500', 'The system is busy.', [$exception->getMessage()]); - } - } - - public function bindEmail($userId, $param) - { - try { - // user_id - if (empty($userId) || $userId <= 0) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 参数校验 email_code email - validate(UserValidate::class)->scene('bindEmail')->check($param); - - // 判断验证码 -// $emailCode = $param['email_code']; - $email = $param['email']; -// $cacheCodeKey = 'USER:sendEmailLoginNoTrade:'.$email; -// $cacheSmsCode = Cache::store('redis')->get($cacheCodeKey); -// if(empty($emailCode) || $emailCode != $cacheSmsCode){ -// return $this->toData('100400', 'The verification code is incorrect.', []); -// } - - // 获取用户信息 - $user = UserModel::getFieldsByUserId('email,user_id', $userId); - if (empty($user)) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 判读是否已经绑定 - if (!empty($user['email'])) { - return $this->toData('100400', 'You have already bound your email', []); - } - - //判断手机号是否已经被别人绑定 - $emailExits = UserModel::checkEmailExists($email); - if ($emailExits) { - return $this->toData('100400', 'The email has been bound', []); - } - - // 执行入库操作 - UserModel::updateFieldsByUserId(['email' => $email], $userId); - - // 返回结果 - return $this->toData('0', 'Binding successful', []); - - } catch (ValidateException $validateException) { - // 参数校验失败 异常类 - $message = $validateException->getError(); - return $this->toData('100400', $message); - } catch (\Exception $exception) { - return $this->toData('100500', 'The system is busy.', [$exception->getMessage()]); - } - } - - /** - * @desc 修改已经绑定的手机号 - * @param $userId - * @param $param - * @return array - * @throws \Psr\SimpleCache\InvalidArgumentException - */ - public function updateEmail($userId, $param): array - { - try { - // user_id - if (empty($userId) || $userId <= 0) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 参数校验 nation phone sms_code - validate(UserValidate::class)->scene('updateEmail')->check($param); - - // 判断验证码 -// $emailCode = $param['email_code']; - $email = $param['email']; -// $cacheCodeKey = 'USER:sendEmailLoginNoTrade:'.$email; -// $cacheSmsCode = Cache::store('redis')->get($cacheCodeKey); -// if(empty($emailCode) || $emailCode != $cacheSmsCode){ -// return $this->toData('100400', 'The verification code is incorrect.', []); -// } - - // 获取用户信息 - $user = UserModel::getFieldsByUserId('login_password,email,user_id,salt', $userId); - if (empty($user)) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 判读是否已经绑定 需要已经绑定 - if (empty($user['email'])) { - return $this->toData('100400', 'Email is not linked/bound.', []); - } - - //校验登陆密码 - $passwordCheck = (new UnqId())->checkPassword($param['password'], $user['login_password'], $user['salt']); - if (!$passwordCheck) { - return $this->toData('100400', 'Incorrect password.', []); - } - - //判断手机号是否已经被别人绑定 - $emailExits = UserModel::checkEmailExists($email); - if ($emailExits) { - return $this->toData('100400', 'The email has already been linked/bound.', []); - } - - // 执行入库操作 - UserModel::updateFieldsByUserId(['email' => $email], $userId); - - // 返回结果 - return $this->toData('0', 'Modification successful.', []); - } catch (ValidateException $validateException) { - // 参数校验失败 异常类 - $message = $validateException->getError(); - return $this->toData('100400', $message); - } catch (\Exception $exception) { - return $this->toData('100500', 'The system is busy.', [$exception->getMessage()]); - } - } - - - public function bindPhone($userId, $param) - { - try { - // user_id - if (empty($userId) || $userId <= 0) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 参数校验 nation phone sms_code - validate(UserValidate::class)->scene('bindPhone')->check($param); - - // 判断验证码 -// $smsCode = $param['sms_code']; -// $mobile = $param['nation'].$param['phone']; -// $cacheSmsKey = 'USER:sendSmsLoginNoTrade:'.$mobile; -// $cacheSmsCode = Cache::store('redis')->get($cacheSmsKey); -// if(empty($smsCode) || $smsCode != $cacheSmsCode){ -// return $this->toData('100400', 'The verification code is incorrect.', []); -// } - - // 获取用户信息 - $user = UserModel::getFieldsByUserId('user_id,country_code,phone_number', $userId); - if (empty($user)) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 判读是否已经绑定 - if (!empty($user['phone_number'])) { - return $this->toData('100400', 'The phone number has already been linked/bound.', []); - } - - //判断手机号是否已经被别人绑定 - $phoneExits = UserModel::checkPhoneExists($param['phone']); - if ($phoneExits) { - return $this->toData('100400', 'The phone number has already been linked/bound.', []); - } - - // 判断国家码是否存在 - $codeExists = CountryModel::checkCodeExists($param['nation']); - if (!$codeExists) { - return $this->toData('100400', 'Unsupported country or region.', []); - } - - // 执行入库操作 - UserModel::updateFieldsByUserId(['phone_number' => $param['phone'], 'country_code' => $param['nation']], $userId); - - // 返回结果 - return $this->toData('0', 'Binding successful.', []); - - } catch (ValidateException $validateException) { - // 参数校验失败 异常类 - $message = $validateException->getError(); - return $this->toData('100400', $message); - } catch (\Exception $exception) { - return $this->toData('100500', 'The system is busy.', [$exception->getMessage()]); - } - } - - /** - * @desc 修改已经绑定的手机号 - * @param $userId - * @param $param - * @return array - * @throws \Psr\SimpleCache\InvalidArgumentException - */ - public function updatePhone($userId, $param): array - { - try { - // user_id - if (empty($userId) || $userId <= 0) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 参数校验 nation phone sms_code - validate(UserValidate::class)->scene('updatePhone')->check($param); - - // 判断验证码 -// $smsCode = $param['sms_code']; -// $mobile = $param['nation'].$param['phone']; -// $cacheSmsKey = 'USER:sendSmsLoginNoTrade:'.$mobile; -// $cacheSmsCode = Cache::store('redis')->get($cacheSmsKey); -// if(empty($smsCode) || $smsCode != $cacheSmsCode){ -// return $this->toData('100400', 'The verification code is incorrect.', []); -// } - - // 判断国家码是否存在 - $codeExists = CountryModel::checkCodeExists($param['nation']); - if (!$codeExists) { - return $this->toData('100400', 'Unsupported country or region', []); - } - - //判断手机号是否已经被别人绑定 - $phoneExits = UserModel::checkPhoneExists($param['phone']); - if ($phoneExits) { - return $this->toData('100400', 'The phone number has already been linked/bound.', []); - } - - // 获取用户信息 - $user = UserModel::getFieldsByUserId('salt,login_password,user_id,country_code,phone_number', $userId); - if (empty($user)) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 判读是否已经绑定 需要已经绑定手机 - if (empty($user['phone_number'])) { - return $this->toData('100400', 'The phone number is not linked/bound.', []); - } - - //校验登陆密码 - $passwordCheck = (new UnqId())->checkPassword($param['password'], $user['login_password'], $user['salt']); - if (!$passwordCheck) { - return $this->toData('100400', 'Incorrect password.', []); - } - - // 执行入库操作 - UserModel::updateFieldsByUserId(['phone_number' => $param['phone'], 'country_code' => $param['nation']], $userId); - - // 返回结果 - return $this->toData('0', 'Modification successful.', []); - } catch (ValidateException $validateException) { - // 参数校验失败 异常类 - $message = $validateException->getError(); - return $this->toData('100400', $message); - } catch (\Exception $exception) { - return $this->toData('100500', 'The system is busy.', [$exception->getMessage()]); - } - } - - /** - * @desc 退出登陆 - * @param $userId - * @return array - */ - public function logout($userId) - { - try { - // 删除缓存 - $this->delUserTokenCache($userId); - return $this->toData('0', 'Modification successful.'); - } catch (\Exception $exception) { - return $this->toData('100500', 'The system is busy.', [$exception->getMessage()]); - } - - } - - /** - * @desc 获取用户登陆信息 - * @param $userId - * @return array - */ - public function loginLog($userId): array - { - try { - if (empty($userId) || $userId <= 0) { - return $this->toData('100403', 'Please log in first.', []); - } - - $data = UserLoginLog::getLog($userId); - if (empty($data)) { - return $this->toData('0', 'Modification successful.', []); - } - - $res = []; - foreach ($data as $item) { - $countryCn = ''; - $countryEn = ''; - $cityCn = ''; - $cityEn = ''; - if (!empty($item['country'])) { - $countryArr = json_decode($item['country'], true); - $countryCn = $countryArr['cn']; - $countryEn = $countryArr['en']; - } - - if (!empty($item['city'])) { - $cityArr = json_decode($item['city'], true); - $cityCn = $cityArr['cn']; - $cityEn = $cityArr['en']; - } - - $res[] = [ - 'device' => $item['device'], - 'ip' => $item['ip'], - 'countryCn' => $countryCn, - 'countryEn' => $countryEn, - 'cityCn' => $cityCn, - 'cityEn' => $cityEn, - 'loginDate' => $item['login_date'], - ]; - } - - return $this->toData('0', 'Modification successful.', $res); - } catch (\Exception $exception) { - return $this->toData('100500', 'The system is busy.', []); - } - } - - /** - * 用户申请使用杠杆 - * @param $userId - * @return array - */ - public function leverApply($userId) - { - try { - if (empty($userId) || $userId <= 0) { - return $this->toData('100403', 'Please log in first.', []); - } - - // 获取用户信息 - $user = UserModel::getFieldsByUserId('lever_status,user_id', $userId); - if (empty($user)) { - return $this->toData('100403', 'Please log in first.', []); - } - - if (in_array($user['lever_status'], [UserModel::LEVER_STATUS_NO, UserModel::LEVER_STATUS_FAIL])) { - UserModel::update(['lever_status' => UserModel::LEVER_STATUS_APPLY, 'update_time' => date('Y-m-d H:i:s')], ['user_id' => $userId]); - return $this->toData('0', 'success.', []); - } - - return $this->toData('0', 'Already submitted.', []); - - } catch (\Exception $exception) { - return $this->toData('100500', 'The system is busy.', []); - } - } -}