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 */ private function row(SettlementBatch $b): array { $financial = SettlementBatchFinancialSummary::forBatch($b); 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, 'review_status' => $b->review_status, 'reviewed_at' => $b->reviewed_at?->toIso8601String(), 'paid_at' => $b->paid_at?->toIso8601String(), 'total_ticket_count' => (int) $b->total_ticket_count, 'total_win_count' => (int) $b->total_win_count, 'total_bet_amount' => $financial['total_bet_amount'], 'total_actual_deduct' => $financial['total_actual_deduct'], 'total_payout_amount' => (int) $b->total_payout_amount, 'total_jackpot_payout_amount' => (int) $b->total_jackpot_payout_amount, 'platform_profit' => $financial['platform_profit'], 'started_at' => $b->started_at?->toIso8601String(), 'finished_at' => $b->finished_at?->toIso8601String(), 'created_at' => $b->created_at?->toIso8601String(), ]; } }