CouponUserMapper.xml 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.CouponUserMapper">
  4. <select id="getAvailableCouponList" resultType="com.cyksj.model.views.CouponUserView">
  5. select distinct cu.id,
  6. cp.id as coupon_id,
  7. cp.name,
  8. cp.goods_type,
  9. cp.type,
  10. cp.goods_sku_ids,
  11. cp.discount,
  12. cp.reduce_money,
  13. cp.is_valid_time,
  14. cp.valid_start_time,
  15. cp.valid_end_time,
  16. cp.valid_days,
  17. cu.created_time,
  18. cp.is_renew,
  19. cu.status as couponUserStatus,
  20. if(ck.id is null, 0, 1) as 'isAvailable'
  21. from `coupon_user` cu
  22. left join `coupon` cp on cp.id = cu.coupon_id
  23. left join `coupon_sku` ck on ck.coupon_id = cp.id
  24. and ck.sku_id = #{skuId}
  25. <if test="isRenew != null">
  26. and cp.is_renew = #{isRenew}
  27. </if>
  28. and cu.status != 'used'
  29. where cu.user_id = #{userId}
  30. order by isAvailable desc
  31. </select>
  32. <select id="countAvailableCouponList" resultType="java.lang.Integer">
  33. select count(distinct cu.id)
  34. from `coupon_user` cu
  35. left join `coupon` cp on cp.id = cu.coupon_id
  36. left join `coupon_sku` ck on ck.coupon_id = cp.id
  37. where ck.sku_id = #{skuId} and cu.user_id = #{userId}
  38. and cu.status = 'unused'
  39. <if test="isRenew != null">
  40. and cp.is_renew = #{isRenew}
  41. </if>
  42. </select>
  43. <select id="couponCenterList" resultType="com.cyksj.model.views.CouponActiveView">
  44. select ca.id,
  45. c.id as coupon_id,
  46. c.name,
  47. c.goods_type,
  48. c.type,
  49. c.reduce_money,
  50. c.discount,
  51. c.scope,
  52. c.goods_sku_ids,
  53. c.is_valid_time,
  54. c.valid_start_time,
  55. c.valid_end_time,
  56. c.valid_days,
  57. c.is_renew,
  58. ca.num,
  59. ca.`status`,
  60. ca.expiry_status,
  61. ca.remain_num,
  62. (case
  63. when ca.expiry_status = 0 then 'stop'
  64. when ca.`status` = 0 then 'stop'
  65. when ca.remain_num &lt;= 0 then 'over'
  66. when cu.id is null then 'collecting'
  67. when cu.id is not null
  68. then 'received' end) as couponStatus,
  69. (case
  70. when ca.expiry_status = 0 then 2
  71. when ca.`status` = 0 then 2
  72. when remain_num &lt;= 0 then 3
  73. when cu.id is null then 0
  74. when cu.id is not null
  75. then 1 end) as `order`
  76. from coupon_active ca
  77. left join coupon c
  78. on c.id = ca.coupon_id
  79. left join coupon_user cu on cu.coupon_id = c.id and cu.user_id = #{userId}
  80. where ca.deleted is true
  81. and c.deleted is true
  82. order by `order`
  83. </select>
  84. </mapper>