feat: 拆分开奖与结算审核流程,新增手动结果录入、重开和派彩审批接口
This commit is contained in:
@@ -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,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Api\V1\Ticket;
|
||||
|
||||
use App\Models\Player;
|
||||
use App\Models\TicketItem;
|
||||
use App\Models\WalletTxn;
|
||||
use App\Support\ApiResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Support\PaginationTrait;
|
||||
@@ -26,6 +27,14 @@ final class TicketItemsIndexController extends Controller
|
||||
$perPage = $this->perPage($request, 'per_page', 20, 50);
|
||||
$page = $this->page($request);
|
||||
$drawNo = $request->query('draw_no');
|
||||
$statusInput = $request->query('status', []);
|
||||
$statusValues = is_array($statusInput) ? array_values(array_filter(array_map(
|
||||
fn ($status) => is_string($status) ? trim($status) : '',
|
||||
$statusInput,
|
||||
))) : [];
|
||||
$number = trim((string) $request->query('number', ''));
|
||||
$startDate = $this->normalizeDate((string) $request->query('start_date', ''));
|
||||
$endDate = $this->normalizeDate((string) $request->query('end_date', ''));
|
||||
|
||||
$query = TicketItem::query()
|
||||
->where('ticket_items.player_id', $player->id)
|
||||
@@ -40,6 +49,26 @@ final class TicketItemsIndexController extends Controller
|
||||
$query->whereHas('draw', fn ($q) => $q->where('draw_no', $drawNo));
|
||||
}
|
||||
|
||||
if ($statusValues !== []) {
|
||||
$query->whereIn('ticket_items.status', $statusValues);
|
||||
}
|
||||
|
||||
if ($number !== '') {
|
||||
$query->where(function ($q) use ($number): void {
|
||||
$q->where('ticket_items.original_number', 'like', '%'.$number.'%')
|
||||
->orWhere('ticket_items.normalized_number', 'like', '%'.$number.'%')
|
||||
->orWhere('ticket_items.ticket_no', 'like', '%'.$number.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if ($startDate !== null) {
|
||||
$query->whereHas('order', fn ($q) => $q->whereDate('created_at', '>=', $startDate));
|
||||
}
|
||||
|
||||
if ($endDate !== null) {
|
||||
$query->whereHas('order', fn ($q) => $q->whereDate('created_at', '<=', $endDate));
|
||||
}
|
||||
|
||||
$paginator = $query->paginate(perPage: $perPage, page: $page);
|
||||
|
||||
$items = collect($paginator->items())->map(function (TicketItem $row): array {
|
||||
@@ -77,4 +106,14 @@ final class TicketItemsIndexController extends Controller
|
||||
'last_page' => $paginator->lastPage(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function normalizeDate(string $value): ?string
|
||||
{
|
||||
$value = trim($value);
|
||||
if ($value === '' || ! preg_match('/^\d{4}-\d{2}-\d{2}$/', $value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user