feat: 添加删除待审核开奖批次功能及相关错误信息
- 在 AdminAuthorizationRegistry 中新增删除待审核开奖批次的权限定义。 - 更新 API 路由以支持删除待审核开奖批次的请求。 - 在多语言文件中添加相关错误信息,确保用户在删除操作中获得清晰的反馈。 - 增加测试用例,验证管理员能够成功删除待审核的开奖批次并返回正确状态。
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
62
app/Services/Draw/DrawPendingResultBatchDiscardService.php
Normal file
62
app/Services/Draw/DrawPendingResultBatchDiscardService.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Draw;
|
||||
|
||||
use App\Models\Draw;
|
||||
use App\Models\DrawResultBatch;
|
||||
use App\Lottery\DrawStatus;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Lottery\DrawResultBatchStatus;
|
||||
use App\Models\SettlementBatch;
|
||||
|
||||
/**
|
||||
* 删除待审核开奖批次,便于作废草稿后重新录入或重新 RNG。
|
||||
*/
|
||||
final class DrawPendingResultBatchDiscardService
|
||||
{
|
||||
public function discard(Draw $draw, DrawResultBatch $batch): Draw
|
||||
{
|
||||
return DB::transaction(function () use ($draw, $batch): Draw {
|
||||
/** @var DrawResultBatch $lockedBatch */
|
||||
$lockedBatch = DrawResultBatch::query()->whereKey($batch->id)->lockForUpdate()->firstOrFail();
|
||||
|
||||
if ((int) $lockedBatch->draw_id !== (int) $draw->id) {
|
||||
throw new \RuntimeException('batch_draw_mismatch');
|
||||
}
|
||||
|
||||
if ($lockedBatch->status !== DrawResultBatchStatus::PendingReview->value) {
|
||||
throw new \RuntimeException('batch_not_pending_review');
|
||||
}
|
||||
|
||||
if (SettlementBatch::query()->where('result_batch_id', $lockedBatch->id)->exists()) {
|
||||
throw new \RuntimeException('batch_linked_to_settlement');
|
||||
}
|
||||
|
||||
/** @var Draw $lockedDraw */
|
||||
$lockedDraw = Draw::query()->whereKey($draw->id)->lockForUpdate()->firstOrFail();
|
||||
|
||||
$lockedBatch->delete();
|
||||
|
||||
if ($lockedDraw->status === DrawStatus::Review->value) {
|
||||
$stillPending = DrawResultBatch::query()
|
||||
->where('draw_id', $lockedDraw->id)
|
||||
->where('status', DrawResultBatchStatus::PendingReview->value)
|
||||
->exists();
|
||||
|
||||
if (! $stillPending) {
|
||||
$hasPublished = DrawResultBatch::query()
|
||||
->where('draw_id', $lockedDraw->id)
|
||||
->where('status', DrawResultBatchStatus::Published->value)
|
||||
->exists();
|
||||
|
||||
$lockedDraw->forceFill([
|
||||
'status' => DrawStatus::Closed->value,
|
||||
'result_source' => $hasPublished ? $lockedDraw->result_source : null,
|
||||
])->save();
|
||||
}
|
||||
}
|
||||
|
||||
return $lockedDraw->refresh();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -410,6 +410,7 @@ final class AdminAuthorizationRegistry
|
||||
['code' => 'admin.draws.risk-pools.show', 'module_code' => 'risk', 'name' => '风控池详情', 'http_method' => 'GET', 'uri_pattern' => '/api/v1/admin/draws/{draw}/risk-pools/{number_4d}', 'route_name' => 'api.v1.admin.draws.risk-pools.show', 'auth_mode' => 'permission_required', 'is_audit_required' => false, 'legacy_permission_slugs' => ['prd.draw_result.manage', 'prd.draw_result.view', 'prd.risk.view', 'prd.risk.manage']],
|
||||
['code' => 'admin.draws.result-batches.store', 'module_code' => 'draw', 'name' => '创建开奖结果批次', 'http_method' => 'POST', 'uri_pattern' => '/api/v1/admin/draws/{draw}/result-batches', 'route_name' => 'api.v1.admin.draws.result-batches.store', 'auth_mode' => 'permission_required', 'is_audit_required' => true, 'legacy_permission_slugs' => ['prd.draw_result.manage']],
|
||||
['code' => 'admin.draws.result-batches.publish', 'module_code' => 'draw', 'name' => '发布开奖结果批次', 'http_method' => 'POST', 'uri_pattern' => '/api/v1/admin/draws/{draw}/result-batches/{batch}/publish', 'route_name' => 'api.v1.admin.draws.result-batches.publish', 'auth_mode' => 'permission_required', 'is_audit_required' => true, 'legacy_permission_slugs' => ['prd.draw_result.manage']],
|
||||
['code' => 'admin.draws.result-batches.destroy', 'module_code' => 'draw', 'name' => '删除待审核开奖批次', 'http_method' => 'DELETE', 'uri_pattern' => '/api/v1/admin/draws/{draw}/result-batches/{batch}', 'route_name' => 'api.v1.admin.draws.result-batches.destroy', 'auth_mode' => 'permission_required', 'is_audit_required' => true, 'legacy_permission_slugs' => ['prd.draw_result.manage']],
|
||||
['code' => 'admin.draws.reopen', 'module_code' => 'draw', 'name' => '重开开奖', 'http_method' => 'POST', 'uri_pattern' => '/api/v1/admin/draws/{draw}/reopen', 'route_name' => 'api.v1.admin.draws.reopen', 'auth_mode' => 'permission_required', 'is_audit_required' => true, 'legacy_permission_slugs' => ['prd.draw_reopen.manage']],
|
||||
['code' => 'admin.draws.generate-plan', 'module_code' => 'draw', 'name' => '生成开奖计划', 'http_method' => 'POST', 'uri_pattern' => '/api/v1/admin/draws/generate-plan', 'route_name' => 'api.v1.admin.draws.generate-plan', 'auth_mode' => 'permission_required', 'is_audit_required' => true, 'legacy_permission_slugs' => ['prd.draw_result.manage']],
|
||||
['code' => 'admin.draws.store', 'module_code' => 'draw', 'name' => '手动创建期号', 'http_method' => 'POST', 'uri_pattern' => '/api/v1/admin/draws', 'route_name' => 'api.v1.admin.draws.store', 'auth_mode' => 'permission_required', 'is_audit_required' => true, 'legacy_permission_slugs' => ['prd.draw_result.manage']],
|
||||
|
||||
Reference in New Issue
Block a user