- 新增 API 路由和控制器,允许管理员手动创建、更新和删除抽奖期号。 - 更新抽奖调度逻辑,确保在抽奖时间和封盘时间的管理上更加灵活。 - 添加多语言支持的错误信息,提升用户体验。 - 更新测试用例,确保新功能的正确性和稳定性。
48 lines
1.8 KiB
PHP
48 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1\Admin\Draw;
|
|
|
|
use App\Models\Draw;
|
|
use App\Lottery\ErrorCode;
|
|
use App\Support\ApiResponse;
|
|
use Illuminate\Http\JsonResponse;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Admin\DrawStoreRequest;
|
|
use App\Services\Draw\DrawManualUpdateService;
|
|
|
|
final class AdminDrawUpdateController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly DrawManualUpdateService $service,
|
|
) {}
|
|
|
|
public function __invoke(DrawStoreRequest $request, Draw $draw): JsonResponse
|
|
{
|
|
try {
|
|
$updated = $this->service->update($draw, $request->validated());
|
|
} catch (\RuntimeException $e) {
|
|
$message = match ($e->getMessage()) {
|
|
'draw_no_exists' => trans('api.draw_no_exists'),
|
|
'draw_timeline_invalid' => trans('api.draw_timeline_invalid'),
|
|
'draw_not_editable' => trans('api.draw_not_editable'),
|
|
'draw_has_bets' => trans('api.draw_has_bets'),
|
|
'draw_result_exists' => trans('api.draw_result_exists'),
|
|
default => trans('api.client_error'),
|
|
};
|
|
|
|
return ApiResponse::error($message, ErrorCode::ClientHttpError->value, ['reason' => $e->getMessage()], 409);
|
|
}
|
|
|
|
return ApiResponse::success([
|
|
'id' => (int) $updated->id,
|
|
'draw_no' => $updated->draw_no,
|
|
'business_date' => (string) $updated->business_date,
|
|
'sequence_no' => (int) $updated->sequence_no,
|
|
'status' => $updated->status,
|
|
'start_time' => $updated->start_time?->toIso8601String(),
|
|
'close_time' => $updated->close_time?->toIso8601String(),
|
|
'draw_time' => $updated->draw_time?->toIso8601String(),
|
|
]);
|
|
}
|
|
}
|