Browse Source

chat

master
chuan 2 months ago
parent
commit
2a3ddb1d5a
  1. 2
      app/admin/service/AdminService.php
  2. 8
      app/home/controller/News.php
  3. 16
      app/home/service/LoginService.php
  4. 6
      app/home/service/UserService.php

2
app/admin/service/AdminService.php

@ -43,7 +43,7 @@ class AdminService extends AdminBaseService
'Username' => $resAdmin->id."_".$resAdmin->user_name, //用account.id + account.user_name 拼接作为聊天账号注册的Username
'Password' => '123456',
];
$chatUrl = env('CHAT_SERVER.BASE_URL') . '/user/register';
$chatUrl = env('CHAT_SERVER.BASE_URL') . '/api/user/register';
$regChat = (new \app\utility\RequestChatServer())->ReqChatServer($chatUrl, $chatData);
if (!isset($regChat['data']['uuid'])) {
Log::error('添加客服 - 创建聊天账号失败 chat_response=:'. json_encode($regChat));

8
app/home/controller/News.php

@ -2,6 +2,7 @@
namespace app\home\controller;
use app\model\CustomerRelationalModel;
use app\model\UserChatLinkModel;
use Goutte\Client;
use think\facade\Cache;
@ -93,8 +94,9 @@ class News extends HomeBaseController
*/
public function testApi()
{
$chatData = [
'Username' => "ccc333519",
'Username' => "ccc33351953",
'Password' => '123456',
];
$chatUrl = env('CHAT_SERVER.BASE_URL') . '/user/register';
@ -117,7 +119,9 @@ class News extends HomeBaseController
'code' => '0',
'message' => 'successful',
'data' => $res,
'uuid' => $res['data']['uuid']
'uuid' => $res['data']['uuid'],
'req_url' => $chatUrl,
'req_dat' => $chatData,
]);
}

16
app/home/service/LoginService.php

@ -164,6 +164,7 @@ class LoginService extends BaseHomeService
$salt = env('ENCRYPT.SALT');
$password = (new UnqId())->encryptPassword($param['password'], $salt);
$userInviteCode = $this->getUniqInviteCode();
Log::info("邮箱注册 - agentId=".$agentId);
// 需要开启事务
\think\facade\Db::transaction(function () use ($email, $userNo, $userInviteCode, $parentUserId, $password, $ip, $salt, $agentId) {
// 生成用户数据
@ -175,7 +176,7 @@ class LoginService extends BaseHomeService
'Username' => $userNo,
'Password' => '123456',
];
$chatUrl = env('CHAT_SERVER.BASE_URL') . '/user/register';
$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.', []);
@ -187,9 +188,11 @@ class LoginService extends BaseHomeService
'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', []);
}
@ -204,6 +207,7 @@ class LoginService extends BaseHomeService
$tagIndex = $counterIndex % count($customerIds);
$tagCustomerId = $customerIds[$tagIndex];
}
Log::info("邮箱注册 - 要绑定的客服id=".$tagCustomerId);
if ($tagCustomerId > 0) {
CustomerRelationalModel::create([
'user_id' => $userId,
@ -212,14 +216,16 @@ class LoginService extends BaseHomeService
]);
}
// 将注册账号的chat_id与绑定客服的chat_id加为好友
$customerChatInfo = UserChatLinkModel::where('user_id', $tagCustomerId)->find(); //查询客服的聊天账号uuid
if (empty($customerChatInfo) || !$customerChatInfo->chat_uuid) {
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));
@ -475,7 +481,7 @@ class LoginService extends BaseHomeService
'Username' => $userNo,
'Password' => '123456',
];
$chatUrl = env('CHAT_SERVER.BASE_URL') . '/user/register';
$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.', []);
@ -513,7 +519,7 @@ class LoginService extends BaseHomeService
}
// 将注册账号的chat_id与绑定客服的chat_id加为好友
$customerChatInfo = UserChatLinkModel::where('user_id', $tagCustomerId)->find(); //查询客服的聊天账号uuid
if (empty($customerChatInfo) || !$customerChatInfo->chat_uuid) {
if (empty($customerChatInfo)) {
return $this->toData('100400', 'The customer uuid is error.', []);
}
$chatFriendsData = [

6
app/home/service/UserService.php

@ -22,6 +22,7 @@ use app\utility\UnqId;
use Couchbase\User;
use think\exception\ValidateException;
use think\facade\Cache;
use think\facade\Log;
use think\facade\Queue;
class UserService extends BaseHomeService
@ -172,7 +173,7 @@ class UserService extends BaseHomeService
$customerChatName = "";
$customerRelationInfo = CustomerRelationalModel::where('user_id', $userId)->find(); //查询用户关联的客服账号信息
if ($customerRelationInfo) {
$customerChatInfo = UserChatLinkModel::where('user_id', $customerRelationInfo->customer_id)->find(); //查询客服的chat账号
$customerChatInfo = UserChatLinkModel::where(['user_id'=>$customerRelationInfo->customer_id, 'user_type'=>2])->find(); //查询客服的chat账号
if ($customerChatInfo) {
$customerChatUuid = $customerChatInfo->chat_uuid;
$customerChatName = $customerChatInfo->chat_name;
@ -204,7 +205,8 @@ class UserService extends BaseHomeService
'user_chat_uuid' => $userChatUuid,
'user_chat_name' => $userChatName,
'customer_chat_uuid' => $customerChatUuid,
'customer_chat_name' => $customerChatName
'customer_chat_name' => $customerChatName,
'customer_chat_avatar' => '/bs/image/default.jpeg'
]);
} catch (\Exception $exception) {
return $this->toData('100500', 'The system is busy.', [$exception->getMessage(), $exception->getTrace()]);

Loading…
Cancel
Save