Browse Source

直播聊天需求

p1
chuan 2 months ago
parent
commit
2ae8b1df73
  1. 40
      app/admin/controller/Agent.php
  2. 5
      app/admin/route/app.php
  3. 2
      app/admin/service/AdminBaseService.php
  4. 30
      app/admin/service/AdminService.php
  5. 176
      app/admin/service/AgentService.php
  6. 8
      app/admin/validate/AdminValidate.php
  7. 34
      app/home/controller/News.php
  8. 1
      app/home/route/app.php
  9. 111
      app/home/service/LoginService.php
  10. 37
      app/home/service/PayService.php
  11. 29
      app/home/service/UserService.php
  12. 8
      app/model/AdminModel.php
  13. 6
      app/model/AwsIvsModel.php
  14. 6
      app/model/CustomerRelationalModel.php
  15. 6
      app/model/UserChatLinkModel.php
  16. 35
      app/utility/RequestChatServer.php

40
app/admin/controller/Agent.php

@ -30,4 +30,44 @@ class Agent extends AdminBaseController
$result = $service->manager($this->request->param()); $result = $service->manager($this->request->param());
return json($result); 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);
}
} }

5
app/admin/route/app.php

@ -147,6 +147,11 @@ Route::group('/', function () {
Route::post('/agent/index', 'Agent/index'); Route::post('/agent/index', 'Agent/index');
Route::post('/agent/user', 'Agent/user'); Route::post('/agent/user', 'Agent/user');
Route::post('/agent/manager', 'Agent/manager'); 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'); Route::post('/user/index', 'User/index');

2
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, 'usable_num'=>$last_usable_num,
'frozen_num'=>$last_frozen_num, 'frozen_num'=>$last_frozen_num,
'update_time'=>date('Y-m-d H:i:s'), 'update_time'=>date('Y-m-d H:i:s'),

30
app/admin/service/AdminService.php

@ -7,9 +7,11 @@ use app\home\service\BaseHomeService;
use app\model\AdminLogModel; use app\model\AdminLogModel;
use app\model\AdminModel; use app\model\AdminModel;
use app\model\AuthRoleModel; use app\model\AuthRoleModel;
use app\model\UserChatLinkModel;
use phpDocumentor\Reflection\Type; use phpDocumentor\Reflection\Type;
use think\exception\ValidateException; use think\exception\ValidateException;
use app\utility\UnqId; use app\utility\UnqId;
use think\facade\Log;
use function Sodium\compare; use function Sodium\compare;
use think\facade\Request; use think\facade\Request;
@ -31,8 +33,32 @@ class AdminService extends AdminBaseService
$param['password'] = (new UnqId())->encryptPassword($param['password'], env('ENCRYPT.ADMINSALT')); $param['password'] = (new UnqId())->encryptPassword($param['password'], env('ENCRYPT.ADMINSALT'));
$param['invite_code'] = (new BaseHomeService())->getUniqInviteCode(); $param['invite_code'] = (new BaseHomeService())->getUniqInviteCode();
AdminModel::create($param); $resAdmin = AdminModel::create($param);
return $this->toData('0', '添加成功.', []);
// 如果是客服账号,需要注册一下聊天账号
$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) { } catch (ValidateException $validateException) {
$message = $validateException->getError(); $message = $validateException->getError();
return $this->toData('100400', $message); return $this->toData('100400', $message);

176
app/admin/service/AgentService.php

@ -4,6 +4,8 @@ namespace app\admin\service;
use app\model\AdminModel; use app\model\AdminModel;
use app\model\AuthGroupAccessModel; use app\model\AuthGroupAccessModel;
use app\model\AwsIvsModel;
use app\model\CustomerRelationalModel;
use app\model\UserModel; use app\model\UserModel;
class AgentService extends AdminBaseService class AgentService extends AdminBaseService
@ -151,4 +153,178 @@ class AgentService extends AdminBaseService
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); 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()]);
}
}
} }

