$t->integer('from')->nullable()); $this->real = $this->agent(); $this->test = $this->agents->create(['username' => 'testagent', 'password' => 'secret1', 'type' => Agent::TYPE_JOINT, 'is_test' => 1]); $this->shareholder = $this->agent(Agent::TYPE_EQUITY); foreach (['r1' => $this->real->id, 't1' => $this->test->id, 'free' => null] as $memberId => $agentId) { $id = DB::table('users')->insertGetId(['member_id' => $memberId, 'username' => $memberId, 'agent_id' => $agentId, 'from' => 1, 'created_at' => '2026-09-07 08:00:00']); DB::table('recharges')->insert(['member_id' => $memberId, 'status' => 1, 'amount' => 100, 'created_at' => '2026-09-07 09:00:00']); DB::table('member_daily_reports')->insert(['report_date' => '2026-09-07', 'user_id' => $id, 'member_id' => $memberId, 'agent_id' => $agentId, 'deposit_amount' => 100, 'bet_count' => 1, 'bet_amount' => 10, 'categories' => '{}', 'created_at' => now(), 'updated_at' => now()]); } } public function test_admin_creates_edits_and_filters_test_agents(): void { $this->seed(); $this->assertSame(1, $this->test->fresh()->is_test); $this->assertSame(0, $this->real->fresh()->is_test); $this->agents->update($this->real, ['is_test' => 1]); $this->assertSame(1, $this->real->fresh()->is_test); $this->agents->update($this->real, ['is_test' => 0, 'status' => 1]); $request = Request::create('/admin/agent', 'GET', ['is_test' => 1]); $request->user = (object) ['id' => 1]; $this->app->instance('request', $request); $list = (new AdminAgent())->index($request, new AgentDomainService())->getData(true)['data']['list']; $this->assertSame(['testagent'], array_column($list, 'username')); $this->assertSame(1, $list[0]['is_test']); } public function test_admin_and_shareholder_stats_skip_test_members_but_test_agent_sees_its_own(): void { $this->seed(); $reports = new AgentReportService(); // 入股股东的全平台统计:不含测试会员 $platform = $reports->dashboard($this->shareholder, '2026-09-07', '2026-09-07'); $this->assertSame([2, '200.0000'], [$platform['member_count'], $platform['deposit_amount']]); $period = (new AgentPeriodReportService())->report($this->shareholder, ['period' => 'day', 'start_date' => '2026-09-07', 'end_date' => '2026-09-07']); $this->assertSame(['200.0000', 2], [$period['totals']['deposit_amount'], $period['totals']['new_members']]); // 测试代理自己的后台照常显示 $own = $reports->dashboard($this->test, '2026-09-07', '2026-09-07'); $this->assertSame([1, '100.0000'], [$own['member_count'], $own['deposit_amount']]); $this->assertSame(1, (new MemberDailyReportService())->paginate(['start_date' => '2026-09-07', 'end_date' => '2026-09-07'], $this->test)['total']); // 总后台:会员盈亏日报、代理报表不含测试数据 $daily = (new MemberDailyReportService())->paginate(['start_date' => '2026-09-07', 'end_date' => '2026-09-07']); $this->assertSame(['free', 'r1'], collect($daily['list'])->pluck('member_id')->sort()->values()->all()); $this->assertSame('200.0000', $daily['totals']['deposit_amount']); $agentRows = array_column($reports->reportRows(null, ['start_date' => '2026-09-07'])['list'], 'username'); $this->assertNotContains('testagent', $agentRows); $this->assertContains($this->real->username, $agentRows); $this->assertSame(['testagent'], array_column($reports->reportRows($this->test, ['start_date' => '2026-09-07'])['list'], 'username'), 'test agent still sees its own report'); // 按会员 / 按代理的资金表 $this->assertSame(200.0, (float) StatsScope::excludeTestMembers(DB::table('recharges'))->sum('amount')); DB::table('agent_withdrawals')->insert([ ['order_no' => 'AW1', 'request_key' => 'k1', 'agent_id' => $this->test->id, 'account_snapshot' => '{}', 'amount' => 50, 'actual_amount' => 50, 'status' => 'paid'], ['order_no' => 'AW2', 'request_key' => 'k2', 'agent_id' => $this->real->id, 'account_snapshot' => '{}', 'amount' => 30, 'actual_amount' => 30, 'status' => 'paid'], ]); $this->assertSame(30.0, (float) StatsScope::excludeTestAgents(DB::table('agent_withdrawals'))->sum('amount'), 'test agent own money is left out'); } public function test_switching_the_flag_moves_history_in_and_out(): void { $this->seed(); $reports = new AgentReportService(); $this->assertSame('200.0000', $reports->dashboard($this->shareholder, '2026-09-07', '2026-09-07')['deposit_amount']); $this->agents->update($this->real, ['is_test' => 1]); $this->assertSame('100.0000', $reports->dashboard($this->shareholder, '2026-09-07', '2026-09-07')['deposit_amount'], 'existing members follow the agent'); $this->agents->update($this->real, ['is_test' => 0]); $this->agents->update($this->test, ['is_test' => 0]); $this->assertSame('300.0000', $reports->dashboard($this->shareholder, '2026-09-07', '2026-09-07')['deposit_amount']); } public function test_equity_summary_skips_test_shareholders(): void { $this->seed(); AgentSetting::current()->update(['equity_enabled' => 1, 'equity_price_per_percent' => 1000, 'equity_min_percent' => 0.1, 'equity_max_percent' => 1]); $equity = new AgentEquityService(new AgentWalletService()); $testShareholder = $this->agents->create(['username' => 'testholder', 'password' => 'secret1', 'type' => Agent::TYPE_EQUITY, 'is_test' => 1]); foreach ([$this->shareholder, $testShareholder] as $holder) { Agent::query()->whereKey($holder->id)->update(['balance' => 1000, 'realtime_balance' => 1000]); $equity->order($holder->fresh(), '0.5'); } $page = $equity->paginate([]); $this->assertSame(2, $page['total'], 'list still shows both'); $this->assertSame(['0.5000', '500.0000', '0.5000'], [$page['summary']['completed_percent'], $page['summary']['completed_amount'], $page['summary']['total_equity_percent']]); $this->assertSame(1, collect($page['list'])->firstWhere('agent_id', $testShareholder->id)->agent->is_test); } }