55 lines
2.1 KiB
PHP
55 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1\Admin\Jackpot;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\JackpotContribution;
|
|
use App\Support\ApiResponse;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
/**
|
|
* GET /api/v1/admin/jackpot/contributions — Jackpot 蓄水流水。
|
|
*/
|
|
final class AdminJackpotContributionIndexController extends Controller
|
|
{
|
|
public function __invoke(Request $request): JsonResponse
|
|
{
|
|
$perPage = min(max((int) $request->integer('per_page', 25), 1), 100);
|
|
$page = max((int) $request->integer('page', 1), 1);
|
|
$drawNo = trim((string) $request->query('draw_no', ''));
|
|
|
|
$q = JackpotContribution::query()
|
|
->with(['draw:id,draw_no', 'pool:id,currency_code', 'player:id,username,site_player_id', 'ticketItem:id,ticket_no'])
|
|
->orderByDesc('id');
|
|
|
|
if ($drawNo !== '') {
|
|
$q->whereHas('draw', fn ($d) => $d->where('draw_no', 'like', '%'.$drawNo.'%'));
|
|
}
|
|
|
|
$paginator = $q->paginate($perPage, ['*'], 'page', $page);
|
|
|
|
return ApiResponse::success([
|
|
'items' => collect($paginator->items())->map(fn (JackpotContribution $r) => [
|
|
'id' => (int) $r->id,
|
|
'draw_id' => (int) $r->draw_id,
|
|
'draw_no' => $r->draw?->draw_no,
|
|
'jackpot_pool_id' => (int) $r->jackpot_pool_id,
|
|
'currency_code' => $r->pool?->currency_code,
|
|
'player_id' => (int) $r->player_id,
|
|
'player_username' => $r->player?->username,
|
|
'ticket_item_id' => $r->ticket_item_id !== null ? (int) $r->ticket_item_id : null,
|
|
'ticket_no' => $r->ticketItem?->ticket_no,
|
|
'contribution_amount' => (int) $r->contribution_amount,
|
|
'created_at' => $r->created_at?->toIso8601String(),
|
|
])->all(),
|
|
'meta' => [
|
|
'current_page' => $paginator->currentPage(),
|
|
'per_page' => $paginator->perPage(),
|
|
'total' => $paginator->total(),
|
|
'last_page' => $paginator->lastPage(),
|
|
],
|
|
]);
|
|
}
|
|
}
|