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']); $this->assertSame('own', $summary['scope']); 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']); } public function test_equity_agent_sees_whole_platform_excluding_demo_accounts(): void { if (!Schema::hasColumn('users', 'from')) Schema::table('users', fn (Blueprint $t) => $t->integer('from')->nullable()); $joint = $this->agent(); $equity = $this->agent(Agent::TYPE_EQUITY); foreach (['a1' => [$joint->id, 1], 'a2' => [null, 1], 'a3' => [null, null], 'demo' => [null, 2]] as $memberId => [$agentId, $from]) { DB::table('users')->insert(['member_id' => $memberId, 'username' => $memberId, 'agent_id' => $agentId, 'from' => $from, 'created_at' => now()]); DB::table('recharges')->insert(['member_id' => $memberId, 'status' => 1, 'amount' => 100, 'created_at' => '2026-09-07 10:00:00']); } $summary = (new AgentReportService())->dashboard($equity, '2026-09-07', '2026-09-07'); $this->assertSame('platform', $summary['scope']); $this->assertSame(3, $summary['member_count'], 'all real members, no demo account, regardless of agent'); $this->assertSame('300.0000', $summary['deposit_amount']); $this->assertSame('0.0000', $summary['commission_amount']); $own = (new AgentReportService())->dashboard($joint, '2026-09-07', '2026-09-07'); $this->assertSame(['own', 1, '100.0000'], [$own['scope'], $own['member_count'], $own['deposit_amount']]); $rows = array_column((new AgentReportService())->reportRows(null, ['start_date' => '2026-09-07'])['list'], null, 'id'); $this->assertSame(0, $rows[$equity->id]['member_count'], 'admin agent report still counts only the equity agent\'s own members'); } }