zoujiajian há 3 anos atrás
pai
commit
f77146948f

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

@@ -3,7 +3,7 @@
 <mapper namespace="com.cyksj.mapper.manage.coupon.CouponRecommendMapper">
 
     <select id="getRecommendCouponViewList" resultType="com.cyksj.model.views.CouponRecommendView">
-        select cr.id,
+        select * from (select cr.id,
         cr.coupon_id,
         c.name,
         c.goods_type,
@@ -16,11 +16,21 @@
         c.valid_end_time,
         c.valid_days,
         c.is_renew,
-        c.scope from coupon_recommend cr left join coupon c on c.id = cr.coupon_id
+        c.scope,
+        (case
+        when cu.id is null then 'collecting'
+        when cu.id is not null and cu.status != 'unused' then 'used'
+        when cu.id is not null and cu.status = 'unused' then 'received'
+        end) as couponStatus,
+        (case
+        when cu.id is null then 0
+        when cu.id is not null and cu.status = 'unused' then 1
+        end) as `order`
+        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 cu.coupon_id is null
+        where cr.deleted is true and c.deleted is true
         <if test='!isNewUser'>
             and c.scope !='newUser'
-        </if>
+        </if>)s where couponStatus != 'used' order by `order`
     </select>
 </mapper>

+ 39 - 34
netflix-dao/src/main/resources/mapper/CouponUserMapper.xml

@@ -64,41 +64,46 @@
     </select>
 
     <select id="couponCenterList" resultType="com.cyksj.model.views.CouponActiveView">
-        select ca.id,
-               c.id as coupon_id,
-               c.name,
-               c.goods_type,
-               c.type,
-               c.reduce_money,
-               c.discount,
-               c.scope,
-               c.goods_sku_ids,
-               c.is_valid_time,
-               c.valid_start_time,
-               c.valid_end_time,
-               c.valid_days,
-               c.is_renew,
-               ca.num,
-               ca.`status`,
-               ca.expiry_status,
-               ca.remain_num,
-               (case
-                    when ca.remain_num &lt;= 0 then 'over'
-                    when cu.id is null then 'collecting'
-                   end)                                                                     as couponStatus,
-               (case
-                    when remain_num &lt;= 0 then 2
-                    when cu.id is null then 0
-                   end)                                                                              as `order`
-        from coupon_active ca
-                 left join coupon c
-                           on c.id = ca.coupon_id
-                 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 ca.expiry_status != 0
+        select *
+        from (select ca.id,
+                     c.id     as coupon_id,
+                     c.name,
+                     c.goods_type,
+                     c.type,
+                     c.reduce_money,
+                     c.discount,
+                     c.scope,
+                     c.goods_sku_ids,
+                     c.is_valid_time,
+                     c.valid_start_time,
+                     c.valid_end_time,
+                     c.valid_days,
+                     c.is_renew,
+                     ca.num,
+                     ca.`status`,
+                     ca.expiry_status,
+                     ca.remain_num,
+                     (case
+                          when ca.remain_num &lt;= 0 then 'over'
+                          when cu.id is null then 'collecting'
+                          when cu.id is not null and cu.status != 'unused' then 'used'
+                          when cu.id is not null and cu.status = 'unused' then 'received'
+                         end) as couponStatus,
+                     (case
+                          when remain_num &lt;= 0 then 2
+                          when cu.id is null then 0
+                          when cu.id is not null and cu.status = 'unused' then 1
+                         end) as `order`
+              from coupon_active ca
+                       left join coupon c
+                                 on c.id = ca.coupon_id
+                       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 ca.expiry_status != 0
         and ca.`status` != 0
-        and cu.id is null
+             ) s
+        where couponStatus != 'used'
         order by `order`
     </select>
 </mapper>