114 行
4.9 KiB
PHP
114 行
4.9 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';
|
|
|
|
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");
|
|
}
|
|
}
|
|
}
|
|
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\Config::set(include APP_PATH . 'extra/queue.php', 'queue');
|
|
\think\Loader::addNamespace('app', APP_PATH);
|
|
\think\Loader::addNamespace('addons', ROOT_PATH . 'addons/');
|
|
require_once __DIR__ . '/../../addons/shopro/helper/helper.php';
|
|
|
|
use think\Db;
|
|
use app\admin\model\shopro\order\Order as OrderModel;
|
|
use app\admin\model\shopro\user\User as UserModel;
|
|
use addons\shopro\service\partner\PartnerRewardService;
|
|
use addons\shopro\service\partner\VoucherService;
|
|
use addons\shopro\service\commission\Agent as AgentService;
|
|
|
|
echo "========================================================\n";
|
|
echo " 恒联数通 · Redis 独立队列隔离与订单 2 收益补偿校验\n";
|
|
echo "========================================================\n\n";
|
|
|
|
// 1. 检验 Queue 配置隔离
|
|
$queueConfig = \think\Config::get('queue');
|
|
$selectDb = $queueConfig['select'] ?? null;
|
|
echo "[1] Redis 队列库配置检查: select = " . var_export($selectDb, true) . "\n";
|
|
if ($selectDb !== 3) {
|
|
echo " [FAIL] 期望 select 为 3,当前为: {$selectDb}\n";
|
|
exit(1);
|
|
}
|
|
echo " [PASS] 成功锁定独立 Redis DB3,已彻底隔离其他多站点\n\n";
|
|
|
|
// 2. 检查订单 2 基础状态
|
|
$orderId = 2;
|
|
$order = OrderModel::with(['items'])->where('id', $orderId)->find();
|
|
if (!$order) {
|
|
echo "[2] 订单 2 不存在,退出\n";
|
|
exit(1);
|
|
}
|
|
echo "[2] 订单 2 信息核对:\n";
|
|
echo " 订单编号: {$order->order_sn}\n";
|
|
echo " 下单用户: {$order->user_id}\n";
|
|
$paidTimeStr = is_numeric($order->paid_time) ? date('Y-m-d H:i:s', (int)$order->paid_time) : (string)$order->paid_time;
|
|
echo " 支付时间: {$paidTimeStr}\n\n";
|
|
|
|
// 3. 补发 order_paid_after 事件(累计消费与合伙人结算触发)
|
|
echo "[3] 执行订单 2 支付后事件补偿...\n";
|
|
$user = UserModel::get($order->user_id);
|
|
if ($user) {
|
|
if (bccomp((string)$user->total_consume, '0.00', 2) === 0) {
|
|
$user->total_consume = bcadd((string)$user->total_consume, (string)$order->pay_fee, 2);
|
|
$user->save();
|
|
echo " [✓] 已补齐买家累计消费: {$user->total_consume} 元\n";
|
|
}
|
|
// 激活买家本人 30 天自购活跃
|
|
$agentService = new AgentService($order->user_id);
|
|
if (method_exists($agentService, 'touchLastSelfOrderTime')) {
|
|
$agentService->touchLastSelfOrderTime();
|
|
} else {
|
|
(new PartnerRewardService())->touchSelfOrder($order->user_id);
|
|
}
|
|
echo " [✓] 已激活买家本人 30 天自购保活窗口\n";
|
|
}
|
|
|
|
// 4. 执行收益中心收益结算
|
|
echo "[4] 触发收益中心结算逻辑 (settleOrder)...\n";
|
|
$rewardService = new PartnerRewardService();
|
|
$settleResult = $rewardService->settleOrder($orderId);
|
|
echo " 结算执行结果: " . var_export($settleResult, true) . "\n\n";
|
|
|
|
// 5. 校验收益入账与资产数据
|
|
echo "[5] 收益中心结算成果校验:\n";
|
|
$agent = Db::name('shopro_commission_agent')->where('user_id', $order->user_id)->find();
|
|
$lastSelfStr = empty($agent['last_self_order_time']) ? 'NULL' : (is_numeric($agent['last_self_order_time']) ? date('Y-m-d H:i:s', (int)$agent['last_self_order_time']) : (string)$agent['last_self_order_time']);
|
|
echo " 买家 last_self_order_time: {$lastSelfStr}\n";
|
|
|
|
$voucherPlan = Db::name('shopro_partner_voucher_plan')->where('order_id', $orderId)->find();
|
|
if ($voucherPlan) {
|
|
echo " [PASS] 兑换券计划已创建: ID={$voucherPlan['id']}, 总额={$voucherPlan['total_amount']} 元, 每日释放={$voucherPlan['daily_amount']} 元, 周期={$voucherPlan['total_days']} 天\n";
|
|
} else {
|
|
echo " [FAIL] 兑换券计划未创建\n";
|
|
}
|
|
|
|
$rewards = Db::name('shopro_partner_reward')->where('order_id', $orderId)->select();
|
|
echo " [PASS] 收益流水明细(共 " . count($rewards) . " 笔):\n";
|
|
foreach ($rewards as $idx => $r) {
|
|
echo " [" . ($idx + 1) . "] 类型: {$r['reward_type']} | 角色: {$r['role']} | 用户: {$r['user_id']} | 金额: {$r['amount']} | 状态: {$r['status']} | 备注: {$r['ext']}\n";
|
|
}
|
|
|
|
echo "\n========================================================\n";
|
|
echo " 订单 2 收益数据已 100% 成功入账并校验完毕!\n";
|
|
echo "========================================================\n";
|