|
|
@ -79,6 +79,16 @@ public class HighOrderController { |
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HighDiscountUserRel highDiscountUserRel = null; |
|
|
|
|
|
|
|
if (highOrder.getMemDiscountId() != null) { |
|
|
|
|
|
|
|
// 卡优惠券信息
|
|
|
|
|
|
|
|
highDiscountUserRel = highDiscountUserRelService.getRelById(highOrder.getMemDiscountId()); |
|
|
|
|
|
|
|
if (highDiscountUserRel == null || highDiscountUserRel.getStatus() != 1) { |
|
|
|
|
|
|
|
log.error("HighOrderController --> addOrder() error!", "优惠券状态错误"); |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券状态错误"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
BigDecimal totalPrice = new BigDecimal("0"); |
|
|
|
BigDecimal totalPrice = new BigDecimal("0"); |
|
|
|
for (HighChildOrder childOrder : highOrder.getHighChildOrderList()) { |
|
|
|
for (HighChildOrder childOrder : highOrder.getHighChildOrderList()) { |
|
|
|
if (childOrder.getGoodsType() == null || childOrder.getGoodsId() == null || childOrder.getSaleCount() == null) { |
|
|
|
if (childOrder.getGoodsType() == null || childOrder.getGoodsId() == null || childOrder.getSaleCount() == null) { |
|
|
@ -98,25 +108,27 @@ public class HighOrderController { |
|
|
|
log.error("HighOrderController --> addOrder() error!", "未找到卡卷信息"); |
|
|
|
log.error("HighOrderController --> addOrder() error!", "未找到卡卷信息"); |
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, ""); |
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, ""); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 是否达到限购数量
|
|
|
|
// 校验优惠券是否可用
|
|
|
|
if (highCouponService.userBuyLimitNumber(userInfoModel.getHighUser().getId(), coupon.getId()) == true) { |
|
|
|
if (highOrder.getMemDiscountId() != null) { |
|
|
|
log.error("HighOrderController --> addOrder() error!", "已达到限购数量"); |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, coupon.getCouponName() + ",已达到限购数量"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 校验优惠券是否可用 如果使用优惠券就只能使用卡券的原价
|
|
|
|
|
|
|
|
if (highDiscountUserRel != null) { |
|
|
|
List<HighDiscountCouponRel> discountCouponRelList = highDiscountCouponRelService.getRelByCoupon(coupon.getId()); |
|
|
|
List<HighDiscountCouponRel> discountCouponRelList = highDiscountCouponRelService.getRelByCoupon(coupon.getId()); |
|
|
|
if (discountCouponRelList.size() > 0) { |
|
|
|
if (discountCouponRelList.size() > 0) { |
|
|
|
List<HighDiscountCouponRel> collect = discountCouponRelList.stream().filter(o -> o.getDiscountId().equals(highOrder.getMemDiscountId())).collect(Collectors.toList()); |
|
|
|
HighDiscountUserRel finalHighDiscountUserRel = highDiscountUserRel; |
|
|
|
|
|
|
|
List<HighDiscountCouponRel> collect = discountCouponRelList.stream().filter(o -> o.getDiscountId().equals(finalHighDiscountUserRel.getDiscountId())).collect(Collectors.toList()); |
|
|
|
if (collect == null || collect.size() == 0) { |
|
|
|
if (collect == null || collect.size() == 0) { |
|
|
|
log.error("HighOrderController --> addOrder() error!", "无法使用优惠券"); |
|
|
|
log.error("HighOrderController --> addOrder() error!", "无法使用优惠券"); |
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法使用优惠券"); |
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法使用优惠券"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
childOrder.setGoodsPrice(coupon.getSalesPrice()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
childOrder.setGoodsPrice(coupon.getDiscountPrice()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 是否到底限购数量
|
|
|
|
|
|
|
|
if (highCouponService.userBuyLimitNumber(userInfoModel.getHighUser().getId(), coupon.getId()) == true) { |
|
|
|
|
|
|
|
log.error("HighOrderController --> addOrder() error!", "已达到限购数量"); |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, coupon.getCouponName() + ",已达到限购数量"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (highCouponCodeService.getStockCountByCoupon(coupon.getId()) <= 0) { |
|
|
|
if (highCouponCodeService.getStockCountByCoupon(coupon.getId()) <= 0) { |
|
|
|
log.error("HighOrderController --> addOrder() error!", "卡卷库存数量不足"); |
|
|
|
log.error("HighOrderController --> addOrder() error!", "卡卷库存数量不足"); |
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COUPON_STOCK_INSUFFICIENT, ""); |
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COUPON_STOCK_INSUFFICIENT, ""); |
|
|
@ -124,7 +136,6 @@ public class HighOrderController { |
|
|
|
childOrder.setGoodsName(coupon.getCouponName()); |
|
|
|
childOrder.setGoodsName(coupon.getCouponName()); |
|
|
|
childOrder.setGoodsImg(coupon.getCouponImg()); |
|
|
|
childOrder.setGoodsImg(coupon.getCouponImg()); |
|
|
|
childOrder.setGoodsSpecName("默认"); |
|
|
|
childOrder.setGoodsSpecName("默认"); |
|
|
|
childOrder.setGoodsPrice(coupon.getDiscountPrice()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (childOrder.getGoodsType() == 2) { |
|
|
|
if (childOrder.getGoodsType() == 2) { |
|
|
@ -152,25 +163,21 @@ public class HighOrderController { |
|
|
|
// 累计订单价格
|
|
|
|
// 累计订单价格
|
|
|
|
totalPrice = totalPrice.add(childOrder.getTotalPrice()); |
|
|
|
totalPrice = totalPrice.add(childOrder.getTotalPrice()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
highOrder.setTotalPrice(totalPrice); |
|
|
|
|
|
|
|
|
|
|
|
// 是否使用了优惠券
|
|
|
|
// 是否使用了优惠券
|
|
|
|
if (highOrder.getMemDiscountId() != null) { |
|
|
|
if (highOrder.getMemDiscountId() != null) { |
|
|
|
// 卡优惠券信息
|
|
|
|
|
|
|
|
HighDiscountUserRel rel = highDiscountUserRelService.getRelById(highOrder.getMemDiscountId()); |
|
|
|
highOrder.setMemDiscountName(highDiscountUserRel.getHighDiscount().getDiscountName()); |
|
|
|
if (rel == null || rel.getStatus() != 1) { |
|
|
|
|
|
|
|
log.error("HighOrderController --> addOrder() error!", "优惠券状态错误"); |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券状态错误"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
highOrder.setMemDiscountName(rel.getHighDiscount().getDiscountName()); |
|
|
|
|
|
|
|
// 卡卷类型 1:满减 2:抵扣 3:折扣
|
|
|
|
// 卡卷类型 1:满减 2:抵扣 3:折扣
|
|
|
|
if (rel.getHighDiscount().getDiscountType() == 1) { |
|
|
|
if (highDiscountUserRel.getHighDiscount().getDiscountType() == 1) { |
|
|
|
// 如果订单总额 小于 满减价格
|
|
|
|
// 如果订单总额 小于 满减价格
|
|
|
|
if (highOrder.getTotalPrice().compareTo(rel.getHighDiscount().getDiscountCondition()) > 1) { |
|
|
|
if (highOrder.getTotalPrice().compareTo(highDiscountUserRel.getHighDiscount().getDiscountCondition()) > 1) { |
|
|
|
log.error("HighOrderController --> addOrder() error!", "订单未达到满减额度"); |
|
|
|
log.error("HighOrderController --> addOrder() error!", "订单未达到满减额度"); |
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.UN_MEMBER_ERROR, "订单未达到"+rel.getHighDiscount().getDiscountCondition()+"元,无法使用此优惠券"); |
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.UN_MEMBER_ERROR, "订单未达到"+highDiscountUserRel.getHighDiscount().getDiscountCondition()+"元,无法使用此优惠券"); |
|
|
|
} |
|
|
|
} |
|
|
|
// 订单总额 - 满减额度
|
|
|
|
// 订单总额 - 满减额度
|
|
|
|
BigDecimal total = highOrder.getTotalPrice().subtract(rel.getHighDiscount().getDiscountPrice()); |
|
|
|
BigDecimal total = highOrder.getTotalPrice().subtract(highDiscountUserRel.getHighDiscount().getDiscountPrice()); |
|
|
|
// 如果总额小于0
|
|
|
|
// 如果总额小于0
|
|
|
|
if (total.compareTo(new BigDecimal("0")) == -1) { |
|
|
|
if (total.compareTo(new BigDecimal("0")) == -1) { |
|
|
|
highOrder.setTotalPrice(new BigDecimal("0")); |
|
|
|
highOrder.setTotalPrice(new BigDecimal("0")); |
|
|
@ -180,9 +187,9 @@ public class HighOrderController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 卡卷类型 1:满减 2:抵扣 3:折扣
|
|
|
|
// 卡卷类型 1:满减 2:抵扣 3:折扣
|
|
|
|
if (rel.getHighDiscount().getDiscountType() == 2) { |
|
|
|
if (highDiscountUserRel.getHighDiscount().getDiscountType() == 2) { |
|
|
|
// 订单总额 - 满减额度
|
|
|
|
// 订单总额 - 满减额度
|
|
|
|
BigDecimal total = highOrder.getTotalPrice().subtract(rel.getHighDiscount().getDiscountPrice()); |
|
|
|
BigDecimal total = highOrder.getTotalPrice().subtract(highDiscountUserRel.getHighDiscount().getDiscountPrice()); |
|
|
|
// 如果总额小于0
|
|
|
|
// 如果总额小于0
|
|
|
|
if (total.compareTo(new BigDecimal("0")) == -1) { |
|
|
|
if (total.compareTo(new BigDecimal("0")) == -1) { |
|
|
|
highOrder.setTotalPrice(new BigDecimal("0")); |
|
|
|
highOrder.setTotalPrice(new BigDecimal("0")); |
|
|
@ -192,9 +199,9 @@ public class HighOrderController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 卡卷类型 1:满减 2:抵扣 3:折扣
|
|
|
|
// 卡卷类型 1:满减 2:抵扣 3:折扣
|
|
|
|
if (rel.getHighDiscount().getDiscountType() == 3) { |
|
|
|
if (highDiscountUserRel.getHighDiscount().getDiscountType() == 3) { |
|
|
|
// 折扣除100
|
|
|
|
// 折扣除100
|
|
|
|
BigDecimal discountPrice = rel.getHighDiscount().getDiscountPrice().divide(new BigDecimal("100")); |
|
|
|
BigDecimal discountPrice = highDiscountUserRel.getHighDiscount().getDiscountPrice().divide(new BigDecimal("10")); |
|
|
|
// 订单总额 * 折扣
|
|
|
|
// 订单总额 * 折扣
|
|
|
|
BigDecimal total = highOrder.getTotalPrice().multiply(discountPrice); |
|
|
|
BigDecimal total = highOrder.getTotalPrice().multiply(discountPrice); |
|
|
|
highOrder.setTotalPrice(total); |
|
|
|
highOrder.setTotalPrice(total); |
|
|
@ -205,13 +212,13 @@ public class HighOrderController { |
|
|
|
highOrder.setMemId(userInfoModel.getHighUser().getId()); |
|
|
|
highOrder.setMemId(userInfoModel.getHighUser().getId()); |
|
|
|
highOrder.setMemName(userInfoModel.getHighUser().getName()); |
|
|
|
highOrder.setMemName(userInfoModel.getHighUser().getName()); |
|
|
|
highOrder.setMemPhone(userInfoModel.getHighUser().getPhone()); |
|
|
|
highOrder.setMemPhone(userInfoModel.getHighUser().getPhone()); |
|
|
|
highOrder.setPayPrice(totalPrice); |
|
|
|
highOrder.setPayPrice(highOrder.getTotalPrice()); |
|
|
|
highOrder.setCreateTime(new Date()); |
|
|
|
highOrder.setCreateTime(new Date()); |
|
|
|
highOrder.setOrderStatus(1); |
|
|
|
highOrder.setOrderStatus(1); |
|
|
|
|
|
|
|
|
|
|
|
highOrderService.insertOrder(highOrder); |
|
|
|
highOrderService.insertOrder(highOrder); |
|
|
|
|
|
|
|
|
|
|
|
return ResponseMsgUtil.success(highOrder); |
|
|
|
return ResponseMsgUtil.success(getOrderById(highOrder.getId())); |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("HighOrderController -> addOrder() error!",e); |
|
|
|
log.error("HighOrderController -> addOrder() error!",e); |
|
|
|