8
app/admin/validate/AdminValidate.php

@ -11,12 +11,12 @@ class AdminValidate extends AdminBaseValidate
'new_password' => 'require|length:5,40', 'new_password' => 'require|length:5,40',
'old_password' => 'require|length:5,40', 'old_password' => 'require|length:5,40',
'nick_name' => 'require|alphaNum', 'nick_name' => 'require|alphaNum',
'parent_id' => 'require|integer',
]; ];
protected $message = [ protected $message = [
'user_name.alphaNum' => '用户名必须包含字母和数字', 'user_name.alphaNum' => '用户名只能包含字母和数字',
'nick_name.alphaNum' => '昵称必须包含字母和数字', 'nick_name.alphaNum' => '昵称只能包含字母和数字',
'password.require' => '请填写密码', 'password.require' => '请填写密码',
// 'password.isString' => '密码格式不正确.', // 'password.isString' => '密码格式不正确.',
'password.length' => '密码必须大于5个字符.', 'password.length' => '密码必须大于5个字符.',
@ -31,7 +31,7 @@ class AdminValidate extends AdminBaseValidate
protected $scene = [ protected $scene = [
'addUser' => ['user_name','password','nick_name'], 'addUser' => ['user_name','password','nick_name','parent_id'],
'updateInfo' => ['nick_name','email'], 'updateInfo' => ['nick_name','email'],
'updateAccount' => ['user_name','nick_name'], 'updateAccount' => ['user_name','nick_name'],
'updatePassword'=>['new_password','old_password'], 'updatePassword'=>['new_password','old_password'],

34
app/home/controller/News.php

@ -2,8 +2,10 @@
namespace app\home\controller; namespace app\home\controller;
use app\model\UserChatLinkModel;
use Goutte\Client; use Goutte\Client;
use think\facade\Cache; use think\facade\Cache;
use think\facade\Log;
use think\Request; use think\Request;
use think\response\Json; 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']
]);
}
} }

1
app/home/route/app.php

@ -276,6 +276,7 @@ Route::group('/',function (){
Route::post('get_ip', 'Login/getIP'); Route::post('get_ip', 'Login/getIP');
Route::get('get_news', 'News/index'); Route::get('get_news', 'News/index');
Route::get('test', 'News/test'); Route::get('test', 'News/test');
Route::get('test_api', 'News/testApi');
})->allowCrossDomain($header); })->allowCrossDomain($header);

111
app/home/service/LoginService.php

@ -6,6 +6,8 @@ use app\home\controller\User;
use app\home\validate\LoginValidate; use app\home\validate\LoginValidate;
use app\model\AdminModel; use app\model\AdminModel;
use app\model\CountryModel; use app\model\CountryModel;
use app\model\CustomerRelationalModel;
use app\model\UserChatLinkModel;
use app\model\UserModel; use app\model\UserModel;
use app\utility\Jwt; use app\utility\Jwt;
use app\utility\SendSms; use app\utility\SendSms;
@ -13,6 +15,7 @@ use app\utility\UnqId;
use Psr\SimpleCache\InvalidArgumentException; use Psr\SimpleCache\InvalidArgumentException;
use think\exception\ValidateException; use think\exception\ValidateException;
use think\facade\Cache; use think\facade\Cache;
use think\facade\Log;
use think\facade\Queue; use think\facade\Queue;
use think\queue\Job; use think\queue\Job;
use GeoIp2\Database\Reader; use GeoIp2\Database\Reader;
@ -167,6 +170,60 @@ 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') . '/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); $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); $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') . '/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));
}
}); });
// 删除缓存 // 删除缓存

37
app/home/service/PayService.php

