Browse Source

fix:优惠卷逻辑调整

wrj 8 months ago
parent
commit
52028636e7

+ 4 - 2
nightFragrance-massage/src/main/java/com/ylx/massage/service/impl/CouponReceiveServiceImpl.java

@@ -113,9 +113,11 @@ public class CouponReceiveServiceImpl extends ServiceImpl<CouponReceiveMapper, C
     public List<Coupon> couponWindows(CouponReceive couponReceive) {
     public List<Coupon> couponWindows(CouponReceive couponReceive) {
         //判断是否领过优惠卷
         //判断是否领过优惠卷
         //查询领取优惠卷
         //查询领取优惠卷
-        List<CouponReceiveVo> CouponReceiveVos = couponReceiveMapper.getByOpenId(couponReceive.getOpenid());
+        LambdaQueryWrapper<CouponReceive> query = new LambdaQueryWrapper<>();
+        query.eq(CouponReceive::getOpenid, couponReceive.getOpenid());
+        List<CouponReceive> couponReceive1 = this.list(query);
         //如果没有领取优惠卷
         //如果没有领取优惠卷
-        if (CollectionUtil.isEmpty(CouponReceiveVos)) {
+        if (CollectionUtil.isEmpty(couponReceive1)) {
             //查询优惠卷
             //查询优惠卷
             LambdaQueryWrapper<Coupon> couponLambdaQueryWrapper = new LambdaQueryWrapper<>();
             LambdaQueryWrapper<Coupon> couponLambdaQueryWrapper = new LambdaQueryWrapper<>();
             couponLambdaQueryWrapper.eq(Coupon::getStatus, 1).like(Coupon::getDeptName, couponReceive.getDeptName());
             couponLambdaQueryWrapper.eq(Coupon::getStatus, 1).like(Coupon::getDeptName, couponReceive.getDeptName());

+ 18 - 7
nightFragrance-massage/src/main/java/com/ylx/massage/service/impl/TOrderServiceImpl.java

@@ -331,6 +331,10 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
         Coupon coupon = couponService.getById(couponReceive.getCouponId());
         Coupon coupon = couponService.getById(couponReceive.getCouponId());
         log.info("订单信息,{}", tOrder);
         log.info("订单信息,{}", tOrder);
         log.info("优惠卷信息,{}", coupon);
         log.info("优惠卷信息,{}", coupon);
+
+
+
+
         //折扣券
         //折扣券
         if (coupon.getDiscountType() == 2) {
         if (coupon.getDiscountType() == 2) {
             //判断门槛金额
             //判断门槛金额
@@ -342,7 +346,6 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
                 //优惠值
                 //优惠值
                 orderVerificationVo.setPreferential(tOrder.getTotalPrice().subtract(bigDecimal));
                 orderVerificationVo.setPreferential(tOrder.getTotalPrice().subtract(bigDecimal));
                 orderVerificationVo.setTotalPrice(bigDecimal);
                 orderVerificationVo.setTotalPrice(bigDecimal);
-                return orderVerificationVo;
             } else {
             } else {
                 throw new ServiceException("不满足优惠券门槛金额");
                 throw new ServiceException("不满足优惠券门槛金额");
             }
             }
@@ -351,11 +354,14 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
                 //优惠值
                 //优惠值
                 orderVerificationVo.setPreferential(coupon.getDiscountValue());
                 orderVerificationVo.setPreferential(coupon.getDiscountValue());
                 orderVerificationVo.setTotalPrice(tOrder.getTotalPrice().subtract(coupon.getDiscountValue()));
                 orderVerificationVo.setTotalPrice(tOrder.getTotalPrice().subtract(coupon.getDiscountValue()));
-                return orderVerificationVo;
             } else {
             } else {
                 throw new ServiceException("不满足优惠券门槛金额");
                 throw new ServiceException("不满足优惠券门槛金额");
             }
             }
         }
         }
+        if(orderVerificationVo.getTotalPrice().compareTo(BigDecimal.ZERO)<0){
+            throw new ServiceException("当前项目不可用");
+        }
+        return orderVerificationVo;
     }
     }
 
 
     private TOrder getOrder(TOrder tOrder) {
     private TOrder getOrder(TOrder tOrder) {
@@ -387,6 +393,7 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
         }
         }
 
 
         orderNew.setPayType(order.getPayType());
         orderNew.setPayType(order.getPayType());
+        //优惠券核销
         if (StringUtils.isNotBlank(order.getCouponReceiveId())) {
         if (StringUtils.isNotBlank(order.getCouponReceiveId())) {
             orderNew.setCouponReceiveId(order.getCouponReceiveId());
             orderNew.setCouponReceiveId(order.getCouponReceiveId());
             orderNew.setPreferential(order.getPreferential());
             orderNew.setPreferential(order.getPreferential());
@@ -434,11 +441,15 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
 
 
     @Transactional(rollbackFor = Exception.class)
     @Transactional(rollbackFor = Exception.class)
     public void orderPayManage(TWxUser user, TOrder orderNew) {
     public void orderPayManage(TWxUser user, TOrder orderNew) {
-
-        //删除优惠卷
-//        if(orderNew.){
-//
-//        }
+        //更新优惠卷状态
+        if(StringUtils.isNotBlank(orderNew.getCouponReceiveId())){
+            CouponReceive couponReceive = new CouponReceive();
+            couponReceive.setId(orderNew.getCouponReceiveId());
+            couponReceive.setUseState(MassageConstants.INTEGER_TWO);
+            if(!couponReceiveService.updateById(couponReceive)){
+                log.error("优惠券状态更新失败id:,{}",orderNew.getCouponReceiveId());
+            }
+        }
 
 
         // 更新用户金额 及下单此时
         // 更新用户金额 及下单此时
         TWxUser paramUser = new TWxUser();
         TWxUser paramUser = new TWxUser();

+ 1 - 0
nightFragrance-massage/src/main/resources/mapper/massage/CouponReceiveMapper.xml

@@ -74,6 +74,7 @@
         LEFT JOIN coupon b ON a.coupon_id = b.id
         LEFT JOIN coupon b ON a.coupon_id = b.id
         WHERE a.is_delete = 0
         WHERE a.is_delete = 0
           AND b.is_delete = 0
           AND b.is_delete = 0
+          and a.expiration_time &gt;= now()
           and a.openid = #{openid}
           and a.openid = #{openid}
     </select>
     </select>