ApiUserCouponMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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="storeTopicId" column="store_topic_id"/>
  8. <result property="couponName" column="coupon_name"/>
  9. <result property="couponNumber" column="coupon_number"/>
  10. <result property="userId" column="user_id"/>
  11. <result property="usedTime" column="used_time"/>
  12. <result property="addTime" column="add_time"/>
  13. <result property="orderId" column="order_id"/>
  14. <result property="sourceKey" column="source_key"/>
  15. <result property="referrer" column="referrer"/>
  16. <result property="showState" column="show_state"/>
  17. <result property="endTime" column="end_time"/>
  18. <result property="typeMoney" column="type_money"/>
  19. <result property="sendType" 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. <result property="advImgUrl" column="adv_img_url"/>
  26. <result property="dicountName" column="dicountName"/>
  27. <result property="applyType" column="applyType"/>
  28. <result property="validTime" column="valid_time"/>
  29. </resultMap>
  30. <select id="queryObject" resultMap="userCouponMap">
  31. select * from mall_user_coupon where id = #{value}
  32. </select>
  33. <select id="queryObjectByStoreTopicIdAndUserId" resultMap="userCouponMap">
  34. select * from mall_user_coupon where user_id = #{userId} and store_topic_id = #{storeTopicId}
  35. </select>
  36. <select id="queryObjectByDiscIdAndUserId" resultMap="userCouponMap">
  37. SELECT
  38. c.*
  39. FROM
  40. mall_user_coupon c
  41. INNER JOIN mk_store_ticket_discount d ON c.store_topic_id = d.store_topic_id
  42. WHERE user_id = #{userId} and d.tick_disc_id = #{ticketDiscId}
  43. </select>
  44. <!--查询未使用且未过期,生效时间小于当前时间且失效时间大于当前时间的优惠券-->
  45. <select id="queryObjectByIdAndUsed" resultMap="userCouponMap">
  46. SELECT
  47. c.*,d.apply_type applyType
  48. FROM
  49. mall_user_coupon c
  50. INNER JOIN mk_store_ticket_discount d ON c.store_topic_id = d.store_topic_id
  51. where user_id = #{userId} AND d.tick_disc_id = #{ticketDiscId} AND is_used = 0 and c.enabled = 1
  52. AND valid_time <![CDATA[ < ]]> now() AND end_time <![CDATA[ > ]]> now() AND d.is_past = 0 and d.is_valid = 0
  53. ORDER BY end_time ASC
  54. </select>
  55. <select id="queryByCouponNumber" resultMap="userCouponMap">
  56. select * from mall_user_coupon where coupon_number = #{coupon_number}
  57. </select>
  58. <select id="queryByOrderId" resultMap="userCouponMap">
  59. select * from mall_user_coupon where order_id = #{order_id} limit 1
  60. </select>
  61. <select id="queryList" resultMap="userCouponMap">
  62. select a.*,d.adv_img_url
  63. from mall_user_coupon a inner join mk_store_ticket_discount d on a.store_topic_id = d.store_topic_id
  64. inner join third_merchant_biz b on d.third_merch_sn = b.third_merch_sn
  65. where 1 = 1
  66. <if test="merchSn != null">
  67. and b.merch_sn = #{merchSn}
  68. </if>
  69. <if test="coupon_number != null">
  70. and a.coupon_number = #{coupon_number}
  71. </if>
  72. <if test="user_id != null">
  73. and a.user_id = #{user_id}
  74. </if>
  75. <if test="send_type != null">
  76. and a.send_type = #{send_type}
  77. </if>
  78. <if test="send_types != null">
  79. and a.send_type in
  80. <foreach item="item" collection="send_types" open="(" separator="," close=")">
  81. #{item}
  82. </foreach>
  83. </if>
  84. <if test="unUsed != null and unUsed == true">
  85. and (a.order_id is null or a.order_id =0)
  86. </if>
  87. <if test="referrer != null">
  88. and a.referrer = #{referrer}
  89. </if>
  90. <if test="source_key != null">
  91. and a.source_key = #{source_key}
  92. </if>
  93. <if test="show_state != null">
  94. and a.show_state = #{show_state}
  95. </if>
  96. <if test="enabled != null and enabled == true">
  97. and a.end_time > now()
  98. </if>
  99. <if test="isUsed != null and isUsed != ''">
  100. and a.is_used = 0
  101. </if>
  102. <choose>
  103. <when test="sidx != null and sidx.trim() != ''">
  104. order by ${sidx} ${order}
  105. </when>
  106. <otherwise>
  107. order by id desc
  108. </otherwise>
  109. </choose>
  110. <if test="offset != null and limit != null">
  111. limit #{offset}, #{limit}
  112. </if>
  113. </select>
  114. <select id="queryTotal" resultType="int">
  115. select count(*) from mall_user_coupon a inner join mk_store_ticket_discount d on a.store_topic_id = d.store_topic_id
  116. inner join third_merchant_biz b on d.third_merch_sn = b.third_merch_sn
  117. where 1 = 1
  118. <if test="merchSn != null">
  119. and b.merch_sn = #{merchSn}
  120. </if>
  121. <if test="coupon_number != null">
  122. and a.coupon_number = #{coupon_number}
  123. </if>
  124. <if test="user_id != null">
  125. and a.user_id = #{user_id}
  126. </if>
  127. <if test="send_type != null">
  128. and a.send_type = #{send_type}
  129. </if>
  130. <if test="send_types != null">
  131. and a.send_type in
  132. <foreach item="item" collection="send_types" open="(" separator="," close=")">
  133. #{item}
  134. </foreach>
  135. </if>
  136. <if test="unUsed != null and unUsed == true">
  137. and (a.order_id is null or a.order_id =0)
  138. </if>
  139. <if test="referrer != null">
  140. and a.referrer = #{referrer}
  141. </if>
  142. <if test="source_key != null">
  143. and a.source_key = #{source_key}
  144. </if>
  145. <if test="show_state != null">
  146. and a.show_state = #{show_state}
  147. </if>
  148. <if test="enabled != null and enabled == true">
  149. and a.end_time > now()
  150. </if>
  151. <if test="isUsed != null and isUsed != ''">
  152. and a.is_used = 0
  153. </if>
  154. </select>
  155. <insert id="save" parameterType="com.kmall.api.entity.UserCouponVo" useGeneratedKeys="true" keyProperty="id">
  156. insert into mall_user_coupon
  157. (
  158. `store_topic_id`,
  159. `coupon_name`,
  160. `is_used`,
  161. `coupon_number`,
  162. `user_id`,
  163. `used_time`,
  164. `order_id`,
  165. `add_time`,
  166. valid_time,
  167. `source_key`,
  168. `referrer`,
  169. show_state,
  170. end_time,
  171. type_money,
  172. send_type,
  173. create_time,
  174. mod_time,
  175. enabled
  176. )
  177. values
  178. (
  179. #{storeTopicId},
  180. #{couponName},
  181. #{isUsed},
  182. #{couponNumber},
  183. #{userId},
  184. #{usedTime},
  185. #{orderId},
  186. #{addTime},
  187. #{validTime},
  188. #{sourceKey},
  189. #{referrer},
  190. #{showState},
  191. #{endTime},
  192. #{typeMoney},
  193. #{sendType},
  194. #{createTime},
  195. #{modTime},
  196. #{enabled}
  197. )
  198. </insert>
  199. <update id="update" parameterType="com.kmall.api.entity.UserCouponVo">
  200. update mall_user_coupon
  201. <set>
  202. <if test="storeTopicId != null">`store_topic_id` = #{storeTopicId},</if>
  203. <if test="couponName != null">`coupon_name` = #{couponName},</if>
  204. <if test="isUsed != null">`is_used` = #{isUsed},</if>
  205. <if test="couponNumber != null">`coupon_number` = #{couponNumber},</if>
  206. <if test="userId != null">`user_id` = #{userId},</if>
  207. <if test="usedTime != null">`used_time` = #{usedTime},</if>
  208. <if test="orderId != null">`order_id` = #{orderId},</if>
  209. <if test="addTime != null">`add_time` = #{addTime},</if>
  210. <if test="validTime != null">`valid_time` = #{validTime},</if>
  211. <if test="sourceKey != null">`source_key` = #{sourceKey},</if>
  212. <if test="referrer != null">`referrer` = #{referrer},</if>
  213. <if test="showState != null">`show_state` = #{showState},</if>
  214. <if test="endTime != null">`end_time` = #{endTime},</if>
  215. <if test="typeMoney != null">`type_money` = #{typeMoney},</if>
  216. <if test="enabled != null">`enabled` = #{enabled},</if>
  217. <if test="sendType != null">`send_type` = #{sendType}</if>
  218. </set>
  219. where id = #{id}
  220. </update>
  221. <update id="cancelOrder" parameterType="com.kmall.api.entity.UserCouponVo">
  222. update mall_user_coupon
  223. <set>
  224. `used_time` = null,
  225. `order_id` = 0,
  226. is_used= 0
  227. </set>
  228. where id = #{id}
  229. </update>
  230. <!--根据优惠券id查询门店活动信息-->
  231. <select id="queryStoreTopicByDictId" resultType="map">
  232. SELECT
  233. t.id 'storeTopicId'
  234. FROM
  235. mall_store_topic t
  236. INNER JOIN mk_store_ticket_discount d ON t.id = d.store_topic_id
  237. WHERE d.tick_disc_id = #{ticketDiscId}
  238. </select>
  239. <select id="queryReceiveNumByStoreTopicId" resultType="java.lang.Integer">
  240. SELECT
  241. count(*)
  242. FROM
  243. mall_user_coupon cc
  244. LEFT JOIN mall_store_topic s ON cc.store_topic_id = s.id
  245. WHERE s.id = #{storeTopicId}
  246. </select>
  247. <select id="queryUserCoupons" resultMap="userCouponMap">
  248. select b.*
  249. from mall_store_topic a
  250. LEFT JOIN mall_user_coupon b ON a.id = b.store_topic_id
  251. where 1 = 1
  252. <if test="user_id != null">
  253. and b.`user_id` = #{user_id}
  254. </if>
  255. <if test="store_id != null">
  256. and a.`store_id` = #{store_id}
  257. </if>
  258. <!-- <if test="send_type != null">-->
  259. <!-- and a.send_type = #{send_type}-->
  260. <!-- </if>-->
  261. <if test="coupon_number != null">
  262. and b.coupon_number = #{coupon_number}
  263. </if>
  264. <if test="source_key != null and source_key != ''">
  265. and b.source_key = #{source_key}
  266. </if>
  267. <if test="unUsed != null and unUsed == true">
  268. and b.used_time is null and (b.order_id is null or b.order_id =0)
  269. </if>
  270. <if test="unUsed != null and unUsed == true">
  271. and (b.order_id is null or b.order_id =0)
  272. </if>
  273. <if test="unObtain != null and unObtain == true">
  274. and b.id is null
  275. </if>
  276. <choose>
  277. <when test="sidx != null and sidx.trim() != ''">
  278. order by ${sidx} ${order}
  279. </when>
  280. <otherwise>
  281. order by a.id desc
  282. </otherwise>
  283. </choose>
  284. <if test="offset != null and limit != null">
  285. limit #{offset}, #{limit}
  286. </if>
  287. </select>
  288. </mapper>