get(); // 准备JSON数据 $jsonData = [ 'generated_ts' => time(), 'house_configs' => [] ]; foreach ($configs as $config) { $jsonData['house_configs'][] = [ 'level' => $config->level, 'output_bonus' => $config->output_bonus, 'special_land_limit' => $config->special_land_limit, 'upgrade_materials' => $config->upgrade_materials, 'downgrade_days' => $config->downgrade_days, ]; } return $jsonData; } catch (\Exception $e) { if (php_sapi_name() === 'cli') { echo "Error: Generate farm_house.json failed: {$e->getMessage()}\n"; } return false; } } /** * 执行命令 * * @return int */ public function handle() { $this->info('开始生成房屋配置JSON文件...'); try { // 直接调用静态方法生成JSON,而不通过缓存类 $result = self::generateJson(); if ($result !== false) { $this->info('房屋配置JSON文件生成成功'); $this->info('共生成 ' . count($result['house_configs']) . ' 条配置数据'); return Command::SUCCESS; } else { $this->error('生成房屋配置JSON文件失败'); return Command::FAILURE; } } catch (\Exception $e) { $this->error('生成房屋配置JSON文件失败: ' . $e->getMessage()); return Command::FAILURE; } } }