| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace App\Console\Commands;
- use App\Module\Farm\Models\FarmSeed;
- use Illuminate\Console\Command;
- /**
- * 调试种子映射关系的命令
- */
- class DebugSeedMapping extends Command
- {
- /**
- * 命令签名
- *
- * @var string
- */
- protected $signature = 'debug:seed-mapping {item_id?}';
- /**
- * 命令描述
- *
- * @var string
- */
- protected $description = '调试种子物品ID和种子配置ID的映射关系';
- /**
- * 执行命令
- *
- * @return int
- */
- public function handle()
- {
- $itemId = $this->argument('item_id');
- if ($itemId) {
- // 查询特定物品ID的种子配置
- $seed = FarmSeed::where('item_id', $itemId)->first();
-
- if ($seed) {
- $this->info("物品ID {$itemId} 对应的种子配置:");
- $this->table(
- ['种子配置ID', '种子名称', '物品ID', '种子类型'],
- [[$seed->id, $seed->name, $seed->item_id, $seed->type]]
- );
- } else {
- $this->error("物品ID {$itemId} 没有对应的种子配置");
- }
- } else {
- // 显示所有种子配置的映射关系
- $seeds = FarmSeed::orderBy('item_id')->get();
-
- $this->info("所有种子配置的映射关系:");
- $data = [];
- foreach ($seeds as $seed) {
- $data[] = [$seed->id, $seed->name, $seed->item_id, $seed->type];
- }
-
- $this->table(
- ['种子配置ID', '种子名称', '物品ID', '种子类型'],
- $data
- );
- }
- return 0;
- }
- }
|