60 lines
2.4 KiB
PHP
60 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1\Admin\Draw;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Lottery\DrawResultBatchStatus;
|
|
use App\Models\Draw;
|
|
use App\Services\Draw\DrawHallSnapshotBuilder;
|
|
use App\Support\ApiResponse;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
/**
|
|
* GET /api/v1/admin/draws/{draw} — 当期状态明细(后台查看 DB 为准 + 大厅展示态预览)。
|
|
*/
|
|
final class AdminDrawShowController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly DrawHallSnapshotBuilder $hallPreview,
|
|
) {}
|
|
|
|
public function __invoke(Draw $draw): JsonResponse
|
|
{
|
|
$nowUtc = now()->utc();
|
|
$batchCounts = [
|
|
'total' => $draw->resultBatches()->count(),
|
|
'pending_review' => $draw->resultBatches()
|
|
->where('status', DrawResultBatchStatus::PendingReview->value)
|
|
->count(),
|
|
'published' => $draw->resultBatches()
|
|
->where('status', DrawResultBatchStatus::Published->value)
|
|
->count(),
|
|
];
|
|
|
|
return ApiResponse::success([
|
|
'id' => (int) $draw->id,
|
|
'draw_no' => $draw->draw_no,
|
|
'business_date' => $draw->business_date instanceof Carbon
|
|
? $draw->business_date->format('Y-m-d')
|
|
: (string) $draw->business_date,
|
|
'sequence_no' => (int) $draw->sequence_no,
|
|
/** 数据库当期状态(权威) */
|
|
'status' => $draw->status,
|
|
/** 与玩家大厅 snapshot 对齐的展示态(未跑 tick 时可能与 status 不一致) */
|
|
'hall_preview_status' => $this->hallPreview->effectiveHallDisplayStatus($draw, $nowUtc),
|
|
'start_time' => $draw->start_time?->toIso8601String(),
|
|
'close_time' => $draw->close_time?->toIso8601String(),
|
|
'draw_time' => $draw->draw_time?->toIso8601String(),
|
|
'cooling_end_time' => $draw->cooling_end_time?->toIso8601String(),
|
|
'result_source' => $draw->result_source,
|
|
'current_result_version' => (int) $draw->current_result_version,
|
|
'settle_version' => (int) $draw->settle_version,
|
|
'is_reopened' => (bool) $draw->is_reopened,
|
|
'created_at' => $draw->created_at?->toIso8601String(),
|
|
'updated_at' => $draw->updated_at?->toIso8601String(),
|
|
'result_batch_counts' => $batchCounts,
|
|
]);
|
|
}
|
|
}
|