diff --git a/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java b/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java index 1e73d7c7..8cdc7cba 100644 --- a/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java +++ b/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java @@ -257,9 +257,6 @@ public class BuyOrderController { } CouponEntity coupon = couponService.getById(couponHistory.getCouponId()); if (coupon != null){ - if (new BigDecimal(coupon.getUseLevel()).compareTo(totalPrice)>0){ - return R.error("未达到优惠券使用门槛"); - } couponHistory.setOrderId(buyOrder.getOrderId()); couponService.useCouponAmount(couponHistory); totalPrice = totalPrice.subtract(coupon.getCouponAmount()); diff --git a/src/main/java/com/peanut/modules/common/service/impl/CouponServiceImpl.java b/src/main/java/com/peanut/modules/common/service/impl/CouponServiceImpl.java index 636b21b1..43e38ca6 100644 --- a/src/main/java/com/peanut/modules/common/service/impl/CouponServiceImpl.java +++ b/src/main/java/com/peanut/modules/common/service/impl/CouponServiceImpl.java @@ -32,7 +32,7 @@ public class CouponServiceImpl extends ServiceImpl impl @Autowired private CourseMedicineDao courseMedicineDao; @Autowired - private RabbitTemplate rabbitTemplate; + private CourseToMedicineDao courseToMedicineDao; @Autowired private ShopProductCourseDao shopProductCourseDao; @Autowired @@ -56,11 +56,17 @@ public class CouponServiceImpl extends ServiceImpl impl if (couponEntity.getCouponRange()==1){ list.add(courseDao.selectOne(new LambdaQueryWrapper() .eq(CourseEntity::getId,Integer.parseInt(str)) - .select(CourseEntity::getId,CourseEntity::getTitle))); + .select(CourseEntity::getId,CourseEntity::getTitle,CourseEntity::getImage))); }else if(couponEntity.getCouponRange()==2){ list.add(courseMedicineDao.selectOne(new LambdaQueryWrapper() .eq(CourseMedicine::getId,Integer.parseInt(str)) .select(CourseMedicine::getId,CourseMedicine::getTitle))); + }else if(couponEntity.getCouponRange()==3){ + MPJLambdaWrapper wrapper = new MPJLambdaWrapper(); + wrapper.leftJoin(CourseEntity.class,CourseEntity::getId,CourseToMedicine::getCourseId); + wrapper.selectAll(CourseEntity.class); + wrapper.select(CourseEntity::getId,CourseEntity::getTitle,CourseEntity::getImage); + list.addAll(courseToMedicineDao.selectJoinList(CourseEntity.class,wrapper)); } } } @@ -107,12 +113,6 @@ public class CouponServiceImpl extends ServiceImpl impl return R.error("优惠券暂未开始发放"); } } - private MessagePostProcessor messagePostProcessor(long date) { - return message -> { - message.getMessageProperties().setDelay((int)date); - return message; - }; - } @Override public List getCouponListPayment(Map params) { @@ -128,8 +128,8 @@ public class CouponServiceImpl extends ServiceImpl impl couponHistory.setCanUse(1); couponHistory.setCanUseReason(""); if (couponHistory.getEffectType()!=0){ - if (couponHistory.getStartTime().getTime() < new Date().getTime() && - couponHistory.getEndTime().getTime() > new Date().getTime()) { + if (couponHistory.getStartTime().getTime() <= new Date().getTime() && + couponHistory.getEndTime().getTime() >= new Date().getTime()) { }else { couponHistory.setCanUse(0); couponHistory.setCanUseReason("优惠券使用时间未到"); @@ -140,13 +140,25 @@ public class CouponServiceImpl extends ServiceImpl impl //无限制 res.add(couponHistory); }else { - String shopProductIds = params.get("shopProductIds").toString(); - String[] ids = shopProductIds.split(","); - for (String shopProductId : ids) { + //课程券和课程分类券 + //"shopProductInfos":"1:69:1,2:79:1"//商品id:价格:数量 + String shopProductInfos = params.get("shopProductInfos").toString(); + String[] infos = shopProductInfos.split(","); + for (String shopProductInfo : infos) { + String[] info = shopProductInfo.split(":"); //通过优惠卷获取商品 Set set = getShopProductByCoupon(couponEntity); //比对用户优惠卷是否有此商品 - if(!set.add(Integer.parseInt(shopProductId))){ + if(!set.add(Integer.parseInt(info[0]))){ + BigDecimal totalAmount = new BigDecimal(info[1]).multiply(new BigDecimal(info[2])); + if (new BigDecimal(couponEntity.getUseLevel()).compareTo(totalAmount)>0){ + couponHistory.setCanUse(0); + couponHistory.setCanUseReason("优惠券未到使用门槛"); + } + if (couponEntity.getCouponAmount().compareTo(totalAmount)>0){ + couponHistory.setCanUse(0); + couponHistory.setCanUseReason("优惠券面额大于商品价值"); + } res.add(couponHistory); } } @@ -183,6 +195,12 @@ public class CouponServiceImpl extends ServiceImpl impl set.add(shopProductCourseEntity.getProductId()); } } + }else if (couponEntity.getCouponRange()==3) { + //3全部课程商品 + List shopProductCourseList = shopProductCourseDao.selectList(new LambdaQueryWrapper<>()); + for (ShopProductCourseEntity shopProductCourseEntity : shopProductCourseList) { + set.add(shopProductCourseEntity.getProductId()); + } } return set; }