From f38576ca8f6751625c0d25f7fbed2f27a4a78631 Mon Sep 17 00:00:00 2001 From: wong <106998207@qq.com> Date: Wed, 11 Jun 2025 15:31:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WorkbenchController.php | 21 ++++++++++------- .../job/WorkbenchTrafficDistributeJob.php | 23 +++++++++++-------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/Server/application/cunkebao/controller/WorkbenchController.php b/Server/application/cunkebao/controller/WorkbenchController.php index 319248b0..cd031c60 100644 --- a/Server/application/cunkebao/controller/WorkbenchController.php +++ b/Server/application/cunkebao/controller/WorkbenchController.php @@ -290,13 +290,18 @@ class WorkbenchController extends Controller ['wf.isDeleted', '=', 0], ['sa.departmentId', '=', $item->companyId] ]) - ->whereIn('wa.currentDeviceId', $item->config->devices) - ->field('wf.id,wf.wechatAccountId,wf.wechatId,wf.labels,sa.userName,wa.currentDeviceId as deviceId') - ->where(function ($q) use ($labels) { - foreach ($labels as $label) { - $q->whereOrRaw("JSON_CONTAINS(wf.labels, '\"{$label}\"')"); - } - })->count(); + ->whereIn('wa.currentDeviceId', $item->config->devices); + + if(!empty($labels) && count($labels) > 0){ + $totalUsers = $totalUsers->where(function ($q) use ($labels) { + foreach ($labels as $label) { + $q->whereOrRaw("JSON_CONTAINS(wf.labels, '\"{$label}\"')"); + } + }); + } + + $totalUsers = $totalUsers->count(); + $totalAccounts = count($item->config->account); @@ -315,7 +320,7 @@ class WorkbenchController extends Controller 'dailyAverage' => intval($dailyAverage), 'totalAccounts' => $totalAccounts, 'deviceCount' => count($item->config->devices), - 'poolCount' => count($item->config->pools), + 'poolCount' => !empty($item->config->pools) ? count($item->config->pools) : 'ALL', 'totalUsers' => $totalUsers >> 0 ]; } diff --git a/Server/application/job/WorkbenchTrafficDistributeJob.php b/Server/application/job/WorkbenchTrafficDistributeJob.php index 88c03df9..d99684cf 100644 --- a/Server/application/job/WorkbenchTrafficDistributeJob.php +++ b/Server/application/job/WorkbenchTrafficDistributeJob.php @@ -90,9 +90,6 @@ class WorkbenchTrafficDistributeJob ->select(); - print_r($accounts); - exit; - $accountNum = count($accounts); if ($accountNum < 1) { Log::info("流量分发工作台 {$workbench->id} 可分配账号少于1个"); @@ -101,6 +98,7 @@ class WorkbenchTrafficDistributeJob $automaticAssign = new AutomaticAssign(); do { $friends = $this->getFriendsByLabels($workbench, $config, $page, $pageSize); + if (empty($friends) || count($friends) == 0) { Log::info("流量分发工作台 {$workbench->id} 没有可分配的好友"); break; @@ -186,11 +184,12 @@ class WorkbenchTrafficDistributeJob if (!empty($config['pools'])) { $labels = is_array($config['pools']) ? $config['pools'] : json_decode($config['pools'], true); } + $devices = []; if (!empty($config['devices'])) { $devices = is_array($config['devices']) ? $config['devices'] : json_decode($config['devices'], true); } - if (empty($labels) || empty($devices)) { + if (empty($devices)) { return []; } $query = Db::table('s2_wechat_friend')->alias('wf') @@ -199,17 +198,21 @@ class WorkbenchTrafficDistributeJob ->join('workbench_traffic_config_item wtci', 'wtci.wechatFriendId = wf.id AND wtci.workbenchId = ' . $config['workbenchId'], 'left') ->where([ ['wf.isDeleted', '=', 0], - ['sa.departmentId', '=', $workbench->companyId], + //['sa.departmentId', '=', $workbench->companyId], ['wtci.id', 'null', null] ]) ->whereIn('wa.currentDeviceId', $devices) ->field('wf.id,wf.wechatAccountId,wf.wechatId,wf.labels,sa.userName,wa.currentDeviceId as deviceId'); - $query->where(function ($q) use ($labels) { - foreach ($labels as $label) { - $q->whereOrRaw("JSON_CONTAINS(wf.labels, '\"{$label}\"')"); - } - }); + + if(!empty($labels)){ + $query->where(function ($q) use ($labels) { + foreach ($labels as $label) { + $q->whereOrRaw("JSON_CONTAINS(wf.labels, '\"{$label}\"')"); + } + }); + } $list = $query->page($page, $pageSize)->order('wf.id DESC')->select(); + return $list; }