TestWealthRank.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Module\Farm\Services\HouseService;
  4. use Illuminate\Console\Command;
  5. class TestWealthRank extends Command
  6. {
  7. protected $signature = 'test:wealth-rank {userId=10001}';
  8. protected $description = '测试财富排行榜功能';
  9. public function handle()
  10. {
  11. $userId = (int) $this->argument('userId');
  12. $this->info("测试财富排行榜功能");
  13. $this->info("==================");
  14. $this->newLine();
  15. try {
  16. // 先检查缓存数据
  17. $this->info("检查缓存数据:");
  18. $houseLogic = new \App\Module\Farm\Logics\HouseLogic();
  19. $reflection = new \ReflectionClass($houseLogic);
  20. $method = $reflection->getMethod('getWealthRankListCache');
  21. $method->setAccessible(true);
  22. $cachedData = $method->invoke($houseLogic);
  23. $this->info("- 缓存数据总数: " . count($cachedData));
  24. $this->newLine();
  25. // 测试第一页
  26. $this->info("测试第一页 (page=1, pageSize=5):");
  27. $page1Data = HouseService::getWealthRankList($userId, 1, 5);
  28. $this->info("第一页数据:");
  29. $this->info("- 列表数量: " . count($page1Data->list));
  30. $this->info("- 用户排名: " . $page1Data->userRank);
  31. $this->info("- 分页信息: " . json_encode($page1Data->page, JSON_UNESCAPED_UNICODE));
  32. // 显示第一页的前3条数据
  33. if (!empty($page1Data->list)) {
  34. $this->info("第一页前3条数据:");
  35. foreach (array_slice($page1Data->list, 0, 3) as $index => $item) {
  36. $this->info(" " . ($index + 1) . ". 排名: {$item->rank}, 用户ID: {$item->userId}, 昵称: {$item->nickname}, 财富: {$item->wealth}");
  37. }
  38. }
  39. $this->newLine();
  40. // 测试第二页
  41. $this->info("测试第二页 (page=2, pageSize=5):");
  42. $page2Data = HouseService::getWealthRankList($userId, 2, 5);
  43. $this->info("第二页数据:");
  44. $this->info("- 列表数量: " . count($page2Data->list));
  45. $this->info("- 用户排名: " . $page2Data->userRank);
  46. $this->info("- 分页信息: " . json_encode($page2Data->page, JSON_UNESCAPED_UNICODE));
  47. $this->newLine();
  48. // 如果第二页有数据,显示前几条
  49. if (!empty($page2Data->list)) {
  50. $this->info("第二页前3条数据:");
  51. foreach (array_slice($page2Data->list, 0, 3) as $index => $item) {
  52. $this->info(" " . ($index + 1) . ". 排名: {$item->rank}, 用户ID: {$item->userId}, 昵称: {$item->nickname}, 财富: {$item->wealth}");
  53. }
  54. } else {
  55. $this->warn("第二页没有数据");
  56. }
  57. } catch (\Exception $e) {
  58. $this->error("错误: " . $e->getMessage());
  59. $this->error("堆栈: " . $e->getTraceAsString());
  60. }
  61. }
  62. }