- 在 AdminAuthorizationRegistry 中新增删除待审核开奖批次的权限定义。 - 更新 API 路由以支持删除待审核开奖批次的请求。 - 在多语言文件中添加相关错误信息,确保用户在删除操作中获得清晰的反馈。 - 增加测试用例,验证管理员能够成功删除待审核的开奖批次并返回正确状态。
48 lines
1.4 KiB
PHP
48 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1\Admin\Draw;
|
|
|
|
use App\Models\Draw;
|
|
use App\Lottery\ErrorCode;
|
|
use App\Support\ApiMessage;
|
|
use App\Support\ApiResponse;
|
|
use Illuminate\Http\Request;
|
|
use App\Models\DrawResultBatch;
|
|
use Illuminate\Http\JsonResponse;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Services\Draw\DrawPendingResultBatchDiscardService;
|
|
|
|
/**
|
|
* DELETE /api/v1/admin/draws/{draw}/result-batches/{batch} — 删除待审核开奖批次。
|
|
*/
|
|
final class DrawResultBatchDestroyController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly DrawPendingResultBatchDiscardService $discardService,
|
|
) {}
|
|
|
|
public function __invoke(Request $request, Draw $draw, DrawResultBatch $batch): JsonResponse
|
|
{
|
|
if ((int) $batch->draw_id !== (int) $draw->id) {
|
|
return ApiResponse::error(
|
|
trans('api.not_found', [], $request->lotteryLocale()),
|
|
ErrorCode::NotFound->value,
|
|
null,
|
|
404,
|
|
);
|
|
}
|
|
|
|
try {
|
|
$draw = $this->discardService->discard($draw, $batch);
|
|
} catch (\RuntimeException $e) {
|
|
return ApiMessage::runtimeErrorResponse($request, $e);
|
|
}
|
|
|
|
return ApiResponse::success([
|
|
'draw_no' => $draw->draw_no,
|
|
'status' => $draw->status,
|
|
'deleted_batch_id' => (int) $batch->id,
|
|
]);
|
|
}
|
|
}
|