feat: 添加新的错误码以支持投注功能,更新数据库填充器以增强玩法和赔率配置,扩展 API 路由以支持风险池管理
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Risk;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Draw;
|
||||
use App\Models\RiskPoolLockLog;
|
||||
use App\Support\ApiResponse;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* GET /api/v1/admin/draws/{draw}/risk-pool-lock-logs — 风险池占用/释放流水(审计与监控)。
|
||||
*/
|
||||
final class AdminRiskPoolLockLogIndexController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request, Draw $draw): JsonResponse
|
||||
{
|
||||
$perPage = min(max((int) $request->integer('per_page', 25), 1), 100);
|
||||
$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($perPage);
|
||||
|
||||
return ApiResponse::success([
|
||||
'draw_id' => (int) $draw->id,
|
||||
'draw_no' => $draw->draw_no,
|
||||
'items' => collect($paginator->items())->map(fn (RiskPoolLockLog $log) => $this->row($log))->all(),
|
||||
'meta' => [
|
||||
'current_page' => $paginator->currentPage(),
|
||||
'per_page' => $paginator->perPage(),
|
||||
'total' => $paginator->total(),
|
||||
'last_page' => $paginator->lastPage(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/** @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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user