feat: 增强抽奖管理功能,支持手动创建、更新和删除期号
- 新增 API 路由和控制器,允许管理员手动创建、更新和删除抽奖期号。 - 更新抽奖调度逻辑,确保在抽奖时间和封盘时间的管理上更加灵活。 - 添加多语言支持的错误信息,提升用户体验。 - 更新测试用例,确保新功能的正确性和稳定性。
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Draw;
|
||||
|
||||
use App\Lottery\ErrorCode;
|
||||
use App\Support\ApiResponse;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Draw\DrawManualCreateService;
|
||||
use App\Http\Requests\Admin\DrawStoreRequest;
|
||||
|
||||
final class AdminDrawStoreController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly DrawManualCreateService $service,
|
||||
) {}
|
||||
|
||||
public function __invoke(DrawStoreRequest $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
$draw = $this->service->create($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'),
|
||||
default => trans('api.client_error'),
|
||||
};
|
||||
|
||||
return ApiResponse::error($message, ErrorCode::ClientHttpError->value, ['reason' => $e->getMessage()], 409);
|
||||
}
|
||||
|
||||
return ApiResponse::success([
|
||||
'id' => (int) $draw->id,
|
||||
'draw_no' => $draw->draw_no,
|
||||
'business_date' => (string) $draw->business_date,
|
||||
'sequence_no' => (int) $draw->sequence_no,
|
||||
'status' => $draw->status,
|
||||
'start_time' => $draw->start_time?->toIso8601String(),
|
||||
'close_time' => $draw->close_time?->toIso8601String(),
|
||||
'draw_time' => $draw->draw_time?->toIso8601String(),
|
||||
])->setStatusCode(201);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user