【操盘手】 流量分发修改及详情接口

This commit is contained in:
wong
2025-05-28 15:45:08 +08:00
parent f5ea0add60
commit d6b34aa431
3 changed files with 74 additions and 54 deletions

View File

@@ -292,15 +292,15 @@ export default function TrafficDistributionPage() {
<div className="bg-white">
<div className="grid grid-cols-3">
<div className="p-3 text-center border-r border-gray-200">
<div className="text-lg font-semibold">{plan.dailyAverage}</div>
<div className="text-lg font-semibold">{plan.config.total.dailyAverage}</div>
<div className="text-xs text-gray-500 mt-1"></div>
</div>
<div className="p-3 text-center border-r border-gray-200">
<div className="text-lg font-semibold">{plan.deviceCount}</div>
<div className="text-lg font-semibold">{plan.config.total.deviceCount}</div>
<div className="text-xs text-gray-500 mt-1"></div>
</div>
<div className="p-3 text-center">
<div className="text-lg font-semibold">{plan.poolCount}</div>
<div className="text-lg font-semibold">{plan.config.total.poolCount}</div>
<div className="text-xs text-gray-500 mt-1"></div>
</div>
</div>
@@ -308,11 +308,11 @@ export default function TrafficDistributionPage() {
<div className="border-t border-gray-200 mx-auto w-full" style={{height: 0}} />
<div className="grid grid-cols-2">
<div className="p-3 text-center border-r border-gray-200">
<div className="text-lg font-semibold">{plan.dailyAverage}</div>
<div className="text-lg font-semibold">{plan.config.total.dailyAverage}</div>
<div className="text-xs text-gray-500 mt-1"></div>
</div>
<div className="p-3 text-center">
<div className="text-lg font-semibold">{plan.totalUsers}</div>
<div className="text-lg font-semibold">{plan.config.total.totalUsers}</div>
<div className="text-xs text-gray-500 mt-1"></div>
</div>
</div>

View File

@@ -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();

View File

@@ -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')