9ddb1a95051ec29cf7400b863ae52009ed9196e4
恒联数通 · 生产环境部署与收益中心队列运维指南
一、系统队列与守护进程配置 (Supervisor)
本项目异步事件与收益结算依赖 ThinkPHP Queue (基于 Redis 独立 DB3)。
1. 队列核心参数 (application/extra/queue.php)
- 驱动:
Redis - 库隔离:
redis.select = 3(彻底隔离服务器其他站点) - 超时保护:
expire = 180秒 (严禁设为 0,防止任务弹出即超时被多 Worker 并发重复消费)
2. Supervisor 队列守护配置
生产服务器必须常驻启动两个队列 Worker:
# /etc/supervisor/conf.d/henglian_queue.conf
[program:henglian-shopro-high]
command=/www/server/php/80/bin/php /www/wwwroot/henglian.gynhc.com/think queue:work --queue shopro-high --daemon
directory=/www/wwwroot/henglian.gynhc.com
user=www
autorestart=true
redirect_stderr=true
stdout_logfile=/www/wwwroot/henglian.gynhc.com/runtime/log/queue_high.log
[program:henglian-shopro]
command=/www/server/php/80/bin/php /www/wwwroot/henglian.gynhc.com/think queue:work --queue shopro --daemon
directory=/www/wwwroot/henglian.gynhc.com
user=www
autorestart=true
redirect_stderr=true
stdout_logfile=/www/wwwroot/henglian.gynhc.com/runtime/log/queue.log
二、定时任务配置 (Crontab)
系统支持传统标准日结与分钟级增量结算。
1. 生产环境推荐日结配置(次日凌晨 00:30 执行)
# 宝塔计划任务 / Crontab (以 www 用户运行)
30 0 * * * cd /www/wwwroot/henglian.gynhc.com && /www/server/php/80/bin/php think shopro:partner:settle --daily >> /www/wwwroot/henglian.gynhc.com/runtime/log/daily_settle.log 2>&1
说明:
--daily模式在执行前会自动触发PartnerCompensateService前置未结算漏单扫描与自动补偿,确保昨日全天所有订单即时收益 100% 入账后再核算 GMV 和加权分红池,杜绝漏发。
三、对账与异常补偿运维工具 (CLI)
系统内置了生产级自动对账、健康检查与安全补偿服务:
1. 全网未结算订单体检与诊断
php think shopro:partner:settle --check
诊断输出示例:
{
"status": "healthy",
"queue": {
"connector": "Redis",
"expire_seconds": 180,
"redis_db": 3,
"default_queue": "default"
},
"unsettled_orders_count": 0,
"failed_marked_orders_count": 0,
"warnings": [],
"check_time": "2026-09-19 16:00:00"
}
2. 自动安全对账与补偿发放 (一键治愈漏单)
当遭遇 Redis 重启、Worker 异常崩溃等极端情况时,无需编写临时脚本,直接运行:
php think shopro:partner:settle --compensate
- 自动扫描所有已支付但未在
shopro_partner_reward中有记录的合格订单。 - 借助
settleOrder()原生行锁(SELECT ... FOR UPDATE)与唯一索引(uk_order_user_type)进行安全补发。 - 具备绝对幂等性,绝不重复发放。
四、自动化回归验证
项目包含全面的生产可靠性测试套件:
# 运行收益中心与队列可靠性规范自动化测试
node tests/partner/verify_production_queue_and_compensation_spec.js
# 运行全套业务回归测试
node tests/verify_minute_settle_spec.js
node tests/verify_all_pools_minute_settle_spec.js
node tests/verify_commission_goods_isolation_spec.js
node tests/verify_commission_goods_rules_spec.js
node tests/partner/verify_admin_views_alignment_spec.js
node tests/partner/verify_partner_reward_to_money_spec.js
仓库描述
编程语言
JavaScript
42.5%
PHP
23.3%
HTML
12%
Vue
11.8%
CSS
5%
其它
5.3%