chuan 2 months ago
parent
commit
d3db4e4cbf
  1. 55
      app/admin/service/AdminService.php
  2. 9
      app/admin/service/AgentService.php
  3. 9
      app/home/controller/News.php
  4. 6
      app/home/controller/User.php
  5. 2
      app/home/route/app.php
  6. 16
      app/home/service/LoginService.php
  7. 46
      app/home/service/UserService.php
  8. 6
      app/model/UserChatGroupModel.php

55
app/admin/service/AdminService.php

@ -7,6 +7,7 @@ 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\UserChatGroupModel;
use app\model\UserChatLinkModel; use app\model\UserChatLinkModel;
use phpDocumentor\Reflection\Type; use phpDocumentor\Reflection\Type;
use think\exception\ValidateException; use think\exception\ValidateException;
@ -35,28 +36,40 @@ class AdminService extends AdminBaseService
$resAdmin = AdminModel::create($param); $resAdmin = AdminModel::create($param);
// 如果是客服账号,需要注册一下聊天账号 // 注册一下聊天账号
$regChat = []; $chatData = [
if (isset($param['parent_id']) && $param['parent_id'] > 0) { 'Username' => $resAdmin->id."_".$resAdmin->user_name, //用account.id + account.user_name 拼接作为聊天账号注册的Username
Log::info('创建客服账号 - parent_id='. $param['parent_id']); 'Password' => '123456',
$chatData = [ ];
'Username' => $resAdmin->id."_".$resAdmin->user_name, //用account.id + account.user_name 拼接作为聊天账号注册的Username $chatUrl = env('CHAT_SERVER.BASE_URL') . '/api/user/register';
'Password' => '123456', $regChat = (new \app\utility\RequestChatServer())->ReqChatServer($chatUrl, $chatData);
]; if (!isset($regChat['data']['uuid'])) {
$chatUrl = env('CHAT_SERVER.BASE_URL') . '/api/user/register'; return $this->toData('0', '注册聊天账号失败.', ['chat_response' => $regChat]);
$regChat = (new \app\utility\RequestChatServer())->ReqChatServer($chatUrl, $chatData); }
if (!isset($regChat['data']['uuid'])) { UserChatLinkModel::create([
Log::error('添加客服 - 创建聊天账号失败 chat_response=:'. json_encode($regChat)); 'user_id' => $resAdmin->id,
return $this->toData('0', '注册聊天账号失败.', ['chat_response' => $regChat]); 'user_type' => 2,
} 'chat_uuid' => $regChat['data']['uuid'],
//将客服账号与聊天账号关联 'chat_name' => $regChat['data']['username']
UserChatLinkModel::create([ ]);
'user_id' => $resAdmin->id,
'user_type' => 2, // 创建聊天群
'chat_uuid' => $regChat['data']['uuid'], $groupName = 'ivs-group'.$resAdmin->id;
'chat_name' => $regChat['data']['username'] $chatGroupData = [
]); 'Name' => $groupName,
];
$chatGroupUrl = env('CHAT_SERVER.BASE_URL') . '/api/group/join/'.$regChat['data']['uuid'];
$chatGroupRes = (new \app\utility\RequestChatServer())->ReqChatServer($chatGroupUrl, $chatGroupData);
if (!isset($chatGroupRes['data']['group_uuid'])) {
return $this->toData('100400', 'Failed to register a chat group.', []);
} }
UserChatGroupModel::create([
'user_id' => $resAdmin->id,
'user_chat_uuid' => $regChat['data']['uuid'],
'group_name' => $groupName,
'group_uuid' => $chatGroupRes['data']['group_uuid']
]);
return $this->toData('0', '添加成功.', ['chatData' => $regChat]); return $this->toData('0', '添加成功.', ['chatData' => $regChat]);
} catch (ValidateException $validateException) { } catch (ValidateException $validateException) {

9
app/admin/service/AgentService.php

@ -270,6 +270,9 @@ class AgentService extends AdminBaseService
if (empty($param['play_url'])) { if (empty($param['play_url'])) {
return $this->toData('1', 'Missing param play_url'); return $this->toData('1', 'Missing param play_url');
} }
if (empty($param['agent_id'])) {
return $this->toData('1', 'Missing param agent_id');
}
$res = AwsIvsModel::create([ $res = AwsIvsModel::create([
'title' => $param['title'], 'title' => $param['title'],
'anchor_name' => $param['anchor_name'], 'anchor_name' => $param['anchor_name'],
@ -277,7 +280,8 @@ class AgentService extends AdminBaseService
'desc' => $param['desc'], 'desc' => $param['desc'],
'push_url' => $param['push_url'], 'push_url' => $param['push_url'],
'secret_key' => $param['secret_key'], 'secret_key' => $param['secret_key'],
'play_url' => $param['play_url'] 'play_url' => $param['play_url'],
'agent_id' => $param['agent_id']
]); ]);
return $this->toData('0', 'SUCCESS', ['id' => $res->id]); return $this->toData('0', 'SUCCESS', ['id' => $res->id]);
} catch (\Exception $exception) { } catch (\Exception $exception) {
@ -309,6 +313,9 @@ class AgentService extends AdminBaseService
if (empty($param['play_url'])) { if (empty($param['play_url'])) {
return $this->toData('1', 'Missing param play_url'); return $this->toData('1', 'Missing param play_url');
} }
if (empty($param['agent_id'])) {
return $this->toData('1', 'Missing param agent_id');
}
// 检查是否存在数据 // 检查是否存在数据
$ckInfo = AwsIvsModel::where('id', $param['id'])->find(); $ckInfo = AwsIvsModel::where('id', $param['id'])->find();
if (empty($ckInfo)) { if (empty($ckInfo)) {

9
app/home/controller/News.php

@ -96,10 +96,10 @@ class News extends HomeBaseController
{ {
$chatData = [ $chatData = [
'Username' => "ccc33351953", 'Username' => "20_agent",
'Password' => '123456', 'Password' => '123456',
]; ];
$chatUrl = env('CHAT_SERVER.BASE_URL') . '/user/register'; $chatUrl = env('CHAT_SERVER.BASE_URL') . '/api/user/register';
$res = (new \app\utility\RequestChatServer())->ReqChatServer($chatUrl, $chatData); $res = (new \app\utility\RequestChatServer())->ReqChatServer($chatUrl, $chatData);
if (!isset($res['data']['uuid'])) { if (!isset($res['data']['uuid'])) {
return json([ return json([
@ -110,9 +110,10 @@ class News extends HomeBaseController
//将客服账号与聊天账号关联 //将客服账号与聊天账号关联
UserChatLinkModel::create([ UserChatLinkModel::create([
'user_id' => 999, 'user_id' => 20,
'user_type' => 1, 'user_type' => 2,
'chat_uuid' => $res['data']['uuid'], 'chat_uuid' => $res['data']['uuid'],
'chat_name' => $res['data']['username']
]); ]);
return json([ return json([

6
app/home/controller/User.php

@ -19,6 +19,12 @@ class User extends HomeBaseController
return json($returnData); return json($returnData);
} }
public function getAnchorForAgent(): Json
{
$returnData = (new UserService())->getAnchorForAgent($this->request->userId);
return json($returnData);
}
/** /**
* @desc 设置用户国家 * @desc 设置用户国家
* @return Json * @return Json

2
app/home/route/app.php

@ -178,6 +178,8 @@ Route::group('/',function (){
Route::post('user/get_time', 'User/getTime'); Route::post('user/get_time', 'User/getTime');
// 获取用户基础信息 // 获取用户基础信息
Route::post('user/info', 'User/getUserInfo'); Route::post('user/info', 'User/getUserInfo');
// 获取用户的代理创建的群聊信息
Route::post('user/get_anchor_for_agent', 'User/getAnchorForAgent');
// 获取登陆记录 // 获取登陆记录
Route::post('user/login_log', 'User/loginLog'); Route::post('user/login_log', 'User/loginLog');
// 退出登陆 // 退出登陆

16
app/home/service/LoginService.php

@ -7,6 +7,7 @@ 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\CustomerRelationalModel;
use app\model\UserChatGroupModel;
use app\model\UserChatLinkModel; use app\model\UserChatLinkModel;
use app\model\UserModel; use app\model\UserModel;
use app\utility\Jwt; use app\utility\Jwt;
@ -229,6 +230,14 @@ class LoginService extends BaseHomeService
$chatFriendsUrl = env('CHAT_SERVER.BASE_URL') . '/api/eachOtherFriends'; $chatFriendsUrl = env('CHAT_SERVER.BASE_URL') . '/api/eachOtherFriends';
$chatFriendsRes = (new \app\utility\RequestChatServer())->ReqChatServer($chatFriendsUrl, $chatFriendsData); $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])->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, []);
} }
}); });
// 删除缓存 // 删除缓存
@ -529,6 +538,13 @@ class LoginService extends BaseHomeService
$chatFriendsUrl = env('CHAT_SERVER.BASE_URL') . '/api/eachOtherFriends'; $chatFriendsUrl = env('CHAT_SERVER.BASE_URL') . '/api/eachOtherFriends';
$chatFriendsRes = (new \app\utility\RequestChatServer())->ReqChatServer($chatFriendsUrl, $chatFriendsData); $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])->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, []);
} }
}); });

46
app/home/service/UserService.php

@ -6,6 +6,7 @@ use app\home\validate\UserValidate;
use app\model\CountryModel; use app\model\CountryModel;
use app\model\CustomerRelationalModel; use app\model\CustomerRelationalModel;
use app\model\FileModel; use app\model\FileModel;
use app\model\UserChatGroupModel;
use app\model\UserChatLinkModel; use app\model\UserChatLinkModel;
use app\model\UserContractModel; use app\model\UserContractModel;
use app\model\UserDigitalModel; use app\model\UserDigitalModel;
@ -133,7 +134,7 @@ class UserService extends BaseHomeService
return $this->toData('100403', 'Please log in first', []); return $this->toData('100403', 'Please log in first', []);
} }
$info = UserModel::getFieldsByUserId('trade_password,lever_status,gender,last_name,first_name,real_status,country_id,user_no,nick_name,email,phone_number,country_code,is_real,head_img_id,invite_code,is_test_user', $userId); $info = UserModel::getFieldsByUserId('trade_password,lever_status,gender,last_name,first_name,real_status,country_id,user_no,nick_name,email,phone_number,country_code,agent_id,is_real,head_img_id,invite_code,is_test_user', $userId);
if (empty($info)) { if (empty($info)) {
return $this->toData('100400', 'The user does not exist.', []); return $this->toData('100400', 'The user does not exist.', []);
} }
@ -179,7 +180,17 @@ class UserService extends BaseHomeService
$customerChatName = $customerChatInfo->chat_name; $customerChatName = $customerChatInfo->chat_name;
} }
} }
// 获取当前用户代理创建的群聊信息
$group_chat_name = "";
$group_chat_uuid = "";
if ($info['agent_id']) {
$agentGroup = UserChatGroupModel::where(['user_id'=>$info['agent_id']])->find();
if (empty($agentGroup)) {
return $this->toData('100400', 'Agent chat group is null.', []);
}
$group_chat_name = $agentGroup->group_name;
$group_chat_uuid = $agentGroup->group_uuid;
}
// 返回数据 // 返回数据
return $this->toData('0', 'Modification successful.', [ return $this->toData('0', 'Modification successful.', [
@ -206,13 +217,42 @@ class UserService extends BaseHomeService
'user_chat_name' => $userChatName, 'user_chat_name' => $userChatName,
'customer_chat_uuid' => $customerChatUuid, 'customer_chat_uuid' => $customerChatUuid,
'customer_chat_name' => $customerChatName, 'customer_chat_name' => $customerChatName,
'customer_chat_avatar' => '/bs/image/default.jpeg' 'customer_chat_avatar' => '/bs/image/default.jpeg',
'group_chat_name' => $group_chat_name,
'group_chat_uuid' => $group_chat_uuid,
]); ]);
} 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()]);
} }
} }
// 查询代理下的一个主播信息
public function getAnchorForAgent($userId)
{
try {
if (empty($userId) || $userId <= 0) {
return $this->toData('100403', 'Please log in first', []);
}
// 查询用户所属的代理id
$info = UserModel::getFieldsByUserId('trade_password,lever_status,gender,last_name,first_name,real_status,country_id,user_no,nick_name,email,phone_number,country_code,agent_id,is_real,head_img_id,invite_code,is_test_user', $userId);
if (empty($info)) {
return $this->toData('100400', 'The user does not exist.', []);
}
if (empty($info['agent_id'])) {
return $this->toData('100400', 'The user does not have a agent.', []);
}
// 查询代理下的一个主播信息
$agentGroup = UserChatGroupModel::where(['user_id'=>$info['agent_id']])->find()->toArray();
if (empty($agentGroup)) {
return $this->toData('100400', 'The chat group is error.', []);
}
return $this->toData('0', 'Modification successful.', $agentGroup);
} catch (\Exception $exception) {
return $this->toData('100500', 'The system is busy.', [$exception->getMessage(), $exception->getTrace()]);
}
}
/** /**
* @desc 设置用户国家 * @desc 设置用户国家
* @param $userId * @param $userId

6
app/model/UserChatGroupModel.php

@ -0,0 +1,6 @@
<?php
namespace app\model;
class UserChatGroupModel extends BaseModel
{
protected $name = 'user_chat_group';
}
Loading…
Cancel
Save