You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.4 KiB

1 month ago
<?php
namespace Database\Seeders;
use App\Models\Competition;
use App\Models\CompetitionTrack;
use Illuminate\Database\Seeder;
/**
* 与 config/contest.php 赛道文案对齐的默认赛道track_code 供报名与后续评委账号按赛道关联)。
*
* php artisan db:seed --class=CompetitionDefaultTracksSeeder
*/
class CompetitionDefaultTracksSeeder extends Seeder
{
/** @var list<array{track_code: string, title: string, description: string, sort: int}> */
private const ROWS = [
[
'track_code' => 'tese_xiaofei',
'title' => '特色消费',
'description' => '(宠物经济、新国货与悦己消费、地标产品与老字号创新、汽车后市场服务等)',
'sort' => 1,
],
[
'track_code' => 'jiankang_xiaofei',
'title' => '健康消费',
'description' => '(医疗美容、减重与健康管理、运动与康复、科技与中医药、银发消费等)',
'sort' => 2,
],
[
'track_code' => 'shang_wen_lv',
'title' => '商文旅融合',
'description' => '(文旅 IP 创新、商业空间与首发经济、特色民宿与乡村旅游等)',
'sort' => 3,
],
[
'track_code' => 'xiaofei_ai',
'title' => '消费+人工智能',
'description' => '智能消费硬件、数字消费、AI 内容创作等)',
'sort' => 4,
],
];
public function run(): void
{
$competitionId = (int) env('DEFAULT_TRACKS_COMPETITION_ID', 1);
$competition = Competition::query()->find($competitionId);
if (! $competition) {
$this->command?->warn("Competition {$competitionId} not found, skip tracks seed.");
return;
}
foreach (self::ROWS as $row) {
CompetitionTrack::query()->updateOrCreate(
[
'competition_id' => $competition->id,
'track_code' => $row['track_code'],
],
[
'title' => $row['title'],
'description' => $row['description'],
'sort' => $row['sort'],
'is_enabled' => true,
]
);
}
$this->command?->info("Synced ".count(self::ROWS)." tracks for competition #{$competitionId}.");
}
}