CouponRecommendMapper.xml 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 and c.deleted and c.is_available
  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 and c.deleted and c.is_available
  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. <select id="checkPresentRecommendByCouponId" resultType="java.lang.Integer">
  59. select count(1)
  60. from coupon_recommend cr
  61. inner join coupon c on c.id = cr.coupon_id
  62. where cr.coupon_id = #{couponId}
  63. and cr.deleted is true
  64. and c.deleted is true
  65. and cr.status = 1
  66. and (cr.up_time is null or cr.up_time &lt;= now())
  67. and (cr.down_time is null or cr.down_time > now())
  68. </select>
  69. <select id="getRecommendCouponByGoodsId" resultType="com.cyksj.model.entity.Coupon">
  70. select c.*
  71. from coupon_recommend cr inner join coupon c on c.id = cr.coupon_id
  72. where cr.deleted is true and c.deleted is true and cr.status is true
  73. and (cr.up_time is null or cr.up_time &lt;= now()) and (cr.down_time is null or cr.down_time > now())
  74. and (select count(1) from coupon_sku cs where cs.coupon_id = cr.coupon_id and cs.goods_id = #{goodsId}) > 0
  75. order by c.discount asc,c.reduce_money desc
  76. limit 1
  77. </select>
  78. </mapper>