feat: 增强报表功能,支持新参数和导出类型

- 在 `ReportJobStoreRequest` 中新增 `draw_id`、`draw_no` 和 `normalized_number` 参数的验证规则。
- 更新 `AdminReportJobService` 以支持动态生成输出路径后缀,确保导出文件名包含相关信息。
- 在 `AdminReportQueryService` 中新增多个报表类型的处理逻辑,包括 `draw_profit_summary` 和 `sold_out_number_report`。
- 添加相应的测试用例,确保新功能的正确性和稳定性。
This commit is contained in:
2026-05-26 11:48:40 +08:00
parent c74bec3f64
commit bba084b3c1
5 changed files with 464 additions and 1 deletions

View File

@@ -3,17 +3,25 @@
use App\Models\AuditLog;
use App\Models\AdminRole;
use App\Models\AdminUser;
use App\Models\Draw;
use App\Models\ReportJob;
use App\Models\RiskPool;
use App\Lottery\ErrorCode;
use App\Models\ReconcileJob;
use App\Services\AuditLogger;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use App\Support\AdminPermissionBridge;
use Database\Seeders\AdminRbacAndUserSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
beforeEach(function (): void {
$this->seed(AdminRbacAndUserSeeder::class);
$this->artisan('lottery:admin-auth-sync')->assertExitCode(0);
});
function phase15SuperToken(): string
{
$admin = AdminUser::query()->create([
@@ -124,6 +132,67 @@ test('report jobs support xlsx export filename convention', function (): void {
->assertHeader('content-type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
});
test('report jobs export draw profit and sold out reports by draw_no', function (): void {
$token = phase15SuperToken();
$draw = Draw::query()->create([
'draw_no' => 'RPT-DRAW-001',
'business_date' => '2026-05-20',
'sequence_no' => 1,
'status' => 'settled',
'start_time' => now()->subDay(),
'close_time' => now()->subDay(),
'draw_time' => now()->subDay(),
'cooling_end_time' => null,
'result_source' => null,
'current_result_version' => 1,
'settle_version' => 1,
'is_reopened' => false,
]);
RiskPool::query()->create([
'draw_id' => $draw->id,
'normalized_number' => '1234',
'total_cap_amount' => 10000,
'locked_amount' => 10000,
'remaining_amount' => 0,
'sold_out_status' => 1,
'version' => 1,
]);
$profit = $this->withHeader('Authorization', 'Bearer '.$token)
->postJson('/api/v1/admin/report-jobs', [
'report_type' => 'draw_profit_summary',
'export_format' => 'csv',
'parameters' => ['draw_no' => 'RPT-DRAW-001'],
]);
$profit->assertOk()->assertJsonPath('code', ErrorCode::Success->value);
$profitId = (int) $profit->json('data.id');
expect(ReportJob::query()->find($profitId)?->output_path)->toContain('RPT-DRAW-001');
$profitCsv = $this->withHeader('Authorization', 'Bearer '.$token)
->get('/api/v1/admin/report-jobs/'.$profitId.'/download')
->assertOk()
->streamedContent();
expect($profitCsv)->toContain('summary')
->and($profitCsv)->toContain('RPT-DRAW-001');
$soldOut = $this->withHeader('Authorization', 'Bearer '.$token)
->postJson('/api/v1/admin/report-jobs', [
'report_type' => 'sold_out_number_report',
'export_format' => 'csv',
'parameters' => ['draw_id' => $draw->id],
]);
$soldOut->assertOk();
$soldOutId = (int) $soldOut->json('data.id');
$soldOutCsv = $this->withHeader('Authorization', 'Bearer '.$token)
->get('/api/v1/admin/report-jobs/'.$soldOutId.'/download')
->assertOk()
->streamedContent();
expect($soldOutCsv)->toContain('1234')
->and($soldOutCsv)->toContain('是');
});
test('reconcile job create with items and nested items index', function (): void {
$token = phase15SuperToken();