好友切换

This commit is contained in:
wong
2026-01-13 10:20:33 +08:00
parent 9eeaaa70c4
commit 3e8b607948
5 changed files with 333 additions and 29 deletions

View File

@@ -3,6 +3,7 @@
namespace app\api\controller;
use app\api\model\WechatMessageModel;
use app\common\service\FriendTransferService;
use think\Db;
use think\facade\Request;
@@ -389,38 +390,17 @@ class MessageController extends BaseController
if ($item['msgType'] == 10000 && strpos($item['content'],'开启了朋友验证') !== false) {
Db::table('s2_wechat_friend')->where('id',$item['wechatFriendId'])->update(['isDeleted'=> 1,'deleteTime' => $wechatTime]);
}else{
//优先分配在线客服
//优先分配在线客服 - 使用新的好友迁移服务
$friend = Db::table('s2_wechat_friend')->where('id',$item['wechatFriendId'])->find();
if (!empty($friend)){
$accountId = $item['accountId'];
$accountData = Db::table('s2_company_account')->where('id',$accountId)->find();
if (!empty($accountData)){
$account = new AccountController();
$account->getlist(['pageIndex' => 0,'pageSize' => 100,'departmentId' => $accountData['departmentId']]);
$accountIds = Db::table('s2_company_account')->where(['departmentId' => $accountData['departmentId'],'alive' => 1])->column('id');
if (!empty($accountIds)){
if (!in_array($friend['accountId'],$accountIds)){
// 执行切换好友命令
$randomKey = array_rand($accountIds, 1);
$toAccountId = $accountIds[$randomKey];
$toAccountData = Db::table('s2_company_account')->where('id',$toAccountId)->find();
$automaticAssign = new AutomaticAssign();
$automaticAssign->allotWechatFriend([
'wechatFriendId' => $friend['id'],
'toAccountId' => $toAccountId
], true);
Db::table('s2_wechat_friend')
->where('id',$friend['id'])
->update([
'accountId' => $toAccountId,
'accountUserName' => $toAccountData['userName'],
'accountRealName' => $toAccountData['realName'],
'accountNickname' => $toAccountData['nickname'],
]);
}
}
}
$friendTransferService = new FriendTransferService();
$result = $friendTransferService->transferFriend(
$item['wechatFriendId'],
$accountId,
'账号不在线,自动迁移到在线账号'
);
// 迁移结果已记录在服务中,这里不需要额外处理
}
}