From 678ae9316e8aa5f7ef09b01b590c8e46d84e2166 Mon Sep 17 00:00:00 2001 From: zpc Date: Sun, 25 Jan 2026 15:46:00 +0800 Subject: [PATCH] 33 --- .../HoneyBox.Core/Services/LotteryEngine.cs | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/server/HoneyBox/src/HoneyBox.Core/Services/LotteryEngine.cs b/server/HoneyBox/src/HoneyBox.Core/Services/LotteryEngine.cs index 150918c6..7b7dac53 100644 --- a/server/HoneyBox/src/HoneyBox.Core/Services/LotteryEngine.cs +++ b/server/HoneyBox/src/HoneyBox.Core/Services/LotteryEngine.cs @@ -394,6 +394,9 @@ public class LotteryEngine : ILotteryEngine // 7. 处理领主赏逻辑(type=8) await ProcessLingZhuLogicAsync(request.UserId, request.GoodsId, selectedPrize.ShangId, selectedPrize.IsLingzhu, orderItem.Id); + + // 8. 处理翻倍赏逻辑(doubling > 1 时赠送积分) + await ProcessDoublingRewardAsync(request.UserId, selectedPrize.Doubling, selectedPrize.Price, selectedPrize.Title); } catch (Exception ex) { @@ -544,6 +547,67 @@ public class LotteryEngine : ILotteryEngine } } + /// + /// 处理翻倍赏逻辑 - 当奖品doubling > 1时,赠送用户额外积分 + /// + /// 用户ID + /// 翻倍倍数 + /// 奖品价格 + /// 奖品标题 + private async Task ProcessDoublingRewardAsync(int userId, int doubling, decimal prizePrice, string prizeTitle) + { + try + { + // 只有翻倍倍数大于1才赠送 + if (doubling <= 1) + { + return; + } + + // 计算赠送积分:奖品价格 * (倍数-1) * 100 + var bei = doubling - 1; + var rewardIntegral = prizePrice * bei * 100; + + if (rewardIntegral <= 0) + { + return; + } + + // 更新用户积分 + var user = await _dbContext.Users.FindAsync(userId); + if (user == null) + { + return; + } + + user.Integral += rewardIntegral; + + // 记录积分流水 + var profitIntegral = new ProfitIntegral + { + UserId = userId, + Type = 6, // 翻倍赏赠送 + ChangeMoney = rewardIntegral, + Money = user.Integral, + Content = $"抽中翻倍赏-{prizeTitle}赠送", + ShareUid = 0, + CreatedAt = DateTime.Now + }; + _dbContext.ProfitIntegrals.Add(profitIntegral); + + await _dbContext.SaveChangesAsync(); + + _logger.LogInformation("Doubling reward granted: UserId={UserId}, Doubling={Doubling}, Reward={Reward}, Prize={Prize}", + userId, doubling, rewardIntegral, prizeTitle); + } + catch (Exception ex) + { + _logger.LogError(ex, "Failed to process doubling reward: UserId={UserId}, Doubling={Doubling}", + userId, doubling); + // 翻倍赏逻辑失败不影响抽奖结果 + } + } + /// /// /// 多次无限赏抽奖流程: