Commit 379c143dbb725b82d327d462ed781810906a640d
1 parent
a532ba05
修复:#320 支付手续费计算不正确,超过付款金额 #334
Showing
2 changed files
with
16 additions
and
5 deletions
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; |
| 39 | 39 | import org.springframework.validation.annotation.Validated; |
| 40 | 40 | |
| 41 | 41 | import javax.annotation.Resource; |
| 42 | -import java.math.RoundingMode; | |
| 43 | 42 | import java.time.LocalDateTime; |
| 44 | 43 | import java.util.List; |
| 45 | 44 | import java.util.Objects; |
| ... | ... | @@ -347,7 +346,7 @@ public class PayOrderServiceImpl implements PayOrderService { |
| 347 | 346 | .successTime(notify.getSuccessTime()).extensionId(orderExtension.getId()).no(orderExtension.getNo()) |
| 348 | 347 | .channelOrderNo(notify.getChannelOrderNo()).channelUserId(notify.getChannelUserId()) |
| 349 | 348 | .channelFeeRate(channel.getFeeRate()) |
| 350 | - .channelFeePrice(MoneyUtils.calculateRatePrice(order.getPrice(), channel.getFeeRate(), 0, RoundingMode.HALF_UP).intValue()) | |
| 349 | + .channelFeePrice(MoneyUtils.calculateRatePrice(order.getPrice(), channel.getFeeRate())) | |
| 351 | 350 | .build()); |
| 352 | 351 | if (updateCounts == 0) { // 校验状态,必须是待支付 |
| 353 | 352 | throw exception(ORDER_STATUS_IS_NOT_WAITING); | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/util/MoneyUtils.java
| 1 | 1 | package cn.iocoder.yudao.module.pay.util; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.util.NumberUtil; | |
| 4 | + | |
| 3 | 5 | import java.math.BigDecimal; |
| 4 | 6 | import java.math.RoundingMode; |
| 5 | 7 | |
| 6 | -import cn.hutool.core.util.NumberUtil; | |
| 7 | - | |
| 8 | 8 | /** |
| 9 | 9 | * 金额工具类 |
| 10 | 10 | * |
| 11 | 11 | * @author 芋道源码 |
| 12 | 12 | */ |
| 13 | 13 | public class MoneyUtils { |
| 14 | + | |
| 15 | + /** | |
| 16 | + * 计算百分比金额,四舍五入 | |
| 17 | + * | |
| 18 | + * @param price 金额 | |
| 19 | + * @param rate 百分比,例如说 56.77% 则传入 56.77 | |
| 20 | + * @return 百分比金额 | |
| 21 | + */ | |
| 22 | + public static Integer calculateRatePrice(Integer price, Double rate) { | |
| 23 | + return calculateRatePrice(price, rate, 0, RoundingMode.HALF_UP).intValue(); | |
| 24 | + } | |
| 25 | + | |
| 14 | 26 | /** |
| 15 | 27 | * 计算百分比金额 |
| 16 | 28 | * |
| ... | ... | @@ -21,7 +33,7 @@ public class MoneyUtils { |
| 21 | 33 | */ |
| 22 | 34 | public static BigDecimal calculateRatePrice(Number price, Number rate, int scale, RoundingMode roundingMode) { |
| 23 | 35 | return NumberUtil.toBigDecimal(price).multiply(NumberUtil.toBigDecimal(rate)) // 乘以 |
| 24 | - .divide(BigDecimal.valueOf(100), scale, roundingMode); // 除以100 | |
| 36 | + .divide(BigDecimal.valueOf(100), scale, roundingMode); // 除以 100 | |
| 25 | 37 | } |
| 26 | 38 | |
| 27 | 39 | } | ... | ... |