diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java index 1bc2cbb98..944df1a10 100755 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java @@ -39,7 +39,6 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; -import java.math.RoundingMode; import java.time.LocalDateTime; import java.util.List; import java.util.Objects; @@ -347,7 +346,7 @@ public class PayOrderServiceImpl implements PayOrderService { .successTime(notify.getSuccessTime()).extensionId(orderExtension.getId()).no(orderExtension.getNo()) .channelOrderNo(notify.getChannelOrderNo()).channelUserId(notify.getChannelUserId()) .channelFeeRate(channel.getFeeRate()) - .channelFeePrice(MoneyUtils.calculateRatePrice(order.getPrice(), channel.getFeeRate(), 0, RoundingMode.HALF_UP).intValue()) + .channelFeePrice(MoneyUtils.calculateRatePrice(order.getPrice(), channel.getFeeRate())) .build()); if (updateCounts == 0) { // 校验状态,必须是待支付 throw exception(ORDER_STATUS_IS_NOT_WAITING); diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/util/MoneyUtils.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/util/MoneyUtils.java index 567c02bec..5e5d859e6 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/util/MoneyUtils.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/util/MoneyUtils.java @@ -1,16 +1,28 @@ package cn.iocoder.yudao.module.pay.util; +import cn.hutool.core.util.NumberUtil; + import java.math.BigDecimal; import java.math.RoundingMode; -import cn.hutool.core.util.NumberUtil; - /** * 金额工具类 * * @author 芋道源码 */ public class MoneyUtils { + + /** + * 计算百分比金额,四舍五入 + * + * @param price 金额 + * @param rate 百分比,例如说 56.77% 则传入 56.77 + * @return 百分比金额 + */ + public static Integer calculateRatePrice(Integer price, Double rate) { + return calculateRatePrice(price, rate, 0, RoundingMode.HALF_UP).intValue(); + } + /** * 计算百分比金额 * @@ -21,7 +33,7 @@ public class MoneyUtils { */ public static BigDecimal calculateRatePrice(Number price, Number rate, int scale, RoundingMode roundingMode) { return NumberUtil.toBigDecimal(price).multiply(NumberUtil.toBigDecimal(rate)) // 乘以 - .divide(BigDecimal.valueOf(100), scale, roundingMode); // 除以100 + .divide(BigDecimal.valueOf(100), scale, roundingMode); // 除以 100 } }