feat: Enhance settlement and draw management functionality
- Implement error handling for skipped settlement runs in DrawSettlementRunController, returning appropriate error messages based on draw status. - Add validation in DrawPublishService to ensure draws are ready for publication, rejecting outdated result batches. - Update SettlementBatchWorkflowService to revert ticket statuses upon settlement rejection and restore jackpot pool amounts. - Refactor LotteryTransferService to improve transaction handling for transfer order reconciliation, ensuring idempotency during reversals. - Add multi-language support for new error messages related to settlement processes.
This commit is contained in:
@@ -31,6 +31,15 @@ final class DrawPublishService
|
||||
|
||||
/** @var Draw $draw */
|
||||
$draw = Draw::query()->whereKey($lockedBatch->draw_id)->lockForUpdate()->firstOrFail();
|
||||
|
||||
$this->assertDrawReadyToPublish($draw, $lockedBatch);
|
||||
|
||||
DrawResultBatch::query()
|
||||
->where('draw_id', $draw->id)
|
||||
->where('id', '!=', $lockedBatch->id)
|
||||
->where('status', DrawResultBatchStatus::Published->value)
|
||||
->update(['status' => DrawResultBatchStatus::Rejected->value]);
|
||||
|
||||
$lockedBatch->forceFill([
|
||||
'status' => DrawResultBatchStatus::Published->value,
|
||||
'confirmed_by' => $admin->id,
|
||||
@@ -90,4 +99,25 @@ final class DrawPublishService
|
||||
|
||||
return $draw->refresh();
|
||||
}
|
||||
|
||||
private function assertDrawReadyToPublish(Draw $draw, DrawResultBatch $batch): void
|
||||
{
|
||||
if ($draw->status === DrawStatus::Cancelled->value || $draw->status === DrawStatus::Settled->value) {
|
||||
throw new \RuntimeException('draw_not_ready_to_publish');
|
||||
}
|
||||
|
||||
if ((int) $batch->result_version < (int) $draw->current_result_version) {
|
||||
throw new \RuntimeException('batch_result_version_stale');
|
||||
}
|
||||
|
||||
$allowed = [
|
||||
DrawStatus::Closed->value,
|
||||
DrawStatus::Review->value,
|
||||
DrawStatus::Cooldown->value,
|
||||
DrawStatus::Settling->value,
|
||||
];
|
||||
if (! in_array($draw->status, $allowed, true)) {
|
||||
throw new \RuntimeException('draw_not_ready_to_publish');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user