【操盘手】 流量分发修改及详情接口
This commit is contained in:
@@ -292,15 +292,15 @@ export default function TrafficDistributionPage() {
|
|||||||
<div className="bg-white">
|
<div className="bg-white">
|
||||||
<div className="grid grid-cols-3">
|
<div className="grid grid-cols-3">
|
||||||
<div className="p-3 text-center border-r border-gray-200">
|
<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 className="text-xs text-gray-500 mt-1">日均分发人数</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="p-3 text-center border-r border-gray-200">
|
<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 className="text-xs text-gray-500 mt-1">分发设备</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="p-3 text-center">
|
<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 className="text-xs text-gray-500 mt-1">流量池</div>
|
||||||
</div>
|
</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="border-t border-gray-200 mx-auto w-full" style={{height: 0}} />
|
||||||
<div className="grid grid-cols-2">
|
<div className="grid grid-cols-2">
|
||||||
<div className="p-3 text-center border-r border-gray-200">
|
<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 className="text-xs text-gray-500 mt-1">日均分发量</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="p-3 text-center">
|
<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 className="text-xs text-gray-500 mt-1">总流量池数量</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -129,6 +129,7 @@ class WorkbenchController extends Controller
|
|||||||
$config->startTime = $param['startTime'];
|
$config->startTime = $param['startTime'];
|
||||||
$config->endTime = $param['endTime'];
|
$config->endTime = $param['endTime'];
|
||||||
$config->devices = json_encode($param['devices'], JSON_UNESCAPED_UNICODE);
|
$config->devices = json_encode($param['devices'], JSON_UNESCAPED_UNICODE);
|
||||||
|
$config->pools = json_encode($param['pools'], JSON_UNESCAPED_UNICODE);
|
||||||
$config->createTime = time();
|
$config->createTime = time();
|
||||||
$config->updateTime = time();
|
$config->updateTime = time();
|
||||||
$config->save();
|
$config->save();
|
||||||
@@ -259,6 +260,13 @@ class WorkbenchController extends Controller
|
|||||||
$item->config = $item->trafficConfig;
|
$item->config = $item->trafficConfig;
|
||||||
$item->config->devices = json_decode($item->config->devices, true);
|
$item->config->devices = json_decode($item->config->devices, true);
|
||||||
$item->config->pools = json_decode($item->config->pools, 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);
|
unset($item->trafficConfig,$item->traffic_config);
|
||||||
break;
|
break;
|
||||||
@@ -304,6 +312,9 @@ class WorkbenchController extends Controller
|
|||||||
'momentsSync' => function($query) {
|
'momentsSync' => function($query) {
|
||||||
$query->field('workbenchId,syncInterval,syncCount,syncType,startTime,endTime,accountType,devices,contentLibraries');
|
$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) {
|
// 'groupPush' => function($query) {
|
||||||
// $query->field('workbenchId,pushInterval,pushContent,pushTime,devices,targetGroups');
|
// $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);
|
$workbench->config->targetGroups = json_decode($workbench->config->targetGroups, true);
|
||||||
}
|
}
|
||||||
break;
|
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);
|
unset($workbench->autoLike, $workbench->momentsSync, $workbench->groupPush, $workbench->groupCreate);
|
||||||
|
|
||||||
@@ -409,7 +436,6 @@ class WorkbenchController extends Controller
|
|||||||
['userId', '=', $this->request->userInfo['id']],
|
['userId', '=', $this->request->userInfo['id']],
|
||||||
['isDel', '=', 0]
|
['isDel', '=', 0]
|
||||||
])->find();
|
])->find();
|
||||||
|
|
||||||
if (!$workbench) {
|
if (!$workbench) {
|
||||||
return json(['code' => 404, 'msg' => '工作台不存在']);
|
return json(['code' => 404, 'msg' => '工作台不存在']);
|
||||||
}
|
}
|
||||||
@@ -484,6 +510,20 @@ class WorkbenchController extends Controller
|
|||||||
$config->save();
|
$config->save();
|
||||||
}
|
}
|
||||||
break;
|
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();
|
Db::commit();
|
||||||
|
|||||||
@@ -121,58 +121,29 @@ class WorkbenchAutoLikeJob
|
|||||||
protected function processAllFriends($workbench, $config, $page = 1, $pageSize = 100)
|
protected function processAllFriends($workbench, $config, $page = 1, $pageSize = 100)
|
||||||
{
|
{
|
||||||
$friendList = $this->getFriendList($config, $page, $pageSize);
|
$friendList = $this->getFriendList($config, $page, $pageSize);
|
||||||
|
|
||||||
if (empty($friendList)) {
|
if (empty($friendList)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 将好友列表分成20组
|
// 直接顺序处理所有好友
|
||||||
$friendGroups = array_chunk($friendList, 20);
|
foreach ($friendList as $friend) {
|
||||||
$processes = [];
|
// 验证是否达到点赞次数上限
|
||||||
|
$likeCount = $this->getTodayLikeCount($workbench, $config, $friend['deviceId']);
|
||||||
foreach ($friendGroups as $groupIndex => $friendGroup) {
|
if ($likeCount >= $config['maxLikes']) {
|
||||||
// 创建子进程
|
Log::info("工作台 {$workbench->id} 点赞次数已达上限");
|
||||||
$pid = pcntl_fork();
|
|
||||||
|
|
||||||
if ($pid == -1) {
|
|
||||||
// 创建进程失败
|
|
||||||
Log::error("工作台 {$workbench->id} 创建进程失败");
|
|
||||||
continue;
|
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) {
|
$friendMaxLikes = Db::name('workbench_auto_like_item')
|
||||||
pcntl_waitpid($pid, $status);
|
->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 = new WebSocketController(['userName' => $username, 'password' => $password, 'accountId' => $toAccountId]);
|
||||||
$webSocket->getMoments(['wechatFriendId' => $friend['friendId'], 'wechatAccountId' => $friend['wechatAccountId']]);
|
|
||||||
|
|
||||||
// 查询未点赞的朋友圈
|
// 查询未点赞的朋友圈
|
||||||
$moments = $this->getUnlikedMoments($friend['friendId']);
|
$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) {
|
if (empty($moments) || count($moments) == 0) {
|
||||||
// 处理完毕切换回原账号
|
// 处理完毕切换回原账号
|
||||||
$automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $friend['accountId']], true);
|
$automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $friend['accountId']], true);
|
||||||
@@ -262,6 +241,7 @@ class WorkbenchAutoLikeJob
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
foreach ($moments as $moment) {
|
foreach ($moments as $moment) {
|
||||||
// 点赞朋友圈
|
// 点赞朋友圈
|
||||||
$this->likeMoment($workbench, $config, $friend, $moment, $webSocket);
|
$this->likeMoment($workbench, $config, $friend, $moment, $webSocket);
|
||||||
@@ -298,7 +278,7 @@ class WorkbenchAutoLikeJob
|
|||||||
['wm.wechatFriendId', '=', $friendId],
|
['wm.wechatFriendId', '=', $friendId],
|
||||||
['wali.id', 'null', null]
|
['wali.id', 'null', null]
|
||||||
])
|
])
|
||||||
->where('wm.create_time', '>=', time() - 86400 * 2)
|
->where('wm.update_time', '>=', time() - 86400)
|
||||||
->field('wm.id, wm.snsId')
|
->field('wm.id, wm.snsId')
|
||||||
->group('wali.wechatFriendId')
|
->group('wali.wechatFriendId')
|
||||||
->order('wm.createTime DESC')
|
->order('wm.createTime DESC')
|
||||||
|
|||||||
Reference in New Issue
Block a user