| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace Tests\Integration;
- use App\Http\Controllers\agent\ProfileController;
- use App\Services\Agent\AgentReportService;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\DB;
- use PHPUnit\Framework\TestCase;
- use Tests\Support\AgentTestEnvironment;
- /** 代理首页 GET /agent/dashboard:只统计本代理名下会员,按日期汇总资金和投注。 */
- class AgentDashboardTest extends TestCase
- {
- use AgentTestEnvironment;
- public function test_dashboard_sums_only_own_members_within_the_date_range(): void
- {
- $agent = $this->agent();
- $other = $this->agent();
- foreach (['m1' => $agent, 'm2' => $agent, 'x1' => $other] as $memberId => $owner) {
- DB::table('users')->insert(['member_id' => $memberId, 'username' => $memberId, 'agent_id' => $owner->id, 'created_at' => now()]);
- DB::table('wallets')->insert(['member_id' => $memberId, 'available_balance' => 100]);
- }
- $in = '2026-09-07 10:00:00';
- $out = '2026-09-01 10:00:00';
- foreach ([['m1', 500, $in], ['m2', 300, $in], ['m1', 999, $out], ['x1', 777, $in]] as [$member, $amount, $at]) {
- DB::table('recharges')->insert(['member_id' => $member, 'status' => 1, 'amount' => $amount, 'created_at' => $at]);
- }
- DB::table('recharges')->insert(['member_id' => 'm1', 'status' => 0, 'amount' => 50, 'created_at' => $in]); // 未到账
- DB::table('payment_orders')->insert(['member_id' => 'm2', 'status' => 2, 'type' => '1', 'amount' => 200, 'created_at' => $in]);
- DB::table('withdraws')->insert(['member_id' => 'm1', 'status' => 1, 'amount' => 150, 'created_at' => $in]);
- foreach ([['人工充值', null, 80], ['人工扣款', null, -30], ['优惠活动', null, 20], ['返水', null, 10], ['人工充值', 0, 5]] as [$type, $related, $amount]) {
- DB::table('balance_logs')->insert(['member_id' => 'm1', 'change_type' => $type, 'related_id' => $related, 'amount' => $amount, 'created_at' => $in]);
- }
- $request = Request::create('/agent/dashboard', 'GET', ['start_date' => '2026-09-07', 'end_date' => '2026-09-07']);
- $request->attributes->set('agent', $agent);
- $this->app->instance('request', $request);
- $data = (new ProfileController())->dashboard($request, new AgentReportService())->getData(true);
- $this->assertSame(0, $data['code'], (string) $data['msg']);
- $summary = $data['data'];
- $this->assertSame(2, $summary['member_count']);
- $this->assertSame('200.0000', $summary['member_balance']);
- $this->assertSame('1000.0000', $summary['deposit_amount'], 'recharges + paid online orders in range');
- $this->assertSame('150.0000', $summary['withdraw_amount']);
- $this->assertSame('80.0000', $summary['manual_credit']);
- $this->assertSame('30.0000', $summary['manual_debit']);
- $this->assertSame('25.0000', $summary['bonus_amount'], '优惠活动 + 人工充值(赠送)');
- $this->assertSame('10.0000', $summary['rebate_amount']);
- $this->assertSame('815.0000', $summary['company_profit'], '1000 - 150 - 25 - 10');
- $this->assertSame('0.0000', $summary['commission_amount']);
- $this->assertSame(0, $summary['agent_count']);
- foreach (['bet_count', 'bet_amount', 'valid_bet_amount', 'win_loss'] as $field) $this->assertArrayHasKey($field, $summary);
- $request = Request::create('/agent/dashboard', 'GET', ['start_date' => '2026-09-08', 'end_date' => '2026-09-07']);
- $request->attributes->set('agent', $agent);
- $this->assertNotSame(0, (new ProfileController())->dashboard($request, new AgentReportService())->getData(true)['code']);
- }
- }
|