From 3ac8d40ed96047325ccf7b900d3952c91c893b29 Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Wed, 31 Aug 2022 16:08:42 +0800 Subject: [PATCH] 1 --- .../order/service/impl/OrderServiceImpl.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/hai-service/src/main/java/com/hai/order/service/impl/OrderServiceImpl.java b/hai-service/src/main/java/com/hai/order/service/impl/OrderServiceImpl.java index c90ef730..f94a9474 100644 --- a/hai-service/src/main/java/com/hai/order/service/impl/OrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/order/service/impl/OrderServiceImpl.java @@ -188,6 +188,78 @@ public class OrderServiceImpl implements OrderService { } order.setHighChildOrderList(childOrderList); + // 是否使用了优惠券 + /* if (discountUserRel != null) { + order.setMemDiscountName(discountUserRel.getHighDiscount().getDiscountName()); + + // 优惠券使用范围 + if (highDiscountUserRel.getHighDiscount().getUseScope().equals(DiscountUseScope.type1.getType())) { + // 暂无限制 + } else if (highDiscountUserRel.getHighDiscount().getUseScope().equals(DiscountUseScope.type2.getType())) { + // 1:卡卷 2:金币充值 3:团油【加油站】 4: KFC 5:电影票 6:话费充值 + if (!highOrder.getHighChildOrderList().get(0).getGoodsType().equals(1)) { + log.error("HighOrderController --> addOrder() error!", "此优惠券只能购买卡券商品使用"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "此优惠券只能购买卡券商品使用"); + } + } else if (highDiscountUserRel.getHighDiscount().getUseScope().equals(DiscountUseScope.type3.getType())) { + if (!highOrder.getHighChildOrderList().get(0).getGoodsType().equals(6)) { + log.error("HighOrderController --> addOrder() error!", "此优惠券只能充值话费中使用"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "此优惠券只能充值话费中使用"); + } + } else if (highDiscountUserRel.getHighDiscount().getUseScope().equals(DiscountUseScope.type7.getType())) { + if (!highOrder.getHighChildOrderList().get(0).getGoodsType().equals(3)) { + log.error("HighOrderController --> addOrder() error!", "此优惠券只能充值话费中使用"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "此优惠券只能充值话费中使用"); + } + } else { + log.error("HighOrderController --> addOrder() error!", "暂时无法使用此优惠券"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "暂时无法使用此优惠券"); + } + + // 卡卷类型 1:满减 2:抵扣 3:折扣 + if (highDiscountUserRel.getHighDiscount().getDiscountType() == 1) { + // 如果订单总额 小于 满减价格 + if (highOrder.getTotalPrice().compareTo(highDiscountUserRel.getHighDiscount().getDiscountCondition()) > 1) { + log.error("HighOrderController --> addOrder() error!", "订单未达到满减额度"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.UN_MEMBER_ERROR, "订单未达到"+highDiscountUserRel.getHighDiscount().getDiscountCondition()+"元,无法使用此优惠券"); + } + // 订单总额 - 满减额度 + BigDecimal payablePrice = highOrder.getTotalPrice().subtract(highDiscountUserRel.getHighDiscount().getDiscountPrice()); + + highOrder.setDeductionPrice(highDiscountUserRel.getHighDiscount().getDiscountPrice()); + // 如果总额小于0 + if (payablePrice.compareTo(new BigDecimal("0")) < 0) { + highOrder.setPayablePrice(new BigDecimal("0")); + } else { + highOrder.setPayablePrice(payablePrice); + } + } + + // 卡卷类型 1:满减 2:抵扣 3:折扣 + if (highDiscountUserRel.getHighDiscount().getDiscountType() == 2) { + // 订单总额 - 满减额度 + BigDecimal payablePrice = highOrder.getTotalPrice().subtract(highDiscountUserRel.getHighDiscount().getDiscountPrice()); + highOrder.setDeductionPrice(highDiscountUserRel.getHighDiscount().getDiscountPrice()); + + // 如果总额小于0 + if (payablePrice.compareTo(new BigDecimal("0")) == -1) { + highOrder.setPayablePrice(new BigDecimal("0")); + } else { + highOrder.setPayablePrice(payablePrice); + } + } + + // 卡卷类型 1:满减 2:抵扣 3:折扣 + if (highDiscountUserRel.getHighDiscount().getDiscountType() == 3) { + // 折扣除100 + BigDecimal discountPrice = highDiscountUserRel.getHighDiscount().getDiscountPrice(); + // 订单总额 * 折扣 + BigDecimal payablePrice = highOrder.getTotalPrice().multiply(discountPrice).setScale(2, BigDecimal.ROUND_HALF_DOWN); + highOrder.setDeductionPrice(highOrder.getTotalPrice().subtract(payablePrice)); + highOrder.setPayablePrice(payablePrice); + } + }*/ + // 计算订单金额 Map calculateOrderPrice = OrderUtil.calculateOrderPrice(order.getHighChildOrderList()); order.setTotalPrice(new BigDecimal(calculateOrderPrice.get("totalPrice").toString()));