📦 数据库 - 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 保护)
59 lines
1.2 KiB
PHP
59 lines
1.2 KiB
PHP
<?php
|
||
|
||
/**
|
||
* 文件功能:双色球开奖队列任务
|
||
*
|
||
* 由调度器在每日指定时间(draw_hour:draw_minute)触发。
|
||
* 流程:关闭本期购票 → 调用 LotteryService::draw() 执行开奖。
|
||
*
|
||
* @author ChatRoom Laravel
|
||
*
|
||
* @version 1.0.0
|
||
*/
|
||
|
||
namespace App\Jobs;
|
||
|
||
use App\Models\LotteryIssue;
|
||
use App\Services\LotteryService;
|
||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||
use Illuminate\Foundation\Queue\Queueable;
|
||
|
||
class DrawLotteryJob implements ShouldQueue
|
||
{
|
||
use Queueable;
|
||
|
||
/**
|
||
* 最大重试次数。
|
||
*/
|
||
public int $tries = 2;
|
||
|
||
/**
|
||
* @param LotteryIssue $issue 要开奖的期次
|
||
*/
|
||
public function __construct(
|
||
public readonly LotteryIssue $issue,
|
||
) {}
|
||
|
||
/**
|
||
* 执行开奖流程。
|
||
*/
|
||
public function handle(LotteryService $lottery): void
|
||
{
|
||
$issue = $this->issue->fresh();
|
||
|
||
// 防止重复开奖
|
||
if (! $issue || $issue->status === 'settled') {
|
||
return;
|
||
}
|
||
|
||
// 标记为已停售(closed),阻止新购票
|
||
if ($issue->status === 'open') {
|
||
$issue->update(['status' => 'closed']);
|
||
$issue->refresh();
|
||
}
|
||
|
||
// 执行开奖
|
||
$lottery->draw($issue);
|
||
}
|
||
}
|