|
@ -172,79 +172,12 @@ class LoginService extends BaseHomeService |
|
|
$userId = UserModel::emailRegister($email, $userNo, $userInviteCode, $parentUserId, $password, $ip, $salt, 1, $agentId); |
|
|
$userId = UserModel::emailRegister($email, $userNo, $userInviteCode, $parentUserId, $password, $ip, $salt, 1, $agentId); |
|
|
// 生成钱包地址 |
|
|
// 生成钱包地址 |
|
|
(new UserService())->doRegInitUserInfo($userId, $parentUserId); |
|
|
(new UserService())->doRegInitUserInfo($userId, $parentUserId); |
|
|
// 注册聊天账号 |
|
|
|
|
|
$chatData = [ |
|
|
|
|
|
'Username' => $userNo, |
|
|
|
|
|
'Password' => '123456', |
|
|
|
|
|
]; |
|
|
|
|
|
$chatUrl = env('CHAT_SERVER.BASE_URL') . '/api/user/register'; |
|
|
|
|
|
$chatRes = (new \app\utility\RequestChatServer())->ReqChatServer($chatUrl, $chatData); |
|
|
|
|
|
if (!isset($chatRes['data']['uuid'])) { |
|
|
|
|
|
return $this->toData('100400', 'Failed to register a chat account.', []); |
|
|
|
|
|
} |
|
|
|
|
|
// 绑定注册账号与聊天账号 |
|
|
|
|
|
UserChatLinkModel::create([ |
|
|
|
|
|
'user_id' => $userId, |
|
|
|
|
|
'user_type' => 1, |
|
|
|
|
|
'chat_uuid' => $chatRes['data']['uuid'], |
|
|
|
|
|
'chat_name' => $chatRes['data']['username'] |
|
|
|
|
|
]); |
|
|
|
|
|
Log::info("邮箱注册 - 用户注册chat账号 - user_id=".$userId. " chat_uiud=".$chatRes['data']['uuid']); |
|
|
|
|
|
// 如果有代理,绑定到代理下一个客服(轮询客服绑定) |
|
|
|
|
|
if ($agentId > 0 ) { |
|
|
|
|
|
$customerIds = AdminModel::getCustomerIdsByAgentId($agentId); // 获取代理下的所有客服ID |
|
|
|
|
|
Log::info("邮箱注册 - 代理下客服ids=".json_encode($customerIds)); |
|
|
|
|
|
if (empty($customerIds)) { |
|
|
|
|
|
return $this->toData('100400', 'There is no customer service account under the current agent', []); |
|
|
|
|
|
} |
|
|
|
|
|
$counterKey = 'counter_bind_customer:'.$agentId; |
|
|
|
|
|
$counterIndex = Cache::store('redis')->get($counterKey); //客服绑定计数器索引 |
|
|
|
|
|
if (empty($counterIndex)) { |
|
|
|
|
|
$counterIndex = 0; |
|
|
|
|
|
Cache::store('redis')->set($counterKey, $counterIndex); |
|
|
|
|
|
$tagCustomerId = $customerIds[0]; |
|
|
|
|
|
} else { |
|
|
|
|
|
Cache::store('redis')->inc($counterKey); //更新计数器索引 |
|
|
|
|
|
$tagIndex = $counterIndex % count($customerIds); |
|
|
|
|
|
$tagCustomerId = $customerIds[$tagIndex]; |
|
|
|
|
|
} |
|
|
|
|
|
Log::info("邮箱注册 - 要绑定的客服id=".$tagCustomerId); |
|
|
|
|
|
if ($tagCustomerId > 0) { |
|
|
|
|
|
CustomerRelationalModel::create([ |
|
|
|
|
|
'user_id' => $userId, |
|
|
|
|
|
'customer_id' => $tagCustomerId, |
|
|
|
|
|
'agent_id' => $agentId, |
|
|
|
|
|
]); |
|
|
|
|
|
} |
|
|
|
|
|
// 将注册账号的chat_id与绑定客服的chat_id加为好友 |
|
|
|
|
|
Log::info("邮箱注册 - 获取去客服聊天账号信息, $tagCustomerId=".$tagCustomerId); |
|
|
|
|
|
$customerChatInfo = UserChatLinkModel::where(['user_id'=>$tagCustomerId, 'user_type'=>2])->find(); //查询客服的聊天账号uuid |
|
|
|
|
|
if (empty($customerChatInfo)) { |
|
|
|
|
|
return $this->toData('100400', 'The customer uuid is error.', []); |
|
|
|
|
|
} |
|
|
|
|
|
$chatFriendsData = [ |
|
|
|
|
|
'UserUuid' => $chatRes['data']['uuid'], |
|
|
|
|
|
'CustomerUuid' => $customerChatInfo->chat_uuid, |
|
|
|
|
|
]; |
|
|
|
|
|
Log::info("邮箱注册 - 请求聊天夫加好友=".$tagCustomerId); |
|
|
|
|
|
$chatFriendsUrl = env('CHAT_SERVER.BASE_URL') . '/api/eachOtherFriends'; |
|
|
|
|
|
$chatFriendsRes = (new \app\utility\RequestChatServer())->ReqChatServer($chatFriendsUrl, $chatFriendsData); |
|
|
|
|
|
Log::info("邮箱注册 - chat服务加好友结果:".json_encode($chatFriendsRes)); |
|
|
|
|
|
// 将当前用户加入到代理创建的群聊中 【需要查出当前用户的代理创建的群聊信息】 |
|
|
|
|
|
$agentGroup = UserChatGroupModel::where(['user_id'=>$agentId])->find(); |
|
|
|
|
|
if (empty($agentGroup)) { |
|
|
|
|
|
return $this->toData('100400', 'The chat group is error.', []); |
|
|
|
|
|
} |
|
|
|
|
|
$joinChatGroupUrl = env('CHAT_SERVER.BASE_URL') . '/api/group/join/'.$chatRes['data']['uuid'].'/'.$agentGroup->group_uuid; |
|
|
|
|
|
$joinChatGroupRes = (new \app\utility\RequestChatServer())->ReqChatServer($joinChatGroupUrl, []); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
}); |
|
|
// 删除缓存 |
|
|
// 删除缓存 |
|
|
$this->delCache($emailKey); |
|
|
$this->delCache($emailKey); |
|
|
// 累加已经注册的个数 |
|
|
// 累加已经注册的个数 |
|
|
$this->updateHadRegisterNumCache($ipCanRegisterNumPerIpPerDay); |
|
|
$this->updateHadRegisterNumCache($ipCanRegisterNumPerIpPerDay); |
|
|
return $this->toData('0', 'Registration Successful.', []); |
|
|
return $this->toData('0', 'Registration Successful.'); |
|
|
} catch (ValidateException $validateException) { |
|
|
} catch (ValidateException $validateException) { |
|
|
// 参数校验失败 异常类 |
|
|
// 参数校验失败 异常类 |
|
|
$message = $validateException->getError(); |
|
|
$message = $validateException->getError(); |
|
@ -485,67 +418,6 @@ class LoginService extends BaseHomeService |
|
|
$userId = UserModel::phoneRegister($param['nation'], $param['phone'], $userNo, $userInviteCode, $parentUserId, $password, $ip, $salt, 1, $agentId); |
|
|
$userId = UserModel::phoneRegister($param['nation'], $param['phone'], $userNo, $userInviteCode, $parentUserId, $password, $ip, $salt, 1, $agentId); |
|
|
// 生成钱包地址 |
|
|
// 生成钱包地址 |
|
|
(new UserService())->doRegInitUserInfo($userId, $parentUserId); |
|
|
(new UserService())->doRegInitUserInfo($userId, $parentUserId); |
|
|
// 注册聊天账号 |
|
|
|
|
|
$chatData = [ |
|
|
|
|
|
'Username' => $userNo, |
|
|
|
|
|
'Password' => '123456', |
|
|
|
|
|
]; |
|
|
|
|
|
$chatUrl = env('CHAT_SERVER.BASE_URL') . '/api/user/register'; |
|
|
|
|
|
$chatRes = (new \app\utility\RequestChatServer())->ReqChatServer($chatUrl, $chatData); |
|
|
|
|
|
if (!isset($chatRes['data']['uuid'])) { |
|
|
|
|
|
return $this->toData('100400', 'Failed to register a chat account.', []); |
|
|
|
|
|
} |
|
|
|
|
|
// 绑定注册账号与聊天账号 |
|
|
|
|
|
UserChatLinkModel::create([ |
|
|
|
|
|
'user_id' => $userId, |
|
|
|
|
|
'user_type' => 1, |
|
|
|
|
|
'chat_uuid' => $chatRes['data']['uuid'], |
|
|
|
|
|
'chat_name' => $chatRes['data']['username'] |
|
|
|
|
|
]); |
|
|
|
|
|
// 如果有代理,绑定到代理下一个客服(轮询客服绑定) |
|
|
|
|
|
if ($agentId > 0 ) { |
|
|
|
|
|
$customerIds = AdminModel::getCustomerIdsByAgentId($agentId); // 获取代理下的所有客服ID |
|
|
|
|
|
if (empty($customerIds)) { |
|
|
|
|
|
return $this->toData('100400', 'There is no customer service account under the current agent', []); |
|
|
|
|
|
} |
|
|
|
|
|
$counterKey = 'counter_bind_customer:'.$agentId; |
|
|
|
|
|
$counterIndex = Cache::store('redis')->get($counterKey); //客服绑定计数器索引 |
|
|
|
|
|
if (empty($counterIndex)) { |
|
|
|
|
|
$counterIndex = 0; |
|
|
|
|
|
Cache::store('redis')->set($counterKey, $counterIndex); |
|
|
|
|
|
$tagCustomerId = $customerIds[0]; |
|
|
|
|
|
} else { |
|
|
|
|
|
Cache::store('redis')->inc($counterKey); //更新计数器索引 |
|
|
|
|
|
$tagIndex = $counterIndex % count($customerIds); |
|
|
|
|
|
$tagCustomerId = $customerIds[$tagIndex]; |
|
|
|
|
|
} |
|
|
|
|
|
if ($tagCustomerId > 0) { |
|
|
|
|
|
CustomerRelationalModel::create([ |
|
|
|
|
|
'user_id' => $userId, |
|
|
|
|
|
'customer_id' => $tagCustomerId, |
|
|
|
|
|
'agent_id' => $agentId, |
|
|
|
|
|
]); |
|
|
|
|
|
} |
|
|
|
|
|
// 将注册账号的chat_id与绑定客服的chat_id加为好友 |
|
|
|
|
|
$customerChatInfo = UserChatLinkModel::where('user_id', $tagCustomerId)->find(); //查询客服的聊天账号uuid |
|
|
|
|
|
if (empty($customerChatInfo)) { |
|
|
|
|
|
return $this->toData('100400', 'The customer uuid is error.', []); |
|
|
|
|
|
} |
|
|
|
|
|
$chatFriendsData = [ |
|
|
|
|
|
'UserUuid' => $chatRes['data']['uuid'], |
|
|
|
|
|
'CustomerUuid' => $customerChatInfo->chat_uuid, |
|
|
|
|
|
]; |
|
|
|
|
|
$chatFriendsUrl = env('CHAT_SERVER.BASE_URL') . '/api/eachOtherFriends'; |
|
|
|
|
|
$chatFriendsRes = (new \app\utility\RequestChatServer())->ReqChatServer($chatFriendsUrl, $chatFriendsData); |
|
|
|
|
|
Log::info("手机号注册 - chat服务加好友结果:".json_encode($chatFriendsRes)); |
|
|
|
|
|
// 将当前用户加入到代理创建的群聊中 【需要查出当前用户的代理创建的群聊信息】 |
|
|
|
|
|
$agentGroup = UserChatGroupModel::where(['user_id'=>$agentId])->find(); |
|
|
|
|
|
if (empty($agentGroup)) { |
|
|
|
|
|
return $this->toData('100400', 'The chat group is error.', []); |
|
|
|
|
|
} |
|
|
|
|
|
$joinChatGroupUrl = env('CHAT_SERVER.BASE_URL') . '/api/group/join/'.$chatRes['data']['uuid'].'/'.$agentGroup->group_uuid; |
|
|
|
|
|
$joinChatGroupRes = (new \app\utility\RequestChatServer())->ReqChatServer($joinChatGroupUrl, []); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// 删除缓存 |
|
|
// 删除缓存 |
|
|