feat: 增强奖池与钱包管理功能
更新 AdminJackpotPoolUpdateController 校验规则,禁止传入 current_amount。 优化 AdminRiskPoolManualStatusController:更新奖池状态后同步 Redis 状态。 在 TransferOrderReconcileController 中新增 completeCredit 方法,用于处理卡住的转账订单对账。 调整 TransferOrderListController:优化转账订单处理条件。 在 TicketItemsIndexController 中实现支持时区的日期筛选,提升日期处理准确性。 扩展 JackpotPool 模型,新增 adjustments 关联关系。 改进票据与钱包相关服务中的错误处理和事务管理。
This commit is contained in:
@@ -8,6 +8,10 @@ use Illuminate\Support\Facades\DB;
|
||||
|
||||
final class DrawAdminActionService
|
||||
{
|
||||
public function __construct(
|
||||
private readonly DrawCancelBetRefundService $cancelBetRefund,
|
||||
) {}
|
||||
|
||||
public function manualClose(Draw $draw): Draw
|
||||
{
|
||||
return DB::transaction(function () use ($draw): Draw {
|
||||
@@ -43,6 +47,8 @@ final class DrawAdminActionService
|
||||
throw new \RuntimeException('draw_result_exists');
|
||||
}
|
||||
|
||||
$this->cancelBetRefund->refundOpenBetsForDraw($locked);
|
||||
|
||||
$locked->forceFill(['status' => DrawStatus::Cancelled->value])->save();
|
||||
|
||||
return $locked->refresh();
|
||||
|
||||
91
app/Services/Draw/DrawCancelBetRefundService.php
Normal file
91
app/Services/Draw/DrawCancelBetRefundService.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Draw;
|
||||
|
||||
use App\Models\Draw;
|
||||
use App\Models\TicketItem;
|
||||
use App\Models\TicketOrder;
|
||||
use App\Models\WalletTxn;
|
||||
use App\Services\Ticket\RiskPoolService;
|
||||
use App\Services\Ticket\TicketWalletService;
|
||||
|
||||
/**
|
||||
* 取消期号前:退本、释池,避免已扣款注单悬空。
|
||||
*/
|
||||
final class DrawCancelBetRefundService
|
||||
{
|
||||
public function __construct(
|
||||
private readonly RiskPoolService $riskPool,
|
||||
private readonly TicketWalletService $ticketWallet,
|
||||
) {}
|
||||
|
||||
public function refundOpenBetsForDraw(Draw $draw): void
|
||||
{
|
||||
$hasBlockedItems = TicketItem::query()
|
||||
->where('draw_id', $draw->id)
|
||||
->whereIn('status', ['settled_win', 'settled_lose', 'pending_payout'])
|
||||
->exists();
|
||||
|
||||
if ($hasBlockedItems) {
|
||||
throw new \RuntimeException('draw_has_settled_tickets');
|
||||
}
|
||||
|
||||
$orders = TicketOrder::query()
|
||||
->where('draw_id', $draw->id)
|
||||
->whereNotIn('status', ['refunded', 'failed'])
|
||||
->orderBy('id')
|
||||
->get();
|
||||
|
||||
foreach ($orders as $order) {
|
||||
$this->refundOrder($draw, $order);
|
||||
}
|
||||
}
|
||||
|
||||
private function refundOrder(Draw $draw, TicketOrder $order): void
|
||||
{
|
||||
$lockedOrder = TicketOrder::query()->whereKey($order->id)->lockForUpdate()->first();
|
||||
if ($lockedOrder === null || in_array($lockedOrder->status, ['refunded', 'failed'], true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$items = TicketItem::query()
|
||||
->where('order_id', $lockedOrder->id)
|
||||
->whereIn('status', ['pending_confirm', 'pending_draw', 'pending_payout'])
|
||||
->with('combinations')
|
||||
->lockForUpdate()
|
||||
->get();
|
||||
|
||||
foreach ($items as $item) {
|
||||
$locks = [];
|
||||
foreach ($item->combinations as $combo) {
|
||||
$locks[] = [
|
||||
'number_4d' => (string) $combo->number_4d,
|
||||
'amount' => (int) $combo->estimated_payout,
|
||||
];
|
||||
}
|
||||
|
||||
if ($locks !== []) {
|
||||
$this->riskPool->release((int) $draw->id, $item, $locks);
|
||||
}
|
||||
|
||||
$item->forceFill([
|
||||
'status' => 'refunded',
|
||||
'fail_reason_code' => 'draw_cancelled',
|
||||
'fail_reason_text' => 'draw_cancelled_refund',
|
||||
'risk_locked_amount' => 0,
|
||||
])->save();
|
||||
}
|
||||
|
||||
$hasPostedDeduct = WalletTxn::query()
|
||||
->where('biz_type', 'bet_deduct')
|
||||
->where('biz_no', $lockedOrder->order_no)
|
||||
->where('status', 'posted')
|
||||
->exists();
|
||||
|
||||
if ($hasPostedDeduct) {
|
||||
$this->ticketWallet->reverseBetDeduct($lockedOrder);
|
||||
}
|
||||
|
||||
$lockedOrder->forceFill(['status' => 'refunded'])->save();
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,14 @@ final class DrawHallSnapshotBuilder
|
||||
return DrawStatus::Closing->value;
|
||||
}
|
||||
|
||||
/** 与大厅 {@see effectiveHallDisplayStatus} 一致:是否仍接受 preview/place。 */
|
||||
public function isBettingOpen(Draw $draw, ?Carbon $nowUtc = null): bool
|
||||
{
|
||||
$nowUtc ??= now()->utc();
|
||||
|
||||
return $this->effectiveHallDisplayStatus($draw, $nowUtc) === DrawStatus::Open->value;
|
||||
}
|
||||
|
||||
private function showsPublishedResults(string $drawStatus): bool
|
||||
{
|
||||
return in_array($drawStatus, [
|
||||
|
||||
@@ -28,6 +28,13 @@ final class DrawManualResultService
|
||||
throw new \RuntimeException('draw_already_settled');
|
||||
}
|
||||
|
||||
if (DrawResultBatch::query()
|
||||
->where('draw_id', $locked->id)
|
||||
->where('status', DrawResultBatchStatus::PendingReview->value)
|
||||
->exists()) {
|
||||
throw new \RuntimeException('draw_pending_result_batch_exists');
|
||||
}
|
||||
|
||||
$nextVersion = max(1, (int) $locked->current_result_version + 1);
|
||||
$batch = DrawResultBatch::query()->create([
|
||||
'draw_id' => $locked->id,
|
||||
|
||||
@@ -6,9 +6,11 @@ use App\Models\Draw;
|
||||
use App\Models\AdminUser;
|
||||
use App\Lottery\DrawStatus;
|
||||
use App\Models\DrawResultBatch;
|
||||
use App\Models\SettlementBatch;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Services\LotterySettings;
|
||||
use App\Lottery\DrawResultBatchStatus;
|
||||
use App\Lottery\SettlementBatchStatus;
|
||||
|
||||
/**
|
||||
* 人工审核通过后发布结果;或 RNG 自动生成路径内联调用同一事务字段更新。
|
||||
@@ -114,10 +116,28 @@ final class DrawPublishService
|
||||
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');
|
||||
}
|
||||
|
||||
$this->assertNoActiveSettlementWorkflow($draw);
|
||||
}
|
||||
|
||||
/** 存在未完结结算批次时不允许改发布结果,避免派彩与大厅展示号码不一致。 */
|
||||
private function assertNoActiveSettlementWorkflow(Draw $draw): void
|
||||
{
|
||||
$active = SettlementBatch::query()
|
||||
->where('draw_id', $draw->id)
|
||||
->whereIn('status', [
|
||||
SettlementBatchStatus::Running->value,
|
||||
SettlementBatchStatus::PendingReview->value,
|
||||
SettlementBatchStatus::Approved->value,
|
||||
])
|
||||
->exists();
|
||||
|
||||
if ($active) {
|
||||
throw new \RuntimeException('draw_settlement_in_progress');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user