更新服务器信息为新的 IP 地址,调整相关文档和代码中的默认配置,确保部署和连接的一致性。同时,优化订单管理界面,增强商品信息的格式化逻辑,提升用户体验。
This commit is contained in:
@@ -360,13 +360,13 @@ async function processReferralCommission(buyerUserId: string, amount: number, or
|
||||
}
|
||||
} catch (e) { /* 使用默认配置 */ }
|
||||
|
||||
// 查找有效的推广绑定关系
|
||||
// 查找当前有效的推广绑定关系(新逻辑:购买时的绑定关系)
|
||||
const bindings = await query(`
|
||||
SELECT rb.id, rb.referrer_id, rb.referee_id, rb.expiry_date, rb.status
|
||||
SELECT rb.id, rb.referrer_id, rb.referee_id, rb.expiry_date, rb.status,
|
||||
rb.purchase_count, rb.total_commission
|
||||
FROM referral_bindings rb
|
||||
WHERE rb.referee_id = ?
|
||||
AND rb.status = 'active'
|
||||
AND rb.expiry_date > NOW()
|
||||
ORDER BY rb.binding_date DESC
|
||||
LIMIT 1
|
||||
`, [buyerUserId]) as any[]
|
||||
@@ -378,16 +378,32 @@ async function processReferralCommission(buyerUserId: string, amount: number, or
|
||||
|
||||
const binding = bindings[0]
|
||||
const referrerId = binding.referrer_id
|
||||
|
||||
// 检查是否已过期(过期也不分佣)
|
||||
const expiryDate = new Date(binding.expiry_date)
|
||||
const now = new Date()
|
||||
if (expiryDate < now) {
|
||||
console.log('[PayNotify] 绑定已过期,跳过分佣:', {
|
||||
buyerUserId,
|
||||
referrerId,
|
||||
expiryDate: expiryDate.toISOString()
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 计算佣金(90%)
|
||||
// 计算佣金
|
||||
const commission = Math.round(amount * distributorShare * 100) / 100
|
||||
const newPurchaseCount = (binding.purchase_count || 0) + 1
|
||||
const newTotalCommission = (binding.total_commission || 0) + commission
|
||||
|
||||
console.log('[PayNotify] 处理分佣:', {
|
||||
referrerId,
|
||||
buyerUserId,
|
||||
amount,
|
||||
commission,
|
||||
shareRate: `${distributorShare * 100}%`
|
||||
shareRate: `${distributorShare * 100}%`,
|
||||
purchaseCount: `${binding.purchase_count || 0} -> ${newPurchaseCount}`,
|
||||
totalCommission: `${binding.total_commission || 0} -> ${newTotalCommission.toFixed(2)}`
|
||||
})
|
||||
|
||||
// 更新推广者的待结算收益
|
||||
@@ -397,17 +413,16 @@ async function processReferralCommission(buyerUserId: string, amount: number, or
|
||||
WHERE id = ?
|
||||
`, [commission, referrerId])
|
||||
|
||||
// 更新绑定记录状态为已转化
|
||||
// 更新绑定记录:累加购买次数和佣金,记录最后购买时间(保持 active 状态)
|
||||
await query(`
|
||||
UPDATE referral_bindings
|
||||
SET status = 'converted',
|
||||
conversion_date = CURRENT_TIMESTAMP,
|
||||
commission_amount = ?,
|
||||
order_id = (SELECT id FROM orders WHERE order_sn = ? LIMIT 1)
|
||||
SET last_purchase_date = CURRENT_TIMESTAMP,
|
||||
purchase_count = purchase_count + 1,
|
||||
total_commission = total_commission + ?
|
||||
WHERE id = ?
|
||||
`, [commission, orderSn, binding.id])
|
||||
`, [commission, binding.id])
|
||||
|
||||
console.log('[PayNotify] 分佣完成: 推广者', referrerId, '获得', commission, '元')
|
||||
console.log('[PayNotify] 分佣完成: 推广者', referrerId, '获得', commission, '元(第', newPurchaseCount, '次购买,累计', newTotalCommission.toFixed(2), '元)')
|
||||
|
||||
} catch (error) {
|
||||
console.error('[PayNotify] 处理分佣失败:', error)
|
||||
|
||||
Reference in New Issue
Block a user