新增:双色球彩票系统后端基础(阶段一)
📦 数据库 - lottery_issues(期次表) - lottery_tickets(购票记录表) - lottery_pool_logs(奖池流水表,透明展示) 🔩 核心组件 - LotteryIssue / LotteryTicket / LotteryPoolLog 完整 Model - LotteryService:购票/机选/开奖/奖池派发/滚存/超级期预热/公屏广播 - LotteryController:current/buy/quickPick/history/my 五个接口 - DrawLotteryJob(每日定时开奖)/ OpenLotteryIssueJob(初始化首期) 💰 货币日志 - CurrencySource 新增 LOTTERY_BUY / LOTTERY_WIN - 所有金币变动均通过 UserCurrencyService::change() 记录流水 🗓️ 调度器 - 每分钟检查停售/开奖时机 - 每日 18:00 超级期预热广播 🔧 配置 - GameConfigSeeder 追加 lottery 默认配置(默认关闭) - /games/enabled 接口追加 lottery 开关状态 - 新增 /lottery/* 路由组(auth 保护)
This commit is contained in:
@@ -127,3 +127,44 @@ Schedule::call(function () {
|
||||
|
||||
\App\Jobs\OpenHorseRaceJob::dispatch()->delay(now()->addSeconds(30));
|
||||
})->everyMinute()->name('horse-race:open-race')->withoutOverlapping();
|
||||
|
||||
// ──────────── 双色球彩票定时任务 ─────────────────────────────────
|
||||
|
||||
// 每分钟:检查是否到开奖时间,到期触发开奖;同时确保有进行中的期次
|
||||
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();
|
||||
|
||||
// 每日 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');
|
||||
|
||||
@@ -162,6 +162,20 @@ Route::middleware(['chat.auth'])->group(function () {
|
||||
Route::get('/history', [\App\Http\Controllers\FortuneTellingController::class, 'history'])->name('history');
|
||||
});
|
||||
|
||||
// ── 双色球彩票(前台)──────────────────────────────────────
|
||||
Route::prefix('lottery')->name('lottery.')->group(function () {
|
||||
// 当期状态:奖池金额 / 剩余购票时间 / 我的购票
|
||||
Route::get('/current', [\App\Http\Controllers\LotteryController::class, 'current'])->name('current');
|
||||
// 购票(自选或机选)
|
||||
Route::post('/buy', [\App\Http\Controllers\LotteryController::class, 'buy'])->name('buy');
|
||||
// 服务端机选号码生成(不扣费,俩前端展示后确认购买)
|
||||
Route::get('/quick-pick', [\App\Http\Controllers\LotteryController::class, 'quickPick'])->name('quick-pick');
|
||||
// 历史期次(最近20期)
|
||||
Route::get('/history', [\App\Http\Controllers\LotteryController::class, 'history'])->name('history');
|
||||
// 我的购票记录
|
||||
Route::get('/my', [\App\Http\Controllers\LotteryController::class, 'my'])->name('my');
|
||||
});
|
||||
|
||||
// ── 游戏大厅:实时开关状态接口 ────────────────────────────────────
|
||||
Route::get('/games/enabled', function () {
|
||||
return response()->json([
|
||||
@@ -171,6 +185,7 @@ Route::middleware(['chat.auth'])->group(function () {
|
||||
'horse_racing' => \App\Models\GameConfig::isEnabled('horse_racing'),
|
||||
'fortune_telling' => \App\Models\GameConfig::isEnabled('fortune_telling'),
|
||||
'fishing' => \App\Models\GameConfig::isEnabled('fishing'),
|
||||
'lottery' => \App\Models\GameConfig::isEnabled('lottery'),
|
||||
]);
|
||||
})->name('games.enabled');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user