| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- namespace App\Module\UrsPromotion\Commands;
- use Illuminate\Console\Command;
- use App\Module\UrsPromotion\Services\UrsTalentService;
- /**
- * URS达人等级测试命令
- *
- * 用于测试URS推广系统的达人等级功能
- */
- class TestUrsTalentCommand extends Command
- {
- /**
- * 命令签名
- */
- protected $signature = 'urs:test-talent {user_id}';
- /**
- * 命令描述
- */
- protected $description = '测试URS达人等级功能';
- /**
- * 执行命令
- */
- public function handle()
- {
- $userId = (int)$this->argument('user_id');
-
- $this->info("开始测试URS达人等级功能");
- $this->info("用户ID: {$userId}");
- $this->line('');
-
- // 显示当前达人信息
- $this->info("=== 当前达人信息 ===");
- $talent = UrsTalentService::getUserTalent($userId);
- if ($talent) {
- $this->line("达人等级: {$talent->getTalentLevelName()} (等级{$talent->talent_level})");
- $this->line("直推人数: {$talent->direct_count}");
- $this->line("间推人数: {$talent->indirect_count}");
- $this->line("三推人数: {$talent->third_count}");
- $this->line("团队总人数: {$talent->promotion_count}");
- } else {
- $this->line("用户暂无达人信息");
- }
- $this->line('');
-
- // 显示团队统计
- $this->info("=== 团队统计信息 ===");
- $stats = UrsTalentService::getUserTeamStats($userId);
- $this->line("直推: {$stats['direct_count']} 人");
- $this->line("间推: {$stats['indirect_count']} 人");
- $this->line("三推: {$stats['third_count']} 人");
- $this->line("总计: {$stats['promotion_count']} 人");
- $this->line("当前等级: {$stats['talent_level_name']}");
- $this->line('');
-
- // 更新达人等级
- $this->info("=== 更新达人等级 ===");
- $updatedTalent = UrsTalentService::updateUserTalent($userId);
- if ($updatedTalent) {
- $this->info("达人等级更新成功");
- $this->line("新等级: {$updatedTalent->getTalentLevelName()} (等级{$updatedTalent->talent_level})");
- $this->line("直推人数: {$updatedTalent->direct_count}");
- $this->line("间推人数: {$updatedTalent->indirect_count}");
- $this->line("三推人数: {$updatedTalent->third_count}");
- $this->line("团队总人数: {$updatedTalent->promotion_count}");
- } else {
- $this->error("达人等级更新失败");
- }
- $this->line('');
-
- // 显示推荐关系树
- $this->info("=== 推荐关系树 ===");
- $tree = UrsTalentService::getUserReferralTree($userId);
- $this->displayReferralTree($tree);
-
- $this->line('');
- $this->info("测试完成!");
- }
-
- /**
- * 显示推荐关系树
- */
- private function displayReferralTree(array $tree): void
- {
- $this->line("用户 {$tree['user_id']} 的团队结构:");
-
- if (!empty($tree['direct'])) {
- $this->line(" 直推用户 (" . count($tree['direct']) . "人):");
- foreach ($tree['direct'] as $user) {
- $this->line(" - 用户{$user['user_id']} (推荐时间: {$user['referral_time']})");
- }
- }
-
- if (!empty($tree['indirect'])) {
- $this->line(" 间推用户 (" . count($tree['indirect']) . "人):");
- foreach ($tree['indirect'] as $user) {
- $this->line(" - 用户{$user['user_id']} (通过用户{$user['referrer_id']}, 推荐时间: {$user['referral_time']})");
- }
- }
-
- if (!empty($tree['third'])) {
- $this->line(" 三推用户 (" . count($tree['third']) . "人):");
- foreach ($tree['third'] as $user) {
- $this->line(" - 用户{$user['user_id']} (通过用户{$user['referrer_id']}, 推荐时间: {$user['referral_time']})");
- }
- }
-
- if (empty($tree['direct']) && empty($tree['indirect']) && empty($tree['third'])) {
- $this->line(" 无团队成员");
- }
- }
- }
|