60 lines
2.1 KiB
PHP
60 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1\Admin\Draw;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Draw;
|
|
use App\Models\DrawResultBatch;
|
|
use App\Models\DrawResultItem;
|
|
use App\Support\ApiResponse;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
/**
|
|
* GET /api/v1/admin/draws/{draw}/result-batches — 开奖批次与号码(审核/结果核对)。
|
|
*/
|
|
final class AdminDrawResultBatchesIndexController extends Controller
|
|
{
|
|
public function __invoke(Draw $draw): JsonResponse
|
|
{
|
|
$batches = $draw->resultBatches()
|
|
->with(['items' => function ($q): void {
|
|
$q->orderBy('prize_type')->orderBy('prize_index');
|
|
}])
|
|
->orderByDesc('result_version')
|
|
->get();
|
|
|
|
return ApiResponse::success([
|
|
'draw_id' => (int) $draw->id,
|
|
'draw_no' => $draw->draw_no,
|
|
'draw_status' => $draw->status,
|
|
'batches' => $batches->map(fn (DrawResultBatch $b) => $this->serializeBatch($b))->all(),
|
|
]);
|
|
}
|
|
|
|
/** @return array<string, mixed> */
|
|
private function serializeBatch(DrawResultBatch $batch): array
|
|
{
|
|
return [
|
|
'id' => (int) $batch->id,
|
|
'result_version' => (int) $batch->result_version,
|
|
'source_type' => $batch->source_type,
|
|
'rng_seed_hash' => $batch->rng_seed_hash,
|
|
'status' => $batch->status,
|
|
'created_by' => $batch->created_by,
|
|
'confirmed_by' => $batch->confirmed_by,
|
|
'confirmed_at' => $batch->confirmed_at?->toIso8601String(),
|
|
'created_at' => $batch->created_at?->toIso8601String(),
|
|
'updated_at' => $batch->updated_at?->toIso8601String(),
|
|
'items' => $batch->items->map(fn (DrawResultItem $item) => [
|
|
'prize_type' => $item->prize_type,
|
|
'prize_index' => (int) $item->prize_index,
|
|
'number_4d' => $item->number_4d,
|
|
'suffix_3d' => $item->suffix_3d,
|
|
'suffix_2d' => $item->suffix_2d,
|
|
'head_digit' => $item->head_digit,
|
|
'tail_digit' => $item->tail_digit,
|
|
])->values()->all(),
|
|
];
|
|
}
|
|
}
|