testAgentTeamStatsIncludeSelf(); $this->testTeamHealthSummaryIncludeSelf(); echo "\n--------------------------------------------------------\n"; echo "测试执行结果: 通过 {$this->passed} 项, 失败 {$this->failed} 项\n"; echo "========================================================\n"; return $this->failed === 0 ? 0 : 1; } private function assert($condition, $testName, $detail = '') { if ($condition) { $this->passed++; echo " [✓ PASS] {$testName}\n"; } else { $this->failed++; echo " [✗ FAIL] {$testName} - {$detail}\n"; } } private function testAgentTeamStatsIncludeSelf() { try { $agent = new AgentService(20); $agent->runAgentUpgradePlan(false); $agentRow = AgentModel::get(20); // 自购单数 >= 1 $this->assert($agentRow->child_order_count_0 >= 1, '分销商自购订单数已记录 (child_order_count_0 >= 1)'); // 团队总单数 = 自购单数 + 直推单数 + 伞下单数 (当前为 1自购 + 3直推 + 1伞下 = 5单) $this->assert($agentRow->child_order_count_all >= 5, "团队总单数包含自购订单 (当前团队总单数: {$agentRow->child_order_count_all}, 包含自购 {$agentRow->child_order_count_0} 单)"); // 团队总金额包含自购金额 $this->assert(floatval($agentRow->child_order_money_all) >= 6990.00, "团队总金额包含自购金额 (当前团队总金额: {$agentRow->child_order_money_all})"); } catch (\Throwable $e) { $this->assert(false, '分销商团队数据统计包含自购测试', $e->getMessage()); } } private function testTeamHealthSummaryIncludeSelf() { try { $ref = new \ReflectionClass(AgentController::class); $controller = $ref->newInstanceWithoutConstructor(); $summaryMethod = $ref->getMethod('getTeamHealthSummary'); $summaryMethod->setAccessible(true); $window = time() - 30 * 86400; $expiring = time() - 23 * 86400; $summary = $summaryMethod->invoke($controller, 20, [21, 22, 23], $window, $expiring); // 团队累计订单数应为 5 笔(包含下级与本人自购) $this->assert(isset($summary['team_order_count']) && $summary['team_order_count'] >= 5, "团队健康度汇总 team_order_count 应为 5 笔 (实测: " . ($summary['team_order_count'] ?? 0) . ")"); // 团队累计自购总业绩应为 6990.00(包含下级与本人自购) $this->assert(isset($summary['team_total_consume']) && floatval($summary['team_total_consume']) >= 6990.00, "团队累计总业绩 team_total_consume 应为 6990.00 (实测: " . ($summary['team_total_consume'] ?? '0.00') . ")"); } catch (\Throwable $e) { $this->assert(false, '团队健康度汇总包含本人自购测试', $e->getMessage()); } } } if (PHP_SAPI === 'cli') { $tester = new VerifyTeamSelfOrderSpec(); exit($tester->run()); }