get(); // 获取所有土地升级配置 $upgradeConfigs = FarmLandUpgradeConfig::with(['fromType', 'toType'])->get(); // 准备JSON数据 $jsonData = [ 'generated_ts' => time(), 'land_types' => [], 'upgrade_paths' => [] ]; // 处理土地类型数据 foreach ($landTypes as $type) { $jsonData['land_types'][] = [ 'id' => $type->id, 'name' => $type->name, 'code' => $type->code, 'output_bonus' => $type->output_bonus, 'disaster_resistance' => $type->disaster_resistance, 'unlock_house_level' => $type->unlock_house_level, 'is_special' => $type->is_special, 'display_attributes' => $type->display_attributes, 'description' => $type->description, ]; } // 处理土地升级路径数据 foreach ($upgradeConfigs as $config) { // 获取完整的材料内容和条件内容 $materials = $config->getUpgradeMaterials(); $conditions = $config->getUpgradeConditions(); $jsonData['upgrade_paths'][] = [ 'from_type_id' => $config->from_type_id, 'to_type_id' => $config->to_type_id, 'materials' => $materials, // 直接输出材料条目 'conditions' => $conditions, 'materials_group_id' => $config->materials, 'conditions_group_id' => $config->conditions, ]; } return $jsonData; } catch (\Exception $e) { if (php_sapi_name() === 'cli') { echo "Error: Generate farm_land.json failed: {$e->getMessage()}\n"; } return false; } } /** * 执行命令 * * @return int */ public function handle() { $this->info('开始生成土地配置JSON文件...'); try { // 通过缓存类生成JSON $result = \App\Module\Game\DCache\FarmLandJsonConfig::getData([], true); if ($result !== false) { $this->info('土地配置JSON文件生成成功'); $this->info('共生成 ' . count($result['land_types']) . ' 条土地类型数据'); $this->info('共生成 ' . count($result['upgrade_paths']) . ' 条升级路径数据'); return Command::SUCCESS; } else { $this->error('生成土地配置JSON文件失败'); return Command::FAILURE; } } catch (\Exception $e) { $this->error('生成土地配置JSON文件失败: ' . $e->getMessage()); return Command::FAILURE; } } }