dev-discount
199901012 4 years ago
commit cd14e48ad8
  1. 42
      hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java

@ -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) {
@ -104,10 +114,11 @@ public class HighOrderController {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, coupon.getCouponName() + ",已达到限购数量"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, coupon.getCouponName() + ",已达到限购数量");
} }
// 校验优惠券是否可用 如果使用优惠券就只能使用卡券的原价 // 校验优惠券是否可用 如果使用优惠券就只能使用卡券的原价
if (highOrder.getMemDiscountId() != null) { 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, "无法使用优惠券");
@ -156,22 +167,17 @@ public class HighOrderController {
// 是否使用了优惠券 // 是否使用了优惠券
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"));
@ -181,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"));
@ -193,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);
@ -206,7 +212,7 @@ 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);

Loading…
Cancel
Save