feat: 初始化雄戈商城服务端代码与Webhook自动部署配置
这个提交包含在:
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* 刷新分销团队统计(child_user_count* / child_agent_count*)
|
||||
*
|
||||
* 用法(在项目根目录):
|
||||
* php addons/shopro/refresh_commission_team_stats.php
|
||||
* php addons/shopro/refresh_commission_team_stats.php 910006
|
||||
*
|
||||
* 说明:Shopro 默认把统计任务投递到 shopro 队列;若守护进程未监听该队列,
|
||||
* 绑定/支付后团队人数可能不更新。本脚本可手动全量或指定用户刷新。
|
||||
*/
|
||||
|
||||
define('APP_PATH', __DIR__ . '/../../application/');
|
||||
require __DIR__ . '/../../thinkphp/base.php';
|
||||
|
||||
\think\App::initCommon();
|
||||
|
||||
use think\Db;
|
||||
use addons\shopro\library\commission\Agent;
|
||||
|
||||
$targetUserId = isset($argv[1]) ? intval($argv[1]) : 0;
|
||||
|
||||
function getUserDepth($userId)
|
||||
{
|
||||
$depth = 0;
|
||||
$visited = [];
|
||||
while ($userId > 0 && !isset($visited[$userId])) {
|
||||
$visited[$userId] = true;
|
||||
$parentId = intval(Db::name('user')->where('id', $userId)->value('parent_user_id'));
|
||||
if ($parentId <= 0) {
|
||||
break;
|
||||
}
|
||||
$depth++;
|
||||
$userId = $parentId;
|
||||
if ($depth > 50) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $depth;
|
||||
}
|
||||
|
||||
function refreshUserStats($userId)
|
||||
{
|
||||
$agent = new Agent($userId);
|
||||
if (!$agent->user) {
|
||||
return false;
|
||||
}
|
||||
$agent->runUpgradeAgentPlan(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($targetUserId > 0) {
|
||||
if (!refreshUserStats($targetUserId)) {
|
||||
echo "用户 {$targetUserId} 不存在\n";
|
||||
exit(1);
|
||||
}
|
||||
$user = Db::name('user')->where('id', $targetUserId)->field('child_user_count,child_user_count_1,child_user_count_2')->find();
|
||||
echo "已刷新用户 {$targetUserId}:团队 {$user['child_user_count']},直推 {$user['child_user_count_1']},间推 {$user['child_user_count_2']}\n";
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$userIds = Db::name('user')->column('id');
|
||||
usort($userIds, function ($a, $b) {
|
||||
return getUserDepth($b) <=> getUserDepth($a);
|
||||
});
|
||||
|
||||
$ok = 0;
|
||||
foreach ($userIds as $userId) {
|
||||
if (refreshUserStats($userId)) {
|
||||
$ok++;
|
||||
}
|
||||
}
|
||||
|
||||
echo "团队统计刷新完成,共处理 {$ok} 个用户\n";
|
||||
echo "请确认守护进程命令包含:php think queue:listen --queue shopro\n";
|
||||
在新工单中引用
屏蔽一个用户