TestUrsTalentCommand.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace App\Module\UrsPromotion\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Module\UrsPromotion\Services\UrsTalentService;
  5. /**
  6. * URS达人等级测试命令
  7. *
  8. * 用于测试URS推广系统的达人等级功能
  9. */
  10. class TestUrsTalentCommand extends Command
  11. {
  12. /**
  13. * 命令签名
  14. */
  15. protected $signature = 'urs:test-talent {user_id}';
  16. /**
  17. * 命令描述
  18. */
  19. protected $description = '测试URS达人等级功能';
  20. /**
  21. * 执行命令
  22. */
  23. public function handle()
  24. {
  25. $userId = (int)$this->argument('user_id');
  26. $this->info("开始测试URS达人等级功能");
  27. $this->info("用户ID: {$userId}");
  28. $this->line('');
  29. // 显示当前达人信息
  30. $this->info("=== 当前达人信息 ===");
  31. $talent = UrsTalentService::getUserTalent($userId);
  32. if ($talent) {
  33. $this->line("达人等级: {$talent->getTalentLevelName()} (等级{$talent->talent_level})");
  34. $this->line("直推人数: {$talent->direct_count}");
  35. $this->line("间推人数: {$talent->indirect_count}");
  36. $this->line("三推人数: {$talent->third_count}");
  37. $this->line("团队总人数: {$talent->promotion_count}");
  38. } else {
  39. $this->line("用户暂无达人信息");
  40. }
  41. $this->line('');
  42. // 显示团队统计
  43. $this->info("=== 团队统计信息 ===");
  44. $stats = UrsTalentService::getUserTeamStats($userId);
  45. $this->line("直推: {$stats['direct_count']} 人");
  46. $this->line("间推: {$stats['indirect_count']} 人");
  47. $this->line("三推: {$stats['third_count']} 人");
  48. $this->line("总计: {$stats['promotion_count']} 人");
  49. $this->line("当前等级: {$stats['talent_level_name']}");
  50. $this->line('');
  51. // 更新达人等级
  52. $this->info("=== 更新达人等级 ===");
  53. $updatedTalent = UrsTalentService::updateUserTalent($userId);
  54. if ($updatedTalent) {
  55. $this->info("达人等级更新成功");
  56. $this->line("新等级: {$updatedTalent->getTalentLevelName()} (等级{$updatedTalent->talent_level})");
  57. $this->line("直推人数: {$updatedTalent->direct_count}");
  58. $this->line("间推人数: {$updatedTalent->indirect_count}");
  59. $this->line("三推人数: {$updatedTalent->third_count}");
  60. $this->line("团队总人数: {$updatedTalent->promotion_count}");
  61. } else {
  62. $this->error("达人等级更新失败");
  63. }
  64. $this->line('');
  65. // 显示推荐关系树
  66. $this->info("=== 推荐关系树 ===");
  67. $tree = UrsTalentService::getUserReferralTree($userId);
  68. $this->displayReferralTree($tree);
  69. $this->line('');
  70. $this->info("测试完成!");
  71. }
  72. /**
  73. * 显示推荐关系树
  74. */
  75. private function displayReferralTree(array $tree): void
  76. {
  77. $this->line("用户 {$tree['user_id']} 的团队结构:");
  78. if (!empty($tree['direct'])) {
  79. $this->line(" 直推用户 (" . count($tree['direct']) . "人):");
  80. foreach ($tree['direct'] as $user) {
  81. $this->line(" - 用户{$user['user_id']} (推荐时间: {$user['referral_time']})");
  82. }
  83. }
  84. if (!empty($tree['indirect'])) {
  85. $this->line(" 间推用户 (" . count($tree['indirect']) . "人):");
  86. foreach ($tree['indirect'] as $user) {
  87. $this->line(" - 用户{$user['user_id']} (通过用户{$user['referrer_id']}, 推荐时间: {$user['referral_time']})");
  88. }
  89. }
  90. if (!empty($tree['third'])) {
  91. $this->line(" 三推用户 (" . count($tree['third']) . "人):");
  92. foreach ($tree['third'] as $user) {
  93. $this->line(" - 用户{$user['user_id']} (通过用户{$user['referrer_id']}, 推荐时间: {$user['referral_time']})");
  94. }
  95. }
  96. if (empty($tree['direct']) && empty($tree['indirect']) && empty($tree['third'])) {
  97. $this->line(" 无团队成员");
  98. }
  99. }
  100. }