feat: 添加结算功能,更新 TicketItem 模型以支持最新结算详情,增强 DrawTickService 以自动处理结算,更新 TicketWalletService 以支持派彩入账,扩展 API 路由以管理结算批次和奖池
This commit is contained in:
@@ -4,6 +4,8 @@ namespace App\Services\Draw;
|
||||
|
||||
use App\Lottery\DrawStatus;
|
||||
use App\Models\Draw;
|
||||
use App\Services\LotterySettings;
|
||||
use App\Services\Settlement\SettlementOrchestrator;
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
@@ -18,6 +20,7 @@ final class DrawTickService
|
||||
private readonly DrawRngRunner $rng,
|
||||
private readonly DrawHallSnapshotBuilder $hallSnapshot,
|
||||
private readonly LotteryHallRealtimeBroadcaster $hallRealtime,
|
||||
private readonly SettlementOrchestrator $settlementOrchestrator,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -41,11 +44,14 @@ final class DrawTickService
|
||||
'cooldown_to_settling' => $this->cooldownToSettling($nowUtc),
|
||||
];
|
||||
|
||||
$settlingSettled = $this->settleSettlingDraws();
|
||||
|
||||
$rngOutcome = $this->rng->runDue($nowUtc);
|
||||
$planned = $this->planner->ensureBuffer($nowUtc);
|
||||
|
||||
$report = [
|
||||
'status_updates' => $statusUpdates,
|
||||
'settling_settled' => $settlingSettled,
|
||||
'rng_rung' => $rngOutcome['rung'],
|
||||
'rng_errors' => $rngOutcome['errors'],
|
||||
'planned' => $planned,
|
||||
@@ -131,4 +137,34 @@ final class DrawTickService
|
||||
->where('cooling_end_time', '<=', $nowUtc)
|
||||
->update(['status' => DrawStatus::Settling->value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 冷静期结束后已进入 `settling` 的期号:执行阶段 6 结算(可经 lottery_settings 关闭自动跑批)。
|
||||
*
|
||||
* @return int 成功跑完结算的期号数量
|
||||
*/
|
||||
private function settleSettlingDraws(): int
|
||||
{
|
||||
if (! (bool) LotterySettings::get('settlement.auto_run_on_tick', true)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$n = 0;
|
||||
$ids = Draw::query()->where('status', DrawStatus::Settling->value)->pluck('id');
|
||||
foreach ($ids as $drawId) {
|
||||
$draw = Draw::query()->find($drawId);
|
||||
if ($draw === null) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
if ($this->settlementOrchestrator->trySettleDraw($draw)) {
|
||||
$n++;
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
report($e);
|
||||
}
|
||||
}
|
||||
|
||||
return $n;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user