支持所有游戏按房间范围配置和运行
This commit is contained in:
+78
-57
@@ -68,16 +68,21 @@ Schedule::call(function () {
|
||||
|
||||
$config = \App\Models\GameConfig::forGame('baccarat')?->params ?? [];
|
||||
$interval = (int) ($config['interval_minutes'] ?? 2);
|
||||
$roomScopeService = app(\App\Services\GameRoomScopeService::class);
|
||||
|
||||
// 检查距上一局触发时间是否已达到间隔
|
||||
$lastRound = \App\Models\BaccaratRound::latest()->first();
|
||||
if ($lastRound && $lastRound->created_at->diffInMinutes(now()) < $interval) {
|
||||
return; // 还没到开局时间
|
||||
}
|
||||
foreach ($roomScopeService->getScopedRoomIdsForGame('baccarat') as $roomId) {
|
||||
$lastRound = \App\Models\BaccaratRound::query()
|
||||
->where('room_id', $roomId)
|
||||
->latest()
|
||||
->first();
|
||||
|
||||
// 无当前进行中的局才开新局
|
||||
if (! \App\Models\BaccaratRound::currentRound()) {
|
||||
\App\Jobs\OpenBaccaratRoundJob::dispatch();
|
||||
if ($lastRound && $lastRound->created_at->diffInMinutes(now()) < $interval) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! \App\Models\BaccaratRound::currentRound($roomId)) {
|
||||
\App\Jobs\OpenBaccaratRoundJob::dispatch($roomId);
|
||||
}
|
||||
}
|
||||
})->everyMinute()->name('baccarat:open-round')->withoutOverlapping();
|
||||
|
||||
@@ -96,30 +101,33 @@ Schedule::call(function () {
|
||||
return;
|
||||
}
|
||||
|
||||
// 当前已有可领取的箱子时跳过(一次只投放一个)
|
||||
if (\App\Models\MysteryBox::currentOpenBox()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$intervalHours = (float) ($config['auto_interval_hours'] ?? 2);
|
||||
$roomScopeService = app(\App\Services\GameRoomScopeService::class);
|
||||
|
||||
// 检查距上次投放时间
|
||||
$lastBox = \App\Models\MysteryBox::latest()->first();
|
||||
if ($lastBox && $lastBox->created_at->diffInHours(now()) < $intervalHours) {
|
||||
return;
|
||||
foreach ($roomScopeService->getScopedRoomIdsForGame('mystery_box') as $roomId) {
|
||||
if (\App\Models\MysteryBox::currentOpenBox($roomId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$lastBox = \App\Models\MysteryBox::query()
|
||||
->where('room_id', $roomId)
|
||||
->latest()
|
||||
->first();
|
||||
if ($lastBox && $lastBox->created_at->diffInHours(now()) < $intervalHours) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$trapChance = (int) ($config['trap_chance_percent'] ?? 10);
|
||||
$rand = random_int(1, 100);
|
||||
|
||||
$boxType = match (true) {
|
||||
$rand <= $trapChance => 'trap',
|
||||
$rand <= $trapChance + 15 => 'rare',
|
||||
default => 'normal',
|
||||
};
|
||||
|
||||
\App\Jobs\DropMysteryBoxJob::dispatch($boxType, $roomId);
|
||||
}
|
||||
|
||||
// 按配置的陷阱概率决定箱子类型
|
||||
$trapChance = (int) ($config['trap_chance_percent'] ?? 10);
|
||||
$rand = random_int(1, 100);
|
||||
|
||||
$boxType = match (true) {
|
||||
$rand <= $trapChance => 'trap',
|
||||
$rand <= $trapChance + 15 => 'rare',
|
||||
default => 'normal',
|
||||
};
|
||||
|
||||
\App\Jobs\DropMysteryBoxJob::dispatch($boxType);
|
||||
})->everyMinute()->name('mystery-box:auto-drop')->withoutOverlapping();
|
||||
|
||||
// ──────────── 赛马竞猜定时任务 ─────────────────────────────────
|
||||
@@ -130,21 +138,25 @@ Schedule::call(function () {
|
||||
return;
|
||||
}
|
||||
|
||||
// 当前已有进行中的场次(押注中/跑马中),跳过
|
||||
if (\App\Models\HorseRace::currentRace()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$config = \App\Models\GameConfig::forGame('horse_racing')?->params ?? [];
|
||||
$interval = (int) ($config['interval_minutes'] ?? 30);
|
||||
$roomScopeService = app(\App\Services\GameRoomScopeService::class);
|
||||
|
||||
// 检查距上一场触发时间是否已达到间隔
|
||||
$lastRace = \App\Models\HorseRace::latest()->first();
|
||||
if ($lastRace && $lastRace->created_at->diffInMinutes(now()) < $interval) {
|
||||
return;
|
||||
foreach ($roomScopeService->getScopedRoomIdsForGame('horse_racing') as $roomId) {
|
||||
if (\App\Models\HorseRace::currentRace($roomId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$lastRace = \App\Models\HorseRace::query()
|
||||
->where('room_id', $roomId)
|
||||
->latest()
|
||||
->first();
|
||||
if ($lastRace && $lastRace->created_at->diffInMinutes(now()) < $interval) {
|
||||
continue;
|
||||
}
|
||||
|
||||
\App\Jobs\OpenHorseRaceJob::dispatch($roomId)->delay(now()->addSeconds(30));
|
||||
}
|
||||
|
||||
\App\Jobs\OpenHorseRaceJob::dispatch()->delay(now()->addSeconds(30));
|
||||
})->everyMinute()->name('horse-race:open-race')->withoutOverlapping();
|
||||
|
||||
// ──────────── 双色球彩票定时任务 ─────────────────────────────────
|
||||
@@ -155,24 +167,29 @@ Schedule::call(function () {
|
||||
return;
|
||||
}
|
||||
|
||||
$issue = \App\Models\LotteryIssue::query()->whereIn('status', ['open', 'closed'])->latest()->first();
|
||||
$roomScopeService = app(\App\Services\GameRoomScopeService::class);
|
||||
|
||||
// 无进行中期次则自动创建一期
|
||||
if (! $issue) {
|
||||
\App\Jobs\OpenLotteryIssueJob::dispatch();
|
||||
foreach ($roomScopeService->getScopedRoomIdsForGame('lottery') as $roomId) {
|
||||
$issue = \App\Models\LotteryIssue::query()
|
||||
->where('room_id', $roomId)
|
||||
->whereIn('status', ['open', 'closed'])
|
||||
->latest()
|
||||
->first();
|
||||
|
||||
return;
|
||||
}
|
||||
if (! $issue) {
|
||||
\App\Jobs\OpenLotteryIssueJob::dispatch($roomId);
|
||||
|
||||
// open 状态:检查是否已到停售时间
|
||||
if ($issue->status === 'open' && $issue->sell_closes_at && now()->gte($issue->sell_closes_at)) {
|
||||
$issue->update(['status' => 'closed']);
|
||||
$issue->refresh();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// closed 状态:检查是否已到开奖时间
|
||||
if ($issue->status === 'closed' && $issue->draw_at && now()->gte($issue->draw_at)) {
|
||||
\App\Jobs\DrawLotteryJob::dispatch($issue);
|
||||
if ($issue->status === 'open' && $issue->sell_closes_at && now()->gte($issue->sell_closes_at)) {
|
||||
$issue->update(['status' => 'closed']);
|
||||
$issue->refresh();
|
||||
}
|
||||
|
||||
if ($issue->status === 'closed' && $issue->draw_at && now()->gte($issue->draw_at)) {
|
||||
\App\Jobs\DrawLotteryJob::dispatch($issue);
|
||||
}
|
||||
}
|
||||
})->everyMinute()->name('lottery:check')->withoutOverlapping();
|
||||
|
||||
@@ -194,8 +211,12 @@ Schedule::call(function () {
|
||||
return;
|
||||
}
|
||||
|
||||
$issue = \App\Models\LotteryIssue::currentIssue();
|
||||
if ($issue && $issue->is_super_issue) {
|
||||
\App\Jobs\OpenLotteryIssueJob::dispatch(); // 触发广播
|
||||
$roomScopeService = app(\App\Services\GameRoomScopeService::class);
|
||||
|
||||
foreach ($roomScopeService->getScopedRoomIdsForGame('lottery') as $roomId) {
|
||||
$issue = \App\Models\LotteryIssue::currentIssue($roomId);
|
||||
if ($issue && $issue->is_super_issue) {
|
||||
\App\Jobs\OpenLotteryIssueJob::dispatch($roomId); // 触发广播
|
||||
}
|
||||
}
|
||||
})->dailyAt('18:00')->name('lottery:super-reminder');
|
||||
|
||||
Reference in New Issue
Block a user