From 2ae8b1df73bfdcc7f420889b5df46dac313679ea Mon Sep 17 00:00:00 2001 From: chuan <2154243450@qq.com> Date: Tue, 14 Jan 2025 14:16:20 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=B4=E6=92=AD=E8=81=8A=E5=A4=A9=E9=9C=80?= =?UTF-8?q?=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/Agent.php | 40 ++++++ app/admin/route/app.php | 5 + app/admin/service/AdminBaseService.php | 2 +- app/admin/service/AdminService.php | 30 ++++- app/admin/service/AgentService.php | 176 +++++++++++++++++++++++++ app/admin/validate/AdminValidate.php | 8 +- app/home/controller/News.php | 34 +++++ app/home/route/app.php | 1 + app/home/service/LoginService.php | 111 ++++++++++++++++ app/home/service/PayService.php | 37 +++--- app/home/service/UserService.php | 29 +++- app/model/AdminModel.php | 8 +- app/model/AwsIvsModel.php | 6 + app/model/CustomerRelationalModel.php | 6 + app/model/UserChatLinkModel.php | 6 + app/utility/RequestChatServer.php | 35 +++++ 16 files changed, 509 insertions(+), 25 deletions(-) create mode 100644 app/model/AwsIvsModel.php create mode 100644 app/model/CustomerRelationalModel.php create mode 100644 app/model/UserChatLinkModel.php create mode 100644 app/utility/RequestChatServer.php diff --git a/app/admin/controller/Agent.php b/app/admin/controller/Agent.php index 93cfa9a..c6cf4ee 100644 --- a/app/admin/controller/Agent.php +++ b/app/admin/controller/Agent.php @@ -30,4 +30,44 @@ class Agent extends AdminBaseController $result = $service->manager($this->request->param()); return json($result); } + + // 代理下客服列表 + public function customerList() + { + $service = new AgentService(); + $result = $service->customerList($this->request->param()); + return json($result); + } + + // 客服下所有注册用户 + public function customerUser() + { + $service = new AgentService(); + $result = $service->customerUser($this->request->param()); + return json($result); + } + + // aws ivs 推流列表 + public function awsIvsList() + { + $service = new AgentService(); + $result = $service->awsIvsList($this->request->param()); + return json($result); + } + + // 添加主播信息 + public function awsIvsAdd() + { + $service = new AgentService(); + $result = $service->awsIvsAdd($this->request->param()); + return json($result); + } + + // 编辑主播信息 + public function awsIvsEdit() + { + $service = new AgentService(); + $result = $service->awsIvsEdit($this->request->param()); + return json($result); + } } \ No newline at end of file diff --git a/app/admin/route/app.php b/app/admin/route/app.php index d4a81ce..09d3a98 100644 --- a/app/admin/route/app.php +++ b/app/admin/route/app.php @@ -147,6 +147,11 @@ Route::group('/', function () { Route::post('/agent/index', 'Agent/index'); Route::post('/agent/user', 'Agent/user'); Route::post('/agent/manager', 'Agent/manager'); + Route::post('/agent/customer_list', 'Agent/customerList'); //客服列表,支持搜索某个代理下的客服 + Route::post('/agent/customer_user_list', 'Agent/customerUser'); //获取客服下所有用户 + Route::post('/agent/aws_ivs_list', 'Agent/aws_ivs_list'); //直播推流列表 + Route::post('/agent/aws_ivs_add', 'Agent/aws_ivs_add'); //直播推流配置添加 + Route::post('/agent/aws_ivs_edit', 'Agent/aws_ivs_edit'); //直播推流配置编辑 // 用户管理 Route::post('/user/index', 'User/index'); diff --git a/app/admin/service/AdminBaseService.php b/app/admin/service/AdminBaseService.php index 2245a36..ed4e9cf 100644 --- a/app/admin/service/AdminBaseService.php +++ b/app/admin/service/AdminBaseService.php @@ -408,7 +408,7 @@ class AdminBaseService } } - $res=UserMoneyModel::where('user_id',$user_id)->where('stock_id','USD')->update([ + $res=UserMoneyModel::where('user_id',$user_id)->where('stock_id','USD')->update([ 'usable_num'=>$last_usable_num, 'frozen_num'=>$last_frozen_num, 'update_time'=>date('Y-m-d H:i:s'), diff --git a/app/admin/service/AdminService.php b/app/admin/service/AdminService.php index fb726c6..774a9e8 100644 --- a/app/admin/service/AdminService.php +++ b/app/admin/service/AdminService.php @@ -7,9 +7,11 @@ 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; +use think\facade\Log; use function Sodium\compare; use think\facade\Request; @@ -31,8 +33,32 @@ class AdminService extends AdminBaseService $param['password'] = (new UnqId())->encryptPassword($param['password'], env('ENCRYPT.ADMINSALT')); $param['invite_code'] = (new BaseHomeService())->getUniqInviteCode(); - AdminModel::create($param); - return $this->toData('0', '添加成功.', []); + $resAdmin = AdminModel::create($param); + + // 如果是客服账号,需要注册一下聊天账号 + $regChat = []; + if (isset($param['parent_id']) && $param['parent_id'] > 0) { + Log::info('创建客服账号 - parent_id='. $param['parent_id']); + $chatData = [ + 'Username' => $resAdmin->id."_".$resAdmin->user_name, //用account.id + account.user_name 拼接作为聊天账号注册的Username + 'Password' => '123456', + ]; + $chatUrl = env('CHAT_SERVER.BASE_URL') . '/user/register'; + $regChat = (new \app\utility\RequestChatServer())->ReqChatServer($chatUrl, $chatData); + if (!isset($regChat['data']['uuid'])) { + Log::error('添加客服 - 创建聊天账号失败 chat_response=:'. json_encode($regChat)); + return $this->toData('0', '注册聊天账号失败.', ['chat_response' => $regChat]); + } + //将客服账号与聊天账号关联 + UserChatLinkModel::create([ + 'user_id' => $resAdmin->id, + 'user_type' => 2, + 'chat_uuid' => $regChat['data']['uuid'], + 'chat_name' => $regChat['data']['username'] + ]); + } + + return $this->toData('0', '添加成功.', ['chatData' => $regChat]); } catch (ValidateException $validateException) { $message = $validateException->getError(); return $this->toData('100400', $message); diff --git a/app/admin/service/AgentService.php b/app/admin/service/AgentService.php index eb62ba5..0a6b5ea 100644 --- a/app/admin/service/AgentService.php +++ b/app/admin/service/AgentService.php @@ -4,6 +4,8 @@ namespace app\admin\service; use app\model\AdminModel; use app\model\AuthGroupAccessModel; +use app\model\AwsIvsModel; +use app\model\CustomerRelationalModel; use app\model\UserModel; class AgentService extends AdminBaseService @@ -151,4 +153,178 @@ class AgentService extends AdminBaseService return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); } } + + public function customerList($param) + { + try { + if (empty($param['page']) || !is_numeric($param['page'])) { + return $this->toData('1', '参错错误'); + } + + // 角色ID + $roleId = 11; + // 代理ID + $agentId = 0; + if (isset($param['agent_id']) && is_numeric($param['agent_id'])) { + $agentId = $param['agent_id']; + } + $list = AdminModel::when($agentId, function ($query) use ($agentId) { + $query->where('parent_id', $agentId)->order('id', 'desc'); //查询代理下的客服列表 + }, function ($query) use($roleId) { + $query->where('role_id', $roleId)->order('id', 'desc'); //查询所有客服列表 + })->paginate([ + 'list_rows' => 15, // 每页显示 10 条 + 'page' => $param['page'], // 使用前端传递的页码 + ]); + + return $this->toData('0', 'SUCCESS', [ + 'list' => $list->items(), // 当前页的数据 + 'page' => $list->currentPage(), // 当前页码 + 'total' => $list->total(), // 总记录数 + 'last_page' => $list->lastPage(), // 最后一页页码 + 'agent_id' => $agentId, + ]); + } catch (\Exception $exception) { + return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); + } + } + + public function customerUser($param) + { + try { + if (empty($param['customer_id']) || !is_numeric($param['customer_id'])) { + return $this->toData('1', '参错错误'); + } + if (empty($param['page']) || !is_numeric($param['page'])) { + return $this->toData('1', '参错错误'); + } + // 查询当前客服下的用户 + $list = CustomerRelationalModel::where('customer_id', $param['customer_id'])->order('id', 'desc')->paginate([ + 'list_rows' => 15, // 每页显示 10 条 + 'page' => $param['page'], // 使用前端传递的页码 + ]); + $userIds = array_column($list->items(), 'user_id'); // 获取当前页的用户id + // 根据user_id查询用户列表 + $userDetails = UserModel::whereIn('id', $userIds)->select()->toArray(); + + return $this->toData('0', 'SUCCESS', [ + 'list' => $list->items(), // 当前页的数据 + 'user_details' => $userDetails, + 'page' => $list->currentPage(), // 当前页码 + 'total' => $list->total(), // 总记录数 + 'last_page' => $list->lastPage(), // 最后一页页码 + ]); + } catch (\Exception $exception) { + return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); + } + } + + public function awsIvsList($param) + { + try { + if (empty($param['page']) || !is_numeric($param['page'])) { + return $this->toData('1', '参错错误'); + } + + if (isset($param['title'])) { + $list = AwsIvsModel::where('title', $param['title'])->order('id', 'desc')->paginate([ + 'list_rows' => 15, + 'page' => $param['page'], + ]); + } else { + $list = AwsIvsModel::order('id', 'desc')->paginate([ + 'list_rows' => 15, + 'page' => $param['page'], + ]); + } + + return $this->toData('0', 'SUCCESS', [ + 'list' => $list->items(), // 当前页的数据 + 'page' => $list->currentPage(), // 当前页码 + 'total' => $list->total(), // 总记录数 + 'last_page' => $list->lastPage(), // 最后一页页码 + ]); + } catch (\Exception $exception) { + return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); + } + } + + public function awsIvsAdd($param) + { + try { + if (empty($param['title'])) { + return $this->toData('1', 'Missing param title'); + } + if (empty($param['anchor_name'])) { + return $this->toData('1', 'Missing param anchor_name'); + } + if (empty($param['desc'])) { + return $this->toData('1', 'Missing param desc'); + } + if (empty($param['push_url'])) { + return $this->toData('1', 'Missing param push_url'); + } + if (empty($param['secret_key'])) { + return $this->toData('1', 'Missing param secret_key'); + } + if (empty($param['play_url'])) { + return $this->toData('1', 'Missing param play_url'); + } + $res = AwsIvsModel::create([ + 'title' => $param['title'], + 'anchor_name' => $param['anchor_name'], + 'avatar' => $param['avatar'], + 'desc' => $param['desc'], + 'push_url' => $param['push_url'], + 'secret_key' => $param['secret_key'], + 'play_url' => $param['play_url'] + ]); + return $this->toData('0', 'SUCCESS', ['id' => $res->id]); + } catch (\Exception $exception) { + return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); + } + } + + public function awsIvsEdit($param) + { + try { + if (empty($param['id'])) { + return $this->toData('1', 'Missing param id'); + } + if (empty($param['title'])) { + return $this->toData('1', 'Missing param title'); + } + if (empty($param['anchor_name'])) { + return $this->toData('1', 'Missing param anchor_name'); + } + if (empty($param['desc'])) { + return $this->toData('1', 'Missing param desc'); + } + if (empty($param['push_url'])) { + return $this->toData('1', 'Missing param push_url'); + } + if (empty($param['secret_key'])) { + return $this->toData('1', 'Missing param secret_key'); + } + if (empty($param['play_url'])) { + return $this->toData('1', 'Missing param play_url'); + } + // 检查是否存在数据 + $ckInfo = AwsIvsModel::where('id', $param['id'])->find(); + if (empty($ckInfo)) { + return $this->toData('1', '编辑的数据不存在'); + } + $ckInfo->title = $param['title']; + $ckInfo->anchor_name = $param['anchor_name']; + $ckInfo->avatar = $param['avatar']; + $ckInfo->desc = $param['desc']; + $ckInfo->push_url = $param['push_url']; + $ckInfo->secret_key = $param['secret_key']; + $ckInfo->play_url = $param['play_url']; + $ckInfo->save(); + return $this->toData('1', 'Successful'); + } catch (\Exception $exception) { + return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); + } + } } \ No newline at end of file diff --git a/app/admin/validate/AdminValidate.php b/app/admin/validate/AdminValidate.php index 195ef69..65c54ff 100644 --- a/app/admin/validate/AdminValidate.php +++ b/app/admin/validate/AdminValidate.php @@ -11,12 +11,12 @@ class AdminValidate extends AdminBaseValidate 'new_password' => 'require|length:5,40', 'old_password' => 'require|length:5,40', 'nick_name' => 'require|alphaNum', - + 'parent_id' => 'require|integer', ]; protected $message = [ - 'user_name.alphaNum' => '用户名必须包含字母和数字', - 'nick_name.alphaNum' => '昵称必须包含字母和数字', + 'user_name.alphaNum' => '用户名只能包含字母和数字', + 'nick_name.alphaNum' => '昵称只能包含字母和数字', 'password.require' => '请填写密码', // 'password.isString' => '密码格式不正确.', 'password.length' => '密码必须大于5个字符.', @@ -31,7 +31,7 @@ class AdminValidate extends AdminBaseValidate protected $scene = [ - 'addUser' => ['user_name','password','nick_name'], + 'addUser' => ['user_name','password','nick_name','parent_id'], 'updateInfo' => ['nick_name','email'], 'updateAccount' => ['user_name','nick_name'], 'updatePassword'=>['new_password','old_password'], diff --git a/app/home/controller/News.php b/app/home/controller/News.php index 121bc25..ba249de 100644 --- a/app/home/controller/News.php +++ b/app/home/controller/News.php @@ -2,8 +2,10 @@ namespace app\home\controller; +use app\model\UserChatLinkModel; use Goutte\Client; use think\facade\Cache; +use think\facade\Log; use think\Request; use think\response\Json; @@ -86,6 +88,38 @@ class News extends HomeBaseController } + /** + * @throws \Exception + */ + public function testApi() + { + $chatData = [ + 'Username' => "ccc333519", + 'Password' => '123456', + ]; + $chatUrl = env('CHAT_SERVER.BASE_URL') . '/user/register'; + $res = (new \app\utility\RequestChatServer())->ReqChatServer($chatUrl, $chatData); + if (!isset($res['data']['uuid'])) { + return json([ + 'code' => '-1', + 'message' => '注册聊天账号失败', + ]); + } + + //将客服账号与聊天账号关联 + UserChatLinkModel::create([ + 'user_id' => 999, + 'user_type' => 1, + 'chat_uuid' => $res['data']['uuid'], + ]); + + return json([ + 'code' => '0', + 'message' => 'successful', + 'data' => $res, + 'uuid' => $res['data']['uuid'] + ]); + } } \ No newline at end of file diff --git a/app/home/route/app.php b/app/home/route/app.php index 1bfe7e9..14199c6 100644 --- a/app/home/route/app.php +++ b/app/home/route/app.php @@ -276,6 +276,7 @@ Route::group('/',function (){ Route::post('get_ip', 'Login/getIP'); Route::get('get_news', 'News/index'); Route::get('test', 'News/test'); + Route::get('test_api', 'News/testApi'); })->allowCrossDomain($header); diff --git a/app/home/service/LoginService.php b/app/home/service/LoginService.php index 8f31db9..3897711 100644 --- a/app/home/service/LoginService.php +++ b/app/home/service/LoginService.php @@ -6,6 +6,8 @@ use app\home\controller\User; use app\home\validate\LoginValidate; use app\model\AdminModel; use app\model\CountryModel; +use app\model\CustomerRelationalModel; +use app\model\UserChatLinkModel; use app\model\UserModel; use app\utility\Jwt; use app\utility\SendSms; @@ -13,6 +15,7 @@ use app\utility\UnqId; use Psr\SimpleCache\InvalidArgumentException; use think\exception\ValidateException; use think\facade\Cache; +use think\facade\Log; use think\facade\Queue; use think\queue\Job; use GeoIp2\Database\Reader; @@ -167,6 +170,60 @@ class LoginService extends BaseHomeService $userId = UserModel::emailRegister($email, $userNo, $userInviteCode, $parentUserId, $password, $ip, $salt, 1, $agentId); // 生成钱包地址 (new UserService())->doRegInitUserInfo($userId, $parentUserId); + // 注册聊天账号 + $chatData = [ + 'Username' => $userNo, + 'Password' => '123456', + ]; + $chatUrl = env('CHAT_SERVER.BASE_URL') . '/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) || !$customerChatInfo->chat_uuid) { + 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)); + } }); // 删除缓存 $this->delCache($emailKey); @@ -413,6 +470,60 @@ class LoginService extends BaseHomeService $userId = UserModel::phoneRegister($param['nation'], $param['phone'], $userNo, $userInviteCode, $parentUserId, $password, $ip, $salt, 1, $agentId); // 生成钱包地址 (new UserService())->doRegInitUserInfo($userId, $parentUserId); + // 注册聊天账号 + $chatData = [ + 'Username' => $userNo, + 'Password' => '123456', + ]; + $chatUrl = env('CHAT_SERVER.BASE_URL') . '/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) || !$customerChatInfo->chat_uuid) { + 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)); + } }); // 删除缓存 diff --git a/app/home/service/PayService.php b/app/home/service/PayService.php index 5c0795f..08d8a27 100644 --- a/app/home/service/PayService.php +++ b/app/home/service/PayService.php @@ -134,22 +134,27 @@ class PayService extends BaseHomeService } break; case 4: - $result = (new HTPayService())->qrPay($data['order_no'], round($data['total_amount'])); - if ($result['status'] == 1) { - RechargeApplyModel::where('order_no', $data['order_no'])->update([ - 'order_idx' => $result['orderNo'], - 'pay_url' => $result['payUrl'], - 'total_amount' => $result['oriAmount'] - ]); - return $this->toData(0, 'Request successful.', [ - 'type' => 'bank_pay', - 'pay_url' => $result['payUrl'], - 'order_no' => $data['order_no'], - ]); - - } else { - return $this->toData('101900', 'The system is busy. Please try again later.6', [$result['status'], $result['message']]); - } +// $result = (new HTPayService())->qrPay($data['order_no'], round($data['total_amount'])); +// if ($result['status'] == 1) { +// RechargeApplyModel::where('order_no', $data['order_no'])->update([ +// 'order_idx' => $result['orderNo'], +// 'pay_url' => $result['payUrl'], +// 'total_amount' => $result['oriAmount'] +// ]); +// return $this->toData(0, 'Request successful.', [ +// 'type' => 'bank_pay', +// 'pay_url' => $result['payUrl'], +// 'order_no' => $data['order_no'], +// ]); +// } else { +// return $this->toData('101900', 'The system is busy. Please try again later.6', [$result['status'], $result['message']]); +// } + // 20250110 跟负责人确认不要第三方验证,后台管理端手动审核订单信息 + return $this->toData(0, 'Request successful.', [ + 'type' => 'bank_pay', + 'pay_url' => '', + 'order_no' => $data['order_no'], + ]); break; case 5: $result = (new XdPayService())->create_order($data['order_no'], $data['total_amount']); diff --git a/app/home/service/UserService.php b/app/home/service/UserService.php index aad0797..53a0518 100644 --- a/app/home/service/UserService.php +++ b/app/home/service/UserService.php @@ -4,7 +4,9 @@ namespace app\home\service; use app\home\validate\UserValidate; use app\model\CountryModel; +use app\model\CustomerRelationalModel; use app\model\FileModel; +use app\model\UserChatLinkModel; use app\model\UserContractModel; use app\model\UserDigitalModel; use app\model\UserForexModel; @@ -157,6 +159,27 @@ class UserService extends BaseHomeService } $leverageNum= empty($leverageNum) ? 1: $leverageNum; + // 查询用户的chat_uuid + $userChatInfo = UserChatLinkModel::where('user_id', $userId)->find(); + $userChatUuid = ""; + $userChatName = ""; + if (!empty($userChatInfo)) { + $userChatUuid = $userChatInfo->chat_uuid; + $userChatName = $userChatInfo->chat_name; + } + // 查询用户绑定的客服chat_uuid + $customerChatUuid = ""; + $customerChatName = ""; + $customerRelationInfo = CustomerRelationalModel::where('user_id', $userId)->find(); //查询用户关联的客服账号信息 + if ($customerRelationInfo) { + $customerChatInfo = UserChatLinkModel::where('user_id', $customerRelationInfo->customer_id)->find(); //查询客服的chat账号 + if ($customerChatInfo) { + $customerChatUuid = $customerChatInfo->chat_uuid; + $customerChatName = $customerChatInfo->chat_name; + } + } + + // 返回数据 return $this->toData('0', 'Modification successful.', [ 'logo' => $headPath, @@ -177,7 +200,11 @@ 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 ]); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy.', [$exception->getMessage(), $exception->getTrace()]); diff --git a/app/model/AdminModel.php b/app/model/AdminModel.php index 4401e9b..b18dbf4 100644 --- a/app/model/AdminModel.php +++ b/app/model/AdminModel.php @@ -78,4 +78,10 @@ class AdminModel extends BaseModel return 0; } return $self; - }} \ No newline at end of file + } + + public static function getCustomerIdsByAgentId($agentId): array + { + return self::where('parent_id', $agentId)->column('id'); + } +} \ No newline at end of file diff --git a/app/model/AwsIvsModel.php b/app/model/AwsIvsModel.php new file mode 100644 index 0000000..717d7ac --- /dev/null +++ b/app/model/AwsIvsModel.php @@ -0,0 +1,6 @@ +post($url, [ + 'json' => $data, + ]); + $statusCode = $response->getStatusCode(); + Log::error("请求聊天服返回:code==".$statusCode); + Log::error("请求聊天服返回:body==". $response->getBody()); + if ($statusCode == 200) { + $resBody = json_decode($response->getBody(), true); // 转换为数组 + } + return $resBody; + } catch (GuzzleException $e) { + Log::error("请求聊天服异常 - guzzle: " . $e->getMessage()); + return []; + } catch (\Exception $exception) { + Log::error("请求聊天服异常 - exc:" . $exception->getMessage()); + return []; + } + } +} \ No newline at end of file