提交代码

master
胡锐 4 months ago
parent fca289b5d4
commit 6714373a81
  1. 75
      service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java

@ -223,49 +223,64 @@ public class BsOrderServiceImpl implements BsOrderService {
BigDecimal payRealPrice = totalPrice.subtract(order.getDeduction().getTotalDeductionPrice()); BigDecimal payRealPrice = totalPrice.subtract(order.getDeduction().getTotalDeductionPrice());
order.setPayRealPrice(payRealPrice.compareTo(new BigDecimal("0")) > 0 ? payRealPrice : new BigDecimal("0")); order.setPayRealPrice(payRealPrice.compareTo(new BigDecimal("0")) > 0 ? payRealPrice : new BigDecimal("0"));
order.setOrderStatus(order.getPayRealPrice().compareTo(new BigDecimal("0")) == 0?OrderStatusEnum.status2.getCode():OrderStatusEnum.status1.getCode()); order.setOrderStatus(order.getPayRealPrice().compareTo(new BigDecimal("0")) == 0?OrderStatusEnum.status2.getCode():OrderStatusEnum.status1.getCode());
BigDecimal totalChildDiscountPrice = new BigDecimal("0");
Long totalIntegralDiscountPrice = 0L;
// 订单入库前处理 // 订单入库前处理
for (OrderChildModel childOrder : order.getOrderChildList()) { for (int i = 0; i < order.getOrderChildList().size();i++) {
OrderChildModel childOrder = order.getOrderChildList().get(i);
childOrder.setSurplusRefundCount(childOrder.getProductCount()); childOrder.setSurplusRefundCount(childOrder.getProductCount());
// 计算 子订单 在交易订单金额中的占比 // 计算 子订单 在交易订单金额中的占比
BigDecimal ratio = childOrder.getProductTotalPrice().divide(order.getTotalPrice(), 2, BigDecimal.ROUND_DOWN); BigDecimal ratio = childOrder.getProductTotalPrice().divide(order.getTotalPrice(), 2, BigDecimal.ROUND_DOWN);
// 计算子订单退款积分 // 优惠券优惠
if (order.getDeduction().getCouponDiscountActualPrice().compareTo(BigDecimal.ZERO) > 0) {
childOrder.setCouponDiscountPrice(order.getDeduction().getCouponDiscountActualPrice().multiply(ratio).setScale(2, BigDecimal.ROUND_DOWN));
} else {
childOrder.setCouponDiscountPrice(new BigDecimal("0"));
}
totalChildDiscountPrice = totalChildDiscountPrice.add(childOrder.getCouponDiscountPrice());
// 积分
if (order.getDeduction().getIntegralDiscountPrice() > 0) { if (order.getDeduction().getIntegralDiscountPrice() > 0) {
childOrder.setSurplusRefundIntegral(new BigDecimal(order.getDeduction().getIntegralDiscountPrice().toString()).multiply(ratio).setScale(2).longValue()); childOrder.setIntegralDiscountPrice(new BigDecimal(order.getDeduction().getIntegralDiscountPrice().toString()).multiply(ratio).setScale(2, BigDecimal.ROUND_DOWN).longValue());
} else { } else {
childOrder.setSurplusRefundIntegral(0L); childOrder.setIntegralDiscountPrice(0L);
} }
totalIntegralDiscountPrice = totalIntegralDiscountPrice + childOrder.getIntegralDiscountPrice();
// 如果是循环的最后一笔商品订单
if ((i+1) == order.getOrderChildList().size()) {
// 优惠券差值
BigDecimal couponDiscountDifference = order.getDeduction().getCouponDiscountActualPrice().subtract(totalChildDiscountPrice);
if (couponDiscountDifference.compareTo(BigDecimal.ZERO) > 0) {
// 大于0
childOrder.setCouponDiscountPrice(childOrder.getCouponDiscountPrice().add(couponDiscountDifference));
} else if (couponDiscountDifference.compareTo(BigDecimal.ZERO) < 0) {
// 小于0
childOrder.setCouponDiscountPrice(childOrder.getCouponDiscountPrice().subtract(couponDiscountDifference));
}
if (order.getDeduction().getCouponDiscountActualPrice().compareTo(BigDecimal.ZERO) == 1) { // 积分差值
// 计算子订单退款金额。 Long integralDiscountDifference = order.getDeduction().getIntegralDiscountPrice() - totalIntegralDiscountPrice;
if (order.getPayRealPrice().compareTo(BigDecimal.ZERO) == 1) { if (integralDiscountDifference > 0) {
// 计算实付金额中的占比 // 大于0
childOrder.setSurplusRefundPrice(order.getPayRealPrice().multiply(ratio).setScale(2, BigDecimal.ROUND_DOWN)); childOrder.setIntegralDiscountPrice(childOrder.getIntegralDiscountPrice() + integralDiscountDifference);
} else { } else if (integralDiscountDifference < 0) {
childOrder.setSurplusRefundPrice(new BigDecimal("0")); // 小于0
childOrder.setIntegralDiscountPrice(childOrder.getIntegralDiscountPrice() - integralDiscountDifference);
} }
} else {
childOrder.setSurplusRefundPrice(
// 商品总金额 - 积分抵扣金额
childOrder.getProductTotalPrice().subtract(
new BigDecimal(childOrder.getSurplusRefundIntegral().toString()).divide(new BigDecimal("100"))
));
} }
childOrder.setIntegralDiscountPrice(childOrder.getSurplusRefundIntegral()); // 商品订单总优惠
childOrder.setCouponDiscountPrice( childOrder.setTotalDeductionPrice(childOrder.getCouponDiscountPrice().add(new BigDecimal(childOrder.getIntegralDiscountPrice())));
// 可退款金额大于0 可退款金额+可退款积分=优惠券优惠
childOrder.getSurplusRefundPrice().compareTo(BigDecimal.ZERO) == 1 // 可退款金额 产品总价 - 优惠总价
? childOrder.getProductTotalPrice().subtract( childOrder.setSurplusRefundPrice(childOrder.getProductTotalPrice().subtract(childOrder.getTotalDeductionPrice()));
childOrder.getSurplusRefundPrice().add(new BigDecimal(childOrder.getSurplusRefundIntegral().toString()).divide(new BigDecimal("100")))) // 可退款积分 积分优惠
: childOrder.getSurplusRefundPrice()); childOrder.setSurplusRefundIntegral(childOrder.getIntegralDiscountPrice());
// 商品实际价格
childOrder.setTotalDeductionPrice( childOrder.setProductActualPrice(childOrder.getSurplusRefundPrice());
childOrder.getCouponDiscountPrice()
.add(new BigDecimal(childOrder.getIntegralDiscountPrice().toString()).divide(new BigDecimal("100")))
);
childOrder.setProductActualPrice(childOrder.getProductTotalPrice().subtract(childOrder.getTotalDeductionPrice()));
orderChildService.editData(childOrder); orderChildService.editData(childOrder);
} }

Loading…
Cancel
Save