value, null, 422); } $pool = RiskPool::query() ->where('draw_id', $draw->id) ->where('normalized_number', $number_4d) ->first(); if ($pool === null) { return ApiResponse::error('该期尚无此号码的风险池记录', ErrorCode::NotFound->value, null, 404); } $perPage = min(max((int) $request->integer('per_page', 20), 1), 100); /** @var LengthAwarePaginator $paginator */ $paginator = RiskPoolLockLog::query() ->where('draw_id', $draw->id) ->where('normalized_number', $number_4d) ->with(['ticketItem:id,ticket_no,play_code,player_id']) ->orderByDesc('created_at') ->orderByDesc('id') ->paginate($perPage); $cap = (int) $pool->total_cap_amount; $locked = (int) $pool->locked_amount; return ApiResponse::success([ 'draw_id' => (int) $draw->id, 'draw_no' => $draw->draw_no, 'pool' => [ 'normalized_number' => $pool->normalized_number, 'total_cap_amount' => $cap, 'locked_amount' => $locked, 'remaining_amount' => (int) $pool->remaining_amount, 'sold_out_status' => (int) $pool->sold_out_status, 'is_sold_out' => (int) $pool->sold_out_status === 1, 'usage_ratio' => $cap > 0 ? round($locked / $cap, 6) : null, 'version' => (int) $pool->version, ], 'logs' => [ 'items' => collect($paginator->items())->map(fn (RiskPoolLockLog $log) => $this->logRow($log))->all(), 'meta' => [ 'current_page' => $paginator->currentPage(), 'per_page' => $paginator->perPage(), 'total' => $paginator->total(), 'last_page' => $paginator->lastPage(), ], ], ]); } /** @return array */ private function logRow(RiskPoolLockLog $log): array { return [ 'id' => (int) $log->id, 'action_type' => $log->action_type, 'amount' => (int) $log->amount, 'source_reason' => $log->source_reason, 'ticket_item_id' => $log->ticket_item_id, 'ticket_no' => $log->ticketItem?->ticket_no, 'play_code' => $log->ticketItem?->play_code, 'player_id' => $log->ticketItem?->player_id, 'created_at' => $log->created_at?->toIso8601String(), ]; } }