流量分发优化

This commit is contained in:
wong
2025-07-15 11:06:52 +08:00
parent 9736416fff
commit c08b9b0b26

View File

@@ -58,7 +58,7 @@ class WorkbenchTrafficDistributeJob
protected function processSingleWorkbench($workbench)
{
$page = 1;
$pageSize = 100;
$pageSize = 20;
$config = WorkbenchTrafficConfig::where('workbenchId', $workbench->id)->find();
if (!$config) {
@@ -89,8 +89,6 @@ class WorkbenchTrafficDistributeJob
->group('a.id')
->having('todayCount <= ' . $config['maxPerDay'])
->select();
$accountNum = count($accounts);
if ($accountNum < 1) {
Log::info("流量分发工作台 {$workbench->id} 可分配账号少于1个");
@@ -134,29 +132,33 @@ class WorkbenchTrafficDistributeJob
}
// 执行切换好友命令
$automaticAssign->allotWechatFriend([
$res = $automaticAssign->allotWechatFriend([
'wechatFriendId' => $friend['id'],
'toAccountId' => $account['id']
], true);
Db::table('s2_wechat_friend')
->where('id',$friend['id'])
->update([
'accountId' => $account['id'],
'accountUserName' => $account['userName'],
'accountRealName' => $account['realName'],
'accountNickname' => $account['nickname'],
$res = json_decode($res,true);
if ($res['code'] == 200){
Db::table('s2_wechat_friend')
->where('id',$friend['id'])
->update([
'accountId' => $account['id'],
'accountUserName' => $account['userName'],
'accountRealName' => $account['realName'],
'accountNickname' => $account['nickname'],
]);
// 写入分配记录表
Db::name('workbench_traffic_config_item')->insert([
'workbenchId' => $workbench->id,
'deviceId' => $friend['deviceId'],
'wechatFriendId' => $friend['id'],
'wechatAccountId' => $account['id'],
'createTime' => time(),
'exp' => $config['exp'],
'expTime' => time() + 86400 * $config['exp'],
]);
Log::info("流量分发工作台 {$workbench->id} 好友[{$friend['id']}]分配给客服[{$account['id']}] 成功");
// 写入分配记录表
Db::name('workbench_traffic_config_item')->insert([
'workbenchId' => $workbench->id,
'deviceId' => $friend['deviceId'],
'wechatFriendId' => $friend['id'],
'wechatAccountId' => $account['id'],
'createTime' => time(),
'exp' => $config['exp'],
'expTime' => time() + 86400 * $config['exp'],
]);
Log::info("流量分发工作台 {$workbench->id} 好友[{$friend['id']}]分配给客服[{$account['id']}] 成功");
}
$i++;
}
break;
@@ -206,24 +208,16 @@ class WorkbenchTrafficDistributeJob
$query = Db::table('s2_wechat_friend')->alias('wf')
->join(['s2_company_account' => 'sa'], 'sa.id = wf.accountId', 'left')
->join(['s2_wechat_account' => 'wa'], 'wa.id = wf.wechatAccountId', 'left')
->join('workbench_traffic_config_item wtci', 'wtci.wechatFriendId = wf.id AND wtci.workbenchId = ' . $config['workbenchId'], 'left')
->join('workbench_traffic_config_item wtci', 'wtci.isRecycle = 0 and wtci.wechatFriendId = wf.id AND wtci.workbenchId = ' . $config['workbenchId'], 'left')
->where([
['wf.isDeleted', '=', 0],
['wf.isDeleted', '=', 0],
['wf.isPassed', '=', 1],
//['sa.departmentId', '=', $workbench->companyId],
['wtci.expTime', '>', time()],
['wtci.id', 'null', null]
])
->whereIn('wa.currentDeviceId', $devices)
->field('wf.id,wf.wechatAccountId,wf.wechatId,wf.labels,sa.userName,wa.currentDeviceId as deviceId');
//lllll
if($workbench->id == 65){
$query->where('wf.accountId',1602);
}
if(!empty($labels)){
$query->where(function ($q) use ($labels) {