修复:#320 支付手续费计算不正确,超过付款金额 #334

This commit is contained in:
YunaiV 2023-09-03 18:39:51 +08:00
parent a532ba0579
commit 379c143dbb
2 changed files with 16 additions and 5 deletions

View File

@ -39,7 +39,6 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.RoundingMode;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -347,7 +346,7 @@ public class PayOrderServiceImpl implements PayOrderService {
.successTime(notify.getSuccessTime()).extensionId(orderExtension.getId()).no(orderExtension.getNo()) .successTime(notify.getSuccessTime()).extensionId(orderExtension.getId()).no(orderExtension.getNo())
.channelOrderNo(notify.getChannelOrderNo()).channelUserId(notify.getChannelUserId()) .channelOrderNo(notify.getChannelOrderNo()).channelUserId(notify.getChannelUserId())
.channelFeeRate(channel.getFeeRate()) .channelFeeRate(channel.getFeeRate())
.channelFeePrice(MoneyUtils.calculateRatePrice(order.getPrice(), channel.getFeeRate(), 0, RoundingMode.HALF_UP).intValue()) .channelFeePrice(MoneyUtils.calculateRatePrice(order.getPrice(), channel.getFeeRate()))
.build()); .build());
if (updateCounts == 0) { // 校验状态必须是待支付 if (updateCounts == 0) { // 校验状态必须是待支付
throw exception(ORDER_STATUS_IS_NOT_WAITING); throw exception(ORDER_STATUS_IS_NOT_WAITING);

View File

@ -1,16 +1,28 @@
package cn.iocoder.yudao.module.pay.util; package cn.iocoder.yudao.module.pay.util;
import cn.hutool.core.util.NumberUtil;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import cn.hutool.core.util.NumberUtil;
/** /**
* 金额工具类 * 金额工具类
* *
* @author 芋道源码 * @author 芋道源码
*/ */
public class MoneyUtils { 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) { public static BigDecimal calculateRatePrice(Number price, Number rate, int scale, RoundingMode roundingMode) {
return NumberUtil.toBigDecimal(price).multiply(NumberUtil.toBigDecimal(rate)) // 乘以 return NumberUtil.toBigDecimal(price).multiply(NumberUtil.toBigDecimal(rate)) // 乘以
.divide(BigDecimal.valueOf(100), scale, roundingMode); // 除以100 .divide(BigDecimal.valueOf(100), scale, roundingMode); // 除以 100
} }
} }