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);
|
|||
|
|
}
|
|||
|
|
}
|