59 lines
2.0 KiB
PHP
59 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1\Admin\Settlement;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\Support\AdminApiList;
|
|
use App\Models\SettlementBatch;
|
|
use Illuminate\Http\JsonResponse;
|
|
use App\Http\Controllers\Controller;
|
|
|
|
/**
|
|
* GET /api/v1/admin/settlement-batches — 结算批次分页列表。
|
|
*/
|
|
final class AdminSettlementBatchIndexController extends Controller
|
|
{
|
|
public function __invoke(Request $request): JsonResponse
|
|
{
|
|
$p = AdminApiList::readPaging($request);
|
|
$drawNo = trim((string) $request->query('draw_no', ''));
|
|
$status = trim((string) $request->query('status', ''));
|
|
|
|
$q = SettlementBatch::query()
|
|
->with(['draw:id,draw_no'])
|
|
->orderByDesc('id');
|
|
|
|
if ($drawNo !== '') {
|
|
$q->whereHas('draw', fn ($d) => $d->where('draw_no', 'like', '%'.$drawNo.'%'));
|
|
}
|
|
|
|
if ($status !== '') {
|
|
$q->where('status', $status);
|
|
}
|
|
|
|
$paginator = $q->paginate($p['perPage'], ['*'], 'page', $p['page']);
|
|
|
|
return AdminApiList::json($paginator, fn (SettlementBatch $b) => $this->row($b));
|
|
}
|
|
|
|
/** @return array<string, mixed> */
|
|
private function row(SettlementBatch $b): array
|
|
{
|
|
return [
|
|
'id' => (int) $b->id,
|
|
'draw_id' => (int) $b->draw_id,
|
|
'draw_no' => $b->draw?->draw_no,
|
|
'result_batch_id' => (int) $b->result_batch_id,
|
|
'settle_version' => (int) $b->settle_version,
|
|
'status' => $b->status,
|
|
'total_ticket_count' => (int) $b->total_ticket_count,
|
|
'total_win_count' => (int) $b->total_win_count,
|
|
'total_payout_amount' => (int) $b->total_payout_amount,
|
|
'total_jackpot_payout_amount' => (int) $b->total_jackpot_payout_amount,
|
|
'started_at' => $b->started_at?->toIso8601String(),
|
|
'finished_at' => $b->finished_at?->toIso8601String(),
|
|
'created_at' => $b->created_at?->toIso8601String(),
|
|
];
|
|
}
|
|
}
|