CouponRecommendMapper.xml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.cyksj.mapper.manage.coupon.CouponRecommendMapper">
  4. <select id="getRecommendCouponViewList" resultType="com.cyksj.model.views.CouponRecommendView">
  5. select * from (select cr.id,
  6. cr.coupon_id,
  7. c.name,
  8. c.goods_type,
  9. c.type,
  10. c.reduce_money,
  11. c.discount,
  12. c.goods_sku_ids,
  13. c.is_valid_time,
  14. c.valid_start_time,
  15. c.valid_end_time,
  16. cu.valid_start_time as userValidStartTime,
  17. cu.valid_end_time as userValidEndTime,
  18. c.valid_days,
  19. c.valid_hours,
  20. c.is_renew,
  21. c.scope,
  22. (case
  23. when cu.id is null then 'collecting'
  24. when cu.id is not null and cu.status != 'unused' then 'used'
  25. when cu.id is not null and cu.valid_end_time &lt; now() then 'expired'
  26. when cu.id is not null and cu.valid_start_time > now() then 'noEffective'
  27. when cu.id is not null and cu.status = 'unused' then 'received'
  28. end) as couponStatus,
  29. (case
  30. when cu.id is null then 0
  31. when cu.id is not null and cu.status = 'unused' then 1
  32. end) as `order`,
  33. if(c.is_valid_time is true and c.valid_end_time &lt; now(),false,true) as flag
  34. from coupon_recommend cr left join coupon c on c.id = cr.coupon_id
  35. left join coupon_user cu on cu.coupon_id = c.id and cu.user_id = #{userId}
  36. where cr.deleted is true and c.deleted is true and cr.status = 1
  37. and (cr.up_time is null or cr.up_time &lt;= now()) and (cr.down_time is null or cr.down_time > now())
  38. <if test="couponId != null">
  39. and c.id = #{couponId}
  40. </if>
  41. <if test='!isNewUser'>
  42. and c.scope !='newUser'
  43. </if>)s where couponStatus not in ('used','expired','noEffective') and flag is true order by `order`
  44. </select>
  45. <select id="getRecommendCouponList" resultType="com.cyksj.model.views.CouponAvailableRecommendView">
  46. select * from (select c.id as couponId,
  47. c.scope,
  48. cr.id as recommendId,
  49. if(c.is_valid_time is true and c.valid_end_time &lt; now(),false,true) as flag
  50. from coupon_recommend cr left join coupon c on c.id = cr.coupon_id
  51. left join coupon_user cu on cu.coupon_id = c.id and cu.user_id = #{userId}
  52. where cr.deleted is true and c.deleted is true and cr.status is true and cu.coupon_id is null
  53. and (cr.up_time is null or cr.up_time &lt;= now()) and (cr.down_time is null or cr.down_time > now())
  54. <if test='!isNewUser'>
  55. and c.scope !='newUser'
  56. </if>)s where flag is true
  57. </select>
  58. </mapper>