fix(queue): 独立分配 Redis 队列库至 DB3 杜绝多站点串台偷单,增加部署自动重载与订单收益补偿校验

这个提交包含在:
chen
2026-09-18 10:17:23 +08:00
父节点 c23544ebf8
当前提交 11e20d9af5
共有 4 个文件被更改,包括 131 次插入 和 4 次删除

查看文件

@@ -9,3 +9,9 @@ username = root
password = root
hostport = 3306
prefix = fa_
[redis]
hostname = 127.0.0.1
hostport = 6379
password =
select = 3

查看文件

@@ -1,12 +1,15 @@
<?php
use think\Env;
return [
'connector' => 'Redis', // Redis 驱动
'expire' => 0, // 任务的过期时间,默认为60秒; 若要禁用,则设置为 null
'default' => 'default', // 默认的队列名称
'host' => '127.0.0.1', // redis 主机ip
'port' => 6379, // redis 端口
'password' => '', // redis 密码
'select' => 0, // 使用哪一个 db,默认为 db0
'host' => Env::get('redis.hostname', '127.0.0.1'),
'port' => Env::get('redis.hostport', 6379),
'password' => Env::get('redis.password', ''),
'select' => (int) Env::get('redis.select', 3), // 独立使用 DB3,彻底隔离服务器其他站点(如 chufang/xgsc/hlst)的队列干扰
'timeout' => 0, // redis连接的超时时间
'persistent' => false,
];

查看文件

@@ -148,6 +148,11 @@ mkdir -p "${PROJECT_DIR}/runtime/cache" "${PROJECT_DIR}/runtime/temp" "${PROJECT
chown -R ${WEB_USER}:${WEB_USER} "${PROJECT_DIR}/runtime" 2>/dev/null || true
chmod -R 777 "${PROJECT_DIR}/runtime" 2>/dev/null || true
if [ -x "/www/server/panel/pyenv/bin/supervisorctl" ]; then
log "重启 Supervisor 队列守护进程..."
/www/server/panel/pyenv/bin/supervisorctl restart henglian-shopro henglian-shopro-high 2>&1 | tee -a "$LOG_FILE" || true
fi
COMMIT=$($GIT rev-parse --short HEAD 2>/dev/null || echo "unknown")
log "当前版本: ${COMMIT}"
log "部署成功"

查看文件

@@ -0,0 +1,113 @@
<?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";
echo " 订单状态: {$order->status} (实付: {$order->pay_fee} 元)\n";
echo " 支付时间: " . date('Y-m-d H:i:s', $order->paid_time) . "\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();
echo " 买家 voucher_total: " . ($agent['voucher_total'] ?? '0') . " 元\n";
echo " 买家 last_self_order_time: " . (empty($agent['last_self_order_time']) ? 'NULL' : date('Y-m-d H:i:s', $agent['last_self_order_time'])) . "\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";