Files
lotteryLaravel/tests/Feature/AdminReportPlatformLifetimeTotalsTest.php
kang e27a00f260 feat: 更新玩法配置管理,简化字段并增强功能
- 将玩法相关的显示名称字段统一为 `display_name`,移除多语言字段。
- 在 `PlayTypePatchController` 中新增即时切换玩法开关的功能,并推送大厅更新。
- 优化多个控制器和服务中的权限检查与数据处理逻辑,提升代码可读性与维护性。
2026-05-25 14:34:24 +08:00

120 lines
3.8 KiB
PHP

<?php
use App\Models\Draw;
use App\Models\Player;
use App\Models\TicketItem;
use App\Models\TicketOrder;
use App\Services\Admin\AdminReportQueryService;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
test('platform lifetime totals aggregate all draws with daily profit口径', function (): void {
$player = Player::query()->create([
'site_code' => 'main',
'site_player_id' => 'plt-p1',
'username' => 'plt_u1',
'nickname' => null,
'default_currency' => 'NPR',
'status' => 0,
]);
$drawA = Draw::query()->create([
'draw_no' => '20260501-001',
'business_date' => '2026-05-01',
'sequence_no' => 1,
'status' => 'settled',
'start_time' => now()->subDays(2),
'close_time' => now()->subDays(2)->addHour(),
'draw_time' => now()->subDays(2)->addHours(2),
'cooling_end_time' => null,
'result_source' => null,
'current_result_version' => 1,
'settle_version' => 1,
'is_reopened' => false,
]);
$drawB = Draw::query()->create([
'draw_no' => '20260502-001',
'business_date' => '2026-05-02',
'sequence_no' => 1,
'status' => 'settled',
'start_time' => now()->subDay(),
'close_time' => now()->subDay()->addHour(),
'draw_time' => now()->subDay()->addHours(2),
'cooling_end_time' => null,
'result_source' => null,
'current_result_version' => 1,
'settle_version' => 1,
'is_reopened' => false,
]);
$orderA = TicketOrder::query()->create([
'order_no' => 'ORD-A',
'player_id' => $player->id,
'draw_id' => $drawA->id,
'currency_code' => 'NPR',
'total_bet_amount' => 10_000,
'total_rebate_amount' => 0,
'total_actual_deduct' => 10_000,
'total_estimated_payout' => 0,
'status' => 'settled',
'submit_source' => 'h5',
'client_trace_id' => null,
]);
TicketOrder::query()->create([
'order_no' => 'ORD-B',
'player_id' => $player->id,
'draw_id' => $drawB->id,
'currency_code' => 'NPR',
'total_bet_amount' => 5_000,
'total_rebate_amount' => 0,
'total_actual_deduct' => 5_000,
'total_estimated_payout' => 0,
'status' => 'settled',
'submit_source' => 'h5',
'client_trace_id' => null,
]);
TicketItem::query()->create([
'ticket_no' => 'TK-PLT-1',
'order_id' => $orderA->id,
'player_id' => $player->id,
'draw_id' => $drawA->id,
'original_number' => '1234',
'normalized_number' => '1234',
'play_code' => 'big',
'dimension' => 4,
'digit_slot' => null,
'bet_mode' => null,
'unit_bet_amount' => 10_000,
'total_bet_amount' => 10_000,
'rebate_rate_snapshot' => 0,
'commission_rate_snapshot' => 0,
'actual_deduct_amount' => 10_000,
'odds_snapshot_json' => null,
'rule_snapshot_json' => null,
'combination_count' => 1,
'estimated_max_payout' => 0,
'risk_locked_amount' => 0,
'status' => 'won',
'fail_reason_code' => null,
'fail_reason_text' => null,
'win_amount' => 3_000,
'jackpot_win_amount' => 0,
'settled_at' => now(),
]);
$totals = app(AdminReportQueryService::class)->platformLifetimeTotals();
expect($totals['total_bet_minor'])->toBe(15_000)
->and($totals['total_payout_minor'])->toBe(3_000)
->and($totals['approx_house_gross_minor'])->toBe(12_000)
->and($totals['draw_count'])->toBe(2)
->and($totals['business_day_count'])->toBe(2)
->and($totals['date_from'])->toBe('2026-05-01')
->and($totals['date_to'])->toBe('2026-05-02')
->and($totals['currency_code'])->toBe('NPR');
});