|
|
@ -66,7 +66,6 @@ class LoginService extends BaseHomeService |
|
|
|
|
|
|
|
// 返回结果 |
|
|
|
return $this->toData('0', lang('email_send_successfully')); |
|
|
|
|
|
|
|
} catch (ValidateException $validateException) { |
|
|
|
// 参数校验失败 异常类 |
|
|
|
$message = $validateException->getError(); |
|
|
@ -75,7 +74,6 @@ class LoginService extends BaseHomeService |
|
|
|
// 异常情况 |
|
|
|
return $this->toData('500', lang('system_busy'), [$exception->getMessage()]); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -166,10 +164,10 @@ class LoginService extends BaseHomeService |
|
|
|
// 查询父级用户 |
|
|
|
$parentIds = ''; |
|
|
|
$originUserId = 0; |
|
|
|
if($parentUserId > 0){ |
|
|
|
if ($parentUserId > 0) { |
|
|
|
$parentUser = UserModel::where('user_id', $parentUserId)->findOrEmpty(); |
|
|
|
if($parentUser){ |
|
|
|
$parentIds = $parentUser['parent_ids']? $parentUser['parent_ids'].','.$parentUserId : $parentUserId; |
|
|
|
if ($parentUser) { |
|
|
|
$parentIds = $parentUser['parent_ids'] ? $parentUser['parent_ids'] . ',' . $parentUserId : $parentUserId; |
|
|
|
// 如果祖先id = 0 说明这个父级就是祖先id |
|
|
|
$originUserId = $parentUser['origin_user_id'] == 0 ? $parentUserId : $parentUser['origin_user_id']; |
|
|
|
} |
|
|
@ -217,13 +215,13 @@ class LoginService extends BaseHomeService |
|
|
|
'chat_name' => $chatRes['data']['username'] |
|
|
|
]); |
|
|
|
// 如果有代理,绑定到代理下一个客服(轮询客服绑定) |
|
|
|
if ($agentId > 0 ) { |
|
|
|
if ($agentId > 0) { |
|
|
|
$customerIds = AdminModel::getCustomerIdsByAgentId($agentId); // 获取代理下的所有客服ID |
|
|
|
Log::info("邮箱注册 - 客服列表:".json_encode($customerIds)); |
|
|
|
Log::info("邮箱注册 - 客服列表:" . json_encode($customerIds)); |
|
|
|
if (empty($customerIds)) { |
|
|
|
return $this->toData('500', lang('account_registration_failed')); |
|
|
|
} |
|
|
|
$counterKey = 'counter_of_bind_customer:'.$agentId; |
|
|
|
$counterKey = 'counter_of_bind_customer:' . $agentId; |
|
|
|
$counterIndex = Cache::store('redis')->get($counterKey); //客服绑定计数器索引 |
|
|
|
if (empty($counterIndex)) { |
|
|
|
Cache::store('redis')->set($counterKey, 1); |
|
|
@ -233,13 +231,13 @@ class LoginService extends BaseHomeService |
|
|
|
$tagIndex = $counterIndex % count($customerIds); |
|
|
|
$tagCustomerId = $customerIds[$tagIndex]; |
|
|
|
} |
|
|
|
Log::info("邮箱注册 - 当前绑定客服ID:".$tagCustomerId); |
|
|
|
Log::info("邮箱注册 - 当前绑定客服ID:" . $tagCustomerId); |
|
|
|
if ($tagCustomerId > 0) { |
|
|
|
$regUser->customer_id = $tagCustomerId; |
|
|
|
$regUser->save(); |
|
|
|
} |
|
|
|
// 将注册账号的chat_id与绑定客服的chat_id加为好友 |
|
|
|
$customerChatInfo = UserChatLinkModel::where(['user_id'=>$tagCustomerId, 'user_type'=>UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_ADMIN])->find(); //查询客服的聊天账号uuid |
|
|
|
$customerChatInfo = UserChatLinkModel::where(['user_id' => $tagCustomerId, 'user_type' => UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_ADMIN])->find(); //查询客服的聊天账号uuid |
|
|
|
if (empty($customerChatInfo)) { |
|
|
|
return $this->toData('500', lang('account_registration_failed')); |
|
|
|
} |
|
|
@ -249,15 +247,15 @@ class LoginService extends BaseHomeService |
|
|
|
]; |
|
|
|
$chatFriendsUrl = env('CHAT_SERVER.BASE_URL') . '/api/eachOtherFriends'; |
|
|
|
$chatFriendsRes = (new \app\utility\RequestChatServer())->ReqChatServer($chatFriendsUrl, $chatFriendsData); |
|
|
|
Log::info("邮箱注册 - 用户与客服加好友结果:".json_encode($chatFriendsRes)); |
|
|
|
Log::info("邮箱注册 - 用户与客服加好友结果:" . json_encode($chatFriendsRes)); |
|
|
|
// 将当前用户加入到代理创建的群聊中 【需要查出当前用户的代理创建的群聊信息】 |
|
|
|
$agentGroup = UserChatGroupModel::where(['user_id'=>$agentId,'remark'=>UserChatGroupModel::USER_CHAT_GROUP_REMARK_ADMIN_INIT])->find(); |
|
|
|
$agentGroup = UserChatGroupModel::where(['user_id' => $agentId, 'remark' => UserChatGroupModel::USER_CHAT_GROUP_REMARK_ADMIN_INIT])->find(); |
|
|
|
if (empty($agentGroup)) { |
|
|
|
return $this->toData('500', lang('account_registration_failed')); |
|
|
|
} |
|
|
|
$joinChatGroupUrl = env('CHAT_SERVER.BASE_URL') . '/api/group/join/'.$chatRes['data']['uuid'].'/'.$agentGroup->group_uuid; |
|
|
|
$joinChatGroupUrl = env('CHAT_SERVER.BASE_URL') . '/api/group/join/' . $chatRes['data']['uuid'] . '/' . $agentGroup->group_uuid; |
|
|
|
$joinChatGroupRes = (new \app\utility\RequestChatServer())->ReqChatServer($joinChatGroupUrl, []); |
|
|
|
Log::info("邮箱注册 - 用户与客服加好友结果:".json_encode($joinChatGroupRes)); |
|
|
|
Log::info("邮箱注册 - 用户与客服加好友结果:" . json_encode($joinChatGroupRes)); |
|
|
|
} |
|
|
|
}); |
|
|
|
// 删除缓存 |
|
|
@ -271,8 +269,8 @@ class LoginService extends BaseHomeService |
|
|
|
$message = $validateException->getError(); |
|
|
|
return $this->toData('500', $message); |
|
|
|
} catch (\Exception $exception) { |
|
|
|
trace('【注册错误】提交数据:'.json_encode($param), 'error'); |
|
|
|
trace('【注册错误】'.$exception->getMessage(), 'error'); |
|
|
|
trace('【注册错误】提交数据:' . json_encode($param), 'error'); |
|
|
|
trace('【注册错误】' . $exception->getMessage(), 'error'); |
|
|
|
return $this->toData('500', lang('system_busy'), [$exception->getMessage(), $exception->getTrace()]); |
|
|
|
} |
|
|
|
} |
|
|
@ -314,7 +312,8 @@ class LoginService extends BaseHomeService |
|
|
|
} |
|
|
|
|
|
|
|
// 用户登陆之后需要进行的操作 异步完成 |
|
|
|
Queue::push('app\home\job\LoginDone', ['userId' => $userId, |
|
|
|
Queue::push('app\home\job\LoginDone', [ |
|
|
|
'userId' => $userId, |
|
|
|
'fields' => [ |
|
|
|
'last_login_time' => date('Y-m-d H:i:s'), |
|
|
|
'ip' => $this->getClientRealIp(), |
|
|
@ -367,6 +366,8 @@ class LoginService extends BaseHomeService |
|
|
|
|
|
|
|
$param['nation'] = trim($param['nation']); |
|
|
|
$param['phone'] = trim($param['phone']); |
|
|
|
//去掉前面0 |
|
|
|
$param['phone'] = ltrim($param['phone'], '0'); |
|
|
|
// 去除国内手机号 |
|
|
|
if ($this->checkForbidNation($param['nation'])) { |
|
|
|
return $this->toData('500', lang('unsupported_country_or_region')); |
|
|
@ -379,7 +380,7 @@ class LoginService extends BaseHomeService |
|
|
|
} |
|
|
|
|
|
|
|
// 发送次数校验 - 号码 |
|
|
|
$phoneSendCodeKey = 'USER:PHONE_SEND_CODE_NUM:' . $param['nation'].':'.$param['phone']; |
|
|
|
$phoneSendCodeKey = 'USER:PHONE_SEND_CODE_NUM:' . $param['nation'] . ':' . $param['phone']; |
|
|
|
if ($this->checkGetNoTradeCodeNumPhone($phoneSendCodeKey)) { |
|
|
|
return $this->toData('100300', 'No worries. Please feel free to reach out again tomorrow.', []); |
|
|
|
} |
|
|
@ -414,8 +415,8 @@ class LoginService extends BaseHomeService |
|
|
|
$message = $validateException->getError(); |
|
|
|
return $this->toData('100400', $message); |
|
|
|
} catch (\Exception $exception) { |
|
|
|
trace('【注册错误】提交数据:'.json_encode($param), 'error'); |
|
|
|
trace('【注册错误】'.$exception->getMessage(), 'error'); |
|
|
|
trace('【注册错误】提交数据:' . json_encode($param), 'error'); |
|
|
|
trace('【注册错误】' . $exception->getMessage(), 'error'); |
|
|
|
return $this->toData('500', lang('system_busy'), [$exception->getMessage()]); |
|
|
|
} |
|
|
|
} |
|
|
@ -455,10 +456,10 @@ class LoginService extends BaseHomeService |
|
|
|
if (!$this->checkCode($smsKey, $param['sms_code'])) { |
|
|
|
return $this->toData('500', lang('incorrect_verification_code')); |
|
|
|
//注册验证码 |
|
|
|
// $reg_key = "USER:REG:CODE"; |
|
|
|
// if (!$this->checkCode($reg_key, $param['sms_code'])) { |
|
|
|
// return $this->toData('100300', 'The verification code is incorrect.', []); |
|
|
|
// } |
|
|
|
// $reg_key = "USER:REG:CODE"; |
|
|
|
// if (!$this->checkCode($reg_key, $param['sms_code'])) { |
|
|
|
// return $this->toData('100300', 'The verification code is incorrect.', []); |
|
|
|
// } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -503,10 +504,10 @@ class LoginService extends BaseHomeService |
|
|
|
// 生成用户数据 |
|
|
|
$parentIds = ''; |
|
|
|
$originUserId = 0; |
|
|
|
if($parentUserId > 0){ |
|
|
|
if ($parentUserId > 0) { |
|
|
|
$parentUser = UserModel::where('user_id', $parentUserId)->findOrEmpty(); |
|
|
|
if($parentUser){ |
|
|
|
$parentIds = $parentUser['parent_ids']? $parentUser['parent_ids'].','.$parentUserId : $parentUserId; |
|
|
|
if ($parentUser) { |
|
|
|
$parentIds = $parentUser['parent_ids'] ? $parentUser['parent_ids'] . ',' . $parentUserId : $parentUserId; |
|
|
|
// 如果祖先id = 0 说明这个父级就是祖先id |
|
|
|
$originUserId = $parentUser['origin_user_id'] == 0 ? $parentUserId : $parentUser['origin_user_id']; |
|
|
|
} |
|
|
@ -524,7 +525,7 @@ class LoginService extends BaseHomeService |
|
|
|
'salt' => $salt, |
|
|
|
'reg_ip' => $ip, |
|
|
|
'is_test_user' => UserModel::IS_TEST_USER_NO, |
|
|
|
'nick_name' => 'user_'.substr($param['phone'], -4), |
|
|
|
'nick_name' => 'user_' . substr($param['phone'], -4), |
|
|
|
'origin_user_id' => $originUserId, |
|
|
|
'parent_ids' => $parentIds, |
|
|
|
'ch_code' => $chCode, |
|
|
@ -546,8 +547,8 @@ class LoginService extends BaseHomeService |
|
|
|
'country' => $param['verify_country'] ?? 0, |
|
|
|
'birth_day' => $param['verify_birth_day'], |
|
|
|
'gender' => $param['verify_gender'], |
|
|
|
// 'addr' => $param['verify_addr'], |
|
|
|
// 'zip_code' => $param['verify_zip_code'], |
|
|
|
// 'addr' => $param['verify_addr'], |
|
|
|
// 'zip_code' => $param['verify_zip_code'], |
|
|
|
'email' => $param['verify_email'] ?? '', |
|
|
|
'create_time' => date('Y-m-d H:i:s'), |
|
|
|
'update_time' => date('Y-m-d H:i:s'), |
|
|
@ -555,7 +556,7 @@ class LoginService extends BaseHomeService |
|
|
|
} |
|
|
|
|
|
|
|
// 生成钱包地址 |
|
|
|
// (new UserService())->doRegInitUserInfo($userId, $parentUserId); |
|
|
|
// (new UserService())->doRegInitUserInfo($userId, $parentUserId); |
|
|
|
// 注册聊天账号 |
|
|
|
$chatData = [ |
|
|
|
'Username' => $userNo, |
|
|
@ -576,14 +577,14 @@ class LoginService extends BaseHomeService |
|
|
|
'chat_name' => $chatRes['data']['username'] |
|
|
|
]); |
|
|
|
// 如果有代理,绑定到代理下一个客服(轮询客服绑定) |
|
|
|
if ($agentId > 0 ) { |
|
|
|
if ($agentId > 0) { |
|
|
|
Log::info("手机号注册 - 开始获取客服列表..."); |
|
|
|
$customerIds = AdminModel::getCustomerIdsByAgentId($agentId); // 获取代理下的所有客服ID |
|
|
|
Log::info("手机号注册 - 获取客服列表结果==".json_encode($customerIds)); |
|
|
|
Log::info("手机号注册 - 获取客服列表结果==" . json_encode($customerIds)); |
|
|
|
if (empty($customerIds)) { |
|
|
|
return $this->toData('500', lang('account_registration_failed')); |
|
|
|
} |
|
|
|
$counterKey = 'counter_of_bind_customer:'.$agentId; |
|
|
|
$counterKey = 'counter_of_bind_customer:' . $agentId; |
|
|
|
$counterIndex = Cache::store('redis')->get($counterKey); //客服绑定计数器索引 |
|
|
|
if (empty($counterIndex)) { |
|
|
|
Cache::store('redis')->set($counterKey, 1); |
|
|
@ -593,13 +594,13 @@ class LoginService extends BaseHomeService |
|
|
|
$tagIndex = $counterIndex % count($customerIds); |
|
|
|
$tagCustomerId = $customerIds[$tagIndex]; |
|
|
|
} |
|
|
|
Log::info("手机号注册 - 或者最终绑定客服ID==".$tagCustomerId); |
|
|
|
Log::info("手机号注册 - 或者最终绑定客服ID==" . $tagCustomerId); |
|
|
|
if ($tagCustomerId > 0) { |
|
|
|
$regUser->customer_id = $tagCustomerId; |
|
|
|
$regUser->save(); |
|
|
|
} |
|
|
|
// 将注册账号的chat_id与绑定客服的chat_id加为好友 |
|
|
|
$customerChatInfo = UserChatLinkModel::where(['user_id'=>$tagCustomerId,'user_type'=>UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_ADMIN])->find(); //查询客服的聊天账号uuid |
|
|
|
$customerChatInfo = UserChatLinkModel::where(['user_id' => $tagCustomerId, 'user_type' => UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_ADMIN])->find(); //查询客服的聊天账号uuid |
|
|
|
if (empty($customerChatInfo)) { |
|
|
|
return $this->toData('100400', 'The customer uuid is error.', []); |
|
|
|
} |
|
|
@ -609,15 +610,15 @@ class LoginService extends BaseHomeService |
|
|
|
]; |
|
|
|
$chatFriendsUrl = env('CHAT_SERVER.BASE_URL') . '/api/eachOtherFriends'; |
|
|
|
$chatFriendsRes = (new \app\utility\RequestChatServer())->ReqChatServer($chatFriendsUrl, $chatFriendsData); |
|
|
|
Log::info("手机号注册 - chat服务加好友结果:".json_encode($chatFriendsRes)); |
|
|
|
Log::info("手机号注册 - chat服务加好友结果:" . json_encode($chatFriendsRes)); |
|
|
|
// 将当前用户加入到代理创建的群聊中 【需要查出当前用户的代理创建的群聊信息】 |
|
|
|
$agentGroup = UserChatGroupModel::where(['user_id'=>$agentId,'remark'=>UserChatGroupModel::USER_CHAT_GROUP_REMARK_ADMIN_INIT])->find(); |
|
|
|
$agentGroup = UserChatGroupModel::where(['user_id' => $agentId, 'remark' => UserChatGroupModel::USER_CHAT_GROUP_REMARK_ADMIN_INIT])->find(); |
|
|
|
if (empty($agentGroup)) { |
|
|
|
return $this->toData('500', lang('account_registration_failed')); |
|
|
|
} |
|
|
|
$joinChatGroupUrl = env('CHAT_SERVER.BASE_URL') . '/api/group/join/'.$chatRes['data']['uuid'].'/'.$agentGroup->group_uuid; |
|
|
|
$joinChatGroupUrl = env('CHAT_SERVER.BASE_URL') . '/api/group/join/' . $chatRes['data']['uuid'] . '/' . $agentGroup->group_uuid; |
|
|
|
$joinChatGroupRes = (new \app\utility\RequestChatServer())->ReqChatServer($joinChatGroupUrl, []); |
|
|
|
Log::info("手机号注册 - 用户与客服加好友结果:".json_encode($joinChatGroupRes)); |
|
|
|
Log::info("手机号注册 - 用户与客服加好友结果:" . json_encode($joinChatGroupRes)); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
@ -680,7 +681,8 @@ class LoginService extends BaseHomeService |
|
|
|
} |
|
|
|
|
|
|
|
// 用户登陆之后需要进行的操作 异步完成 |
|
|
|
Queue::push('app\home\job\LoginDone', ['userId' => $userId, |
|
|
|
Queue::push('app\home\job\LoginDone', [ |
|
|
|
'userId' => $userId, |
|
|
|
'fields' => [ |
|
|
|
'last_login_time' => date('Y-m-d H:i:s'), |
|
|
|
'ip' => $this->getClientRealIp(), |
|
|
@ -834,7 +836,8 @@ class LoginService extends BaseHomeService |
|
|
|
} |
|
|
|
|
|
|
|
// 用户登陆之后需要进行的操作 异步完成 |
|
|
|
Queue::push('app\home\job\LoginDone', ['userId' => $userId, |
|
|
|
Queue::push('app\home\job\LoginDone', [ |
|
|
|
'userId' => $userId, |
|
|
|
'fields' => [ |
|
|
|
'last_login_time' => date('Y-m-d H:i:s'), |
|
|
|
'ip' => $this->getClientRealIp(), |
|
|
@ -876,7 +879,7 @@ class LoginService extends BaseHomeService |
|
|
|
return $this->toData('500', lang('Missing parameters')); |
|
|
|
} |
|
|
|
// 检测用户是否存在 |
|
|
|
$info = UserModel::where(['user_id'=>$param['user_id']])->find(); |
|
|
|
$info = UserModel::where(['user_id' => $param['user_id']])->find(); |
|
|
|
if (empty($info)) { |
|
|
|
return $this->toData('500', lang('user_does_not_exist')); |
|
|
|
} |
|
|
@ -894,17 +897,17 @@ class LoginService extends BaseHomeService |
|
|
|
public function autoLogin($param): array |
|
|
|
{ |
|
|
|
try { |
|
|
|
$login_token=$param['login_token']; |
|
|
|
$tokenUserKey = 'AUTO:TOKEN:'.$login_token; |
|
|
|
$login_token = $param['login_token']; |
|
|
|
$tokenUserKey = 'AUTO:TOKEN:' . $login_token; |
|
|
|
$userId = Cache::store('redis')->get($tokenUserKey); |
|
|
|
if(empty($userId) || $userId <= 0){ |
|
|
|
if (empty($userId) || $userId <= 0) { |
|
|
|
return $this->toData('500', 'Incorrect token', []); |
|
|
|
} |
|
|
|
$info = UserModel::getFieldsByUserId('invite_code,is_real,nick_name,user_no,user_id,login_password,salt', $userId); |
|
|
|
if (empty($info)) { |
|
|
|
return $this->toData('500', lang('user_does_not_exist')); |
|
|
|
} |
|
|
|
// 生成token |
|
|
|
// 生成token |
|
|
|
$token = (new Jwt())->getToken($userId, env('ENCRYPT.SALT')); |
|
|
|
if (empty($token)) { |
|
|
|
return $this->toData('500', lang('system_busy'), []); |
|
|
@ -933,15 +936,14 @@ class LoginService extends BaseHomeService |
|
|
|
} catch (\Exception $exception) { |
|
|
|
return $this->toData('500', lang('system_busy')); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
public function testLogin($param): array |
|
|
|
{ |
|
|
|
try { |
|
|
|
$login_token=$param['login_token']; |
|
|
|
$tokenUserKey = 'AUTO:TOKEN:'.$login_token; |
|
|
|
$login_token = $param['login_token']; |
|
|
|
$tokenUserKey = 'AUTO:TOKEN:' . $login_token; |
|
|
|
$userId = Cache::store('redis')->get($tokenUserKey); |
|
|
|
if(empty($userId) || $userId <= 0){ |
|
|
|
if (empty($userId) || $userId <= 0) { |
|
|
|
return $this->toData('100300', 'Incorrect token', []); |
|
|
|
} |
|
|
|
$info = UserModel::getFieldsByUserId('invite_code,is_real,nick_name,user_no,user_id,login_password,salt', $userId); |
|
|
@ -977,29 +979,28 @@ class LoginService extends BaseHomeService |
|
|
|
} catch (\Exception $exception) { |
|
|
|
return $this->toData('500', lang('system_busy'), []); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
public function getIP(): array |
|
|
|
{ |
|
|
|
$ip=$this->getClientRealIp(); |
|
|
|
$countryDb = base_path().'GeoLite2-Country.mmdb'; |
|
|
|
$cityDb = base_path().'GeoLite2-City.mmdb'; |
|
|
|
$ip = $this->getClientRealIp(); |
|
|
|
$countryDb = base_path() . 'GeoLite2-Country.mmdb'; |
|
|
|
$cityDb = base_path() . 'GeoLite2-City.mmdb'; |
|
|
|
$countryReader = new Reader($countryDb); |
|
|
|
$cityReader = new Reader($cityDb); |
|
|
|
try{ |
|
|
|
try { |
|
|
|
$countryNames = $countryReader->country($ip)->country->names; |
|
|
|
$cityNames = $cityReader->city($ip)->city->names; |
|
|
|
return $this->toData('0', 'Request successful.', [ |
|
|
|
'country' => $countryNames['zh-CN'], |
|
|
|
'city' => $cityNames['zh-CN'], |
|
|
|
'ip'=>$ip |
|
|
|
'ip' => $ip |
|
|
|
]); |
|
|
|
}catch (\Exception $exception){ |
|
|
|
} catch (\Exception $exception) { |
|
|
|
return $this->toData('0', 'Request successful.', [ |
|
|
|
'country' => '未知', |
|
|
|
'city' =>'未知', |
|
|
|
'ip'=>$ip |
|
|
|
'city' => '未知', |
|
|
|
'ip' => $ip |
|
|
|
]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|