TestPromotionInfoRefactorCommand.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace App\Module\AppGame\Commands;
  3. use App\Module\AppGame\Handler\Promotion\InfoHandler;
  4. use App\Module\UrsPromotion\Services\UrsUserMappingService;
  5. use Illuminate\Console\Command;
  6. use Illuminate\Support\Facades\Log;
  7. use Uraus\Kku\Request\RequestPromotionInfo;
  8. use Uraus\Kku\Response;
  9. /**
  10. * 测试推广信息重构后的功能
  11. */
  12. class TestPromotionInfoRefactorCommand extends Command
  13. {
  14. /**
  15. * 命令名称和参数
  16. *
  17. * @var string
  18. */
  19. protected $signature = 'test:promotion-info-refactor {user_id : 农场用户ID}';
  20. /**
  21. * 命令描述
  22. *
  23. * @var string
  24. */
  25. protected $description = '测试推广信息重构后的功能';
  26. /**
  27. * 执行命令
  28. */
  29. public function handle()
  30. {
  31. $userId = (int)$this->argument('user_id');
  32. $this->info("开始测试推广信息重构功能...");
  33. $this->info("测试用户ID: {$userId}");
  34. try {
  35. // 检查用户映射关系
  36. $ursUserId = UrsUserMappingService::getUrsUserId($userId);
  37. if (!$ursUserId) {
  38. $this->error("用户 {$userId} 未映射到URS系统");
  39. return 1;
  40. }
  41. $this->info("URS用户ID: {$ursUserId}");
  42. // 创建模拟响应对象
  43. $response = new Response();
  44. // 创建Handler实例并设置用户ID
  45. $handler = new InfoHandler($response);
  46. $handler->user_id = $userId;
  47. // 创建请求对象
  48. $request = new RequestPromotionInfo();
  49. $request->setTimes(time());
  50. // 调用处理方法
  51. $result = $handler->handle($request);
  52. // 输出结果
  53. $this->info("=== 推广团队信息 ===");
  54. $this->info("总人数: " . $result->getTotalCount());
  55. $this->info("直推人数: " . $result->getDirectCount());
  56. $this->info("间推人数: " . $result->getIndirectCount());
  57. $this->info("今日新增: " . $result->getDayRecentCount());
  58. $this->info("今日直推: " . $result->getDayDirectCount());
  59. $this->info("活跃人数: " . $result->getActiveCount());
  60. $this->info("直推活跃: " . $result->getDirectActiveCount());
  61. $this->info("达人等级: " . $result->getStarLevel());
  62. // 输出收益信息
  63. $this->info("=== 收益信息 ===");
  64. $todayReward = $result->getTodayReward();
  65. if ($todayReward) {
  66. $coins = $todayReward->getCoins();
  67. if (!empty($coins)) {
  68. foreach ($coins as $coin) {
  69. $this->info("今日收益: {$coin->getQuantity()} 钻石 (类型: {$coin->getType()})");
  70. }
  71. } else {
  72. $this->info("今日收益: 无");
  73. }
  74. } else {
  75. $this->info("今日收益: 无");
  76. }
  77. $totalReward = $result->getTotalReward();
  78. if ($totalReward) {
  79. $coins = $totalReward->getCoins();
  80. if (!empty($coins)) {
  81. foreach ($coins as $coin) {
  82. $this->info("总收益: {$coin->getQuantity()} 钻石 (类型: {$coin->getType()})");
  83. }
  84. } else {
  85. $this->info("总收益: 无");
  86. }
  87. } else {
  88. $this->info("总收益: 无");
  89. }
  90. $this->info("✅ 推广信息重构功能测试完成!");
  91. } catch (\Exception $e) {
  92. $this->error("测试失败: " . $e->getMessage());
  93. $this->error("错误堆栈: " . $e->getTraceAsString());
  94. return 1;
  95. }
  96. return 0;
  97. }
  98. }