瀏覽代碼

Merge branch 'coupons_status'

zoujiajian 3 月之前
父節點
當前提交
5b860a7d7c

+ 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.status")
 public class CouponDetailView {
 	/**
 	 * 优惠券id

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

@@ -21,7 +21,8 @@ import java.util.Date;
 @Getter
 @Setter
 @SearchBean(tables = "coupon_user cu left join coupon_active ca on ca.id = cu.coupon_active_id" +
-		" left join coupon c on c.id = cu.coupon_id left join coupon_classification cc on cc.id = c.classification_id")
+        " left join coupon c on c.id = cu.coupon_id left join coupon_classification cc on cc.id = c.classification_id",
+        where = "c.deleted and c.status")
 public class CouponUserView {
 	@DbField("cu.id")
 	private Long id;

+ 1 - 1
netflix-dao/src/main/resources/mapper/CouponMapper.xml

@@ -38,7 +38,7 @@
                             from `coupon_distribute_popularize`
                             where deleted is true) cdp
                            on cdp.coupon_id = cp.id
-        where cp.deleted is true
+        where cp.deleted is true and cp.status
           and (cp.ex_code = #{couponExCode} or cdp.ex_code = #{couponExCode}) limit 1
     </select>
 

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

@@ -34,7 +34,7 @@
         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
         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
+        where cr.deleted is true and c.deleted is true and c.status 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())
         <if test="couponId != null">
             and c.id = #{couponId}
@@ -51,7 +51,7 @@
         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
         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
+        where cr.deleted is true and c.deleted is true and c.status 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())
         <if test='!isNewUser'>
             and c.scope !='newUser'

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

@@ -49,6 +49,7 @@
         </choose>
         where cu.user_id = #{userId}
         and cu.channel != 'exCode'
+        and cp.deleted and cp.status
         and cu.valid_end_time > now()
         <if test="couponId == null">
             order by isAvailable desc,orderby,couponMoney desc,cu.valid_end_time asc
@@ -75,6 +76,7 @@
             ck.sku_id = #{skuId}
         </if>
         and cu.user_id = #{userId}
+        and cp.deleted and cp.status
         and cu.status = 'unused'
         and cu.channel != 'exCode'
         and cu.valid_start_time &lt; now()
@@ -129,6 +131,7 @@
                        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
+                and c.status
                 and cu.id is null
                 and ca.expiry_status != 0
         and ca.`status` != 0
@@ -174,6 +177,7 @@
                  left join `coupon` c on c.id = cu.coupon_id
                  left join `coupon_active` ca on ca.id = cu.coupon_active_id
         where cu.user_id = #{userId}
+        and c.deleted and c.status
         <if test="couponId !=null">
             and cu.coupon_id = #{couponId}
         </if>
@@ -333,4 +337,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.status
+    </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);