ApiMkStoreTicketDiscountMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  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.mk.ApiMkStoreTicketDiscountMapper">
  4. <resultMap type="com.kmall.api.entity.mk.MkStoreTicketDiscountVo" id="mkStoreTicketDiscountMap">
  5. <result property="tickDiscId" column="tick_disc_id"/>
  6. <result property="tickDiscType" column="tick_disc_type"/>
  7. <result property="tickDiscSubTitle" column="tick_disc_sub_title"/>
  8. <result property="merchSn" column="merch_sn"/>
  9. <result property="thirdMerchSn" column="third_merch_sn"/>
  10. <result property="storeId" column="store_id"/>
  11. <result property="storeTopicId" column="store_topic_id"/>
  12. <result property="name" column="name"/>
  13. <result property="voucherMoney" column="voucher_money"/>
  14. <result property="voucherCond" column="voucher_cond"/>
  15. <result property="discRatio" column="disc_ratio"/>
  16. <result property="discCond" column="disc_cond"/>
  17. <result property="exchCond" column="exch_cond"/>
  18. <result property="effectTimeType" column="effect_time_type"/>
  19. <result property="fixBegTime" column="fix_beg_time"/>
  20. <result property="fixEndTime" column="fix_end_time"/>
  21. <result property="postponeNum" column="postpone_num"/>
  22. <result property="validDayNum" column="valid_day_num"/>
  23. <result property="ticketNum" column="ticket_num"/>
  24. <result property="applyType" column="apply_type"/>
  25. <result property="getEnter" column="get_enter"/>
  26. <result property="canShareGet" column="can_share_get"/>
  27. <result property="limitNum" column="limit_num"/>
  28. <result property="advImgUrl" column="adv_img_url"/>
  29. <result property="storeLogoUrl" column="store_logo_url"/>
  30. <result property="storeName" column="store_name"/>
  31. <result property="ticketColor" column="ticket_color"/>
  32. <result property="optDecl" column="opt_decl"/>
  33. <result property="discDecl" column="disc_decl"/>
  34. <result property="useNoti" column="use_noti"/>
  35. <result property="svrTel" column="svr_tel"/>
  36. <result property="isValid" column="is_valid"/>
  37. <result property="note" column="note"/>
  38. <result property="createrSn" column="creater_sn"/>
  39. <result property="createTime" column="create_time"/>
  40. <result property="moderSn" column="moder_sn"/>
  41. <result property="modTime" column="mod_time"/>
  42. <result property="tstm" column="tstm"/>
  43. <result property="sendType" column="send_type"/>
  44. <result property="discSellCount" column="disc_sell_count"/>
  45. <result property="discSellDoller" column="disc_sell_doller"/>
  46. <result property="guid" column="guid"/>
  47. <result property="userId" column="user_id"/>
  48. <result property="referrer" column="referrer"/>
  49. <result property="isUsed" column="is_used"/>
  50. <result property="isPast" column="is_past"/>
  51. </resultMap>
  52. <select id="queryObject" resultType="com.kmall.api.entity.mk.MkStoreTicketDiscountVo">
  53. select
  54. `tick_disc_id`,
  55. `tick_disc_type`,
  56. `tick_disc_sub_title`,
  57. `merch_sn`,
  58. `third_merch_sn`,
  59. `store_id`,goods_biz_type,
  60. `store_topic_id`,
  61. `name`,
  62. `voucher_money`,
  63. `voucher_cond`,
  64. `disc_ratio`,
  65. `disc_cond`,
  66. `exch_cond`,
  67. `effect_time_type`,
  68. `fix_beg_time`,
  69. `fix_end_time`,
  70. `postpone_num`,
  71. `valid_day_num`,
  72. `ticket_num`,
  73. `apply_type`,
  74. `get_enter`,
  75. `can_share_get`,
  76. `limit_num`,
  77. `adv_img_url`,
  78. `store_logo_url`,
  79. `store_name`,
  80. `ticket_color`,
  81. `opt_decl`,
  82. `disc_decl`,
  83. `use_noti`,
  84. `svr_tel`,
  85. `is_valid`,
  86. disc_sell_count,
  87. disc_sell_doller,
  88. `note`,
  89. `creater_sn`,
  90. `create_time`,
  91. `moder_sn`,
  92. `mod_time`,
  93. `tstm`,
  94. `send_type`,guid
  95. from mk_store_ticket_discount d
  96. where tick_disc_id = #{id}
  97. </select>
  98. <!--根据用户id、优惠券id查询优惠券详情信息-->
  99. <select id="queryDiscObjectByUserId" resultType="com.kmall.api.entity.mk.MkStoreTicketDiscountVo">
  100. select
  101. `tick_disc_id`,
  102. `tick_disc_type`,
  103. `tick_disc_sub_title`,
  104. `merch_sn`,
  105. `third_merch_sn`,
  106. `store_id`,goods_biz_type,
  107. `store_topic_id`,
  108. `name`,
  109. `voucher_money`,
  110. `voucher_cond`,
  111. `disc_ratio`,
  112. `disc_cond`,
  113. `exch_cond`,
  114. `effect_time_type`,
  115. `fix_beg_time`,
  116. `fix_end_time`,
  117. `postpone_num`,
  118. `valid_day_num`,
  119. `ticket_num`,
  120. `apply_type`,
  121. `get_enter`,
  122. `can_share_get`,
  123. `limit_num`,
  124. `adv_img_url`,
  125. `store_logo_url`,
  126. `store_name`,
  127. `ticket_color`,
  128. `opt_decl`,
  129. `disc_decl`,
  130. `use_noti`,
  131. `svr_tel`,
  132. `is_valid`,
  133. disc_sell_count,
  134. disc_sell_doller,
  135. `note`,
  136. `creater_sn`,
  137. `create_time`,
  138. `moder_sn`,
  139. `mod_time`,
  140. `tstm`,
  141. `send_type`,
  142. guid,
  143. is_past,
  144. ( SELECT count( * ) FROM mall_user_coupon WHERE store_topic_id = d.store_topic_id AND user_id = #{userId} ) 'receiveCount'
  145. from mk_store_ticket_discount d
  146. where tick_disc_id = #{id}
  147. </select>
  148. <!--根据用户优惠券id、门店id、用户id查询优惠券详情信息-->
  149. <select id="queryTickObjectByIdAndStoreIdAndUserId" resultType="com.kmall.api.entity.mk.MkStoreTicketDiscountVo">
  150. select
  151. d.`tick_disc_id`,
  152. d.`tick_disc_type`,
  153. d.`tick_disc_sub_title`,
  154. d.`merch_sn`,
  155. d.`third_merch_sn`,
  156. d.`store_id`,
  157. d.goods_biz_type,
  158. d.`store_topic_id`,
  159. d.`name`,
  160. d.`voucher_money`,
  161. d.`voucher_cond`,
  162. d.`disc_ratio`,
  163. d.`disc_cond`,
  164. d.`exch_cond`,
  165. d.`effect_time_type`,
  166. d.`fix_beg_time`,
  167. d.`fix_end_time`,
  168. d.`postpone_num`,
  169. d.`valid_day_num`,
  170. d.`ticket_num`,
  171. d.`apply_type`,
  172. d.`get_enter`,
  173. d.`can_share_get`,
  174. d.`limit_num`,
  175. d.`adv_img_url`,
  176. d.`store_logo_url`,
  177. d.`store_name`,
  178. d.`ticket_color`,
  179. d.`opt_decl`,
  180. d.`disc_decl`,
  181. d.`use_noti`,
  182. d.`svr_tel`,
  183. d.`is_valid`,
  184. d.disc_sell_count,
  185. d.disc_sell_doller,
  186. d.`note`,
  187. d.`creater_sn`,
  188. d.`create_time`,
  189. d.`moder_sn`,
  190. d.`mod_time`,
  191. d.`tstm`,
  192. d.`send_type`,d.guid,cc.add_time addTime,cc.valid_time validTime,cc.end_time endTime,cc.id 'couponId',d.is_past,
  193. ( SELECT count( * ) FROM mall_user_coupon WHERE store_topic_id = d.store_topic_id AND user_id = #{userId} ) 'receiveCount'
  194. from mk_store_ticket_discount d LEFT JOIN mall_user_coupon cc on d.store_topic_id = cc.store_topic_id
  195. where cc.id = #{couponId} and store_id = #{storeId}
  196. </select>
  197. <select id="queryList" resultType="com.kmall.api.entity.mk.MkStoreTicketDiscountVo">
  198. select
  199. `tick_disc_id`,
  200. `tick_disc_type`,
  201. `tick_disc_sub_title`,
  202. `merch_sn`,
  203. `third_merch_sn`,
  204. `store_id`,goods_biz_type,
  205. `store_topic_id`,
  206. `name`,
  207. `voucher_money`,
  208. `voucher_cond`,
  209. `disc_ratio`,
  210. `disc_cond`,
  211. `exch_cond`,
  212. `effect_time_type`,
  213. `fix_beg_time`,
  214. `fix_end_time`,
  215. `postpone_num`,
  216. `valid_day_num`,
  217. `ticket_num`,
  218. `apply_type`,
  219. `get_enter`,
  220. `can_share_get`,
  221. `limit_num`,
  222. `adv_img_url`,
  223. `store_logo_url`,
  224. `store_name`,
  225. `ticket_color`,
  226. `opt_decl`,
  227. `disc_decl`,
  228. `use_noti`,
  229. `svr_tel`,
  230. `is_valid`,
  231. disc_sell_count,
  232. disc_sell_doller,
  233. `note`,
  234. `creater_sn`,
  235. `create_time`,
  236. `moder_sn`,
  237. `mod_time`,
  238. `tstm`,
  239. `send_type`,guid
  240. from mk_store_ticket_discount
  241. WHERE 1=1
  242. <if test="name != null and name.trim() != ''">
  243. AND name LIKE concat('%',#{name},'%')
  244. </if>
  245. <if test="storeId != null and storeId != ''">
  246. AND store_id = #{storeId}
  247. </if>
  248. <choose>
  249. <when test="sidx != null and sidx.trim() != ''">
  250. order by ${sidx} ${order}
  251. </when>
  252. <otherwise>
  253. order by tick_disc_id desc
  254. </otherwise>
  255. </choose>
  256. <if test="offset != null and limit != null">
  257. limit #{offset}, #{limit}
  258. </if>
  259. </select>
  260. <select id="queryTotal" resultType="int">
  261. select count(*) from mk_store_ticket_discount
  262. WHERE 1=1
  263. <if test="name != null and name.trim() != ''">
  264. AND name LIKE concat('%',#{name},'%')
  265. </if>
  266. <if test="storeId != null and storeId != ''">
  267. AND store_id = #{storeId}
  268. </if>
  269. </select>
  270. <!--查询用户已领取的优惠券信息-->
  271. <select id="queryStoreDiscountByUserId" resultType="com.kmall.api.entity.mk.MkStoreTicketDiscountVo">
  272. SELECT
  273. d.*,
  274. a.user_id,
  275. a.referrer,
  276. a.is_used,a.add_time 'addTime',
  277. a.valid_time 'validTime',a.id 'couponId'
  278. FROM
  279. mk_store_ticket_discount d
  280. INNER JOIN mall_user_coupon a ON a.store_topic_id = d.store_topic_id
  281. INNER JOIN third_merchant_biz b on d.third_merch_sn = b.third_merch_sn
  282. WHERE
  283. 1 = 1 and d.is_valid = 0
  284. <if test="merchSn != null">
  285. and b.merch_sn = #{merchSn}
  286. </if>
  287. <if test="couponNumber != null">
  288. and a.coupon_number = #{couponNumber}
  289. </if>
  290. <if test="userId != null">
  291. and a.user_id = #{userId}
  292. </if>
  293. <if test="storeId != null">
  294. and d.store_id = #{storeId}
  295. </if>
  296. <if test="storeTopicId != null">
  297. and d.store_topic_id = #{storeTopicId}
  298. </if>
  299. <if test="tickDiscId != null">
  300. and d.tick_disc_id = #{tickDiscId}
  301. </if>
  302. <if test="unUsed != null and unUsed == true">
  303. and (a.order_id is null or a.order_id =0)
  304. </if>
  305. <if test="referrer != null">
  306. and a.referrer = #{referrer}
  307. </if>
  308. <if test="sourceKey != null">
  309. and a.source_key = #{sourceKey}
  310. </if>
  311. <if test="showState != null">
  312. and a.show_state = #{showState}
  313. </if>
  314. <if test="isUsed != null and isUsed == true">
  315. and a.is_used = 0
  316. </if>
  317. <if test="isUsed != null and isUsed == false">
  318. and a.is_used = 1
  319. </if>
  320. <if test="enabled != null and enabled == true">
  321. and a.enabled = 1 and a.end_time > NOW()
  322. </if>
  323. <if test="enabled != null and enabled == false">
  324. and a.enabled = 0 and a.end_time <![CDATA[ < ]]> NOW()
  325. </if>
  326. </select>
  327. <!--详情页根据门店id、用户id、业务类型获取当前门店所有的优惠券-->
  328. <!--优惠券页查询门店id可领取的优惠券信息-->
  329. <select id="getDiscountByStoreIdList" resultType="com.kmall.api.entity.mk.MkStoreTicketDiscountVo">
  330. SELECT
  331. d.*,
  332. ( SELECT count( * ) FROM mall_user_coupon WHERE store_topic_id = d.store_topic_id AND user_id = #{userId} ) 'receiveCount'
  333. FROM
  334. mk_store_ticket_discount d
  335. WHERE
  336. tick_disc_id IN (
  337. SELECT
  338. d.tick_disc_id
  339. FROM
  340. mk_store_ticket_discount d
  341. LEFT JOIN mall_user_coupon c ON d.store_topic_id = c.store_topic_id
  342. AND c.user_id = #{userId}
  343. WHERE
  344. 1 = 1
  345. AND d.ticket_num >= 0
  346. AND d.is_valid = 0
  347. <if test="storeId != null">
  348. and d.store_id = #{storeId}
  349. </if>
  350. <if test="storeTopicId != null">
  351. and d.store_topic_id = #{storeTopicId}
  352. </if>
  353. <if test="tickDiscId != null">
  354. and d.tick_disc_id = #{tickDiscId}
  355. </if>
  356. <if test="isUsed != null">
  357. and c.is_used = #{isUsed}
  358. </if>
  359. <if test="goodsBizType != null">
  360. and d.goods_biz_type = #{goodsBizType}
  361. </if>
  362. <if test="isPast != null">
  363. AND d.is_past = #{isPast}
  364. </if>
  365. <if test="notIsPast != null">
  366. AND d.is_past <![CDATA[ <> ]]> #{notIsPast}
  367. </if>
  368. )
  369. </select>
  370. <select id="getTotalByDiscountByStoreId" resultType="int">
  371. SELECT count(*)
  372. FROM
  373. mk_store_ticket_discount d
  374. WHERE
  375. tick_disc_id IN (
  376. SELECT
  377. d.tick_disc_id
  378. FROM
  379. mk_store_ticket_discount d
  380. LEFT JOIN mall_user_coupon c ON d.store_topic_id = c.store_topic_id
  381. AND c.user_id = #{userId}
  382. WHERE
  383. 1 = 1
  384. AND d.ticket_num >= 0
  385. AND d.is_valid = 0
  386. <if test="storeId != null">
  387. and d.store_id = #{storeId}
  388. </if>
  389. <if test="storeTopicId != null">
  390. and d.store_topic_id = #{storeTopicId}
  391. </if>
  392. <if test="tickDiscId != null">
  393. and d.tick_disc_id = #{tickDiscId}
  394. </if>
  395. <if test="isUsed != null">
  396. and c.is_used = #{isUsed}
  397. </if>
  398. <if test="goodsBizType != null">
  399. and d.goods_biz_type = #{goodsBizType}
  400. </if>
  401. <if test="isPast != null">
  402. AND d.is_past = #{isPast}
  403. </if>
  404. )
  405. </select>
  406. <update id="update" parameterType="com.kmall.admin.entity.mk.store.MkStoreTicketDiscountEntity">
  407. update mk_store_ticket_discount
  408. <set>
  409. <if test="ticketNum != null">`ticket_num` = #{ticketNum}</if>
  410. </set>
  411. where tick_disc_id = #{tickDiscId}
  412. </update>
  413. <!--获取购物车中根据门店id、用户id、业务类型,获取is_used已领取、is_valid有效、enabled可用、ticket_num有库存、isPast未过期、且失效时间没超时的优惠券-->
  414. <select id="getDiscountByCartGoodsIdList" resultType="com.kmall.api.entity.mk.MkStoreTicketDiscountVo">
  415. SELECT
  416. d.*,
  417. c.user_id,
  418. c.referrer,
  419. c.is_used,
  420. c.enabled,c.add_time 'addTime',
  421. (select count(*) from mall_user_coupon where store_topic_id = d.store_topic_id AND user_id = #{userId} ) 'receiveCount'
  422. FROM
  423. mk_store_ticket_discount d
  424. LEFT JOIN mall_user_coupon c ON d.store_topic_id = c.store_topic_id AND c.user_id = #{userId}
  425. WHERE
  426. 1 = 1 AND d.ticket_num >= 0 AND d.is_valid = 0 AND c.enabled = 1 AND c.valid_time <![CDATA[ < ]]> now()
  427. <if test="storeId != null">
  428. AND d.store_id = #{storeId}
  429. </if>
  430. <if test="storeTopicId != null">
  431. AND d.store_topic_id = #{storeTopicId}
  432. </if>
  433. <if test="tickDiscId != null">
  434. AND d.tick_disc_id = #{tickDiscId}
  435. </if>
  436. <if test="isUsed != null">
  437. AND c.is_used = #{isUsed}
  438. </if>
  439. <if test="goodsBizType != null">
  440. AND d.goods_biz_type = #{goodsBizType}
  441. </if>
  442. <if test="isPast != null">
  443. AND d.is_past = #{isPast}
  444. </if>
  445. </select>
  446. <select id="getDiscountByUserCouponId" resultType="com.kmall.api.entity.mk.MkStoreTicketDiscountVo">
  447. select
  448. d.`tick_disc_id`,
  449. d.`tick_disc_type`,
  450. d.`tick_disc_sub_title`,
  451. d.`merch_sn`,
  452. d.`third_merch_sn`,
  453. d.`store_id`,
  454. d.goods_biz_type,
  455. d.`store_topic_id`,
  456. d.`name`,
  457. d.`voucher_money`,
  458. d.`voucher_cond`,
  459. d.`disc_ratio`,
  460. d.`disc_cond`,
  461. d.`exch_cond`,
  462. d.`effect_time_type`,
  463. d.`fix_beg_time`,
  464. d.`fix_end_time`,
  465. d.`postpone_num`,
  466. d.`valid_day_num`,
  467. d.`ticket_num`,
  468. d.`apply_type`,
  469. d.`get_enter`,
  470. d.`can_share_get`,
  471. d.`limit_num`,
  472. d.`adv_img_url`,
  473. d.`store_logo_url`,
  474. d.`store_name`,
  475. d.`ticket_color`,
  476. d.`opt_decl`,
  477. d.`disc_decl`,
  478. d.`use_noti`,
  479. d.`svr_tel`,
  480. d.`is_valid`,
  481. d.disc_sell_count,
  482. d.disc_sell_doller,
  483. d.`note`,
  484. d.`send_type`,
  485. d.guid
  486. from mk_store_ticket_discount d
  487. LEFT JOIN mall_user_coupon c ON d.store_topic_id = c.store_topic_id
  488. WHERE
  489. c.id = #{userCouponId}
  490. </select>
  491. </mapper>