1
0

ApiCouponMapper.xml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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.kmall.api.dao.ApiCouponMapper">
  4. <!-- 可根据自己的需求,是否要使用 -->
  5. <resultMap type="com.kmall.api.entity.CouponVo" id="couponMap">
  6. <result property="id" column="id"/>
  7. <result property="name" column="name"/>
  8. <result property="type_money" column="type_money"/>
  9. <result property="send_type" column="send_type"/>
  10. <result property="min_amount" column="min_amount"/>
  11. <result property="max_amount" column="max_amount"/>
  12. <result property="send_start_date" column="send_start_date"/>
  13. <result property="send_end_date" column="send_end_date"/>
  14. <result property="use_start_date" column="use_start_date"/>
  15. <result property="use_end_date" column="use_end_date"/>
  16. <result property="min_goods_amount" column="min_goods_amount"/>
  17. <result property="coupon_txt" column="coupon_txt"/>
  18. <result property="user_id" column="user_id"/>
  19. <result property="coupon_number" column="coupon_number"/>
  20. <result property="min_transmit_num" column="min_transmit_num"/>
  21. <result property="show_state" column="show_state"/>
  22. <result property="pic_url" column="pic_url"/>
  23. <result property="isAll" column="is_all"/>
  24. <result property="couponUrl" column="coupon_url"/>
  25. </resultMap>
  26. <select id="queryObject" resultMap="couponMap">
  27. select * from mall_coupon where id = #{value}
  28. </select>
  29. <select id="queryList" resultMap="couponMap">
  30. select * from mall_coupon a
  31. where 1 = 1
  32. <if test="store_id != null">
  33. and a.`store_id` = #{store_id}
  34. </if>
  35. <if test="send_types != null">
  36. and send_type in
  37. <foreach item="item" collection="send_types" open="(" separator="," close=")">
  38. #{item}
  39. </foreach>
  40. </if>
  41. <if test="enabled != null and enabled == true">
  42. and a.use_end_date >= now()
  43. and now() >= a.use_start_date
  44. </if>
  45. <choose>
  46. <when test="sidx != null and sidx.trim() != ''">
  47. order by ${sidx} ${order}
  48. </when>
  49. <otherwise>
  50. order by a.id desc
  51. </otherwise>
  52. </choose>
  53. <if test="offset != null and limit != null">
  54. limit #{offset}, #{limit}
  55. </if>
  56. </select>
  57. <select id="queryTotal" resultType="int">
  58. select count(*) from mall_coupon a
  59. where 1 = 1
  60. <if test="send_types != null">
  61. and send_type in
  62. <foreach item="item" collection="send_types" open="(" separator="," close=")">
  63. #{item}
  64. </foreach>
  65. </if>
  66. <if test="store_id != null">
  67. and a.`store_id` = #{store_id}
  68. </if>
  69. <if test="enabled != null and enabled == true">
  70. and a.use_end_date >= now()
  71. and now() >= a.use_start_date
  72. </if>
  73. </select>
  74. <select id="queryUserCoupons" resultMap="couponMap">
  75. select a.*,b.coupon_number,b.user_id
  76. from mall_coupon a
  77. left join mall_user_coupon b on a.id = b.coupon_id
  78. where 1 = 1
  79. <if test="user_id != null">
  80. and b.`user_id` = #{user_id}
  81. </if>
  82. <if test="store_id != null">
  83. and a.`store_id` = #{store_id}
  84. </if>
  85. <if test="send_type != null">
  86. and a.send_type = #{send_type}
  87. </if>
  88. <if test="coupon_number != null">
  89. and b.coupon_number = #{coupon_number}
  90. </if>
  91. <if test="source_key != null and source_key != ''">
  92. and b.source_key = #{source_key}
  93. </if>
  94. <if test="unUsed != null and unUsed == true">
  95. and b.used_time is null and (b.order_id is null or b.order_id =0)
  96. </if>
  97. <if test="unUsed != null and unUsed == true">
  98. and (b.order_id is null or b.order_id =0)
  99. </if>
  100. <if test="unObtain != null and unObtain == true">
  101. and b.id is null
  102. </if>
  103. <choose>
  104. <when test="sidx != null and sidx.trim() != ''">
  105. order by ${sidx} ${order}
  106. </when>
  107. <otherwise>
  108. order by a.id desc
  109. </otherwise>
  110. </choose>
  111. <if test="offset != null and limit != null">
  112. limit #{offset}, #{limit}
  113. </if>
  114. </select>
  115. <select id="queryMaxUserEnableCoupon" resultMap="couponMap">
  116. select a.*
  117. from mall_coupon a
  118. where 1 = 1
  119. and a.use_end_date >= now()
  120. and now() >= a.use_start_date
  121. <if test="send_type != null">
  122. and a.send_type = #{send_type}
  123. </if>
  124. <if test="send_types != null">
  125. and a.send_type in
  126. <foreach item="item" collection="send_types" open="(" separator="," close=")">
  127. #{item}
  128. </foreach>
  129. </if>
  130. <if test="filterCouponIds != null">
  131. and a.`id` not in
  132. <foreach item="item" collection="filterCouponIds" open="(" separator="," close=")">
  133. #{item}
  134. </foreach>
  135. </if>
  136. order by type_money desc
  137. limit 1
  138. </select>
  139. </mapper>