*/ private const ROWS = [ [ 'track_code' => 'guang_xinpian', 'title' => '芯片与组件', 'description' => '光芯片、光电元器件、光模块等核心芯片与组件研发创新', 'sort' => 1, ], [ 'track_code' => 'zhizao_fengzhuang', 'title' => '制造与封装', 'description' => '光电子精密制造、器件封装耦合、量产工艺优化等制造封装技术攻关', 'sort' => 2, ], [ 'track_code' => 'guangdian_cailiao', 'title' => '材料与设备', 'description' => '光电功能新材料、光纤基材及光刻、镀膜、精密测试等专用设备研发', 'sort' => 3, ], [ 'track_code' => 'guangtongxin_yingyong', 'title' => '场景与应用', 'description' => '面向算力网络、移动通信、车载互联、工业传感、航空航天、医疗等领域的系统方案与应用创新', 'sort' => 4, ], ]; /** 历史赛道编码,同步时停用 */ private const LEGACY_TRACK_CODES = [ 'tese_xiaofei', 'jiankang_xiaofei', 'shang_wen_lv', 'xiaofei_ai', ]; public function run(): void { $envId = (int) env('DEFAULT_TRACKS_COMPETITION_ID', 0); $competitions = $envId > 0 ? Competition::query()->whereKey($envId)->get() : Competition::query()->orderBy('id')->get(); if ($competitions->isEmpty()) { $this->command?->warn('No competition found, skip tracks seed.'); return; } foreach ($competitions as $competition) { CompetitionTrack::query() ->where('competition_id', $competition->id) ->whereIn('track_code', self::LEGACY_TRACK_CODES) ->update(['is_enabled' => false]); foreach (self::ROWS as $row) { $sheet = DefaultTrackScoringSheets::forTrackCode($row['track_code'], $row['title']); CompetitionTrack::query()->updateOrCreate( [ 'competition_id' => $competition->id, 'track_code' => $row['track_code'], ], [ 'title' => $row['title'], 'description' => $row['description'], 'sort' => $row['sort'], 'is_enabled' => true, 'scoring_sheet_json' => $sheet, ] ); } $this->command?->info( 'Synced '.count(self::ROWS)." tracks for competition #{$competition->id}." ); } } }