diff --git a/server/HoneyBox/src/HoneyBox.Core/Services/PaymentNotifyService.cs b/server/HoneyBox/src/HoneyBox.Core/Services/PaymentNotifyService.cs
index bfe45a30..4a63389f 100644
--- a/server/HoneyBox/src/HoneyBox.Core/Services/PaymentNotifyService.cs
+++ b/server/HoneyBox/src/HoneyBox.Core/Services/PaymentNotifyService.cs
@@ -497,11 +497,15 @@ public class PaymentNotifyService : IPaymentNotifyService
// 处理成功后的后续操作
if (processResult)
{
- // 分销奖励(仅对抽盒子订单生效,不包括充值、运费等)
- if (attach.StartsWith("order_") || attach.StartsWith("infinite_") ||
+ // 分销奖励(抽盒子订单和充值生效,运费不生效)
+ if (attach == OrderAttachType.UserRecharge)
+ {
+ await ProcessDistributionRewardAsync(orderNo, user.Id, isRecharge: true);
+ }
+ else if (attach.StartsWith("order_") || attach.StartsWith("infinite_") ||
LotteryOrderTypes.Contains(attach) || InfiniteOrderTypes.Contains(attach))
{
- await ProcessDistributionRewardAsync(orderNo, user.Id);
+ await ProcessDistributionRewardAsync(orderNo, user.Id, isRecharge: false);
}
// 调用微信发货接口
@@ -1518,17 +1522,33 @@ public class PaymentNotifyService : IPaymentNotifyService
///
/// 订单号
/// 下级用户ID
- private async Task ProcessDistributionRewardAsync(string orderNo, int userId)
+ /// 是否为充值订单
+ private async Task ProcessDistributionRewardAsync(string orderNo, int userId, bool isRecharge = false)
{
try
{
- // 1. 获取订单信息
- var order = await _dbContext.Orders
- .Where(o => o.OrderNum == orderNo)
- .Select(o => new { o.Price, o.UserId })
- .FirstOrDefaultAsync();
+ // 1. 获取支付金额
+ decimal price;
+ if (isRecharge)
+ {
+ // 充值订单从 UserRecharges 表获取金额
+ var rechargeOrder = await _dbContext.UserRecharges
+ .Where(r => r.OrderNum == orderNo)
+ .Select(r => r.Money)
+ .FirstOrDefaultAsync();
+ price = rechargeOrder;
+ }
+ else
+ {
+ // 抽盒子订单从 Orders 表获取金额
+ var order = await _dbContext.Orders
+ .Where(o => o.OrderNum == orderNo)
+ .Select(o => o.Price)
+ .FirstOrDefaultAsync();
+ price = order;
+ }
- if (order == null || order.Price <= 0)
+ if (price <= 0)
{
return;
}
@@ -1543,7 +1563,7 @@ public class PaymentNotifyService : IPaymentNotifyService
// 3. 计算奖励金额
// fx_bili 是百分比,如 3 表示 3%
var ratio = fxBili / 100m;
- var rewardRmb = Math.Round(order.Price * ratio, 2);
+ var rewardRmb = Math.Round(price * ratio, 2);
if (rewardRmb <= 0)
{
return;
@@ -1574,8 +1594,8 @@ public class PaymentNotifyService : IPaymentNotifyService
if (result)
{
_logger.LogInformation(
- "分销奖励发放成功: OrderNo={OrderNo}, 下级UserId={UserId}, 上级Pid={Pid}, 支付金额={Price}, 奖励比例={Ratio}%, 奖励哈尼券={Reward}",
- orderNo, userId, pid, order.Price, fxBili, rewardIntegral);
+ "分销奖励发放成功: OrderNo={OrderNo}, 下级UserId={UserId}, 上级Pid={Pid}, 支付金额={Price}, 奖励比例={Ratio}%, 奖励哈尼券={Reward}, 类型={Type}",
+ orderNo, userId, pid, price, fxBili, rewardIntegral, isRecharge ? "充值" : "抽盒子");
}
else
{