feat: 订单支持优惠金额字段,优先使用优惠金额
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -30,10 +30,15 @@ public class CreateOrderRequest {
|
||||
private List<OrderItemDTO> items;
|
||||
|
||||
/**
|
||||
* 折扣率(百分比), 默认100
|
||||
* 折扣率(百分比), 默认100(保留此逻辑)
|
||||
*/
|
||||
private BigDecimal discountRate;
|
||||
|
||||
/**
|
||||
* 优惠金额(元)
|
||||
*/
|
||||
private BigDecimal discountMoney;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
|
||||
@@ -57,6 +57,11 @@ public class Order {
|
||||
*/
|
||||
private BigDecimal discountAmount;
|
||||
|
||||
/**
|
||||
* 优惠金额(元,用户输入)
|
||||
*/
|
||||
private BigDecimal discountMoney;
|
||||
|
||||
/**
|
||||
* 实收金额
|
||||
* 计算公式: totalAmount - discountAmount
|
||||
@@ -64,7 +69,7 @@ public class Order {
|
||||
private BigDecimal actualAmount;
|
||||
|
||||
/**
|
||||
* 折扣率(百分比)
|
||||
* 折扣率(百分比,保留此逻辑)
|
||||
*/
|
||||
private BigDecimal discountRate;
|
||||
|
||||
|
||||
@@ -117,9 +117,21 @@ public class OrderServiceImpl implements OrderService {
|
||||
order.setTotalAmount(totalAmount);
|
||||
|
||||
// 5. 计算优惠金额和实付金额
|
||||
BigDecimal discountAmount;
|
||||
BigDecimal discountRate = order.getDiscountRate();
|
||||
BigDecimal discountAmount = totalAmount.multiply(new BigDecimal("100").subtract(discountRate))
|
||||
BigDecimal discountMoney = request.getDiscountMoney();
|
||||
|
||||
// 优先使用优惠金额,如果没有填则用折扣率计算
|
||||
if (discountMoney != null && discountMoney.compareTo(BigDecimal.ZERO) > 0) {
|
||||
discountAmount = discountMoney;
|
||||
} else {
|
||||
// 折扣率默认100,即不打折
|
||||
if (discountRate == null) {
|
||||
discountRate = new BigDecimal("100");
|
||||
}
|
||||
discountAmount = totalAmount.multiply(new BigDecimal("100").subtract(discountRate))
|
||||
.divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
|
||||
}
|
||||
BigDecimal actualAmount = totalAmount.subtract(discountAmount);
|
||||
|
||||
order.setDiscountAmount(discountAmount);
|
||||
@@ -342,9 +354,20 @@ public class OrderServiceImpl implements OrderService {
|
||||
|
||||
order.setTotalAmount(totalAmount);
|
||||
|
||||
BigDecimal discountAmount;
|
||||
BigDecimal discountRate = order.getDiscountRate();
|
||||
BigDecimal discountAmount = totalAmount.multiply(new BigDecimal("100").subtract(discountRate))
|
||||
BigDecimal discountMoney = order.getDiscountMoney();
|
||||
|
||||
// 优先使用优惠金额,如果没有填则用折扣率计算
|
||||
if (discountMoney != null && discountMoney.compareTo(BigDecimal.ZERO) > 0) {
|
||||
discountAmount = discountMoney;
|
||||
} else {
|
||||
if (discountRate == null) {
|
||||
discountRate = new BigDecimal("100");
|
||||
}
|
||||
discountAmount = totalAmount.multiply(new BigDecimal("100").subtract(discountRate))
|
||||
.divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
|
||||
}
|
||||
BigDecimal actualAmount = totalAmount.subtract(discountAmount);
|
||||
|
||||
order.setDiscountAmount(discountAmount);
|
||||
|
||||
Reference in New Issue
Block a user