@ -134,22 +134,27 @@ class PayService extends BaseHomeService
} }
break; break;
case 4: case 4:
$result = (new HTPayService())->qrPay($data['order_no'], round($data['total_amount'])); // $result = (new HTPayService())->qrPay($data['order_no'], round($data['total_amount']));
if ($result['status'] == 1) { // if ($result['status'] == 1) {
RechargeApplyModel::where('order_no', $data['order_no'])->update([ // RechargeApplyModel::where('order_no', $data['order_no'])->update([
'order_idx' => $result['orderNo'], // 'order_idx' => $result['orderNo'],
'pay_url' => $result['payUrl'], // 'pay_url' => $result['payUrl'],
'total_amount' => $result['oriAmount'] // 'total_amount' => $result['oriAmount']
]); // ]);
return $this->toData(0, 'Request successful.', [ // return $this->toData(0, 'Request successful.', [
'type' => 'bank_pay', // 'type' => 'bank_pay',
'pay_url' => $result['payUrl'], // 'pay_url' => $result['payUrl'],
'order_no' => $data['order_no'], // 'order_no' => $data['order_no'],
]); // ]);
// } else {
} else { // return $this->toData('101900', 'The system is busy. Please try again later.6', [$result['status'], $result['message']]);
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; break;
case 5: case 5:
$result = (new XdPayService())->create_order($data['order_no'], $data['total_amount']); $result = (new XdPayService())->create_order($data['order_no'], $data['total_amount']);

29
app/home/service/UserService.php

@ -4,7 +4,9 @@ namespace app\home\service;
use app\home\validate\UserValidate; use app\home\validate\UserValidate;
use app\model\CountryModel; use app\model\CountryModel;
use app\model\CustomerRelationalModel;
use app\model\FileModel; use app\model\FileModel;
use app\model\UserChatLinkModel;
use app\model\UserContractModel; use app\model\UserContractModel;
use app\model\UserDigitalModel; use app\model\UserDigitalModel;
use app\model\UserForexModel; use app\model\UserForexModel;
@ -157,6 +159,27 @@ class UserService extends BaseHomeService
} }
$leverageNum= empty($leverageNum) ? 1: $leverageNum; $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.', [ return $this->toData('0', 'Modification successful.', [
'logo' => $headPath, 'logo' => $headPath,
@ -177,7 +200,11 @@ class UserService extends BaseHomeService
'country' => $countryName, 'country' => $countryName,
'countryId' => $countryId, 'countryId' => $countryId,
'lever_status' => $info['lever_status'], '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) { } catch (\Exception $exception) {
return $this->toData('100500', 'The system is busy.', [$exception->getMessage(), $exception->getTrace()]); return $this->toData('100500', 'The system is busy.', [$exception->getMessage(), $exception->getTrace()]);

8
app/model/AdminModel.php

@ -78,4 +78,10 @@ class AdminModel extends BaseModel
return 0; return 0;
} }
return $self; return $self;
}} }
public static function getCustomerIdsByAgentId($agentId): array
{
return self::where('parent_id', $agentId)->column('id');
}
}

6
app/model/AwsIvsModel.php

@ -0,0 +1,6 @@
<?php
namespace app\model;
class AwsIvsModel extends BaseModel
{
protected $table = 'aws_ivs';
}

6
app/model/CustomerRelationalModel.php

@ -0,0 +1,6 @@
<?php
namespace app\model;
class CustomerRelationalModel extends BaseModel
{
protected $name = 'customer_relational';
}

6
app/model/UserChatLinkModel.php

@ -0,0 +1,6 @@
<?php
namespace app\model;
class UserChatLinkModel extends BaseModel
{
protected $name = 'user_chat_link';
}

35
app/utility/RequestChatServer.php

@ -0,0 +1,35 @@
<?php
namespace app\utility;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use think\facade\Log;
class RequestChatServer
{
public function ReqChatServer(string $url, array $data): array
{
try {
Log::info("请求URL==".$url." 请求Param==".json_encode($data));
$resBody = [];
$client = new Client();
$response = $client->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 [];
}
}
}
Loading…
Cancel
Save