GenerateTaskConfigCommand.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace App\Module\Task\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Module\Task\Services\TaskConfigService;
  5. use Illuminate\Support\Facades\File;
  6. class GenerateTaskConfigCommand extends Command
  7. {
  8. /**
  9. * 命令名称
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'task:generate-config {--output=public/json}';
  14. /**
  15. * 命令描述
  16. *
  17. * @var string
  18. */
  19. protected $description = '生成任务模块配置表';
  20. /**
  21. * 任务配置服务
  22. *
  23. * @var TaskConfigService
  24. */
  25. protected $configService;
  26. /**
  27. * 创建命令实例
  28. *
  29. * @param TaskConfigService $configService
  30. * @return void
  31. */
  32. public function __construct(TaskConfigService $configService)
  33. {
  34. parent::__construct();
  35. $this->configService = $configService;
  36. }
  37. /**
  38. * 执行命令
  39. *
  40. * @return int
  41. */
  42. public function handle()
  43. {
  44. $outputPath = $this->option('output');
  45. // 确保输出目录存在
  46. if (!File::exists($outputPath)) {
  47. File::makeDirectory($outputPath, 0755, true);
  48. }
  49. // 生成任务基础配置表
  50. $taskConfig = $this->configService->exportTaskConfig();
  51. File::put("$outputPath/task_config.json", $taskConfig);
  52. $this->info("任务基础配置表已生成:$outputPath/task_config.json");
  53. // 生成任务条件配置表
  54. $conditionConfig = $this->configService->exportTaskConditionConfig();
  55. File::put("$outputPath/task_condition_config.json", $conditionConfig);
  56. $this->info("任务条件配置表已生成:$outputPath/task_condition_config.json");
  57. // 生成任务奖励配置表
  58. $rewardConfig = $this->configService->exportTaskRewardConfig();
  59. File::put("$outputPath/task_reward_config.json", $rewardConfig);
  60. $this->info("任务奖励配置表已生成:$outputPath/task_reward_config.json");
  61. // 生成任务消耗配置表
  62. $costConfig = $this->configService->exportTaskCostConfig();
  63. File::put("$outputPath/task_cost_config.json", $costConfig);
  64. $this->info("任务消耗配置表已生成:$outputPath/task_cost_config.json");
  65. return 0;
  66. }
  67. }