ApiUserCouponMapper.xml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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.ApiUserCouponMapper">
  4. <!-- 可根据自己的需求,是否要使用 -->
  5. <resultMap type="com.kmall.api.entity.UserCouponVo" id="userCouponMap">
  6. <result property="id" column="id"/>
  7. <result property="coupon_id" column="coupon_id"/>
  8. <result property="coupon_name" column="coupon_name"/>
  9. <result property="coupon_number" column="coupon_number"/>
  10. <result property="user_id" column="user_id"/>
  11. <result property="used_time" column="used_time"/>
  12. <result property="add_time" column="add_time"/>
  13. <result property="order_id" column="order_id"/>
  14. <result property="source_key" column="source_key"/>
  15. <result property="referrer" column="referrer"/>
  16. <result property="show_state" column="show_state"/>
  17. <result property="end_time" column="end_time"/>
  18. <result property="type_money" column="type_money"/>
  19. <result property="send_type" column="send_type"/>
  20. <result property="min_goods_amount" column="min_goods_amount"/>
  21. <result property="isAll" column="is_all"/>
  22. <result property="couponUrl" column="coupon_url"/>
  23. <result property="isUsed" column="is_used"/>
  24. </resultMap>
  25. <select id="queryObject" resultMap="userCouponMap">
  26. select * from mall_user_coupon where id = #{value}
  27. </select>
  28. <select id="queryObjectByIdAndUsed" resultMap="userCouponMap">
  29. select * from mall_user_coupon where id = #{value} and is_used = 0
  30. </select>
  31. <select id="queryByCouponNumber" resultMap="userCouponMap">
  32. select * from mall_user_coupon where coupon_number = #{coupon_number}
  33. </select>
  34. <select id="queryByOrderId" resultMap="userCouponMap">
  35. select * from mall_user_coupon where order_id = #{order_id} limit 1
  36. </select>
  37. <select id="queryList" resultMap="userCouponMap">
  38. select a.*,c.is_all,c.coupon_url
  39. from mall_user_coupon a inner join mall_coupon c on a.coupon_id = c.id
  40. where 1 = 1
  41. <if test="coupon_number != null">
  42. and a.coupon_number = #{coupon_number}
  43. </if>
  44. <if test="user_id != null">
  45. and a.user_id = #{user_id}
  46. </if>
  47. <if test="send_type != null">
  48. and a.send_type = #{send_type}
  49. </if>
  50. <if test="send_types != null">
  51. and a.send_type in
  52. <foreach item="item" collection="send_types" open="(" separator="," close=")">
  53. #{item}
  54. </foreach>
  55. </if>
  56. <if test="unUsed != null and unUsed == true">
  57. and (a.order_id is null or a.order_id =0)
  58. </if>
  59. <if test="referrer != null">
  60. and a.referrer = #{referrer}
  61. </if>
  62. <if test="source_key != null">
  63. and a.source_key = #{source_key}
  64. </if>
  65. <if test="show_state != null">
  66. and a.show_state = #{show_state}
  67. </if>
  68. <if test="enabled != null and enabled == true">
  69. and a.end_time > now()
  70. </if>
  71. <if test="isUsed != null and isUsed != ''">
  72. and a.is_used = 0
  73. </if>
  74. <choose>
  75. <when test="sidx != null and sidx.trim() != ''">
  76. order by ${sidx} ${order}
  77. </when>
  78. <otherwise>
  79. order by id desc
  80. </otherwise>
  81. </choose>
  82. <if test="offset != null and limit != null">
  83. limit #{offset}, #{limit}
  84. </if>
  85. </select>
  86. <select id="queryTotal" resultType="int">
  87. select count(*) from mall_user_coupon a
  88. where 1 = 1
  89. <if test="coupon_number != null">
  90. and a.coupon_number = #{coupon_number}
  91. </if>
  92. <if test="user_id != null">
  93. and a.user_id = #{user_id}
  94. </if>
  95. <if test="send_type != null">
  96. and a.send_type = #{send_type}
  97. </if>
  98. <if test="referrer != null">
  99. and a.referrer = #{referrer}
  100. </if>
  101. <if test="source_key != null">
  102. and a.source_key = #{source_key}
  103. </if>
  104. <if test="show_state != null">
  105. and a.show_state = #{show_state}
  106. </if>
  107. <if test="enabled != null and enabled == true">
  108. and a.end_time > now()
  109. </if>
  110. </select>
  111. <insert id="save" parameterType="com.kmall.api.entity.UserCouponVo" useGeneratedKeys="true" keyProperty="id">
  112. insert into mall_user_coupon
  113. (
  114. `coupon_id`,
  115. `coupon_name`,
  116. `is_used`,
  117. `coupon_number`,
  118. `user_id`,
  119. `used_time`,
  120. `order_id`,
  121. `add_time`,
  122. `source_key`,
  123. `referrer`,
  124. show_state,
  125. end_time,
  126. type_money,
  127. send_type,
  128. min_goods_amount
  129. )
  130. values
  131. (
  132. #{coupon_id},
  133. #{coupon_name},
  134. #{isUsed},
  135. #{coupon_number},
  136. #{user_id},
  137. #{used_time},
  138. #{order_id},
  139. #{add_time},
  140. #{source_key},
  141. #{referrer},
  142. #{show_state},
  143. #{end_time},
  144. #{type_money},
  145. #{send_type},
  146. #{min_goods_amount}
  147. )
  148. </insert>
  149. <update id="update" parameterType="com.kmall.api.entity.UserCouponVo">
  150. update mall_user_coupon
  151. <set>
  152. <if test="coupon_id != null">`coupon_id` = #{coupon_id},</if>
  153. <if test="coupon_name != null">`coupon_name` = #{coupon_name},</if>
  154. <if test="isUsed != null">`is_used` = #{isUsed},</if>
  155. <if test="coupon_number != null">`coupon_number` = #{coupon_number},</if>
  156. <if test="user_id != null">`user_id` = #{user_id},</if>
  157. <if test="used_time != null">`used_time` = #{used_time},</if>
  158. <if test="order_id != null">`order_id` = #{order_id},</if>
  159. <if test="add_time != null">`add_time` = #{add_time},</if>
  160. <if test="source_key != null">`source_key` = #{source_key},</if>
  161. <if test="referrer != null">`referrer` = #{referrer},</if>
  162. <if test="show_state != null">`show_state` = #{show_state},</if>
  163. <if test="end_time != null">`end_time` = #{end_time},</if>
  164. <if test="type_money != null">`type_money` = #{type_money},</if>
  165. <if test="send_type != null">`send_type` = #{send_type},</if>
  166. <if test="min_goods_amount != null">`min_goods_amount` = #{min_goods_amount},</if>
  167. </set>
  168. where id = #{id}
  169. </update>
  170. <update id="cancelOrder" parameterType="com.kmall.api.entity.UserCouponVo">
  171. update mall_user_coupon
  172. <set>
  173. `used_time` = null,
  174. `order_id` = 0
  175. </set>
  176. where id = #{id}
  177. </update>
  178. </mapper>