doge 4 дней назад
Родитель
Сommit
7494d59ae7

+ 1 - 1
app/Http/Controllers/agent/ProfileController.php

@@ -96,7 +96,7 @@ class ProfileController extends AgentApiController
             ]);
             $start = $data['start_date'] ?? now()->toDateString();
             $end = $data['end_date'] ?? $start;
-            return $reports->summaryForTree($this->currentAgent(), $start, $end);
+            return $reports->dashboard($this->currentAgent(), $start, $end);
         });
     }
 }

+ 14 - 0
app/Services/Agent/AgentReportService.php

@@ -19,6 +19,20 @@ class AgentReportService
         return $includeSelf ? [(int) $root->id] : [];
     }
 
+    /**
+     * 代理首页汇总(GET /agent/dashboard)。合营代理:自己名下的会员;入股代理(股东):全平台会员
+     * (不含试玩账号 users.from=2,口径同总后台首页),没有合营分成,commission_amount 为 0。
+     * scope 告诉前端统计范围:own / platform。代理报表(reportRows)仍按各自名下会员统计。
+     */
+    public function dashboard(Agent $agent, string $startDate, string $endDate): array
+    {
+        if ($agent->isEquity()) {
+            $members = User::query()->where(fn ($q) => $q->whereNull('from')->orWhere('from', '<>', 2));
+            return $this->aggregate($members, 0, [], $startDate, $endDate) + ['scope' => 'platform'];
+        }
+        return $this->summaryForTree($agent, $startDate, $endDate) + ['scope' => 'own'];
+    }
+
     public function summaryForTree(Agent $root, string $startDate, string $endDate): array
     {
         $ids = $this->visibleAgentIds($root);

+ 14 - 5
docs/代理/代理首页.md

@@ -11,7 +11,14 @@
 
 ## 1. 首页汇总 `GET /agent/dashboard`
 
-只统计**本代理名下的直属会员**(二级代理已取消)。
+统计范围按代理类型不同:
+
+| 代理类型 | 统计范围 | `scope` |
+|---|---|---|
+| 合营(`type=1`) | **本代理名下的直属会员**(二级代理已取消) | `own` |
+| 入股(`type=2`,股东) | **全平台会员**(不含试玩账号,口径同总后台首页);`commission_amount` 固定为 `0` | `platform` |
+
+页面可以按 `scope` 改标题,例如 `own` 显示「名下会员汇总统计」,`platform` 显示「平台汇总统计」。
 
 | 参数 | 类型 | 必填 | 默认 | 说明 |
 |---|---|---:|---|---|
@@ -42,7 +49,8 @@ GET /agent/dashboard?start_date=2026-11-08&end_date=2026-11-08
     "win_loss": "-3000.0000",
     "commission_amount": "310.0000",
     "company_profit": "39600.0000",
-    "agent_count": 0
+    "agent_count": 0,
+    "scope": "own"
   }
 }
 ```
@@ -55,7 +63,7 @@ GET /agent/dashboard?start_date=2026-11-08&end_date=2026-11-08
 
 | 页面 | 字段 | 说明 |
 |---|---|---|
-| 总会员数 | `member_count` | 名下会员总数(**不受日期影响**) |
+| 总会员数 | `member_count` | 名下会员总数;入股代理为全平台会员数(**不受日期影响**) |
 | 总投注笔数 | `bet_count` | 日期内的已结算注单数 |
 | 总会员输赢 | `win_loss` | 日期内会员输赢合计。**正数 = 会员赢(平台亏),负数 = 会员输** |
 
@@ -63,7 +71,7 @@ GET /agent/dashboard?start_date=2026-11-08&end_date=2026-11-08
 
 | 页面 | 字段 | 说明 |
 |---|---|---|
-| 会员总余额 | `member_balance` | 名下会员当前钱包可用余额合计(**实时值,不受日期影响**) |
+| 会员总余额 | `member_balance` | 名下(入股代理为全平台)会员当前钱包可用余额合计(**实时值,不受日期影响**) |
 | 总充值金额 | `deposit_amount` | 日期内到账的充值:USDT 充值 + 在线充值 + 人工充值 |
 | 总提现金额 | `withdraw_amount` | 日期内成功的提现:USDT 提现 + 三方代付 + 人工提现 |
 | 总手动加款 | `manual_credit` | 后台人工加款、订单补偿(不含后台赠送) |
@@ -87,7 +95,8 @@ GET /agent/dashboard?start_date=2026-11-08&end_date=2026-11-08
 
 | 字段 | 说明 |
 |---|---|
-| `agent_count` | 已废弃:二级代理取消后固定为 `0`,页面不要展示 |
+| `scope` | 统计范围:`own` 名下会员(合营)/ `platform` 全平台(入股) |
+| `agent_count` | 已废弃:二级代理取消后固定为 `0`,页面不要展示;入股代理不返回此字段 |
 
 ## 3. 顶部信息(`GET /agent/profile`)
 

+ 25 - 0
tests/Integration/AgentDashboardTest.php

@@ -3,9 +3,12 @@
 namespace Tests\Integration;
 
 use App\Http\Controllers\agent\ProfileController;
+use App\Models\Agent\Agent;
 use App\Services\Agent\AgentReportService;
 use Illuminate\Http\Request;
+use Illuminate\Database\Schema\Blueprint;
 use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Schema;
 use PHPUnit\Framework\TestCase;
 use Tests\Support\AgentTestEnvironment;
 
@@ -51,10 +54,32 @@ class AgentDashboardTest extends TestCase
         $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');
+    }
 }