117 行
4.9 KiB
PHP
117 行
4.9 KiB
PHP
<?php
|
||
/**
|
||
* 测试分销商升级向上兼容累计规则及目标账号升级验证
|
||
*/
|
||
define('APP_PATH', __DIR__ . '/../application/');
|
||
define('ROOT_PATH', dirname(realpath(APP_PATH)) . '/');
|
||
require_once __DIR__ . '/../thinkphp/base.php';
|
||
require_once __DIR__ . '/../thinkphp/helper.php';
|
||
|
||
if (is_file(ROOT_PATH . '.env')) {
|
||
$env = parse_ini_file(ROOT_PATH . '.env', true);
|
||
foreach ($env as $key => $val) {
|
||
$name = 'PHP_' . strtoupper($key);
|
||
if (is_array($val)) {
|
||
foreach ($val as $k => $v) {
|
||
$item = $name . '_' . strtoupper($k);
|
||
putenv("$item=$v");
|
||
}
|
||
} else {
|
||
putenv("$name=$val");
|
||
}
|
||
}
|
||
}
|
||
|
||
\think\Config::set(\think\Config::load(APP_PATH . 'config.php'));
|
||
\think\Config::set(include APP_PATH . 'database.php', 'database');
|
||
foreach (glob(APP_PATH . 'extra/*.php') as $extraFile) {
|
||
$extraName = basename($extraFile, '.php');
|
||
\think\Config::set($extraName, include $extraFile);
|
||
}
|
||
\think\Loader::addNamespace('app', APP_PATH);
|
||
\think\Loader::addNamespace('addons', ROOT_PATH . 'addons/');
|
||
require_once __DIR__ . '/../application/common.php';
|
||
require_once __DIR__ . '/../addons/shopro/helper/helper.php';
|
||
|
||
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'xmlhttprequest';
|
||
@ini_set('session.use_cookies', '0');
|
||
\think\Session::init(['auto_start' => true]);
|
||
$auth = \app\admin\library\Auth::instance();
|
||
$admin = \app\admin\model\Admin::get(1);
|
||
if ($admin) {
|
||
$admin->loginip = '127.0.0.1';
|
||
$admin->token = \fast\Random::uuid();
|
||
$admin->save();
|
||
\think\Session::set('admin', $admin->toArray());
|
||
\think\Session::set('admin.safecode', $auth->getEncryptSafecode($admin));
|
||
$ref = new \ReflectionProperty($auth, 'logined');
|
||
$ref->setAccessible(true);
|
||
$ref->setValue($auth, true);
|
||
}
|
||
|
||
use addons\shopro\service\commission\Agent as AgentService;
|
||
use app\admin\model\shopro\commission\Agent as AgentModel;
|
||
use app\admin\model\shopro\commission\Level as LevelModel;
|
||
|
||
echo "=== 开始分销商升级规则验证 ===" . PHP_EOL;
|
||
|
||
// 1. 获取目标测试账号(默认为 User ID 17)
|
||
$userId = intval($argv[1] ?? 17);
|
||
$agent = AgentModel::where('user_id', $userId)->find();
|
||
if (!$agent) {
|
||
die("未找到用户 ID {$userId} 的分销商记录\n");
|
||
}
|
||
|
||
echo "当前账号 ID: {$userId}, 等级: {$agent->level}" . PHP_EOL;
|
||
echo "child_user_count_1: {$agent->child_user_count_1}" . PHP_EOL;
|
||
echo "child_order_count_all: {$agent->child_order_count_all}" . PHP_EOL;
|
||
echo "child_agent_count_1: {$agent->child_agent_count_1}" . PHP_EOL;
|
||
echo "child_agent_level_1: " . json_encode($agent->child_agent_level_1, JSON_UNESCAPED_UNICODE) . PHP_EOL;
|
||
|
||
// 2. 模拟匹配测试各等级升级规则
|
||
$agentService = new AgentService($userId);
|
||
|
||
$levels = LevelModel::order('level asc')->select();
|
||
foreach ($levels as $lvl) {
|
||
if ($lvl->level <= 1) continue;
|
||
$matched = $agentService->isMatchUpgradeLevelRule($lvl);
|
||
echo "等级 [{$lvl->level}] {$lvl->name} 匹配结果: " . ($matched ? "【符合】" : "【不符合】") . PHP_EOL;
|
||
}
|
||
|
||
// 3. 执行升级计划
|
||
echo "执行升级计划 runAgentUpgradePlan(true)..." . PHP_EOL;
|
||
$agentService->runAgentUpgradePlan(true);
|
||
|
||
// 4. 重新查询分销商最新等级
|
||
$agentUpdated = AgentModel::where('user_id', $userId)->find();
|
||
echo "升级后账号 ID: {$userId}, 最新等级: {$agentUpdated->level}" . PHP_EOL;
|
||
echo "升级后 child_agent_level_1: " . json_encode($agentUpdated->child_agent_level_1, JSON_UNESCAPED_UNICODE) . PHP_EOL;
|
||
|
||
// 5. 校验结果
|
||
if ($agentUpdated->level > 1) {
|
||
echo ">>> SUCCESS: 账号已成功自动晋升!最新等级为: {$agentUpdated->level} <<<" . PHP_EOL;
|
||
} else {
|
||
echo ">>> FAILED: 账号仍未能晋升! <<<" . PHP_EOL;
|
||
}
|
||
|
||
// 6. 验证后台详情 API 返回数据
|
||
echo PHP_EOL . "=== 验证后台详情接口 (Agent::detail) 返回数据 ===" . PHP_EOL;
|
||
$request = \think\Request::instance();
|
||
$request->get(['id' => $userId]);
|
||
$request->header(['accept' => 'application/json']);
|
||
$controller = new \app\admin\controller\shopro\commission\Agent($request);
|
||
|
||
try {
|
||
$controller->detail($userId);
|
||
} catch (\think\exception\HttpResponseException $e) {
|
||
$resp = $e->getResponse();
|
||
$detailData = $resp->getData()['data'] ?? [];
|
||
$radar = $detailData['operational_stats']['upgrade_radar'];
|
||
|
||
echo "当前身份等级: " . $detailData['level'] . " (" . $radar['current_level_name'] . ")" . PHP_EOL;
|
||
echo "下一目标等级: " . $radar['next_level'] . " (" . $radar['next_level_name'] . ")" . PHP_EOL;
|
||
echo "直推品酒师指标: " . $radar['current_direct_agents'] . " / " . $radar['target_direct_agents'] . " (达标: " . ($radar['direct_agent_reached'] ? "是" : "否") . ")" . PHP_EOL;
|
||
echo "团队订单指标: " . $radar['current_team_orders'] . " / " . $radar['target_team_orders'] . " (缺: " . $radar['team_order_gap'] . " 单, 达标: " . ($radar['team_order_reached'] ? "是" : "否") . ")" . PHP_EOL;
|
||
echo "全部条件达标: " . ($radar['all_reached'] ? "已全部达标" : "尚未全部达标") . PHP_EOL;
|
||
}
|