102 行
4.2 KiB
PHP
102 行
4.2 KiB
PHP
<?php
|
|
|
|
namespace tests\partner;
|
|
|
|
define('APP_PATH', __DIR__ . '/../../application/');
|
|
define('ROOT_PATH', dirname(realpath(APP_PATH)) . '/');
|
|
require_once __DIR__ . '/../../thinkphp/base.php';
|
|
require_once __DIR__ . '/../../thinkphp/helper.php';
|
|
require_once __DIR__ . '/../../application/common.php';
|
|
|
|
\think\Config::set(\think\Config::load(APP_PATH . 'config.php'));
|
|
\think\Config::set(include APP_PATH . 'database.php', 'database');
|
|
\think\Loader::addNamespace('app', APP_PATH);
|
|
require_once __DIR__ . '/../../addons/shopro/helper/helper.php';
|
|
|
|
use addons\shopro\service\commission\Agent as AgentService;
|
|
use app\admin\model\shopro\commission\Agent as AgentModel;
|
|
use addons\shopro\controller\commission\Agent as AgentController;
|
|
|
|
class VerifyTeamSelfOrderSpec
|
|
{
|
|
private $passed = 0;
|
|
private $failed = 0;
|
|
|
|
public function run()
|
|
{
|
|
echo "========================================================\n";
|
|
echo " 团队订单包含自己的订单 (Self Order Included) 专项测试 \n";
|
|
echo "========================================================\n\n";
|
|
|
|
$this->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());
|
|
}
|