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";