2026-02-26 12:02:00 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
use Illuminate\Foundation\Inspiring;
|
|
|
|
|
|
use Illuminate\Support\Facades\Artisan;
|
2026-02-27 00:12:16 +08:00
|
|
|
|
use Illuminate\Support\Facades\Schedule;
|
2026-02-26 12:02:00 +08:00
|
|
|
|
|
|
|
|
|
|
Artisan::command('inspire', function () {
|
|
|
|
|
|
$this->comment(Inspiring::quote());
|
|
|
|
|
|
})->purpose('Display an inspiring quote');
|
2026-02-27 00:12:16 +08:00
|
|
|
|
|
|
|
|
|
|
// 每天凌晨 3 点清理超过 30 天的聊天记录
|
|
|
|
|
|
Schedule::command('messages:purge')->dailyAt('03:00');
|
2026-02-27 12:39:23 +08:00
|
|
|
|
|
|
|
|
|
|
// 每 5 分钟为所有在线用户自动存点(经验/金币/等级)
|
|
|
|
|
|
Schedule::command('chatroom:auto-save-exp')->everyFiveMinutes();
|
2026-03-01 15:16:46 +08:00
|
|
|
|
|
2026-03-26 11:15:11 +08:00
|
|
|
|
// 每 1 分钟为 AI小班长 独立模拟一次挂机心跳,触发随机事件
|
|
|
|
|
|
Schedule::command('chatroom:ai-heartbeat')->everyMinute();
|
|
|
|
|
|
|
2026-03-17 20:27:04 +08:00
|
|
|
|
// 每 15 分钟:关闭掉线用户的开放职务日志(久无心跳 = 掉线,自动写入 logout_at)
|
|
|
|
|
|
Schedule::command('duty:close-stale-logs')->everyFifteenMinutes();
|
|
|
|
|
|
|
2026-03-01 15:16:46 +08:00
|
|
|
|
// ──────────── 婚姻系统定时任务 ────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
|
|
// 每 5 分钟:扫描超时求婚(48h后失效 + 戒指消失 + 广播通知)
|
|
|
|
|
|
Schedule::job(new \App\Jobs\ExpireMarriageProposals)->everyFiveMinutes();
|
|
|
|
|
|
|
|
|
|
|
|
// 每 5 分钟:触发到时的定时婚礼(红包分发 + 广播庆典)
|
|
|
|
|
|
Schedule::job(new \App\Jobs\TriggerScheduledWeddings)->everyFiveMinutes();
|
|
|
|
|
|
|
|
|
|
|
|
// 每小时:协议离婚超时自动升级为强制(72h无响应)
|
|
|
|
|
|
Schedule::job(new \App\Jobs\AutoExpireDivorces)->hourly();
|
|
|
|
|
|
|
|
|
|
|
|
// 每小时:清理过期婚礼红包(expired_at 过后标记 completed)
|
|
|
|
|
|
Schedule::job(new \App\Jobs\ExpireWeddingEnvelopes)->hourly();
|
|
|
|
|
|
|
|
|
|
|
|
// 每天 00:05:全量处理婚姻亲密度时间奖励(每日加分)
|
|
|
|
|
|
Schedule::job(new \App\Jobs\ProcessMarriageIntimacy)->dailyAt('00:05');
|
2026-03-01 20:06:53 +08:00
|
|
|
|
|
|
|
|
|
|
// ──────────── 节日福利定时任务 ────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
|
|
// 每分钟:扫描并触发到期的节日福利活动
|
|
|
|
|
|
Schedule::call(function () {
|
|
|
|
|
|
\App\Models\HolidayEvent::pendingToTrigger()
|
|
|
|
|
|
->each(fn ($e) => \App\Jobs\TriggerHolidayEventJob::dispatch($e));
|
|
|
|
|
|
})->everyMinute()->name('holiday-events:trigger')->withoutOverlapping();
|
2026-03-01 20:25:09 +08:00
|
|
|
|
|
2026-04-21 17:53:11 +08:00
|
|
|
|
// 每分钟:收尾已过期但尚未结算的节日福利批次
|
|
|
|
|
|
Schedule::call(function () {
|
|
|
|
|
|
\App\Models\HolidayEventRun::pendingToExpire()
|
|
|
|
|
|
->each(function (\App\Models\HolidayEventRun $run): void {
|
|
|
|
|
|
$run->update(['status' => 'expired']);
|
|
|
|
|
|
});
|
|
|
|
|
|
})->everyMinute()->name('holiday-event-runs:expire')->withoutOverlapping();
|
|
|
|
|
|
|
2026-04-11 23:27:29 +08:00
|
|
|
|
// 每分钟:推进百家乐买单活动状态(开始 / 等待结算 / 开放领取 / 过期收尾)
|
|
|
|
|
|
Schedule::call(function () {
|
|
|
|
|
|
app(\App\Services\BaccaratLossCoverService::class)->tick();
|
|
|
|
|
|
})->everyMinute()->name('baccarat-loss-cover:tick')->withoutOverlapping();
|
|
|
|
|
|
|
2026-03-01 20:25:09 +08:00
|
|
|
|
// ──────────── 百家乐定时任务 ─────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
|
|
// 每分钟:检查是否应开新一局(游戏开启 + 无正在进行的局)
|
|
|
|
|
|
Schedule::call(function () {
|
|
|
|
|
|
if (! \App\Models\GameConfig::isEnabled('baccarat')) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$config = \App\Models\GameConfig::forGame('baccarat')?->params ?? [];
|
|
|
|
|
|
$interval = (int) ($config['interval_minutes'] ?? 2);
|
|
|
|
|
|
|
|
|
|
|
|
// 检查距上一局触发时间是否已达到间隔
|
|
|
|
|
|
$lastRound = \App\Models\BaccaratRound::latest()->first();
|
|
|
|
|
|
if ($lastRound && $lastRound->created_at->diffInMinutes(now()) < $interval) {
|
|
|
|
|
|
return; // 还没到开局时间
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 无当前进行中的局才开新局
|
|
|
|
|
|
if (! \App\Models\BaccaratRound::currentRound()) {
|
|
|
|
|
|
\App\Jobs\OpenBaccaratRoundJob::dispatch();
|
|
|
|
|
|
}
|
|
|
|
|
|
})->everyMinute()->name('baccarat:open-round')->withoutOverlapping();
|
2026-03-03 19:29:43 +08:00
|
|
|
|
|
|
|
|
|
|
// ──────────── 神秘箱子定时投放 ─────────────────────────────────
|
|
|
|
|
|
|
|
|
|
|
|
// 每分钟:检查是否应自动投放一个新箱子
|
|
|
|
|
|
Schedule::call(function () {
|
|
|
|
|
|
if (! \App\Models\GameConfig::isEnabled('mystery_box')) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$config = \App\Models\GameConfig::forGame('mystery_box')?->params ?? [];
|
|
|
|
|
|
|
|
|
|
|
|
// 自动投放开关
|
|
|
|
|
|
if (! ($config['auto_drop_enabled'] ?? false)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 当前已有可领取的箱子时跳过(一次只投放一个)
|
|
|
|
|
|
if (\App\Models\MysteryBox::currentOpenBox()) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$intervalHours = (float) ($config['auto_interval_hours'] ?? 2);
|
|
|
|
|
|
|
|
|
|
|
|
// 检查距上次投放时间
|
|
|
|
|
|
$lastBox = \App\Models\MysteryBox::latest()->first();
|
|
|
|
|
|
if ($lastBox && $lastBox->created_at->diffInHours(now()) < $intervalHours) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 按配置的陷阱概率决定箱子类型
|
|
|
|
|
|
$trapChance = (int) ($config['trap_chance_percent'] ?? 10);
|
|
|
|
|
|
$rand = random_int(1, 100);
|
|
|
|
|
|
|
|
|
|
|
|
$boxType = match (true) {
|
2026-03-03 23:19:59 +08:00
|
|
|
|
$rand <= $trapChance => 'trap',
|
2026-03-03 19:29:43 +08:00
|
|
|
|
$rand <= $trapChance + 15 => 'rare',
|
2026-03-03 23:19:59 +08:00
|
|
|
|
default => 'normal',
|
2026-03-03 19:29:43 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
\App\Jobs\DropMysteryBoxJob::dispatch($boxType);
|
|
|
|
|
|
})->everyMinute()->name('mystery-box:auto-drop')->withoutOverlapping();
|
|
|
|
|
|
|
2026-03-03 23:19:59 +08:00
|
|
|
|
// ──────────── 赛马竞猜定时任务 ─────────────────────────────────
|
|
|
|
|
|
|
|
|
|
|
|
// 每分钟:检查是否应开启新一场赛马
|
|
|
|
|
|
Schedule::call(function () {
|
|
|
|
|
|
if (! \App\Models\GameConfig::isEnabled('horse_racing')) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 当前已有进行中的场次(押注中/跑马中),跳过
|
|
|
|
|
|
if (\App\Models\HorseRace::currentRace()) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$config = \App\Models\GameConfig::forGame('horse_racing')?->params ?? [];
|
|
|
|
|
|
$interval = (int) ($config['interval_minutes'] ?? 30);
|
|
|
|
|
|
|
|
|
|
|
|
// 检查距上一场触发时间是否已达到间隔
|
|
|
|
|
|
$lastRace = \App\Models\HorseRace::latest()->first();
|
|
|
|
|
|
if ($lastRace && $lastRace->created_at->diffInMinutes(now()) < $interval) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-04 15:06:06 +08:00
|
|
|
|
\App\Jobs\OpenHorseRaceJob::dispatch()->delay(now()->addSeconds(30));
|
2026-03-03 23:19:59 +08:00
|
|
|
|
})->everyMinute()->name('horse-race:open-race')->withoutOverlapping();
|
2026-03-04 15:38:02 +08:00
|
|
|
|
|
|
|
|
|
|
// ──────────── 双色球彩票定时任务 ─────────────────────────────────
|
|
|
|
|
|
|
|
|
|
|
|
// 每分钟:检查是否到开奖时间,到期触发开奖;同时确保有进行中的期次
|
|
|
|
|
|
Schedule::call(function () {
|
|
|
|
|
|
if (! \App\Models\GameConfig::isEnabled('lottery')) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$issue = \App\Models\LotteryIssue::query()->whereIn('status', ['open', 'closed'])->latest()->first();
|
|
|
|
|
|
|
|
|
|
|
|
// 无进行中期次则自动创建一期
|
|
|
|
|
|
if (! $issue) {
|
|
|
|
|
|
\App\Jobs\OpenLotteryIssueJob::dispatch();
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// open 状态:检查是否已到停售时间
|
|
|
|
|
|
if ($issue->status === 'open' && $issue->sell_closes_at && now()->gte($issue->sell_closes_at)) {
|
|
|
|
|
|
$issue->update(['status' => 'closed']);
|
|
|
|
|
|
$issue->refresh();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// closed 状态:检查是否已到开奖时间
|
|
|
|
|
|
if ($issue->status === 'closed' && $issue->draw_at && now()->gte($issue->draw_at)) {
|
|
|
|
|
|
\App\Jobs\DrawLotteryJob::dispatch($issue);
|
|
|
|
|
|
}
|
|
|
|
|
|
})->everyMinute()->name('lottery:check')->withoutOverlapping();
|
|
|
|
|
|
|
2026-04-28 23:48:32 +08:00
|
|
|
|
// ──────────── 猜成语自动出题 ────────────────────────────────────
|
|
|
|
|
|
//
|
|
|
|
|
|
// 每分钟:检查是否到时间自动出题(仅 auto_start_interval > 0 时生效)
|
|
|
|
|
|
Schedule::call(function () {
|
|
|
|
|
|
if (! \App\Models\GameConfig::isEnabled('idiom')) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-29 10:32:12 +08:00
|
|
|
|
// 先统一结算超时回合,避免旧题长期占用进行中状态。
|
|
|
|
|
|
$roomId = 1;
|
|
|
|
|
|
app(\App\Services\IdiomGameService::class)->expireActiveRoundsForRoom($roomId);
|
|
|
|
|
|
|
2026-04-28 23:48:32 +08:00
|
|
|
|
$config = \App\Models\GameConfig::forGame('idiom')?->params ?? [];
|
|
|
|
|
|
$interval = (int) ($config['auto_start_interval'] ?? 0);
|
|
|
|
|
|
if ($interval <= 0) {
|
|
|
|
|
|
return; // 仅手动模式
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查每个房间是否有进行中的回合(先只处理 1 号房间)
|
|
|
|
|
|
$activeRound = \App\Models\IdiomGameRound::where('room_id', $roomId)
|
|
|
|
|
|
->whereIn('status', ['pending', 'active'])
|
|
|
|
|
|
->first();
|
|
|
|
|
|
if ($activeRound) {
|
|
|
|
|
|
return; // 当前有未答完的题,跳过
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查距上一题结束/创建时间是否已达到间隔
|
|
|
|
|
|
$lastRound = \App\Models\IdiomGameRound::where('room_id', $roomId)
|
|
|
|
|
|
->latest()
|
|
|
|
|
|
->first();
|
|
|
|
|
|
if ($lastRound) {
|
|
|
|
|
|
$lastTime = $lastRound->ended_at ?? $lastRound->started_at ?? $lastRound->created_at;
|
|
|
|
|
|
if ($lastTime && $lastTime->diffInMinutes(now()) < $interval) {
|
|
|
|
|
|
return; // 还没到时间
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 随机选一道启用的题目
|
|
|
|
|
|
$idiom = \App\Models\Idiom::where('is_active', true)->inRandomOrder()->first();
|
|
|
|
|
|
if (! $idiom) {
|
|
|
|
|
|
return; // 题库为空
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$rewardGold = (int) ($config['reward_gold'] ?? 50);
|
|
|
|
|
|
$rewardExp = (int) ($config['reward_exp'] ?? 30);
|
|
|
|
|
|
|
2026-04-29 10:32:12 +08:00
|
|
|
|
// 创建新回合,并以 started_at 作为后续过期判断起点。
|
2026-04-28 23:48:32 +08:00
|
|
|
|
$round = \App\Models\IdiomGameRound::create([
|
|
|
|
|
|
'room_id' => $roomId,
|
|
|
|
|
|
'idiom_id' => $idiom->id,
|
|
|
|
|
|
'status' => 'active',
|
|
|
|
|
|
'reward_gold' => $rewardGold,
|
|
|
|
|
|
'reward_exp' => $rewardExp,
|
|
|
|
|
|
'started_at' => now(),
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
// 广播到聊天室
|
|
|
|
|
|
broadcast(new \App\Events\IdiomGameStarted(
|
|
|
|
|
|
roomId: $roomId,
|
|
|
|
|
|
hint: $idiom->hint,
|
|
|
|
|
|
roundId: $round->id,
|
|
|
|
|
|
rewardGold: $rewardGold,
|
|
|
|
|
|
rewardExp: $rewardExp,
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
// 同时推一条 MessageSent 消息显示在聊天窗口
|
|
|
|
|
|
$msg = [
|
|
|
|
|
|
'id' => app(\App\Services\ChatStateService::class)->nextMessageId($roomId),
|
|
|
|
|
|
'room_id' => $roomId,
|
|
|
|
|
|
'from_user' => '星海小博士',
|
|
|
|
|
|
'to_user' => '大家',
|
|
|
|
|
|
'content' => "🧩 猜成语时间!{$idiom->hint}",
|
|
|
|
|
|
'is_secret' => false,
|
|
|
|
|
|
'font_color' => '#7c3aed',
|
|
|
|
|
|
'action' => '',
|
|
|
|
|
|
'idiom_game_round_id' => $round->id,
|
|
|
|
|
|
'idiom_reward_gold' => $rewardGold,
|
|
|
|
|
|
'idiom_reward_exp' => $rewardExp,
|
|
|
|
|
|
'sent_at' => now()->toDateTimeString(),
|
|
|
|
|
|
];
|
|
|
|
|
|
app(\App\Services\ChatStateService::class)->pushMessage($roomId, $msg);
|
|
|
|
|
|
broadcast(new \App\Events\MessageSent($roomId, $msg));
|
|
|
|
|
|
})->everyMinute()->name('idiom:auto-start')->withoutOverlapping();
|
|
|
|
|
|
|
2026-03-04 15:38:02 +08:00
|
|
|
|
// 每日 18:00:超级期预热广播(若当前期次为超级期,提醒用户购票)
|
|
|
|
|
|
Schedule::call(function () {
|
|
|
|
|
|
if (! \App\Models\GameConfig::isEnabled('lottery')) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$issue = \App\Models\LotteryIssue::currentIssue();
|
|
|
|
|
|
if ($issue && $issue->is_super_issue) {
|
|
|
|
|
|
\App\Jobs\OpenLotteryIssueJob::dispatch(); // 触发广播
|
|
|
|
|
|
}
|
|
|
|
|
|
})->dailyAt('18:00')->name('lottery:super-reminder');
|