feat: 拆分开奖与结算审核流程,新增手动结果录入、重开和派彩审批接口

This commit is contained in:
2026-05-16 18:01:06 +08:00
parent 83046b402d
commit 4f143c7cb1
38 changed files with 1992 additions and 170 deletions

View File

@@ -4,7 +4,10 @@ namespace App\Http\Controllers\Api\V1\Ticket;
use App\Models\Player;
use App\Lottery\ErrorCode;
use App\Models\SettlementBatch;
use App\Models\TicketItem;
use App\Models\TicketOrder;
use App\Models\WalletTxn;
use App\Support\ApiResponse;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
@@ -51,6 +54,89 @@ final class TicketItemShowController extends Controller
$drawPayload = $published && $draw !== null ? $this->drawResultView->summarizeDraw($draw) : null;
$detail = $item->latestSettlementDetail;
$settlementBatch = $detail?->batch;
$order = $item->order;
$betTxn = WalletTxn::query()
->where('player_id', $player->id)
->where('biz_type', 'bet_deduct')
->where('biz_no', $order?->order_no)
->orderByDesc('id')
->first();
$payoutTxn = WalletTxn::query()
->where('player_id', $player->id)
->where('biz_type', 'settle_payout')
->where('biz_no', 'like', 'SB%')
->orderByDesc('id')
->first();
$timeline = [];
if ($order?->created_at !== null) {
$timeline[] = [
'code' => 'placed',
'label' => '已下注',
'time' => $order->created_at->toIso8601String(),
];
}
if ($betTxn?->created_at !== null) {
$timeline[] = [
'code' => 'deducted',
'label' => '已扣款',
'time' => $betTxn->created_at->toIso8601String(),
];
}
if ($drawPayload !== null && $draw?->current_result_version !== null) {
$timeline[] = [
'code' => 'draw_published',
'label' => '开奖结果已发布',
'time' => $draw->draw_time?->toIso8601String() ?? $draw->updated_at?->toIso8601String(),
];
}
if ($settlementBatch?->started_at !== null) {
$timeline[] = [
'code' => 'settlement_started',
'label' => '结算开始',
'time' => $settlementBatch->started_at->toIso8601String(),
];
}
if ($item->settled_at !== null) {
$timeline[] = [
'code' => 'settled',
'label' => $item->status === 'settled_win' ? '已派彩' : '已结算',
'time' => $item->settled_at->toIso8601String(),
];
} elseif ($payoutTxn?->created_at !== null) {
$timeline[] = [
'code' => 'settled',
'label' => '已派彩',
'time' => $payoutTxn->created_at->toIso8601String(),
];
}
$matchDetail = $detail?->match_detail_json;
$matchedLines = [];
if (is_array($matchDetail['lines'] ?? null)) {
foreach ($matchDetail['lines'] as $line) {
if (! is_array($line)) {
continue;
}
$matchedLines[] = [
'number_4d' => isset($line['number_4d']) ? (string) $line['number_4d'] : null,
'matched_tier' => isset($line['matched_tier']) ? (string) $line['matched_tier'] : null,
'bet_amount' => isset($line['bet_amount']) ? (int) $line['bet_amount'] : null,
'odds_value' => isset($line['odds_value']) ? (int) $line['odds_value'] : null,
'payout' => isset($line['payout']) ? (int) $line['payout'] : null,
];
}
}
$matchResult = [
'matched' => $detail !== null && ((int) $detail->win_amount > 0 || (int) $detail->jackpot_allocation_amount > 0),
'matched_prize_tier' => $detail?->matched_prize_tier,
'win_amount_minor' => $detail !== null ? (int) $detail->win_amount : 0,
'jackpot_allocation_minor' => $detail !== null ? (int) $detail->jackpot_allocation_amount : 0,
'match_detail' => $matchDetail,
'lines' => $matchedLines,
];
return ApiResponse::success([
'ticket_no' => $item->ticket_no,
@@ -83,6 +169,8 @@ final class TicketItemShowController extends Controller
'win_amount_minor' => (int) $detail->win_amount,
'jackpot_allocation_minor' => (int) $detail->jackpot_allocation_amount,
],
'match_result' => $matchResult,
'timeline' => $timeline,
'published_draw_results' => $drawPayload,
]);
}