fix: 修复抽奖消费时未记录资产流水的问题 - OrderService.DeductUserAssetsAsync 增加余额/积分/钻石流水记录 - 记录到 ProfitMoney/ProfitIntegral/ProfitMoney2 表
This commit is contained in:
parent
3248274998
commit
269f85c77b
|
|
@ -1082,7 +1082,7 @@ public class OrderService : IOrderService
|
||||||
order.PayTime = (int)currentTimestamp;
|
order.PayTime = (int)currentTimestamp;
|
||||||
|
|
||||||
// 扣减用户资产
|
// 扣减用户资产
|
||||||
await DeductUserAssetsAsync(userId, paymentResult.UseMoney, paymentResult.UseIntegral, paymentResult.UseMoney2);
|
await DeductUserAssetsAsync(userId, paymentResult.UseMoney, paymentResult.UseIntegral, paymentResult.UseMoney2, goods.Title);
|
||||||
|
|
||||||
// 使用优惠券
|
// 使用优惠券
|
||||||
if (paymentResult.CouponId > 0)
|
if (paymentResult.CouponId > 0)
|
||||||
|
|
@ -1254,26 +1254,61 @@ public class OrderService : IOrderService
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 扣减用户资产
|
/// 扣减用户资产并记录流水
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private async Task DeductUserAssetsAsync(int userId, decimal useMoney, decimal useIntegral, decimal useMoney2)
|
private async Task DeductUserAssetsAsync(int userId, decimal useMoney, decimal useIntegral, decimal useMoney2, string goodsName = "")
|
||||||
{
|
{
|
||||||
var user = await _dbContext.Users.FindAsync(userId);
|
var user = await _dbContext.Users.FindAsync(userId);
|
||||||
if (user == null) return;
|
if (user == null) return;
|
||||||
|
|
||||||
|
var content = string.IsNullOrEmpty(goodsName) ? "抽奖消费" : $"抽奖消费-{goodsName}";
|
||||||
|
|
||||||
|
// 扣减余额并记录流水
|
||||||
if (useMoney > 0)
|
if (useMoney > 0)
|
||||||
{
|
{
|
||||||
user.Money -= useMoney;
|
user.Money -= useMoney;
|
||||||
|
_dbContext.ProfitMoneys.Add(new ProfitMoney
|
||||||
|
{
|
||||||
|
UserId = userId,
|
||||||
|
ChangeMoney = -useMoney,
|
||||||
|
Money = user.Money,
|
||||||
|
Type = 3, // 消费
|
||||||
|
Content = content,
|
||||||
|
ShareUid = 0,
|
||||||
|
CreatedAt = DateTime.Now
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 扣减积分并记录流水
|
||||||
if (useIntegral > 0)
|
if (useIntegral > 0)
|
||||||
{
|
{
|
||||||
user.Integral -= useIntegral;
|
user.Integral -= useIntegral;
|
||||||
|
_dbContext.ProfitIntegrals.Add(new ProfitIntegral
|
||||||
|
{
|
||||||
|
UserId = userId,
|
||||||
|
ChangeMoney = -useIntegral,
|
||||||
|
Money = user.Integral,
|
||||||
|
Type = 3, // 消费
|
||||||
|
Content = content,
|
||||||
|
ShareUid = 0,
|
||||||
|
CreatedAt = DateTime.Now
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 扣减钻石/哈尼券并记录流水
|
||||||
if (useMoney2 > 0 && user.Money2.HasValue)
|
if (useMoney2 > 0 && user.Money2.HasValue)
|
||||||
{
|
{
|
||||||
user.Money2 -= useMoney2;
|
user.Money2 -= useMoney2;
|
||||||
|
_dbContext.ProfitMoney2s.Add(new ProfitMoney2
|
||||||
|
{
|
||||||
|
UserId = userId,
|
||||||
|
ChangeMoney = -useMoney2,
|
||||||
|
Money = user.Money2 ?? 0,
|
||||||
|
Type = 3, // 消费
|
||||||
|
Content = content,
|
||||||
|
ShareUid = 0,
|
||||||
|
CreatedAt = DateTime.Now
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
user.UpdatedAt = DateTime.Now;
|
user.UpdatedAt = DateTime.Now;
|
||||||
|
|
@ -1517,7 +1552,7 @@ public class OrderService : IOrderService
|
||||||
order.PayTime = (int)currentTimestamp;
|
order.PayTime = (int)currentTimestamp;
|
||||||
|
|
||||||
// 扣减用户资产
|
// 扣减用户资产
|
||||||
await DeductUserAssetsAsync(userId, paymentResult.UseMoney, paymentResult.UseIntegral, paymentResult.UseMoney2);
|
await DeductUserAssetsAsync(userId, paymentResult.UseMoney, paymentResult.UseIntegral, paymentResult.UseMoney2, goods.Title);
|
||||||
|
|
||||||
// 使用优惠券
|
// 使用优惠券
|
||||||
if (paymentResult.CouponId > 0)
|
if (paymentResult.CouponId > 0)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user