diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighDiscountAgentRelController.java b/hai-bweb/src/main/java/com/bweb/controller/HighDiscountAgentRelController.java index ae436423..066d1fde 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighDiscountAgentRelController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighDiscountAgentRelController.java @@ -97,7 +97,7 @@ public class HighDiscountAgentRelController { // 是否已分配 if (highDiscountAgentRelService.getRelByDiscountAgent(highDiscountAgentRel.getDiscountId(), highDiscountAgentRel.getAgentId()) != null) { log.error("HighDiscountAgentRelController -> insertDiscountAgent() error!", discount.getDiscountName() + "重复分配给" + agent.getAgentName()); - throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, discount.getDiscountName() + "重复分配给" + agent.getAgentName()); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, discount.getDiscountName() + "重复分配给" + agent.getAgentName()); } highDiscountAgentRel.setCreateTime(new Date()); highDiscountAgentRel.setStatus(1); @@ -110,7 +110,7 @@ public class HighDiscountAgentRelController { //参数 Map map = new HashMap<>(); map.put("type", QrCodeType.AGENT_QR_CODE); - map.put("code", AESEncodeUtil.aesEncrypt(Base64Util.encode(highDiscountAgentRel.getId().toString()))); + map.put("code", Base64Util.encode(AESEncodeUtil.aesEncrypt(highDiscountAgentRel.getId().toString()))); QRCodeGenerator.generateQRCodeImage(JSON.toJSONString(map), 350, 350, qrCodeUrl); highDiscountAgentRel.setQrCode(qrCodeImg); highDiscountAgentRelService.updateDiscountAgentRel(highDiscountAgentRel); diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java b/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java index ffea0fa8..813793b7 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java +++ b/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, ""); } + 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"); for (HighChildOrder childOrder : highOrder.getHighChildOrderList()) { if (childOrder.getGoodsType() == null || childOrder.getGoodsId() == null || childOrder.getSaleCount() == null) { @@ -98,25 +108,27 @@ public class HighOrderController { log.error("HighOrderController --> addOrder() error!", "未找到卡卷信息"); throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, ""); } - - // 校验优惠券是否可用 - if (highOrder.getMemDiscountId() != null) { + // 是否达到限购数量 + 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 (highDiscountUserRel != null) { List discountCouponRelList = highDiscountCouponRelService.getRelByCoupon(coupon.getId()); if (discountCouponRelList.size() > 0) { - List collect = discountCouponRelList.stream().filter(o -> o.getDiscountId().equals(highOrder.getMemDiscountId())).collect(Collectors.toList()); + HighDiscountUserRel finalHighDiscountUserRel = highDiscountUserRel; + List collect = discountCouponRelList.stream().filter(o -> o.getDiscountId().equals(finalHighDiscountUserRel.getDiscountId())).collect(Collectors.toList()); if (collect == null || collect.size() == 0) { log.error("HighOrderController --> addOrder() 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) { log.error("HighOrderController --> addOrder() error!", "卡卷库存数量不足"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COUPON_STOCK_INSUFFICIENT, ""); @@ -124,7 +136,6 @@ public class HighOrderController { childOrder.setGoodsName(coupon.getCouponName()); childOrder.setGoodsImg(coupon.getCouponImg()); childOrder.setGoodsSpecName("默认"); - childOrder.setGoodsPrice(coupon.getDiscountPrice()); } if (childOrder.getGoodsType() == 2) { @@ -152,25 +163,21 @@ public class HighOrderController { // 累计订单价格 totalPrice = totalPrice.add(childOrder.getTotalPrice()); } - + highOrder.setTotalPrice(totalPrice); + // 是否使用了优惠券 if (highOrder.getMemDiscountId() != null) { - // 卡优惠券信息 - HighDiscountUserRel rel = highDiscountUserRelService.getRelById(highOrder.getMemDiscountId()); - if (rel == null || rel.getStatus() != 1) { - log.error("HighOrderController --> addOrder() error!", "优惠券状态错误"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券状态错误"); - } - highOrder.setMemDiscountName(rel.getHighDiscount().getDiscountName()); + + highOrder.setMemDiscountName(highDiscountUserRel.getHighDiscount().getDiscountName()); // 卡卷类型 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!", "订单未达到满减额度"); - 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 if (total.compareTo(new BigDecimal("0")) == -1) { highOrder.setTotalPrice(new BigDecimal("0")); @@ -180,9 +187,9 @@ public class HighOrderController { } // 卡卷类型 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 if (total.compareTo(new BigDecimal("0")) == -1) { highOrder.setTotalPrice(new BigDecimal("0")); @@ -192,9 +199,9 @@ public class HighOrderController { } // 卡卷类型 1:满减 2:抵扣 3:折扣 - if (rel.getHighDiscount().getDiscountType() == 3) { + if (highDiscountUserRel.getHighDiscount().getDiscountType() == 3) { // 折扣除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); highOrder.setTotalPrice(total); @@ -205,13 +212,13 @@ public class HighOrderController { highOrder.setMemId(userInfoModel.getHighUser().getId()); highOrder.setMemName(userInfoModel.getHighUser().getName()); highOrder.setMemPhone(userInfoModel.getHighUser().getPhone()); - highOrder.setPayPrice(totalPrice); + highOrder.setPayPrice(highOrder.getTotalPrice()); highOrder.setCreateTime(new Date()); highOrder.setOrderStatus(1); highOrderService.insertOrder(highOrder); - return ResponseMsgUtil.success(highOrder); + return ResponseMsgUtil.success(getOrderById(highOrder.getId())); } catch (Exception e) { log.error("HighOrderController -> addOrder() error!",e); diff --git a/hai-schedule/src/main/java/com/hai/schedule/HighCouponSchedule.java b/hai-schedule/src/main/java/com/hai/schedule/HighCouponSchedule.java index ec8b0a5f..68c564db 100644 --- a/hai-schedule/src/main/java/com/hai/schedule/HighCouponSchedule.java +++ b/hai-schedule/src/main/java/com/hai/schedule/HighCouponSchedule.java @@ -30,7 +30,7 @@ public class HighCouponSchedule { * @Date 2021/4/4 22:44 **/ // @Scheduled(cron="0 0/1 * * * ?") //每1分钟执行一次 - //@Scheduled(cron = "0 0 0 * * ?") //每天 凌晨0点执行 + @Scheduled(cron = "0 0 0 * * ?") //每天 凌晨0点执行 public void expiredCoupon() { // 查询过期的卡券 List userCoupons = highUserCouponService.getOverdueCoupon(); diff --git a/hai-schedule/src/main/java/com/hai/schedule/HighDiscountSchedule.java b/hai-schedule/src/main/java/com/hai/schedule/HighDiscountSchedule.java index 8fd41af8..b370a79c 100644 --- a/hai-schedule/src/main/java/com/hai/schedule/HighDiscountSchedule.java +++ b/hai-schedule/src/main/java/com/hai/schedule/HighDiscountSchedule.java @@ -29,7 +29,7 @@ public class HighDiscountSchedule { * @Description 处理过期的优惠券 * @Date 2021/4/4 22:44 **/ - //@Scheduled(cron = "0 0 0 * * ?") //每1分钟执行一次 + @Scheduled(cron = "0 0 0 * * ?") //每1分钟执行一次 public void expiredDiscount() { List expiredDiscount = highDiscountUserRelService.getExpiredDiscount(); for (HighDiscountUserRel rel : expiredDiscount) { diff --git a/hai-schedule/src/main/java/com/hai/schedule/HighOrderSchedule.java b/hai-schedule/src/main/java/com/hai/schedule/HighOrderSchedule.java index 9573b7d0..789bef83 100644 --- a/hai-schedule/src/main/java/com/hai/schedule/HighOrderSchedule.java +++ b/hai-schedule/src/main/java/com/hai/schedule/HighOrderSchedule.java @@ -33,7 +33,7 @@ public class HighOrderSchedule { * @Description 取消订单 15分钟 * @Date 2021/4/4 22:45 **/ - //@Scheduled(cron="0 0/1 * * * ?") //每1分钟执行一次 + @Scheduled(cron="0 0/1 * * * ?") //每1分钟执行一次 public void cancelOrder() { List orderList = highOrderService.getCloseOrder(); if (orderList != null && orderList.size() > 0) { diff --git a/hai-schedule/src/main/java/com/hai/schedule/SynchronizeCNPC.java b/hai-schedule/src/main/java/com/hai/schedule/SynchronizeCNPC.java index 9bbdd083..21d355fe 100644 --- a/hai-schedule/src/main/java/com/hai/schedule/SynchronizeCNPC.java +++ b/hai-schedule/src/main/java/com/hai/schedule/SynchronizeCNPC.java @@ -29,7 +29,7 @@ public class SynchronizeCNPC { private static final String[] HEX_DIGITS = {"0" ,"1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"}; - @Scheduled(cron="0 0/1 * * * ?") //每1分钟执行一次 + //@Scheduled(cron="0 0/1 * * * ?") //每1分钟执行一次 public void certification() { Map tokenMap = new HashMap<>(); tokenMap.put("appId", "jsVpwDoHZfR2rrpjhA"); diff --git a/hai-service/src/main/java/com/hai/entity/HighOrder.java b/hai-service/src/main/java/com/hai/entity/HighOrder.java index 87eba376..89f50ac9 100644 --- a/hai-service/src/main/java/com/hai/entity/HighOrder.java +++ b/hai-service/src/main/java/com/hai/entity/HighOrder.java @@ -125,6 +125,16 @@ public class HighOrder implements Serializable { private List highChildOrderList; + private HighDiscount highDiscount; + + public HighDiscount getHighDiscount() { + return highDiscount; + } + + public void setHighDiscount(HighDiscount highDiscount) { + this.highDiscount = highDiscount; + } + public List getHighChildOrderList() { return highChildOrderList; } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighCouponCodeServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighCouponCodeServiceImpl.java index ebfa787e..b1f5490a 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighCouponCodeServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighCouponCodeServiceImpl.java @@ -11,6 +11,7 @@ import com.hai.dao.HighCouponCodeMapperExt; import com.hai.entity.*; import com.hai.model.UserInfoModel; import com.hai.service.HighCouponCodeService; +import com.hai.service.HighCouponService; import com.hai.service.HighOrderService; import com.hai.service.HighUserCouponService; import org.apache.commons.collections4.MapUtils; @@ -42,6 +43,9 @@ public class HighCouponCodeServiceImpl implements HighCouponCodeService { @Resource private HighOrderService highOrderService; + @Resource + private HighCouponService highCouponService; + @Resource private HighUserCouponService highUserCouponService; @@ -87,6 +91,15 @@ public class HighCouponCodeServiceImpl implements HighCouponCodeService { throw ErrorHelp.genException(SysCode.System, ErrorCode.COUPON_CODE_OVERDUE, ""); } + // 卡券信息 + HighCoupon coupon = highCouponService.getCouponById(salesCode.getCouponId()); + if (coupon == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_DISCOUNT, ""); + } + // 卡券来源:1.中石化 + if (coupon.getCouponSource() == 1) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "此卡券无法消核"); + } salesCode.setStoreId(userInfoModel.getMerchantStore().getId()); salesCode.setConsumeTime(new Date()); salesCode.setStatus(3); diff --git a/hai-service/src/main/java/com/hai/service/impl/HighCouponServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighCouponServiceImpl.java index 5c023bbd..1d2b4166 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighCouponServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighCouponServiceImpl.java @@ -353,6 +353,12 @@ public class HighCouponServiceImpl implements HighCouponService { criteria.andStatusEqualTo(MapUtils.getInteger(map, "status")); } + if (MapUtils.getInteger(map, "couponSource") != null) { + criteria.andCouponSourceEqualTo(MapUtils.getInteger(map, "status")); + } else { + criteria.andCouponSourceNotEqualTo(2); + } + example.setOrderByClause("create_time desc"); List coupons = highCouponMapper.selectByExample(example); if (coupons != null && coupons.size() > 0) { diff --git a/hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java index a7c4e060..04d06dce 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java @@ -52,6 +52,9 @@ public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelServic if (rel == null || rel.getHighDiscount() == null || rel.getAgentId() == null){ throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_DISCOUNT, ""); } + rel.setStockCount(rel.getStockCount() - 1); + highDiscountAgentRelService.updateDiscountAgentRel(rel); + // 校验卡卷状态 if (rel.getHighDiscount().getStatus() != 2) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "卡券已下架"); diff --git a/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java index 9b7a735f..fab67a21 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java @@ -264,6 +264,9 @@ public class HighOrderServiceImpl implements HighOrderService { return null; } order.setHighChildOrderList(getChildOrderByOrder(order.getId())); + if (order.getMemDiscountId() != null) { + order.setHighDiscount(highDiscountUserRelService.getRelById(order.getMemDiscountId()).getHighDiscount()); + } return order; } @@ -367,7 +370,7 @@ public class HighOrderServiceImpl implements HighOrderService { HighDiscountUserRel rel = highDiscountUserRelService.getRelById(order.getMemDiscountId()); if (rel != null) { rel.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用 - rel.setUseTime(new Date()); + rel.setUseTime(null); highDiscountUserRelService.updateDiscountUserRel(rel); } } @@ -383,8 +386,6 @@ public class HighOrderServiceImpl implements HighOrderService { criteria.andMemIdEqualTo(memId); criteria.andOrderStatusEqualTo(status); - - return highOrderMapper.selectByExample(example).size(); } @@ -394,6 +395,15 @@ public class HighOrderServiceImpl implements HighOrderService { HighDiscountUserRelExample example = new HighDiscountUserRelExample(); HighDiscountUserRelExample.Criteria criteria = example.createCriteria(); + if (userId != null) { + criteria.andUserIdEqualTo(userId); + } + + if (status != null) { + criteria.andStatusEqualTo(status); + } + + example.setOrderByClause("create_time desc"); return highDiscountUserRelMapper.selectByExample(example).size(); } }