|
|
@ -11,6 +11,7 @@ use app\model\AwsS3Model; |
|
|
|
use app\model\CountryModel; |
|
|
|
use app\model\StockMarketModel; |
|
|
|
use app\model\UserBankModel; |
|
|
|
use app\model\UserChatGroupModel; |
|
|
|
use app\model\UserChatLinkModel; |
|
|
|
use app\model\UserContractModel; |
|
|
|
use app\model\UserContractSecModel; |
|
|
@ -38,6 +39,7 @@ use app\model\UserStockFundModel; |
|
|
|
use think\exception\ValidateException; |
|
|
|
use app\utility\UnqId; |
|
|
|
use think\facade\Cache; |
|
|
|
use think\facade\Log; |
|
|
|
|
|
|
|
class UserService extends AdminBaseService |
|
|
|
{ |
|
|
@ -756,22 +758,81 @@ class UserService extends AdminBaseService |
|
|
|
if ($emailExists) { |
|
|
|
return $this->toData('100300', 'The email has already been registered.', []); |
|
|
|
} |
|
|
|
|
|
|
|
// 获取代理id |
|
|
|
$isAgent = AdminModel::checkUserIsAgent($adminId); |
|
|
|
if ($isAgent) { |
|
|
|
$agentId = $adminId; |
|
|
|
} else { // 指定一个默认代理 |
|
|
|
$getAgent = AdminModel::where(['role_id'=>AdminModel::ROLE_ID_AGENT])->find(); |
|
|
|
if (empty($getAgent)) { |
|
|
|
return $this->toData('500', '系统缺少代理账号'); |
|
|
|
} |
|
|
|
$agentId = $getAgent->id; |
|
|
|
} |
|
|
|
// 查询代理下的一个客服 |
|
|
|
$getCustomer = AdminModel::where(['parent_id'=>$agentId])->find(); |
|
|
|
if (empty($getCustomer)) { |
|
|
|
return $this->toData('500', '代理下缺少客服账号', ['agent_id'=>$agentId]); |
|
|
|
} |
|
|
|
$customerId = $getCustomer->id; |
|
|
|
// 查询客服的chat信息 |
|
|
|
$customerChatInfo = UserChatLinkModel::where(['user_id'=>$customerId, 'user_type'=>UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_ADMIN])->find(); //查询客服的聊天账号uuid |
|
|
|
if (empty($customerChatInfo)) { |
|
|
|
return $this->toData('500', '客服账号缺少chat信息'); |
|
|
|
} |
|
|
|
// 查询代理创建的chat群聊信息 |
|
|
|
$agentGroup = UserChatGroupModel::where(['user_id'=>$agentId,'remark'=>UserChatGroupModel::USER_CHAT_GROUP_REMARK_ADMIN_INIT])->find(); |
|
|
|
if (empty($agentGroup)) { |
|
|
|
return $this->toData('500', '当前代理还未创建chat群聊'); |
|
|
|
} |
|
|
|
|
|
|
|
// 入库 |
|
|
|
|
|
|
|
// 生成userNo |
|
|
|
$userNo = (new BaseHomeService())->getUniqUserNo(); |
|
|
|
|
|
|
|
// 请求聊天服务,注册聊天账号 |
|
|
|
$chatData = [ |
|
|
|
'Username' => $userNo, |
|
|
|
'Password' => '123456', |
|
|
|
'Nickname' => 'user_'.explode('@', $param['email'])[0], |
|
|
|
'Email' => $param['email'], |
|
|
|
]; |
|
|
|
$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', '注册聊天账号失败,请稍后再试'); |
|
|
|
} |
|
|
|
|
|
|
|
// 創建用戶 |
|
|
|
$salt = env('ENCRYPT.SALT'); |
|
|
|
$password = (new UnqId())->encryptPassword($param['password'], $salt); |
|
|
|
$userInviteCode = (new BaseHomeService())->getUniqInviteCode(); |
|
|
|
$parentUserId = 0; |
|
|
|
$ip = (new BaseHomeService())->getClientRealIp(); |
|
|
|
$userId = UserModel::emailRegister($param['email'], $userNo, $userInviteCode, $parentUserId, $password, $ip, $salt, $param['is_test_user'] ?? 1, 0); |
|
|
|
// 判断是否是代理 |
|
|
|
$isAgent = AdminModel::checkUserIsAgent($adminId); |
|
|
|
if ($isAgent) { |
|
|
|
UserModel::where('user_id', $userId)->update([ |
|
|
|
'agent_id' => $adminId |
|
|
|
]); |
|
|
|
} |
|
|
|
$userId = UserModel::emailRegister($param['email'], $userNo, $userInviteCode, $parentUserId, $password, $ip, $salt, $param['is_test_user'] ?? 1, $agentId, $customerId); |
|
|
|
|
|
|
|
// 关联用户与聊天账号 |
|
|
|
UserChatLinkModel::create([ |
|
|
|
'user_id' => $userId, |
|
|
|
'user_type' => 1, |
|
|
|
'chat_uuid' => $chatRes['data']['uuid'], |
|
|
|
'chat_name' => $chatRes['data']['username'] |
|
|
|
]); |
|
|
|
|
|
|
|
// 将当前账号与客服账号的chat_id加为好友 |
|
|
|
$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("admin创建用户 - 用户与客服chat_id加好友结果:".json_encode($chatFriendsRes)); |
|
|
|
// 将当前用户加入到代理创建的群聊中 |
|
|
|
$joinChatGroupUrl = env('CHAT_SERVER.BASE_URL') . '/api/group/join/'.$chatRes['data']['uuid'].'/'.$agentGroup->group_uuid; |
|
|
|
$joinChatGroupRes = (new \app\utility\RequestChatServer())->ReqChatServer($joinChatGroupUrl, []); |
|
|
|
Log::info("admin创建用户 - 用户的chat_id加入群聊结果:".json_encode($joinChatGroupRes)); |
|
|
|
|
|
|
|
(new \app\home\service\UserService())->doRegInitUserInfo($userId, $parentUserId); |
|
|
|
return $this->toData('0', 'SUCCESS'); |
|
|
|
} catch (ValidateException $validateException) { |
|
|
|