CmCouponMapper.xml 11 KB

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