From 46faa2cf1695dfec11f1d228685bd8652f1cf688 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=9D=BE?= <8605635+zhang3064194730@user.noreply.gitee.com> Date: Mon, 13 Oct 2025 14:29:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=AE=A2=E7=AB=8B=E5=87=8F=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...kShopConsumeDiscountRecordServiceImpl.java | 75 ++++++++++--------- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkShopConsumeDiscountRecordServiceImpl.java b/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkShopConsumeDiscountRecordServiceImpl.java index 9121c163..7ebdb788 100644 --- a/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkShopConsumeDiscountRecordServiceImpl.java +++ b/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkShopConsumeDiscountRecordServiceImpl.java @@ -122,48 +122,53 @@ public class MkShopConsumeDiscountRecordServiceImpl extends ServiceImpl randomList = consumeDiscountVO.getRandomDiscountList(); - if (randomList == null || randomList.isEmpty()) { - throw new ApiNotPrintException("随机立减配置错误"); - } - - // 生成 1~100 的随机数 - int rand = new Random().nextInt(100) + 1; - int current = 0; - - for (MkConsumeDiscountRandom item : randomList) { - int prob = item.getProbability().intValue(); - current += prob; - if (rand <= current) { - shopConsumeDiscountRecord.setAmount(item.getAmount()); + // 固定金额 + if (TableValueConstant.ConsumeDiscount.DiscountType.FIXED.getCode().equals(consumeDiscountVO.getDiscountType())) { + shopConsumeDiscountRecord.setAmount(consumeDiscountVO.getDiscountAmount()); save(shopConsumeDiscountRecord); return shopConsumeDiscountRecord; } - } - throw new ApiNotPrintException("随机立减计算失败"); + // 随机金额(概率加起来是100) + List randomList = consumeDiscountVO.getRandomDiscountList(); + if (randomList == null || randomList.isEmpty()) { + throw new ApiNotPrintException("随机立减配置错误"); + } + + // 生成 1~100 的随机数 + int rand = new Random().nextInt(100) + 1; + int current = 0; + + for (MkConsumeDiscountRandom item : randomList) { + int prob = item.getProbability().intValue(); + current += prob; + if (rand <= current) { + shopConsumeDiscountRecord.setAmount(item.getAmount()); + save(shopConsumeDiscountRecord); + return shopConsumeDiscountRecord; + } + } + + throw new ApiNotPrintException("随机立减计算失败"); + } catch (Exception e) { + log.info(e.getMessage()); + return null; + } } }