From 2987ec0f865eb816cdcb3fd10e2d556f9b7d95d4 Mon Sep 17 00:00:00 2001 From: xuhy <3313886187@qq.com> Date: 星期三, 03 九月 2025 16:18:10 +0800 Subject: [PATCH] bug修改 --- ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 50 insertions(+), 3 deletions(-) diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java index 1726f68..e7c0e93 100644 --- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java +++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java @@ -179,12 +179,36 @@ orderGoodsVO.setGoodsName(goods.getName()); orderGoodsVO.setGoodsPic(goods.getHomePagePicture()); orderGoodsVO.setNum(order.getNum()); + + // 获取积分兑换比例配置 + R<SysConfig> sysConfigR = sysConfigClient.getInfo(6L); + if (sysConfigR == null || sysConfigR.getData() == null) { + throw new ServiceException("获取积分兑换比例配置失败"); + } + String configValue = sysConfigR.getData().getConfigValue(); + if (StringUtils.isBlank(configValue)) { + throw new ServiceException("积分兑换比例配置值为空"); + } + // 使用BigDecimal处理比例,避免精度问题 + BigDecimal ratio = new BigDecimal(configValue.trim()); + if (ratio.compareTo(BigDecimal.ZERO) <= 0) { + throw new ServiceException("积分兑换比例必须大于0"); + } + if (null != goodsSeckill) { + if(Objects.nonNull(goodsSeckill.getSellingPrice())){ + orderGoodsVO.setIntegral(goodsSeckill.getSellingPrice().multiply(ratio).intValue()); + }else { + orderGoodsVO.setIntegral(goodsSeckill.getIntegral()); + } orderGoodsVO.setSellingPrice(goodsSeckill.getSellingPrice()); - orderGoodsVO.setIntegral(goodsSeckill.getIntegral()); } else { + if(Objects.nonNull(goods.getSellingPrice())){ + orderGoodsVO.setIntegral(goods.getSellingPrice().multiply(ratio).intValue()); + }else { + orderGoodsVO.setIntegral(goods.getIntegral()); + } orderGoodsVO.setSellingPrice(goods.getSellingPrice()); - orderGoodsVO.setIntegral(goods.getIntegral()); } @@ -786,7 +810,30 @@ confirmOrderVo.setResidualPoint(appUser.getAvailablePoint()); //插入价格 confirmOrderVo.setCash(good.getSellingPrice()); - confirmOrderVo.setPoint(good.getIntegral()); + + // 获取积分兑换比例配置 + R<SysConfig> sysConfigR = sysConfigClient.getInfo(6L); + if (sysConfigR == null || sysConfigR.getData() == null) { + throw new ServiceException("获取积分兑换比例配置失败"); + } + String configValue = sysConfigR.getData().getConfigValue(); + if (StringUtils.isBlank(configValue)) { + throw new ServiceException("积分兑换比例配置值为空"); + } + try { + // 使用BigDecimal处理比例,避免精度问题 + BigDecimal ratio = new BigDecimal(configValue.trim()); + if (ratio.compareTo(BigDecimal.ZERO) <= 0) { + throw new ServiceException("积分兑换比例必须大于0"); + } + // 计算积分并四舍五入取整 + int point = good.getSellingPrice().multiply(ratio).intValue(); + confirmOrderVo.setPoint(point); + } catch (NumberFormatException e) { + throw new RuntimeException("积分兑换比例配置值格式错误", e); + } catch (ArithmeticException e) { + throw new RuntimeException("积分计算结果溢出", e); + } //是否在秒杀活动中 GetSeckillActivityInfo info = new GetSeckillActivityInfo(); -- Gitblit v1.7.1