- 新增 API 路由和控制器,允许管理员手动创建、更新和删除抽奖期号。 - 更新抽奖调度逻辑,确保在抽奖时间和封盘时间的管理上更加灵活。 - 添加多语言支持的错误信息,提升用户体验。 - 更新测试用例,确保新功能的正确性和稳定性。
57 lines
1.8 KiB
PHP
57 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1\Admin\Draw;
|
|
|
|
use App\Lottery\ErrorCode;
|
|
use App\Support\ApiResponse;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Services\Draw\DrawDestroyService;
|
|
|
|
final class AdminDrawBatchDestroyController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly DrawDestroyService $service,
|
|
) {}
|
|
|
|
public function __invoke(Request $request): JsonResponse
|
|
{
|
|
$drawIds = $request->input('draw_ids', []);
|
|
|
|
if (!is_array($drawIds) || empty($drawIds)) {
|
|
return ApiResponse::error(trans('api.invalid_params'), ErrorCode::ClientHttpError->value, [], 400);
|
|
}
|
|
|
|
$results = [
|
|
'success' => [],
|
|
'failed' => [],
|
|
];
|
|
|
|
foreach ($drawIds as $drawId) {
|
|
try {
|
|
$draw = \App\Models\Draw::findOrFail($drawId);
|
|
$this->service->destroy($draw);
|
|
$results['success'][] = $drawId;
|
|
} catch (\RuntimeException $e) {
|
|
$results['failed'][] = [
|
|
'id' => $drawId,
|
|
'reason' => match ($e->getMessage()) {
|
|
'draw_not_deletable' => trans('api.draw_not_deletable'),
|
|
'draw_has_bets' => trans('api.draw_has_bets'),
|
|
'draw_result_exists' => trans('api.draw_result_exists'),
|
|
default => trans('api.client_error'),
|
|
},
|
|
];
|
|
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
|
|
$results['failed'][] = [
|
|
'id' => $drawId,
|
|
'reason' => trans('api.draw_not_found'),
|
|
];
|
|
}
|
|
}
|
|
|
|
return ApiResponse::success($results);
|
|
}
|
|
}
|