瀏覽代碼

fix 过滤可用优惠券

zoujiajian 3 年之前
父節點
當前提交
d6e40dcd14
共有 1 個文件被更改,包括 20 次插入18 次删除
  1. 20 18
      netflix-dao/src/main/resources/mapper/CouponUserMapper.xml

+ 20 - 18
netflix-dao/src/main/resources/mapper/CouponUserMapper.xml

@@ -4,24 +4,26 @@
 <mapper namespace="com.cyksj.mapper.manage.coupon.CouponUserMapper">
 
     <select id="getAvailableCouponList" resultType="com.cyksj.model.views.CouponUserView">
-        select distinct cu.id,
-                        cp.id as coupon_id,
-                        cp.name,
-                        cp.goods_type,
-                        cp.type,
-                        cp.goods_sku_ids,
-                        cp.discount,
-                        cp.reduce_money,
-                        cp.is_valid_time,
-                        cu.valid_start_time,
-                        cu.valid_end_time,
-                        cp.valid_days,
-                        cu.created_time,
-                        cp.is_renew,
-                        cu.status as couponUserStatus,
-                        if(ck.id is null, 0, 1) as 'isAvailable'
+        select * from (select distinct cu.id,
+        cp.id as coupon_id,
+        cp.name,
+        cp.goods_type,
+        cp.type,
+        cp.goods_sku_ids,
+        cp.discount,
+        cp.reduce_money,
+        cp.is_valid_time,
+        cu.valid_start_time,
+        cu.valid_end_time,
+        cp.valid_days,
+        cu.created_time,
+        cp.is_renew,
+        cu.status as couponUserStatus,
+        if(ck.id is null, 0, 1) as 'isAvailable',
+        if(ca.id is not null and ca.status = 0,false,true) flag
         from `coupon_user` cu
         left join `coupon` cp on cp.id = cu.coupon_id
+        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">
             and ck.goods_id = #{goodsId}
@@ -32,15 +34,15 @@
         <if test="isRenew != null and isRenew">
             and cp.is_renew = #{isRenew}
         </if>
-        and cu.status != 'used'
         where cu.user_id = #{userId}
         and cu.channel != 'exCode'
+        and cu.valid_end_time > now()
         <if test="couponId == null">
             order by isAvailable desc
         </if>
         <if test="couponId != null">
             order by case when cp.id = #{couponId} then 2 else isAvailable end desc
-        </if>
+        </if>)s where flag = 1 and couponUserStatus != 'used'
     </select>
 
     <select id="countAvailableCouponList" resultType="java.lang.Integer">