소스 검색

可用优惠券排除删除/后台失效的

zoujiajian 4 달 전
부모
커밋
a4dc1f4d68

+ 3 - 0
netflix-dao/src/main/java/com/cyksj/mapper/manage/coupon/CouponUserMapper.java

@@ -1,5 +1,6 @@
 package com.cyksj.mapper.manage.coupon;
 
+import cn.hutool.core.date.DateTime;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -43,4 +44,6 @@ public interface CouponUserMapper extends BaseMapper<CouponUser> {
 	Coupon selectUserCouponBySkuId(@Param("userId") Long userId, @Param("skuId") Long skuId);
 
 	Coupon selectNoLoginRecommendCouponReduce(@Param("goodsId") Long goodsId, @Param("price") BigDecimal price);
+
+    Integer selectAvailableCoupons(@Param("userId") long userId, @Param("status") CouponUser.Status status, @Param("now") DateTime now);
 }

+ 2 - 1
netflix-dao/src/main/java/com/cyksj/model/views/CouponDetailView.java

@@ -19,7 +19,8 @@ import java.util.List;
  */
 @Getter
 @Setter
-@SearchBean(tables = "coupon c left join coupon_classification cc on cc.id = c.classification_id")
+@SearchBean(tables = "coupon c left join coupon_classification cc on cc.id = c.classification_id",
+        where = "c.deleted and c.is_available")
 public class CouponDetailView {
 	/**
 	 * 优惠券id

+ 2 - 2
netflix-dao/src/main/resources/mapper/CouponRecommendMapper.xml

@@ -32,7 +32,7 @@
         when cu.id is not null and cu.status = 'unused' then 1
         end) as `order`,
         if(c.is_valid_time is true and c.valid_end_time &lt; now(),false,true) as flag
-        from coupon_recommend cr left join coupon c on c.id = cr.coupon_id
+        from coupon_recommend cr left join coupon c on c.id = cr.coupon_id and c.deleted and c.is_available
         left join coupon_user cu on cu.coupon_id = c.id and cu.user_id = #{userId}
         where cr.deleted is true and c.deleted is true and cr.status = 1
         and (cr.up_time is null or cr.up_time &lt;= now()) and (cr.down_time is null or cr.down_time > now())
@@ -49,7 +49,7 @@
                               c.scope,
                               cr.id as recommendId,
         if(c.is_valid_time is true and c.valid_end_time &lt; now(),false,true) as flag
-        from coupon_recommend cr left join coupon c on c.id = cr.coupon_id
+        from coupon_recommend cr left join coupon c on c.id = cr.coupon_id and c.deleted and c.is_available
         left join coupon_user cu on cu.coupon_id = c.id and cu.user_id = #{userId}
         where cr.deleted is true and c.deleted is true and cr.status is true and cu.coupon_id is null
         and (cr.up_time is null or cr.up_time &lt;= now()) and (cr.down_time is null or cr.down_time > now())

+ 17 - 4
netflix-dao/src/main/resources/mapper/CouponUserMapper.xml

@@ -30,7 +30,7 @@
         when cu.status = 'unused' then 0
         end)                 as orderby
         from `coupon_user` cu
-        left join `coupon` cp on cp.id = cu.coupon_id
+        left join `coupon` cp on cp.id = cu.coupon_id and cp.deleted and cp.is_available
         left join `coupon_active` ca on ca.id = cu.coupon_active_id
         left join `coupon_sku` ck on ck.coupon_id = cp.id
         <if test="goodsId != null">
@@ -64,7 +64,7 @@
                      cp.reduce_condition,
                      cp.type
         from `coupon_user` cu
-        left join `coupon` cp on cp.id = cu.coupon_id
+        left join `coupon` cp on cp.id = cu.coupon_id and cp.deleted and cp.is_available
         left join `coupon_sku` ck on ck.coupon_id = cp.id
         left join `coupon_active` ca on ca.id = cu.coupon_active_id
         where
@@ -125,7 +125,7 @@
                      if(c.is_valid_time is true and c.valid_end_time &lt; now(), false, true) as flag
               from coupon_active ca
                        left join coupon c
-                                 on c.id = ca.coupon_id
+                                 on c.id = ca.coupon_id and c.deleted and c.is_available
                        left join coupon_user cu on cu.coupon_id = c.id and cu.user_id = #{userId}
               where ca.deleted is true
                 and c.deleted is true
@@ -171,7 +171,7 @@
                     when cu.status = 'unused' then 0
                    end)                 as orderby
         from `coupon_user` cu
-                 left join `coupon` c on c.id = cu.coupon_id
+                 left join `coupon` c on c.id = cu.coupon_id and c.deleted and c.is_available
                  left join `coupon_active` ca on ca.id = cu.coupon_active_id
         where cu.user_id = #{userId}
         <if test="couponId !=null">
@@ -333,4 +333,17 @@
           and c.use_scope != 'renew'
         order by couponMoney desc limit 1
     </select>
+
+    <select id="selectAvailableCoupons" resultType="java.lang.Integer">
+        select count(1)
+        from (select coupon_id
+              from coupon_user
+              where user_id = #{userId}
+                and status = #{status}
+                and valid_start_time &lt; #{now}
+                and valid_end_time > #{now}) cu
+                 inner join coupon c on c.id = cu.coupon_id
+        where c.deleted
+          and c.is_available
+    </select>
 </mapper>

+ 2 - 6
netflix-web/src/main/java/com/cyksj/web/controller/user/UserController.java

@@ -177,12 +177,8 @@ public class UserController {
         }).collect(Collectors.toList());
         //车票
         personalView.setNumOfTickets(renewalViews.size());
-        //优惠券
-        Integer couponSize = couponUserMapper.selectCount(Wrappers.lambdaQuery(CouponUser.class)
-                .eq(CouponUser::getUserId, userId)
-                .eq(CouponUser::getStatus, CouponUser.Status.unused)
-                .le(CouponUser::getValidStartTime, now)
-                .gt(CouponUser::getValidEndTime, now));
+        //优惠券 需要排除已删除/后台失效的优惠券
+        Integer couponSize = couponUserMapper.selectAvailableCoupons(userId, CouponUser.Status.unused, now);
         personalView.setNumOfCoupons(couponSize);
         //积分
         User user = userService.getById(userId);