DebugSeedMapping.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Module\Farm\Models\FarmSeed;
  4. use Illuminate\Console\Command;
  5. /**
  6. * 调试种子映射关系的命令
  7. */
  8. class DebugSeedMapping extends Command
  9. {
  10. /**
  11. * 命令签名
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'debug:seed-mapping {item_id?}';
  16. /**
  17. * 命令描述
  18. *
  19. * @var string
  20. */
  21. protected $description = '调试种子物品ID和种子配置ID的映射关系';
  22. /**
  23. * 执行命令
  24. *
  25. * @return int
  26. */
  27. public function handle()
  28. {
  29. $itemId = $this->argument('item_id');
  30. if ($itemId) {
  31. // 查询特定物品ID的种子配置
  32. $seed = FarmSeed::where('item_id', $itemId)->first();
  33. if ($seed) {
  34. $this->info("物品ID {$itemId} 对应的种子配置:");
  35. $this->table(
  36. ['种子配置ID', '种子名称', '物品ID', '种子类型'],
  37. [[$seed->id, $seed->name, $seed->item_id, $seed->type]]
  38. );
  39. } else {
  40. $this->error("物品ID {$itemId} 没有对应的种子配置");
  41. }
  42. } else {
  43. // 显示所有种子配置的映射关系
  44. $seeds = FarmSeed::orderBy('item_id')->get();
  45. $this->info("所有种子配置的映射关系:");
  46. $data = [];
  47. foreach ($seeds as $seed) {
  48. $data[] = [$seed->id, $seed->name, $seed->item_id, $seed->type];
  49. }
  50. $this->table(
  51. ['种子配置ID', '种子名称', '物品ID', '种子类型'],
  52. $data
  53. );
  54. }
  55. return 0;
  56. }
  57. }