|
|
@ -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().getIntegralDiscountPrice() > 0) { |
|
|
|
if (order.getDeduction().getCouponDiscountActualPrice().compareTo(BigDecimal.ZERO) > 0) { |
|
|
|
childOrder.setSurplusRefundIntegral(new BigDecimal(order.getDeduction().getIntegralDiscountPrice().toString()).multiply(ratio).setScale(2).longValue()); |
|
|
|
childOrder.setCouponDiscountPrice(order.getDeduction().getCouponDiscountActualPrice().multiply(ratio).setScale(2, BigDecimal.ROUND_DOWN)); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
childOrder.setSurplusRefundIntegral(0L); |
|
|
|
childOrder.setCouponDiscountPrice(new BigDecimal("0")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
totalChildDiscountPrice = totalChildDiscountPrice.add(childOrder.getCouponDiscountPrice()); |
|
|
|
|
|
|
|
|
|
|
|
if (order.getDeduction().getCouponDiscountActualPrice().compareTo(BigDecimal.ZERO) == 1) { |
|
|
|
// 积分
|
|
|
|
// 计算子订单退款金额。
|
|
|
|
if (order.getDeduction().getIntegralDiscountPrice() > 0) { |
|
|
|
if (order.getPayRealPrice().compareTo(BigDecimal.ZERO) == 1) { |
|
|
|
childOrder.setIntegralDiscountPrice(new BigDecimal(order.getDeduction().getIntegralDiscountPrice().toString()).multiply(ratio).setScale(2, BigDecimal.ROUND_DOWN).longValue()); |
|
|
|
// 计算实付金额中的占比
|
|
|
|
|
|
|
|
childOrder.setSurplusRefundPrice(order.getPayRealPrice().multiply(ratio).setScale(2, BigDecimal.ROUND_DOWN)); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
childOrder.setSurplusRefundPrice(new BigDecimal("0")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
childOrder.setSurplusRefundPrice( |
|
|
|
childOrder.setIntegralDiscountPrice(0L); |
|
|
|
// 商品总金额 - 积分抵扣金额
|
|
|
|
} |
|
|
|
childOrder.getProductTotalPrice().subtract( |
|
|
|
totalIntegralDiscountPrice = totalIntegralDiscountPrice + childOrder.getIntegralDiscountPrice(); |
|
|
|
new BigDecimal(childOrder.getSurplusRefundIntegral().toString()).divide(new BigDecimal("100")) |
|
|
|
|
|
|
|
)); |
|
|
|
// 如果是循环的最后一笔商品订单
|
|
|
|
} |
|
|
|
if ((i+1) == order.getOrderChildList().size()) { |
|
|
|
|
|
|
|
// 优惠券差值
|
|
|
|
childOrder.setIntegralDiscountPrice(childOrder.getSurplusRefundIntegral()); |
|
|
|
BigDecimal couponDiscountDifference = order.getDeduction().getCouponDiscountActualPrice().subtract(totalChildDiscountPrice); |
|
|
|
childOrder.setCouponDiscountPrice( |
|
|
|
if (couponDiscountDifference.compareTo(BigDecimal.ZERO) > 0) { |
|
|
|
// 可退款金额大于0 可退款金额+可退款积分=优惠券优惠
|
|
|
|
// 大于0
|
|
|
|
childOrder.getSurplusRefundPrice().compareTo(BigDecimal.ZERO) == 1 |
|
|
|
childOrder.setCouponDiscountPrice(childOrder.getCouponDiscountPrice().add(couponDiscountDifference)); |
|
|
|
? childOrder.getProductTotalPrice().subtract( |
|
|
|
} else if (couponDiscountDifference.compareTo(BigDecimal.ZERO) < 0) { |
|
|
|
childOrder.getSurplusRefundPrice().add(new BigDecimal(childOrder.getSurplusRefundIntegral().toString()).divide(new BigDecimal("100")))) |
|
|
|
// 小于0
|
|
|
|
: childOrder.getSurplusRefundPrice()); |
|
|
|
childOrder.setCouponDiscountPrice(childOrder.getCouponDiscountPrice().subtract(couponDiscountDifference)); |
|
|
|
|
|
|
|
} |
|
|
|
childOrder.setTotalDeductionPrice( |
|
|
|
|
|
|
|
childOrder.getCouponDiscountPrice() |
|
|
|
// 积分差值
|
|
|
|
.add(new BigDecimal(childOrder.getIntegralDiscountPrice().toString()).divide(new BigDecimal("100"))) |
|
|
|
Long integralDiscountDifference = order.getDeduction().getIntegralDiscountPrice() - totalIntegralDiscountPrice; |
|
|
|
); |
|
|
|
if (integralDiscountDifference > 0) { |
|
|
|
childOrder.setProductActualPrice(childOrder.getProductTotalPrice().subtract(childOrder.getTotalDeductionPrice())); |
|
|
|
// 大于0
|
|
|
|
|
|
|
|
childOrder.setIntegralDiscountPrice(childOrder.getIntegralDiscountPrice() + integralDiscountDifference); |
|
|
|
|
|
|
|
} else if (integralDiscountDifference < 0) { |
|
|
|
|
|
|
|
// 小于0
|
|
|
|
|
|
|
|
childOrder.setIntegralDiscountPrice(childOrder.getIntegralDiscountPrice() - integralDiscountDifference); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 商品订单总优惠
|
|
|
|
|
|
|
|
childOrder.setTotalDeductionPrice(childOrder.getCouponDiscountPrice().add(new BigDecimal(childOrder.getIntegralDiscountPrice()))); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 可退款金额 产品总价 - 优惠总价
|
|
|
|
|
|
|
|
childOrder.setSurplusRefundPrice(childOrder.getProductTotalPrice().subtract(childOrder.getTotalDeductionPrice())); |
|
|
|
|
|
|
|
// 可退款积分 积分优惠
|
|
|
|
|
|
|
|
childOrder.setSurplusRefundIntegral(childOrder.getIntegralDiscountPrice()); |
|
|
|
|
|
|
|
// 商品实际价格
|
|
|
|
|
|
|
|
childOrder.setProductActualPrice(childOrder.getSurplusRefundPrice()); |
|
|
|
orderChildService.editData(childOrder); |
|
|
|
orderChildService.editData(childOrder); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|