mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-23 07:41:53 +08:00
修复:#320 支付手续费计算不正确,超过付款金额
(cherry picked from commit 0df2d7191f7a467f2eeeb5bd19217a4a039395db)
This commit is contained in:
parent
d82729e4c6
commit
3d894ca7f5
@ -39,6 +39,7 @@ 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;
|
||||||
@ -345,7 +346,8 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|||||||
.channelId(channel.getId()).channelCode(channel.getCode())
|
.channelId(channel.getId()).channelCode(channel.getCode())
|
||||||
.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()).channelFeePrice(MoneyUtils.calculateRatePrice(order.getPrice(), channel.getFeeRate()))
|
.channelFeeRate(channel.getFeeRate())
|
||||||
|
.channelFeePrice(MoneyUtils.calculateRatePrice(order.getPrice(), channel.getFeeRate(), 0, RoundingMode.HALF_UP).intValue())
|
||||||
.build());
|
.build());
|
||||||
if (updateCounts == 0) { // 校验状态,必须是待支付
|
if (updateCounts == 0) { // 校验状态,必须是待支付
|
||||||
throw exception(ORDER_STATUS_IS_NOT_WAITING);
|
throw exception(ORDER_STATUS_IS_NOT_WAITING);
|
||||||
|
@ -3,25 +3,25 @@ package cn.iocoder.yudao.module.pay.util;
|
|||||||
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 price 金额
|
* @param rate 百分比,例如说 56.77% 则传入 56.77
|
||||||
* @param rate 百分比,例如说 56.77% 则传入 56.77
|
* @param scale 保留小数位数
|
||||||
* @return 百分比金额
|
* @param roundingMode 舍入模式
|
||||||
*/
|
*/
|
||||||
public static Integer calculateRatePrice(Integer price, Double rate) {
|
public static BigDecimal calculateRatePrice(Number price, Number rate, int scale, RoundingMode roundingMode) {
|
||||||
return new BigDecimal(price)
|
return NumberUtil.toBigDecimal(price).multiply(NumberUtil.toBigDecimal(rate)) // 乘以
|
||||||
.multiply(BigDecimal.valueOf(rate)) // 乘以
|
.divide(BigDecimal.valueOf(100), scale, roundingMode); // 除以100
|
||||||
.setScale(0, RoundingMode.HALF_UP) // 四舍五入
|
}
|
||||||
.intValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user