feat(admin): 增强玩家注单查询过滤并返回金额格式化字段
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Models\Player;
|
||||
use App\Models\TicketItem;
|
||||
use App\Support\ApiResponse;
|
||||
use App\Support\PaginationTrait;
|
||||
use App\Support\CurrencyFormatter;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\AdminPlayerTicketItemsRequest;
|
||||
@@ -13,7 +14,7 @@ use App\Http\Requests\Admin\AdminPlayerTicketItemsRequest;
|
||||
/**
|
||||
* GET /api/v1/admin/players/{player}/ticket-items — 客服/财务按玩家查注单(PRD §15.4)。
|
||||
*
|
||||
* Query:`page`、`per_page`(最大 50)、`draw_no`(可选,精确期号)。
|
||||
* Query:`page`、`per_page`(最大 50)、`draw_no`、`status[]`、`number`、`start_date`、`end_date`。
|
||||
*/
|
||||
final class AdminPlayerTicketItemsIndexController extends Controller
|
||||
{
|
||||
@@ -27,6 +28,17 @@ final class AdminPlayerTicketItemsIndexController extends Controller
|
||||
if (is_string($drawNo)) {
|
||||
$drawNo = trim($drawNo);
|
||||
}
|
||||
$statusInput = $request->validated('status', []);
|
||||
if (is_string($statusInput)) {
|
||||
$statusInput = [$statusInput];
|
||||
}
|
||||
$statusValues = is_array($statusInput) ? array_values(array_filter(array_map(
|
||||
fn ($status) => is_string($status) ? trim($status) : '',
|
||||
$statusInput,
|
||||
))) : [];
|
||||
$number = trim((string) $request->validated('number', ''));
|
||||
$startDate = $request->validated('start_date');
|
||||
$endDate = $request->validated('end_date');
|
||||
|
||||
$query = TicketItem::query()
|
||||
->where('ticket_items.player_id', $player->id)
|
||||
@@ -40,9 +52,35 @@ final class AdminPlayerTicketItemsIndexController 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.'%')
|
||||
->orWhereHas('order', fn ($order) => $order->where('order_no', 'like', '%'.$number.'%'));
|
||||
});
|
||||
}
|
||||
|
||||
if (is_string($startDate) && $startDate !== '') {
|
||||
$query->whereHas('order', fn ($q) => $q->whereDate('created_at', '>=', $startDate));
|
||||
}
|
||||
|
||||
if (is_string($endDate) && $endDate !== '') {
|
||||
$query->whereHas('order', fn ($q) => $q->whereDate('created_at', '<=', $endDate));
|
||||
}
|
||||
|
||||
$paginator = $query->paginate(perPage: $perPage, page: $page, columns: ['*']);
|
||||
|
||||
$items = collect($paginator->items())->map(function (TicketItem $row): array {
|
||||
$totalBet = (int) $row->total_bet_amount;
|
||||
$actualDeduct = (int) $row->actual_deduct_amount;
|
||||
$winAmount = (int) $row->win_amount;
|
||||
$jackpotWin = (int) $row->jackpot_win_amount;
|
||||
|
||||
return [
|
||||
'ticket_no' => $row->ticket_no,
|
||||
'order_no' => $row->order?->order_no,
|
||||
@@ -50,13 +88,17 @@ final class AdminPlayerTicketItemsIndexController extends Controller
|
||||
'currency_code' => $row->order?->currency_code,
|
||||
'play_code' => $row->play_code,
|
||||
'original_number' => $row->original_number,
|
||||
'total_bet_amount' => (int) $row->total_bet_amount,
|
||||
'actual_deduct_amount' => (int) $row->actual_deduct_amount,
|
||||
'total_bet_amount' => $totalBet,
|
||||
'total_bet_amount_formatted' => CurrencyFormatter::fromMinor($totalBet),
|
||||
'actual_deduct_amount' => $actualDeduct,
|
||||
'actual_deduct_amount_formatted' => CurrencyFormatter::fromMinor($actualDeduct),
|
||||
'status' => $row->status,
|
||||
'fail_reason_code' => $row->fail_reason_code,
|
||||
'fail_reason_text' => $row->fail_reason_text,
|
||||
'win_amount' => (int) $row->win_amount,
|
||||
'jackpot_win_amount' => (int) $row->jackpot_win_amount,
|
||||
'win_amount' => $winAmount,
|
||||
'win_amount_formatted' => CurrencyFormatter::fromMinor($winAmount),
|
||||
'jackpot_win_amount' => $jackpotWin,
|
||||
'jackpot_win_amount_formatted' => CurrencyFormatter::fromMinor($jackpotWin),
|
||||
'placed_at' => $row->order?->created_at?->toIso8601String(),
|
||||
'updated_at' => $row->updated_at?->toIso8601String(),
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user