| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace App\Module\Task\Commands;
- use Illuminate\Console\Command;
- use App\Module\Task\Services\TaskConfigService;
- use Illuminate\Support\Facades\File;
- class GenerateTaskConfigCommand extends Command
- {
- /**
- * 命令名称
- *
- * @var string
- */
- protected $signature = 'task:generate-config {--output=public/json}';
- /**
- * 命令描述
- *
- * @var string
- */
- protected $description = '生成任务模块配置表';
- /**
- * 任务配置服务
- *
- * @var TaskConfigService
- */
- protected $configService;
- /**
- * 创建命令实例
- *
- * @param TaskConfigService $configService
- * @return void
- */
- public function __construct(TaskConfigService $configService)
- {
- parent::__construct();
- $this->configService = $configService;
- }
- /**
- * 执行命令
- *
- * @return int
- */
- public function handle()
- {
- $outputPath = $this->option('output');
- // 确保输出目录存在
- if (!File::exists($outputPath)) {
- File::makeDirectory($outputPath, 0755, true);
- }
- // 生成任务基础配置表
- $taskConfig = $this->configService->exportTaskConfig();
- File::put("$outputPath/task_config.json", $taskConfig);
- $this->info("任务基础配置表已生成:$outputPath/task_config.json");
- // 生成任务条件配置表
- $conditionConfig = $this->configService->exportTaskConditionConfig();
- File::put("$outputPath/task_condition_config.json", $conditionConfig);
- $this->info("任务条件配置表已生成:$outputPath/task_condition_config.json");
- // 生成任务奖励配置表
- $rewardConfig = $this->configService->exportTaskRewardConfig();
- File::put("$outputPath/task_reward_config.json", $rewardConfig);
- $this->info("任务奖励配置表已生成:$outputPath/task_reward_config.json");
- // 生成任务消耗配置表
- $costConfig = $this->configService->exportTaskCostConfig();
- File::put("$outputPath/task_cost_config.json", $costConfig);
- $this->info("任务消耗配置表已生成:$outputPath/task_cost_config.json");
- return 0;
- }
- }
|