feat: 添加删除待审核开奖批次功能及相关错误信息

- 在 AdminAuthorizationRegistry 中新增删除待审核开奖批次的权限定义。
- 更新 API 路由以支持删除待审核开奖批次的请求。
- 在多语言文件中添加相关错误信息,确保用户在删除操作中获得清晰的反馈。
- 增加测试用例,验证管理员能够成功删除待审核的开奖批次并返回正确状态。
This commit is contained in:
2026-06-01 15:37:33 +08:00
parent e6cf94af46
commit b13776b480
8 changed files with 181 additions and 0 deletions

View File

@@ -640,6 +640,68 @@ test('admin can create manual result batch with 23 numbers for review', function
Carbon::setTestNow();
});
test('admin can discard pending manual result batch and draw returns to closed', function (): void {
Carbon::setTestNow(Carbon::parse('2026-05-09 14:25:00', 'UTC'));
$draw = Draw::query()->create([
'draw_no' => '20260509-221',
'business_date' => '2026-05-09',
'sequence_no' => 221,
'status' => DrawStatus::Closed->value,
'start_time' => now()->copy()->subMinutes(20),
'close_time' => now()->copy()->subMinutes(2),
'draw_time' => now()->copy()->subMinute(),
'cooling_end_time' => null,
'result_source' => null,
'current_result_version' => 0,
'settle_version' => 0,
'is_reopened' => false,
]);
$admin = AdminUser::query()->create([
'username' => 'discard_batch_admin',
'name' => 'Discard Batch Admin',
'email' => null,
'password' => Hash::make('secret-strong'),
'status' => 0,
]);
grantSuperAdminRole($admin);
$token = $admin->createToken('test', ['*'], now()->addDay())->plainTextToken;
$items = [];
foreach (array_values(App\Services\Draw\DrawPrizeLayout::slots()) as $i => $slot) {
$items[] = [
'prize_type' => $slot['prize_type'],
'prize_index' => $slot['prize_index'],
'number_4d' => str_pad((string) ($i + 11), 4, '0', STR_PAD_LEFT),
];
}
$this->withHeader('Authorization', 'Bearer '.$token)
->postJson("/api/v1/admin/draws/{$draw->id}/result-batches", ['items' => $items])
->assertOk();
$batchId = (int) DrawResultBatch::query()->where('draw_id', $draw->id)->value('id');
expect($batchId)->toBeGreaterThan(0);
$draw->refresh();
expect($draw->status)->toBe(DrawStatus::Review->value);
$this->withHeader('Authorization', 'Bearer '.$token)
->deleteJson("/api/v1/admin/draws/{$draw->id}/result-batches/{$batchId}")
->assertOk()
->assertJsonPath('data.status', DrawStatus::Closed->value)
->assertJsonPath('data.deleted_batch_id', $batchId);
$draw->refresh();
expect($draw->status)->toBe(DrawStatus::Closed->value);
expect($draw->result_source)->toBeNull();
expect(DrawResultBatch::query()->where('draw_id', $draw->id)->count())->toBe(0);
expect(DrawResultItem::query()->where('draw_id', $draw->id)->count())->toBe(0);
Carbon::setTestNow();
});
test('admin can reopen cooldown draw for a replacement result batch', function (): void {
Carbon::setTestNow(Carbon::parse('2026-05-09 14:30:00', 'UTC'));