xuhy
2025-09-03 2987ec0f865eb816cdcb3fd10e2d556f9b7d95d4
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) {
            orderGoodsVO.setSellingPrice(goodsSeckill.getSellingPrice());
            orderGoodsVO.setIntegral(goodsSeckill.getIntegral());
            if(Objects.nonNull(goodsSeckill.getSellingPrice())){
                orderGoodsVO.setIntegral(goodsSeckill.getSellingPrice().multiply(ratio).intValue());
        } else {
            orderGoodsVO.setSellingPrice(goods.getSellingPrice());
                orderGoodsVO.setIntegral(goodsSeckill.getIntegral());
            }
            orderGoodsVO.setSellingPrice(goodsSeckill.getSellingPrice());
        } else {
            if(Objects.nonNull(goods.getSellingPrice())){
                orderGoodsVO.setIntegral(goods.getSellingPrice().multiply(ratio).intValue());
            }else {
            orderGoodsVO.setIntegral(goods.getIntegral());
            }
            orderGoodsVO.setSellingPrice(goods.getSellingPrice());
        }
@@ -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();