TestPromotionInfoRefactorCommand.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. $items = $todayReward->getItems();
  68. if (!empty($coins)) {
  69. foreach ($coins as $coin) {
  70. $this->info("今日收益(代币): {$coin->getQuantity()} (类型: {$coin->getType()})");
  71. }
  72. }
  73. if (!empty($items)) {
  74. foreach ($items as $item) {
  75. $this->info("今日收益(物品): 物品ID {$item->getItemId()} x{$item->getQuantity()}");
  76. }
  77. }
  78. if (empty($coins) && empty($items)) {
  79. $this->info("今日收益: 无");
  80. }
  81. } else {
  82. $this->info("今日收益: 无");
  83. }
  84. $totalReward = $result->getTotalReward();
  85. if ($totalReward) {
  86. $coins = $totalReward->getCoins();
  87. $items = $totalReward->getItems();
  88. if (!empty($coins)) {
  89. foreach ($coins as $coin) {
  90. $this->info("总收益(代币): {$coin->getQuantity()} (类型: {$coin->getType()})");
  91. }
  92. }
  93. if (!empty($items)) {
  94. foreach ($items as $item) {
  95. $this->info("总收益(物品): 物品ID {$item->getItemId()} x{$item->getQuantity()}");
  96. }
  97. }
  98. if (empty($coins) && empty($items)) {
  99. $this->info("总收益: 无");
  100. }
  101. } else {
  102. $this->info("总收益: 无");
  103. }
  104. $this->info("✅ 推广信息重构功能测试完成!");
  105. } catch (\Exception $e) {
  106. $this->error("测试失败: " . $e->getMessage());
  107. $this->error("错误堆栈: " . $e->getTraceAsString());
  108. return 1;
  109. }
  110. return 0;
  111. }
  112. }