From f31342fb0ac693b1d8ad2134c2f84f1b2603f391 Mon Sep 17 00:00:00 2001 From: wuchunlei Date: Fri, 1 Nov 2024 11:32:05 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=85=A8=E9=83=A8=E8=AF=BE=E7=A8=8B=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../book/controller/BuyOrderController.java | 3 -- .../service/impl/CouponServiceImpl.java | 46 +++++++++++++------ 2 files changed, 32 insertions(+), 17 deletions(-) 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; } From b5467bb0117a5216191374d553cd7037badcddc6 Mon Sep 17 00:00:00 2001 From: wuchunlei Date: Fri, 1 Nov 2024 15:59:08 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=88=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../book/controller/BuyOrderController.java | 39 ++++++------ .../mq/Consumer/OrderCancelConsumer.java | 1 - .../service/impl/AliPayServiceImpl.java | 61 ++++++++++--------- .../service/impl/WxpayServiceImpl.java | 32 +++++----- 4 files changed, 70 insertions(+), 63 deletions(-) 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 8cdc7cba..12a86d47 100644 --- a/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java +++ b/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java @@ -201,9 +201,6 @@ public class BuyOrderController { @RequestMapping(value = "/placeOrder", method = RequestMethod.POST) @Transactional public R placeOrder(@RequestBody BuyOrder buyOrder) { - String orderSn = IdWorker.getTimeId().substring(0, 32); - buyOrder.setOrderSn(orderSn); - buyOrderService.save(buyOrder); List buyOrderProductList = buyOrder.getProductList(); // 订单实收金额 BigDecimal totalPrice = new BigDecimal(0); @@ -245,21 +242,27 @@ public class BuyOrderController { totalPrice = totalPrice.add(price.multiply(BigDecimal.valueOf(quantity))); } //商品价格减去优惠券的优惠金额 - if (buyOrder!=null&&buyOrder.getCouponId()!=null&&buyOrder.getCouponId()!=0){ + if (buyOrder.getCouponId()!=null&&buyOrder.getCouponId()!=0){ CouponHistory couponHistory = couponHistoryService.getById(buyOrder.getCouponId()); if (couponHistory!=null){ - if (couponHistory.getEffectType()!=0){ - if (couponHistory.getStartTime().getTime()new Date().getTime()){ - }else { - return R.error("优惠券使用时间未到"); + if (couponHistory.getStatus()==0){ + if (couponHistory.getEffectType()!=0){ + if (couponHistory.getStartTime().getTime()new Date().getTime()){ + }else { + return R.error("优惠券使用时间未到"); + } + } + CouponEntity coupon = couponService.getById(couponHistory.getCouponId()); + if (coupon != null){ + totalPrice = totalPrice.subtract(coupon.getCouponAmount()); + } + }else { + if (couponHistory.getStatus()==1){ + return R.error("优惠券已被使用"); + }else if (couponHistory.getStatus() == 2){ + return R.error("优惠券已过期"); } - } - CouponEntity coupon = couponService.getById(couponHistory.getCouponId()); - if (coupon != null){ - couponHistory.setOrderId(buyOrder.getOrderId()); - couponService.useCouponAmount(couponHistory); - totalPrice = totalPrice.subtract(coupon.getCouponAmount()); } } } @@ -276,6 +279,8 @@ public class BuyOrderController { return R.error("系统错误订单金额异常!"); } + String orderSn = IdWorker.getTimeId().substring(0, 32); + buyOrder.setOrderSn(orderSn); if(buyOrder.getAddressId()!=0){ QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("id", buyOrder.getAddressId()); @@ -292,7 +297,7 @@ public class BuyOrderController { } } buyOrder.setOrderStatus("0"); - buyOrderService.updateById(buyOrder); + buyOrderService.save(buyOrder); //解决购物车相关问题 for (BuyOrderProduct buyOrderProduct : buyOrderProductList) { @@ -492,7 +497,6 @@ public class BuyOrderController { } //回滚优惠卷 if (buyOrder.getCouponId()!=null&&buyOrder.getCouponId()!=0){ - couponService.rollbackCoupon(buyOrder.getCouponId()); buyOrder.setCouponId(null); buyOrderService.updateById(buyOrder); } @@ -542,7 +546,6 @@ public class BuyOrderController { if (buyOrder != null) { //回滚优惠卷 if (buyOrder.getCouponId()!=null&&buyOrder.getCouponId()!=0){ - couponService.rollbackCoupon(buyOrder.getCouponId()); buyOrder.setCouponId(null); buyOrderService.updateById(buyOrder); } diff --git a/src/main/java/com/peanut/modules/mq/Consumer/OrderCancelConsumer.java b/src/main/java/com/peanut/modules/mq/Consumer/OrderCancelConsumer.java index e2b6c818..8f5033ed 100644 --- a/src/main/java/com/peanut/modules/mq/Consumer/OrderCancelConsumer.java +++ b/src/main/java/com/peanut/modules/mq/Consumer/OrderCancelConsumer.java @@ -42,7 +42,6 @@ public class OrderCancelConsumer { buyOrder.setOrderStatus(Constants.ORDER_STATUS_OUT_OF_TIME); //回滚优惠卷 if (buyOrder.getCouponId()!=null&&buyOrder.getCouponId()!=0){ - couponService.rollbackCoupon(buyOrder.getCouponId()); buyOrder.setCouponId(null); } //回滚库存 diff --git a/src/main/java/com/peanut/modules/pay/alipay/service/impl/AliPayServiceImpl.java b/src/main/java/com/peanut/modules/pay/alipay/service/impl/AliPayServiceImpl.java index c6ba23eb..88b84fb7 100644 --- a/src/main/java/com/peanut/modules/pay/alipay/service/impl/AliPayServiceImpl.java +++ b/src/main/java/com/peanut/modules/pay/alipay/service/impl/AliPayServiceImpl.java @@ -12,6 +12,7 @@ import com.peanut.common.utils.OrderUtils; import com.peanut.modules.common.dao.*; import com.peanut.modules.book.service.*; import com.peanut.modules.common.entity.*; +import com.peanut.modules.common.service.CouponHistoryService; import com.peanut.modules.common.service.CouponService; import com.peanut.modules.master.service.UserCourseBuyService; import com.peanut.modules.pay.alipay.config.AliPayConfig; @@ -75,6 +76,8 @@ public class AliPayServiceImpl implements AliPayService { private UserVipDao userVipDao; @Autowired private CouponService couponService; + @Autowired + private CouponHistoryService couponHistoryService; @Override public String pay(AlipayDTO payDto) { @@ -158,25 +161,31 @@ public class AliPayServiceImpl implements AliPayService { String body = oldPayZfbOrderEntity.getBody(); String customerid = oldPayZfbOrderEntity.getCustomerid(); + BuyOrder order = buyOrderService.getBaseMapper().selectOne(new QueryWrapper() + .eq("order_sn", oldPayZfbOrderEntity.getRelevanceoid())); + //使用优惠券 + if (order.getCouponId()!=null&&order.getCouponId()!=0){ + CouponHistory couponHistory = couponHistoryService.getById(order.getCouponId()); + couponHistory.setOrderId(order.getOrderId()); + couponService.useCouponAmount(couponHistory); + } + if("relearn".equals(subject)){ - BuyOrder orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper() - .eq("order_sn", oldPayZfbOrderEntity.getRelevanceoid())); //更新 订单 记录 buyOrderService.updateOrderStatus(Integer.valueOf(customerid),oldPayZfbOrderEntity.getRelevanceoid(),"2"); //插入复读记录 - userCourseBuyService.addUserCourseBuyRelearn(orderEntity,"支付宝购买:"+orderEntity.getOrderSn()); + userCourseBuyService.addUserCourseBuyRelearn(order,"支付宝购买:"+order.getOrderSn()); } if ("vip".equals(subject)) { - BuyOrder orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper().eq("order_sn", oldPayZfbOrderEntity.getRelevanceoid())); //更新 订单 记录 buyOrderService.updateOrderStatus(Integer.valueOf(customerid),oldPayZfbOrderEntity.getRelevanceoid(),"2"); //处理抵扣积分 - if(orderEntity.getJfDeduction().compareTo(BigDecimal.ZERO)>0){ - userCoinJf(orderEntity); + if(order.getJfDeduction().compareTo(BigDecimal.ZERO)>0){ + userCoinJf(order); } //开通vip - openVipForUser(orderEntity); + openVipForUser(order); //获取会员开通 日期 // BookBuyConfigEntity bookBuyConfigEntity = bookBuyConfigService.getById(Integer.valueOf(body)); // String month = bookBuyConfigEntity.getMonth(); @@ -219,42 +228,36 @@ public class AliPayServiceImpl implements AliPayService { buyOrderService.updateOrderStatus(Integer.valueOf(customerid),oldPayZfbOrderEntity.getRelevanceoid(),"2"); } if ("order".equals(subject)) { - - BuyOrder orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper().eq("order_sn", oldPayZfbOrderEntity.getRelevanceoid())); //更新 订单 记录 - String ActString = buyOrderService.checkWlOrder(orderEntity.getOrderSn())?"0":"2"; + String ActString = buyOrderService.checkWlOrder(order.getOrderSn())?"0":"2"; buyOrderService.updateOrderStatus(Integer.valueOf(customerid),oldPayZfbOrderEntity.getRelevanceoid(),ActString); - //处理抵扣积分 - if(orderEntity.getJfDeduction().compareTo(BigDecimal.ZERO)>0){ - userCoinJf(orderEntity); + if(order.getJfDeduction().compareTo(BigDecimal.ZERO)>0){ + userCoinJf(order); } - /* 记录用户购买的书籍 */ // 查询订单的所有 book_id - List orderBookIdList = shopProductBookDao.getOrderBookId(orderEntity.getOrderSn()); + List orderBookIdList = shopProductBookDao.getOrderBookId(order.getOrderSn()); // 去重 Set set = new HashSet<>(orderBookIdList); orderBookIdList.clear(); orderBookIdList.addAll(set); // 查询用户的所有 book_id - List userBookIdList = userEbookBuyDao.getUserBookId(orderEntity.getUserId()); + List userBookIdList = userEbookBuyDao.getUserBookId(order.getUserId()); // 取差集 orderBookIdList.removeAll(userBookIdList); // 为用户添加书籍 for (Integer bookId : orderBookIdList) { UserEbookBuyEntity entity = new UserEbookBuyEntity(); - entity.setUserId(orderEntity.getUserId()); + entity.setUserId(order.getUserId()); entity.setBookId(bookId); userEbookBuyDao.insert(entity); } - - //开通course,start - List orderCourse = buyOrderService.getOrderCourse(orderEntity.getOrderSn()); + List orderCourse = buyOrderService.getOrderCourse(order.getOrderSn()); for ( ShopProductCourseEntity s : orderCourse){ LambdaQueryWrapper wrapper2 = new LambdaQueryWrapper<>(); - wrapper2.eq(UserCourseBuyEntity::getUserId,orderEntity.getUserId()); + wrapper2.eq(UserCourseBuyEntity::getUserId,order.getUserId()); wrapper2.eq(UserCourseBuyEntity::getCatalogueId,s.getCatalogueId()); wrapper2.and(r->r.isNull(UserCourseBuyEntity::getEndTime).or().gt(UserCourseBuyEntity::getEndTime,new Date())); List userCourseBuyEntities = userCourseBuyDao.selectList(wrapper2); @@ -267,11 +270,11 @@ public class AliPayServiceImpl implements AliPayService { calendar.add(Calendar.DAY_OF_MONTH,s.getDays()); userCourseBuyEntity.setEndTime(calendar.getTime()); } - userCourseBuyEntity.setCome(userCourseBuyEntity.getCome()+";延期(支付宝购买:"+orderEntity.getOrderSn()+")"); + userCourseBuyEntity.setCome(userCourseBuyEntity.getCome()+";延期(支付宝购买:"+order.getOrderSn()+")"); userCourseBuyDao.updateById(userCourseBuyEntity); }else{ UserCourseBuyEntity userCourseBuyEntity = new UserCourseBuyEntity(); - userCourseBuyEntity.setUserId(orderEntity.getUserId()); + userCourseBuyEntity.setUserId(order.getUserId()); userCourseBuyEntity.setCourseId(s.getCourseId()); userCourseBuyEntity.setCatalogueId(s.getCatalogueId()); userCourseBuyEntity.setDays(s.getDays()); @@ -281,34 +284,34 @@ public class AliPayServiceImpl implements AliPayService { // cal.setTime(new Date()); // cal.add(Calendar.DAY_OF_MONTH,s.getDays()); // userCourseBuyEntity.setEndTime(cal.getTime()); - userCourseBuyEntity.setCome("支付宝购买:"+orderEntity.getOrderSn()); + userCourseBuyEntity.setCome("支付宝购买:"+order.getOrderSn()); userCourseBuyDao.insert(userCourseBuyEntity); } } //开通course,end - List collect = buyOrderProductDao.selectList(new LambdaQueryWrapper().eq(BuyOrderProduct::getOrderId, orderEntity.getOrderId())).stream().map(BuyOrderProduct::getProductId).collect(Collectors.toList()); + List collect = buyOrderProductDao.selectList(new LambdaQueryWrapper().eq(BuyOrderProduct::getOrderId, order.getOrderId())).stream().map(BuyOrderProduct::getProductId).collect(Collectors.toList()); //发放优惠卷 couponService.insertCouponHistoryByProductId(collect); //手摸脚模购买后会开启用户的脉穴的功能 if(collect.contains(128)||collect.contains(129)||collect.contains(130)||collect.contains(131)||collect.contains(136)||collect.contains(137)){ - MyUserEntity userInfo = userService.getById(orderEntity.getUserId()); + MyUserEntity userInfo = userService.getById(order.getUserId()); userInfo.setPointPower(1); userService.updateById(userInfo); } if(collect.contains(133)||collect.contains(134)||collect.contains(135)){ - MyUserEntity userInfo = userService.getById(orderEntity.getUserId()); + MyUserEntity userInfo = userService.getById(order.getUserId()); userInfo.setTgdzPower(1); userService.updateById(userInfo); } if(collect.contains(39)||collect.contains(62)||collect.contains(123)||collect.contains(127)){ - MyUserEntity userInfo = userService.getById(orderEntity.getUserId()); + MyUserEntity userInfo = userService.getById(order.getUserId()); userInfo.setWylqPower(1); userService.updateById(userInfo); } if(collect.contains(43)||collect.contains(62)||collect.contains(124)){ - MyUserEntity userInfo = userService.getById(orderEntity.getUserId()); + MyUserEntity userInfo = userService.getById(order.getUserId()); userInfo.setPrescriptBPower(1); userService.updateById(userInfo); } diff --git a/src/main/java/com/peanut/modules/pay/weChatPay/service/impl/WxpayServiceImpl.java b/src/main/java/com/peanut/modules/pay/weChatPay/service/impl/WxpayServiceImpl.java index b2f634f4..71db02fd 100644 --- a/src/main/java/com/peanut/modules/pay/weChatPay/service/impl/WxpayServiceImpl.java +++ b/src/main/java/com/peanut/modules/pay/weChatPay/service/impl/WxpayServiceImpl.java @@ -10,6 +10,7 @@ import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.peanut.modules.common.dao.*; import com.peanut.modules.book.service.*; import com.peanut.modules.common.entity.*; +import com.peanut.modules.common.service.CouponHistoryService; import com.peanut.modules.common.service.CouponService; import com.peanut.modules.master.service.UserCourseBuyService; import com.peanut.modules.pay.refund.entity.PayRefundOrder; @@ -83,6 +84,8 @@ public class WxpayServiceImpl extends ServiceImpl().eq("order_sn", orderNo)); - + //使用优惠券 + if (order.getCouponId()!=null&&order.getCouponId()!=0){ + CouponHistory couponHistory = couponHistoryService.getById(order.getCouponId()); + couponHistory.setOrderId(order.getOrderId()); + couponService.useCouponAmount(couponHistory); + } if("relearn".equals(order.getOrderType())){ - BuyOrder orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper() - .eq("order_sn", orderNo)); //更新 订单 记录 - buyOrderService.updateOrderStatus(orderEntity.getUserId(),orderNo,"2"); + buyOrderService.updateOrderStatus(order.getUserId(),orderNo,"2"); //插入复读记录 - userCourseBuyService.addUserCourseBuyRelearn(orderEntity,"微信购买:"+orderEntity.getOrderSn()); + userCourseBuyService.addUserCourseBuyRelearn(order,"微信购买:"+order.getOrderSn()); } if("vip".equals(order.getOrderType())){ - BuyOrder orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper().eq("order_sn", orderNo)); //更新 订单 记录 - buyOrderService.updateOrderStatus(orderEntity.getUserId(),orderNo,"2"); + buyOrderService.updateOrderStatus(order.getUserId(),orderNo,"2"); //处理抵扣积分 - if(orderEntity.getJfDeduction().compareTo(BigDecimal.ZERO)>0){ - userCoinJf(orderEntity); + if(order.getJfDeduction().compareTo(BigDecimal.ZERO)>0){ + userCoinJf(order); } //开通vip - openVipForUser(orderEntity); + openVipForUser(order); } // 1.根据订单id获取订单信息 if ("order".equals(order.getOrderType())) { - BuyOrder orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper().eq("order_sn", orderNo)); - BigDecimal realMoney = orderEntity.getRealMoney(); - - if(orderEntity.getJfDeduction().compareTo(BigDecimal.ZERO)>0){ - userCoinJf(orderEntity); + if(order.getJfDeduction().compareTo(BigDecimal.ZERO)>0){ + userCoinJf(order); } //开通book,start