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.

118 lines
3.9 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace Database\Seeders;
use App\Models\AudienceSession;
use App\Models\Competition;
use App\Support\BizDateTime;
use Carbon\Carbon;
use Illuminate\Database\Seeder;
/**
* 与原型 audience-form 四场观众活动对齐。
*
* php artisan db:seed --class=CompetitionAudienceSessionsSeeder
*/
class CompetitionAudienceSessionsSeeder extends Seeder
{
/**
* @var list<array{
* code: string,
* name: string,
* event_date_text: string,
* address: string,
* capacity: int,
* signup_start: string,
* signup_end: string,
* is_final: bool,
* sort: int
* }>
*/
private const ROWS = [
[
'code' => 'shanghai-preliminary',
'name' => '上海预赛路演',
'event_date_text' => '2026年9月18日(星期五)',
'address' => '上海市浦东新区张江科学会堂',
'capacity' => 300,
'signup_start' => '2026-08-10 00:00:00',
'signup_end' => '2026-09-10 23:59:59',
'is_final' => false,
'sort' => 1,
],
[
'code' => 'suzhou-preliminary',
'name' => '苏州预赛路演',
'event_date_text' => '2026年10月30日(星期五)',
'address' => '苏州市工业园区苏州国际博览中心',
'capacity' => 260,
'signup_start' => '2026-09-15 00:00:00',
'signup_end' => '2026-10-20 23:59:59',
'is_final' => false,
'sort' => 2,
],
[
'code' => 'shenzhen-preliminary',
'name' => '深圳预赛路演',
'event_date_text' => '2026年12月25日(星期五)',
'address' => '深圳市南山区深圳湾科技生态园',
'capacity' => 200,
'signup_start' => '2026-11-01 00:00:00',
'signup_end' => '2026-12-18 23:59:59',
'is_final' => false,
'sort' => 3,
],
[
'code' => 'suzhou-final',
'name' => '苏州总决赛',
'event_date_text' => '2027年3月19日(星期五)',
'address' => '苏州市工业园区金鸡湖国际会议中心',
'capacity' => 500,
'signup_start' => '2027-02-01 00:00:00',
'signup_end' => '2027-03-10 23:59:59',
'is_final' => true,
'sort' => 4,
],
];
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 audience sessions seed.');
return;
}
foreach ($competitions as $competition) {
foreach (self::ROWS as $row) {
AudienceSession::query()->updateOrCreate(
[
'competition_id' => $competition->id,
'code' => $row['code'],
],
[
'name' => $row['name'],
'event_date_text' => $row['event_date_text'],
'address' => $row['address'],
'capacity' => $row['capacity'],
'signup_start_at' => Carbon::parse($row['signup_start'], BizDateTime::TIMEZONE),
'signup_end_at' => Carbon::parse($row['signup_end'], BizDateTime::TIMEZONE),
'is_final' => $row['is_final'],
'sort' => $row['sort'],
'enabled' => true,
]
);
}
$this->command?->info(
'Synced '.count(self::ROWS)." audience sessions for competition #{$competition->id}."
);
}
}
}