64 lines
2.2 KiB
PHP
64 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1\Admin\Risk;
|
|
|
|
use App\Models\Draw;
|
|
use Illuminate\Http\Request;
|
|
use App\Support\AdminApiList;
|
|
use App\Models\RiskPoolLockLog;
|
|
use Illuminate\Http\JsonResponse;
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
|
|
|
/**
|
|
* GET /api/v1/admin/draws/{draw}/risk-pool-lock-logs — 风险池占用/释放流水(审计与监控)。
|
|
*/
|
|
final class AdminRiskPoolLockLogIndexController extends Controller
|
|
{
|
|
public function __invoke(Request $request, Draw $draw): JsonResponse
|
|
{
|
|
$p = AdminApiList::readPaging($request);
|
|
$action = trim((string) $request->query('action_type', ''));
|
|
$number = trim((string) $request->query('normalized_number', ''));
|
|
|
|
$q = RiskPoolLockLog::query()
|
|
->where('draw_id', $draw->id)
|
|
->with(['ticketItem:id,ticket_no,play_code,player_id'])
|
|
->orderByDesc('created_at')
|
|
->orderByDesc('id');
|
|
|
|
if ($action !== '' && in_array($action, ['lock', 'release'], true)) {
|
|
$q->where('action_type', $action);
|
|
}
|
|
|
|
if ($number !== '' && preg_match('/^[0-9]{4}$/', $number) === 1) {
|
|
$q->where('normalized_number', $number);
|
|
}
|
|
|
|
/** @var LengthAwarePaginator $paginator */
|
|
$paginator = $q->paginate($p['perPage'], ['*'], 'page', $p['page']);
|
|
|
|
return AdminApiList::jsonWith($paginator, fn (RiskPoolLockLog $log) => $this->row($log), [
|
|
'draw_id' => (int) $draw->id,
|
|
'draw_no' => $draw->draw_no,
|
|
]);
|
|
}
|
|
|
|
/** @return array<string, mixed> */
|
|
private function row(RiskPoolLockLog $log): array
|
|
{
|
|
return [
|
|
'id' => (int) $log->id,
|
|
'normalized_number' => $log->normalized_number,
|
|
'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(),
|
|
];
|
|
}
|
|
}
|