dev-discount
胡锐 2 years ago
parent 87f22e4585
commit 3ac8d40ed9
  1. 72
      hai-service/src/main/java/com/hai/order/service/impl/OrderServiceImpl.java

@ -188,6 +188,78 @@ public class OrderServiceImpl implements OrderService {
} }
order.setHighChildOrderList(childOrderList); 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<String, Object> calculateOrderPrice = OrderUtil.calculateOrderPrice(order.getHighChildOrderList()); Map<String, Object> calculateOrderPrice = OrderUtil.calculateOrderPrice(order.getHighChildOrderList());
order.setTotalPrice(new BigDecimal(calculateOrderPrice.get("totalPrice").toString())); order.setTotalPrice(new BigDecimal(calculateOrderPrice.get("totalPrice").toString()));

Loading…
Cancel
Save