ApiUserCouponMapper.xml 6.8 KB

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