diff --git a/Cunkebao/app/workspace/traffic-distribution/page.tsx b/Cunkebao/app/workspace/traffic-distribution/page.tsx index fd9c21e9..85775f09 100644 --- a/Cunkebao/app/workspace/traffic-distribution/page.tsx +++ b/Cunkebao/app/workspace/traffic-distribution/page.tsx @@ -292,15 +292,15 @@ export default function TrafficDistributionPage() {
-
{plan.dailyAverage}
+
{plan.config.total.dailyAverage}
日均分发人数
-
{plan.deviceCount}
+
{plan.config.total.deviceCount}
分发设备
-
{plan.poolCount}
+
{plan.config.total.poolCount}
流量池
@@ -308,11 +308,11 @@ export default function TrafficDistributionPage() {
-
{plan.dailyAverage}
+
{plan.config.total.dailyAverage}
日均分发量
-
{plan.totalUsers}
+
{plan.config.total.totalUsers}
总流量池数量
diff --git a/Server/application/cunkebao/controller/WorkbenchController.php b/Server/application/cunkebao/controller/WorkbenchController.php index a9e07969..c4c03e09 100644 --- a/Server/application/cunkebao/controller/WorkbenchController.php +++ b/Server/application/cunkebao/controller/WorkbenchController.php @@ -129,6 +129,7 @@ class WorkbenchController extends Controller $config->startTime = $param['startTime']; $config->endTime = $param['endTime']; $config->devices = json_encode($param['devices'], JSON_UNESCAPED_UNICODE); + $config->pools = json_encode($param['pools'], JSON_UNESCAPED_UNICODE); $config->createTime = time(); $config->updateTime = time(); $config->save(); @@ -259,6 +260,13 @@ class WorkbenchController extends Controller $item->config = $item->trafficConfig; $item->config->devices = json_decode($item->config->devices, true); $item->config->pools = json_decode($item->config->pools, true); + $item->config->total = [ + 'dailyAverage' => 0, + 'deviceCount' => count($item->config->devices), + 'poolCount' => count($item->config->pools), + 'dailyAverage' => $item->config->maxPerDay, + 'totalUsers' => $item->config->maxPerDay * count($item->config->devices) * count($item->config->pools) + ]; } unset($item->trafficConfig,$item->traffic_config); break; @@ -304,6 +312,9 @@ class WorkbenchController extends Controller 'momentsSync' => function($query) { $query->field('workbenchId,syncInterval,syncCount,syncType,startTime,endTime,accountType,devices,contentLibraries'); }, + 'trafficConfig' => function($query) { + $query->field('workbenchId,distributeType,maxPerDay,timeType,startTime,endTime,devices,pools'); + }, // 'groupPush' => function($query) { // $query->field('workbenchId,pushInterval,pushContent,pushTime,devices,targetGroups'); // }, @@ -378,6 +389,22 @@ class WorkbenchController extends Controller $workbench->config->targetGroups = json_decode($workbench->config->targetGroups, true); } break; + case self::TYPE_TRAFFIC_DISTRIBUTION: + if (!empty($workbench->trafficConfig)) { + $workbench->config = $workbench->trafficConfig; + $workbench->config->devices = json_decode($workbench->config->devices, true); + $workbench->config->pools = json_decode($workbench->config->pools, true); + $workbench->config->total = [ + 'dailyAverage' => 0, + 'deviceCount' => count($workbench->config->devices), + 'poolCount' => count($workbench->config->pools ), + 'dailyAverage' => $workbench->config->maxPerDay, + 'totalUsers' => $workbench->config->maxPerDay * count($workbench->config->devices) * count($workbench->config->pools) + + ]; + unset($workbench->trafficConfig,$workbench->traffic_config); + } + break; } unset($workbench->autoLike, $workbench->momentsSync, $workbench->groupPush, $workbench->groupCreate); @@ -409,7 +436,6 @@ class WorkbenchController extends Controller ['userId', '=', $this->request->userInfo['id']], ['isDel', '=', 0] ])->find(); - if (!$workbench) { return json(['code' => 404, 'msg' => '工作台不存在']); } @@ -484,6 +510,20 @@ class WorkbenchController extends Controller $config->save(); } break; + case self::TYPE_TRAFFIC_DISTRIBUTION: + $config = WorkbenchTrafficDistribution::where('workbenchId', $param['id'])->find(); + if ($config) { + $config->distributeType = $param['distributeType']; + $config->maxPerDay = $param['maxPerDay']; + $config->timeType = $param['timeType']; + $config->startTime = $param['startTime']; + $config->endTime = $param['endTime']; + $config->devices = json_encode($param['devices']); + $config->pools = json_encode($param['pools']); + $config->updateTime = time(); + $config->save(); + } + break; } Db::commit(); diff --git a/Server/application/job/WorkbenchAutoLikeJob.php b/Server/application/job/WorkbenchAutoLikeJob.php index 058dd243..58e013b4 100644 --- a/Server/application/job/WorkbenchAutoLikeJob.php +++ b/Server/application/job/WorkbenchAutoLikeJob.php @@ -121,58 +121,29 @@ class WorkbenchAutoLikeJob protected function processAllFriends($workbench, $config, $page = 1, $pageSize = 100) { $friendList = $this->getFriendList($config, $page, $pageSize); + if (empty($friendList)) { return; } - // 将好友列表分成20组 - $friendGroups = array_chunk($friendList, 20); - $processes = []; - - foreach ($friendGroups as $groupIndex => $friendGroup) { - // 创建子进程 - $pid = pcntl_fork(); - - if ($pid == -1) { - // 创建进程失败 - Log::error("工作台 {$workbench->id} 创建进程失败"); + // 直接顺序处理所有好友 + foreach ($friendList as $friend) { + // 验证是否达到点赞次数上限 + $likeCount = $this->getTodayLikeCount($workbench, $config, $friend['deviceId']); + if ($likeCount >= $config['maxLikes']) { + Log::info("工作台 {$workbench->id} 点赞次数已达上限"); continue; - } else if ($pid) { - // 父进程 - $processes[] = $pid; - } else { - // 子进程 - try { - foreach ($friendGroup as $friend) { - // 验证是否达到点赞次数上限 - $likeCount = $this->getTodayLikeCount($workbench, $config, $friend['deviceId']); - if ($likeCount >= $config['maxLikes']) { - Log::info("工作台 {$workbench->id} 点赞次数已达上限"); - continue; - } - - // 验证是否达到好友点赞次数上限 - $friendMaxLikes = Db::name('workbench_auto_like_item') - ->where('workbenchId', $workbench->id) - ->where('wechatFriendId', $friend['friendId']) - ->count(); - - if ($friendMaxLikes < $config['friendMaxLikes']) { - $this->processFriendMoments($workbench, $config, $friend); - } - } - } catch (\Exception $e) { - Log::error("工作台 {$workbench->id} 子进程异常: " . $e->getMessage()); - } - - // 子进程执行完毕后退出 - exit(0); } - } - // 等待所有子进程完成 - foreach ($processes as $pid) { - pcntl_waitpid($pid, $status); + // 验证是否达到好友点赞次数上限 + $friendMaxLikes = Db::name('workbench_auto_like_item') + ->where('workbenchId', $workbench->id) + ->where('wechatFriendId', $friend['friendId']) + ->count(); + + if ($friendMaxLikes < $config['friendMaxLikes']) { + $this->processFriendMoments($workbench, $config, $friend); + } } // 如果当前页数据量等于页大小,说明可能还有更多数据,继续处理下一页 @@ -251,10 +222,18 @@ class WorkbenchAutoLikeJob // 执行采集朋友圈命令 $webSocket = new WebSocketController(['userName' => $username, 'password' => $password, 'accountId' => $toAccountId]); - $webSocket->getMoments(['wechatFriendId' => $friend['friendId'], 'wechatAccountId' => $friend['wechatAccountId']]); - + // 查询未点赞的朋友圈 $moments = $this->getUnlikedMoments($friend['friendId']); + if (empty($moments) || count($moments) == 0) { + //采集最新朋友圈 + $webSocket->getMoments(['wechatFriendId' => $friend['friendId'], 'wechatAccountId' => $friend['wechatAccountId']]); + $moments = $this->getUnlikedMoments($friend['friendId']); + } + + + + if (empty($moments) || count($moments) == 0) { // 处理完毕切换回原账号 $automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $friend['accountId']], true); @@ -262,6 +241,7 @@ class WorkbenchAutoLikeJob return; } + foreach ($moments as $moment) { // 点赞朋友圈 $this->likeMoment($workbench, $config, $friend, $moment, $webSocket); @@ -298,7 +278,7 @@ class WorkbenchAutoLikeJob ['wm.wechatFriendId', '=', $friendId], ['wali.id', 'null', null] ]) - ->where('wm.create_time', '>=', time() - 86400 * 2) + ->where('wm.update_time', '>=', time() - 86400) ->field('wm.id, wm.snsId') ->group('wali.wechatFriendId') ->order('wm.createTime DESC')