CmCouponMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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.caimei.modules.coupon.dao.CmCouponDao">
  4. <sql id="cmCouponColumns">
  5. a.id AS "id",
  6. a.name AS "name",
  7. a.couponAmount AS "couponAmount",
  8. a.touchPrice AS "touchPrice",
  9. a.startDate AS "startDate",
  10. a.endDate AS "endDate",
  11. a.receivePeriod,
  12. a.receiveFlag,
  13. a.usePeriod,
  14. a.status AS "status",
  15. a.couponType AS "couponType",
  16. a.vipFlag AS "vipFlag",
  17. a.userId AS "userId",
  18. a.shopId AS "shopId",
  19. a.productType AS "productType",
  20. a.pcBanner AS "pcBanner",
  21. a.appletsBanner AS "appletsBanner",
  22. a.categoryType AS "categoryType",
  23. a.couponsMode AS "couponsMode",
  24. a.createDate AS "createDate",
  25. a.delFlag AS "delFlag"
  26. </sql>
  27. <sql id="cmCouponJoins">
  28. </sql>
  29. <select id="get" resultType="CmCoupon">
  30. SELECT
  31. <include refid="cmCouponColumns"/>
  32. FROM cm_coupon a
  33. <include refid="cmCouponJoins"/>
  34. WHERE a.id = #{id}
  35. </select>
  36. <select id="findList" resultType="CmCoupon">
  37. SELECT
  38. <include refid="cmCouponColumns"/>,
  39. u.name AS "clubName",
  40. s.name AS "shopName"
  41. FROM cm_coupon a
  42. LEFT JOIN cm_coupon_club ccc ON ccc.couponId = a.id
  43. LEFT JOIN USER u ON u.userID = a.userId
  44. LEFT JOIN shop s ON s.shopID = a.shopId
  45. <include refid="cmCouponJoins"/>
  46. <where>
  47. AND a.delFlag = 0 AND a.vipFlag != '1'
  48. <if test="couponType != null">
  49. AND a.couponType = #{couponType}
  50. </if>
  51. <if test="name != null and name != ''">
  52. AND a.name LIKE
  53. <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
  54. <if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
  55. <if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
  56. </if>
  57. <if test="startDate != null and startDate != ''">
  58. AND a.startDate <![CDATA[ >= ]]> #{startDate}
  59. </if>
  60. <if test="endDate != null and endDate != ''">
  61. AND a.endDate <![CDATA[ <= ]]> #{endDate}
  62. </if>
  63. <if test='status == "0"'>
  64. AND a.startDate <![CDATA[ > ]]> NOW()
  65. </if>
  66. <if test='status == "1"'>
  67. AND a.startDate <![CDATA[ <= ]]> NOW()
  68. AND a.endDate <![CDATA[ >= ]]> NOW()
  69. AND a.status != '2'
  70. </if>
  71. <if test='status == "2"'>
  72. AND a.status = '2'
  73. </if>
  74. <if test='status == "3"'>
  75. AND a.endDate <![CDATA[ < ]]> NOW()
  76. </if>
  77. <if test="clubName != null and clubName != ''">
  78. AND u.name LIKE concat('%',#{clubName},'%')
  79. </if>
  80. <if test='claimStatus == "1"'>
  81. AND ccc.id IS NULL
  82. </if>
  83. <if test='claimStatus == "2"'>
  84. AND ccc.id IS NOT NULL
  85. </if>
  86. <if test='useStatus == "1"'>
  87. AND (ccc.status IS NULL OR ccc.status = #{useStatus})
  88. </if>
  89. <if test='useStatus == "2"'>
  90. AND ccc.status = #{useStatus}
  91. </if>
  92. <if test="source != null and source != ''">
  93. AND ccc.source = #{source}
  94. </if>
  95. <if test="shopName != null and shopName != ''">
  96. AND s.name LIKE concat('%',#{shopName},'%')
  97. </if>
  98. <if test="couponsMode != null and couponsMode != ''">
  99. AND a.couponsMode = #{couponsMode}
  100. </if>
  101. </where>
  102. GROUP BY a.id
  103. <choose>
  104. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  105. ORDER BY ${page.orderBy}
  106. </when>
  107. <otherwise>
  108. ORDER BY createDate DESC
  109. </otherwise>
  110. </choose>
  111. </select>
  112. <select id="findAllList" resultType="CmCoupon">
  113. SELECT
  114. <include refid="cmCouponColumns"/>
  115. FROM cm_coupon a
  116. <include refid="cmCouponJoins"/>
  117. <where>
  118. </where>
  119. <choose>
  120. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  121. ORDER BY ${page.orderBy}
  122. </when>
  123. <otherwise>
  124. </otherwise>
  125. </choose>
  126. </select>
  127. <insert id="insert" parameterType="CmCoupon" keyProperty="id" useGeneratedKeys="true">
  128. INSERT INTO cm_coupon(
  129. name,
  130. couponAmount,
  131. touchPrice,
  132. startDate,
  133. endDate,
  134. receivePeriod,
  135. receiveFlag,
  136. usePeriod,
  137. status,
  138. couponType,
  139. vipFlag,
  140. userId,
  141. shopId,
  142. productType,
  143. pcBanner,
  144. appletsBanner,
  145. categoryType,
  146. couponsMode,
  147. createDate,
  148. delFlag
  149. ) VALUES (
  150. #{name},
  151. #{couponAmount},
  152. #{touchPrice},
  153. #{startDate},
  154. #{endDate},
  155. #{receivePeriod},
  156. #{receiveFlag},
  157. #{usePeriod},
  158. #{status},
  159. #{couponType},
  160. #{vipFlag},
  161. #{userId},
  162. #{shopId},
  163. #{productType},
  164. #{pcBanner},
  165. #{appletsBanner},
  166. #{categoryType},
  167. #{couponsMode},
  168. #{createDate},
  169. #{delFlag}
  170. )
  171. </insert>
  172. <update id="update">
  173. UPDATE cm_coupon SET
  174. name = #{name},
  175. couponAmount = #{couponAmount},
  176. touchPrice = #{touchPrice},
  177. startDate = #{startDate},
  178. endDate = #{endDate},
  179. receivePeriod = #{receivePeriod},
  180. receiveFlag = #{receiveFlag},
  181. usePeriod = #{usePeriod},
  182. status = #{status},
  183. couponType = #{couponType},
  184. vipFlag = #{vipFlag},
  185. userId = #{userId},
  186. shopId = #{shopId},
  187. productType = #{productType},
  188. pcBanner = #{pcBanner},
  189. appletsBanner = #{appletsBanner},
  190. categoryType = #{categoryType},
  191. couponsMode = #{couponsMode}
  192. WHERE id = #{id}
  193. </update>
  194. <delete id="delete">
  195. DELETE FROM cm_coupon
  196. WHERE id = #{id}
  197. </delete>
  198. <select id="findByProductType" resultType="com.caimei.modules.coupon.entity.CmCouponAssociate">
  199. SELECT
  200. cca.id,
  201. cca.couponId,
  202. cca.productId,
  203. cca.pcStatus,
  204. cca.appletsStatus,
  205. cca.sort,
  206. cca.addTime,
  207. cca.delFlag,
  208. s.name AS shopName,
  209. p.name AS productName,
  210. p.mainImage AS image
  211. FROM
  212. cm_coupon_product cca
  213. LEFT JOIN product p ON cca.productId = p.productID
  214. LEFT JOIN shop s ON p.shopID = s.shopID
  215. WHERE
  216. cca.couponId = #{couponId}
  217. AND delFlag = 0
  218. ORDER BY
  219. - sort DESC
  220. </select>
  221. <insert id="insertCouponAssociate">
  222. INSERT INTO `cm_coupon_product` (
  223. `couponId`, `productId`, `pcStatus`,
  224. `appletsStatus`,
  225. `sort`, `addTime`, `delFlag`
  226. )
  227. VALUES
  228. (
  229. #{couponId}, #{productId}, #{pcStatus},
  230. #{appletsStatus},
  231. #{sort}, #{addTime}, #{delFlag}
  232. )
  233. </insert>
  234. <select id="findByCouponId" resultType="integer">
  235. SELECT id FROM cm_coupon_product WHERE couponId = #{couponId} AND delFlag = 0
  236. </select>
  237. <update id="updateCouponAssociate">
  238. UPDATE
  239. `cm_coupon_product`
  240. <set>
  241. <if test="pcStatus != null and pcStatus != ''">
  242. `pcStatus` = #{pcStatus},
  243. </if>
  244. <if test="appletsStatus != null and appletsStatus != ''">
  245. `appletsStatus` = #{appletsStatus},
  246. </if>
  247. <if test="sort != null">
  248. `sort` = #{sort},
  249. </if>
  250. </set>
  251. WHERE
  252. `id` = #{id}
  253. </update>
  254. <update id="logicDeleteCouponAssociate">
  255. UPDATE cm_coupon_product SET delFlag = 1 WHERE id = #{id}
  256. </update>
  257. <update id="updateByDelFlag">
  258. UPDATE cm_coupon SET delFlag = 1 WHERE id = #{couponId}
  259. </update>
  260. <update id="updateAssociateByDelFlag">
  261. UPDATE cm_coupon_product SET delFlag = 1 WHERE couponId = #{couponId}
  262. </update>
  263. <select id="findCouponClub" resultType="com.caimei.modules.coupon.entity.CmCouponClub">
  264. SELECT
  265. `userId`,
  266. `couponId`,
  267. orderId,
  268. `source`,
  269. `status`,
  270. `createDate`,
  271. `useDate`,
  272. `delFlag`
  273. FROM
  274. `cm_coupon_club`
  275. WHERE
  276. couponId = #{couponId}
  277. AND delFlag = 0
  278. LIMIT
  279. 1
  280. </select>
  281. <select id="findUserList" resultType="com.caimei.modules.user.entity.CmUser">
  282. SELECT
  283. u.clubID,
  284. u.userID,
  285. u.userName,
  286. u.bindMobile,
  287. u.name,
  288. u.userIdentity,
  289. c.sname AS shortName
  290. FROM
  291. club c
  292. LEFT JOIN USER u ON c.userID = u.userID
  293. WHERE
  294. c.status IN (1, 90)
  295. <if test="userID != null">
  296. AND u.userID = #{userID}
  297. </if>
  298. <if test="name != null and name != ''">
  299. AND u.name LIKE CONCAT('%',#{name},'%')
  300. </if>
  301. <if test="shortName != null and shortName != ''">
  302. AND c.sname LIKE CONCAT('%',#{shortName},'%')
  303. </if>
  304. ORDER BY
  305. userID ASC
  306. </select>
  307. <select id="findShopList" resultType="com.caimei.modules.user.entity.NewCmShop">
  308. SELECT
  309. s.shopID,
  310. s.userID,
  311. IFNULL(s.name, u.name) AS name,
  312. IFNULL(s.sname, u.realName) AS sname,
  313. IFNULL(s.contractMobile, u.bindMobile) AS contractMobile,
  314. IFNULL(s.linkMan, u.userName) AS linkMan
  315. FROM
  316. shop s
  317. LEFT JOIN USER u ON u.`shopID` = s.`shopID`
  318. WHERE
  319. s.status = 90
  320. <if test="shopID != null">
  321. AND s.shopID = #{shopID}
  322. </if>
  323. <if test="name != null and name != ''">
  324. AND (s.name LIKE CONCAT('%',#{name},'%') OR u.name LIKE CONCAT('%',#{name},'%'))
  325. </if>
  326. <if test="sname != null and sname != ''">
  327. AND (s.sname LIKE CONCAT('%',#{sname},'%') OR u.realName LIKE CONCAT('%',#{sname},'%'))
  328. </if>
  329. ORDER BY
  330. s.shopID
  331. </select>
  332. <select id="findRedemptionCodeNum" resultType="integer">
  333. SELECT COUNT(id) FROM cm_coupon_redemption_code WHERE couponId = #{couponId}
  334. </select>
  335. <select id="findByRedemptionCode" resultType="com.caimei.modules.coupon.entity.CmCouponRedemptionCode">
  336. SELECT
  337. `id`,
  338. `couponId`,
  339. `clubCouponId`,
  340. `redemptionCode`,
  341. `status`,
  342. `redemptionTime`,
  343. `addTime`
  344. FROM
  345. cm_coupon_redemption_code
  346. WHERE
  347. redemptionCode = #{redemptionCode}
  348. </select>
  349. <insert id="insertRedemptionCode">
  350. INSERT INTO `cm_coupon_redemption_code` (
  351. `couponId`,
  352. `clubCouponId`,
  353. `redemptionCode`,
  354. `status`,
  355. `redemptionTime`,
  356. `addTime`
  357. )
  358. VALUES
  359. (
  360. #{couponId},
  361. #{clubCouponId},
  362. #{redemptionCode},
  363. #{status},
  364. #{redemptionTime},
  365. #{addTime}
  366. )
  367. </insert>
  368. <select id="findRedemptionCode" resultType="com.caimei.modules.coupon.entity.CmCouponRedemptionCode">
  369. SELECT
  370. `id`,
  371. `couponId`,
  372. `clubCouponId`,
  373. `redemptionCode`,
  374. `status`,
  375. `redemptionTime`,
  376. `addTime`
  377. FROM
  378. cm_coupon_redemption_code
  379. WHERE
  380. couponId = #{couponId}
  381. <if test="status != null and status != ''">
  382. AND status = #{status}
  383. </if>
  384. ORDER BY
  385. addTime DESC
  386. </select>
  387. <select id="findQuantityRedeemed" resultType="integer">
  388. SELECT COUNT(id) FROM cm_coupon_redemption_code WHERE couponId = #{couponId} AND status = 2
  389. </select>
  390. <select id="findClubCouponList" resultType="com.caimei.modules.coupon.entity.CmCoupon">
  391. SELECT
  392. cc.`id`,
  393. cc.`name`,
  394. cc.`couponAmount`,
  395. cc.`touchPrice`,
  396. cc.`startDate`,
  397. cc.`endDate`,
  398. a.`createDate` as `receiveDate`,
  399. date_add(a.createDate,interval cc.usePeriod DAY) as `useEndDate`,
  400. cc.`status`,
  401. cc.`couponType`,
  402. cc.`userId`,
  403. cc.`shopId`,
  404. cc.`productType`,
  405. cc.`pcBanner`,
  406. cc.`appletsBanner`,
  407. cc.`categoryType`,
  408. cc.`couponsMode`,
  409. cc.`createDate`,
  410. cc.`delFlag`,
  411. a.id AS clubCouponId,
  412. ccrc.redemptionCode
  413. FROM
  414. cm_coupon_club a
  415. LEFT JOIN cm_coupon cc ON a.couponId = cc.id
  416. LEFT JOIN cm_coupon_redemption_code ccrc ON a.id = ccrc.clubCouponId
  417. WHERE
  418. cc.delFlag = 0
  419. AND a.delFlag = 0
  420. AND a.userId = #{userId}
  421. AND a.status = 1
  422. AND NOW() <![CDATA[ < ]]> date_add(a.createDate,interval cc.usePeriod DAY)
  423. AND cc.status != 2
  424. ORDER BY
  425. a.createDate DESC
  426. </select>
  427. <select id="findAllProductId" resultType="integer">
  428. SELECT
  429. productId
  430. FROM
  431. cm_coupon_product
  432. WHERE
  433. couponId = #{couponId}
  434. AND (
  435. pcStatus = 1
  436. OR appletsStatus = 1
  437. )
  438. </select>
  439. <select id="findNotRedeemedCoupon" resultType="com.caimei.modules.coupon.entity.CmCoupon">
  440. SELECT
  441. a.`id`,
  442. a.`name`,
  443. a.`couponAmount`,
  444. a.`touchPrice`,
  445. a.`startDate`,
  446. a.`endDate`,
  447. a.`status`,
  448. a.`couponType`,
  449. a.`userId`,
  450. a.`shopId`,
  451. a.`productType`,
  452. a.`pcBanner`,
  453. a.`appletsBanner`,
  454. a.`categoryType`,
  455. a.`couponsMode`,
  456. a.`createDate`,
  457. a.`delFlag`,
  458. ccrc.redemptionCode
  459. FROM
  460. cm_coupon a
  461. LEFT JOIN cm_coupon_redemption_code ccrc ON a.id = ccrc.couponId
  462. WHERE
  463. a.status != 2
  464. AND a.delFlag = 0
  465. AND NOW() BETWEEN a.startDate
  466. AND a.endDate
  467. AND a.couponsMode = 1
  468. AND ccrc.status = 1
  469. </select>
  470. <update id="updateClubCoupon">
  471. UPDATE
  472. cm_coupon_club
  473. SET
  474. STATUS = 2,
  475. orderId = #{orderId},
  476. useDate = NOW()
  477. WHERE
  478. id = #{clubCouponId}
  479. </update>
  480. </mapper>