feat: 增强抽奖管理功能,支持手动创建、更新和删除期号

- 新增 API 路由和控制器,允许管理员手动创建、更新和删除抽奖期号。
- 更新抽奖调度逻辑,确保在抽奖时间和封盘时间的管理上更加灵活。
- 添加多语言支持的错误信息,提升用户体验。
- 更新测试用例,确保新功能的正确性和稳定性。
This commit is contained in:
2026-05-25 18:00:22 +08:00
parent 770fd8950d
commit c74bec3f64
21 changed files with 855 additions and 51 deletions

View File

@@ -0,0 +1,75 @@
<?php
namespace App\Services\Draw;
use Carbon\Carbon;
use App\Lottery\DrawStatus;
/**
* 由开奖时刻推导下注窗口、封盘时刻与期号初始状态。
*/
final class DrawTimelineBuilder
{
public function closeBeforeDrawSeconds(): int
{
return (int) config('lottery.draw.close_before_draw_seconds', 30);
}
public function bettingWindowSeconds(): int
{
return (int) config('lottery.draw.betting_window_seconds', 270);
}
/**
* @return array{start_local: Carbon, close_local: Carbon, draw_local: Carbon}
*/
public function windowsFromDrawLocal(Carbon $drawLocal): array
{
$closeLocal = $drawLocal->copy()->subSeconds($this->closeBeforeDrawSeconds());
$startLocal = $closeLocal->copy()->subSeconds($this->bettingWindowSeconds());
return [
'start_local' => $startLocal,
'close_local' => $closeLocal,
'draw_local' => $drawLocal->copy(),
];
}
/**
* @return array{start_utc: Carbon, close_utc: Carbon, draw_utc: Carbon, status: string}
*/
public function buildFromLocals(Carbon $startLocal, Carbon $closeLocal, Carbon $drawLocal, Carbon $nowUtc): array
{
$startUtc = $startLocal->copy()->timezone('UTC');
$closeUtc = $closeLocal->copy()->timezone('UTC');
$drawUtc = $drawLocal->copy()->timezone('UTC');
return [
'start_utc' => $startUtc,
'close_utc' => $closeUtc,
'draw_utc' => $drawUtc,
'status' => $this->statusForTimeline($nowUtc, $startUtc, $closeUtc, $drawUtc),
];
}
public function statusForTimeline(Carbon $nowUtc, Carbon $startUtc, Carbon $closeUtc, Carbon $drawUtc): string
{
if ($nowUtc < $startUtc) {
return DrawStatus::Pending->value;
}
if ($nowUtc < $closeUtc) {
return DrawStatus::Open->value;
}
if ($nowUtc < $drawUtc) {
return DrawStatus::Closing->value;
}
return DrawStatus::Closed->value;
}
public function drawNo(string $businessDate, int $sequenceNo): string
{
return str_replace('-', '', $businessDate).'-'.
str_pad((string) $sequenceNo, 3, '0', STR_PAD_LEFT);
}
}