feat: 彩票业务迁移并补全后台权限与代理结算体系
This commit is contained in:
@@ -41,16 +41,16 @@ final class SettlementOrchestrator
|
||||
*/
|
||||
public function trySettleDraw(Draw $draw): bool
|
||||
{
|
||||
return (bool) DB::transaction(function () use ($draw): bool {
|
||||
$afterCommit = DB::transaction(function () use ($draw): array {
|
||||
/** @var Draw $locked */
|
||||
$locked = Draw::query()->whereKey($draw->id)->lockForUpdate()->firstOrFail();
|
||||
|
||||
if ($locked->status === DrawStatus::Settled->value) {
|
||||
return false;
|
||||
return ['handled' => false, 'jackpot_bursts' => [], 'should_notify_status' => false];
|
||||
}
|
||||
|
||||
if ($locked->status !== DrawStatus::Settling->value) {
|
||||
return false;
|
||||
return ['handled' => false, 'jackpot_bursts' => [], 'should_notify_status' => false];
|
||||
}
|
||||
|
||||
$publishedBatch = DrawResultBatch::query()
|
||||
@@ -61,7 +61,7 @@ final class SettlementOrchestrator
|
||||
->first();
|
||||
|
||||
if ($publishedBatch === null) {
|
||||
return false;
|
||||
return ['handled' => false, 'jackpot_bursts' => [], 'should_notify_status' => false];
|
||||
}
|
||||
|
||||
$existingDone = SettlementBatch::query()
|
||||
@@ -81,7 +81,11 @@ final class SettlementOrchestrator
|
||||
'settle_version' => (int) $existingDone->settle_version,
|
||||
])->save();
|
||||
|
||||
return true;
|
||||
return [
|
||||
'handled' => true,
|
||||
'jackpot_bursts' => [],
|
||||
'should_notify_status' => true,
|
||||
];
|
||||
}
|
||||
|
||||
$items = DrawResultItem::query()
|
||||
@@ -224,21 +228,39 @@ final class SettlementOrchestrator
|
||||
'settle_version' => $nextSettleVersion,
|
||||
])->save();
|
||||
|
||||
foreach ($jackpotBursts as $burst) {
|
||||
$this->hallRealtime->notifyJackpotBurst(
|
||||
(int) $locked->id,
|
||||
(string) $locked->draw_no,
|
||||
$board->firstPrizeNumber4d(),
|
||||
(string) $burst['currency'],
|
||||
(int) $burst['payout'],
|
||||
(int) $burst['winner_count'],
|
||||
(string) $burst['trigger'],
|
||||
(int) $burst['pool_after'],
|
||||
);
|
||||
$this->hallRealtime->notifyStatusChange($this->hallSnapshot->build());
|
||||
}
|
||||
|
||||
return true;
|
||||
return [
|
||||
'handled' => true,
|
||||
'jackpot_bursts' => array_map(fn (array $burst): array => [
|
||||
'draw_id' => (int) $locked->id,
|
||||
'draw_no' => (string) $locked->draw_no,
|
||||
'first_prize_number' => $board->firstPrizeNumber4d(),
|
||||
'currency' => (string) $burst['currency'],
|
||||
'payout' => (int) $burst['payout'],
|
||||
'winner_count' => (int) $burst['winner_count'],
|
||||
'trigger' => (string) $burst['trigger'],
|
||||
'pool_after' => (int) $burst['pool_after'],
|
||||
], $jackpotBursts),
|
||||
'should_notify_status' => true,
|
||||
];
|
||||
});
|
||||
|
||||
foreach ($afterCommit['jackpot_bursts'] as $burst) {
|
||||
$this->hallRealtime->notifyJackpotBurst(
|
||||
$burst['draw_id'],
|
||||
$burst['draw_no'],
|
||||
$burst['first_prize_number'],
|
||||
$burst['currency'],
|
||||
$burst['payout'],
|
||||
$burst['winner_count'],
|
||||
$burst['trigger'],
|
||||
$burst['pool_after'],
|
||||
);
|
||||
}
|
||||
|
||||
if (($afterCommit['should_notify_status'] ?? false) === true) {
|
||||
$this->hallRealtime->notifyStatusChange($this->hallSnapshot->build());
|
||||
}
|
||||
|
||||
return (bool) ($afterCommit['handled'] ?? false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ final class SettlementTickFinalizer
|
||||
$pending = SettlementBatch::query()
|
||||
->where('status', SettlementBatchStatus::PendingReview->value)
|
||||
->orderBy('id')
|
||||
->limit((int) config('lottery.draw_tick_finalize_limit', 5))
|
||||
->get();
|
||||
|
||||
foreach ($pending as $batch) {
|
||||
|
||||
Reference in New Issue
Block a user