CmCouponMapper.xml 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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. </if>
  66. <if test='status == "2"'>
  67. AND a.status = '2'
  68. </if>
  69. <if test='status == "3"'>
  70. AND a.endDate <![CDATA[ < ]]> NOW()
  71. </if>
  72. <if test="clubName != null and clubName != ''">
  73. AND u.name LIKE concat('%',#{clubName},'%')
  74. </if>
  75. <if test='claimStatus == "1"'>
  76. AND ccc.id IS NULL
  77. </if>
  78. <if test='claimStatus == "2"'>
  79. AND ccc.id IS NOT NULL
  80. </if>
  81. <if test='useStatus == "1"'>
  82. AND (ccc.status IS NULL OR ccc.status = #{useStatus})
  83. </if>
  84. <if test='useStatus == "2"'>
  85. AND ccc.status = #{useStatus}
  86. </if>
  87. <if test="source != null and source != ''">
  88. AND ccc.source = #{source}
  89. </if>
  90. <if test="shopName != null and shopName != ''">
  91. AND s.name LIKE concat('%',#{shopName},'%')
  92. </if>
  93. <if test="couponsMode != null and couponsMode != ''">
  94. AND a.couponsMode = #{couponsMode}
  95. </if>
  96. </where>
  97. GROUP BY a.id
  98. <choose>
  99. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  100. ORDER BY ${page.orderBy}
  101. </when>
  102. <otherwise>
  103. ORDER BY createDate DESC
  104. </otherwise>
  105. </choose>
  106. </select>
  107. <select id="findAllList" resultType="CmCoupon">
  108. SELECT
  109. <include refid="cmCouponColumns"/>
  110. FROM cm_coupon a
  111. <include refid="cmCouponJoins"/>
  112. <where>
  113. </where>
  114. <choose>
  115. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  116. ORDER BY ${page.orderBy}
  117. </when>
  118. <otherwise>
  119. </otherwise>
  120. </choose>
  121. </select>
  122. <insert id="insert" parameterType="CmCoupon" keyProperty="id" useGeneratedKeys="true">
  123. INSERT INTO cm_coupon(
  124. name,
  125. couponAmount,
  126. touchPrice,
  127. startDate,
  128. endDate,
  129. status,
  130. couponType,
  131. userId,
  132. shopId,
  133. productType,
  134. pcBanner,
  135. appletsBanner,
  136. categoryType,
  137. couponsMode,
  138. createDate,
  139. delFlag
  140. ) VALUES (
  141. #{name},
  142. #{couponAmount},
  143. #{touchPrice},
  144. #{startDate},
  145. #{endDate},
  146. #{status},
  147. #{couponType},
  148. #{userId},
  149. #{shopId},
  150. #{productType},
  151. #{pcBanner},
  152. #{appletsBanner},
  153. #{categoryType},
  154. #{couponsMode},
  155. #{createDate},
  156. #{delFlag}
  157. )
  158. </insert>
  159. <update id="update">
  160. UPDATE cm_coupon SET
  161. name = #{name},
  162. couponAmount = #{couponAmount},
  163. touchPrice = #{touchPrice},
  164. startDate = #{startDate},
  165. endDate = #{endDate},
  166. status = #{status},
  167. couponType = #{couponType},
  168. userId = #{userId},
  169. shopId = #{shopId},
  170. productType = #{productType},
  171. pcBanner = #{pcBanner},
  172. appletsBanner = #{appletsBanner},
  173. categoryType = #{categoryType},
  174. couponsMode = #{couponsMode}
  175. WHERE id = #{id}
  176. </update>
  177. <delete id="delete">
  178. DELETE FROM cm_coupon
  179. WHERE id = #{id}
  180. </delete>
  181. <select id="findByProductType" resultType="com.caimei.modules.coupon.entity.CmCouponAssociate">
  182. SELECT
  183. cca.id,
  184. cca.couponId,
  185. cca.productId,
  186. cca.pcStatus,
  187. cca.appletsStatus,
  188. cca.sort,
  189. cca.addTime,
  190. cca.delFlag,
  191. s.name AS shopName,
  192. p.name AS productName,
  193. p.mainImage AS image
  194. FROM
  195. cm_coupon_product cca
  196. LEFT JOIN product p ON cca.productId = p.productID
  197. LEFT JOIN shop s ON p.shopID = s.shopID
  198. WHERE
  199. cca.couponId = #{couponId}
  200. AND delFlag = 0
  201. ORDER BY
  202. - sort DESC
  203. </select>
  204. <insert id="insertCouponAssociate">
  205. INSERT INTO `cm_coupon_product` (
  206. `couponId`, `productId`, `pcStatus`,
  207. `appletsStatus`,
  208. `sort`, `addTime`, `delFlag`
  209. )
  210. VALUES
  211. (
  212. #{couponId}, #{productId}, #{pcStatus},
  213. #{appletsStatus},
  214. #{sort}, #{addTime}, #{delFlag}
  215. )
  216. </insert>
  217. <select id="findByCouponId" resultType="integer">
  218. SELECT id FROM cm_coupon_product WHERE couponId = #{couponId} AND delFlag = 0
  219. </select>
  220. <update id="updateCouponAssociate">
  221. UPDATE
  222. `cm_coupon_product`
  223. <set>
  224. <if test="pcStatus != null and pcStatus != ''">
  225. `pcStatus` = #{pcStatus},
  226. </if>
  227. <if test="appletsStatus != null and appletsStatus != ''">
  228. `appletsStatus` = #{appletsStatus},
  229. </if>
  230. <if test="sort != null">
  231. `sort` = #{sort},
  232. </if>
  233. </set>
  234. WHERE
  235. `id` = #{id}
  236. </update>
  237. <update id="logicDeleteCouponAssociate">
  238. UPDATE cm_coupon_product SET delFlag = 1 WHERE id = #{id}
  239. </update>
  240. <update id="updateByDelFlag">
  241. UPDATE cm_coupon SET delFlag = 1 WHERE id = #{couponId}
  242. </update>
  243. <update id="updateAssociateByDelFlag">
  244. UPDATE cm_coupon_product SET delFlag = 1 WHERE couponId = #{couponId}
  245. </update>
  246. <select id="findCouponClub" resultType="com.caimei.modules.coupon.entity.CmCouponClub">
  247. SELECT
  248. `userId`,
  249. `couponId`,
  250. orderId,
  251. `source`,
  252. `status`,
  253. `createDate`,
  254. `useDate`,
  255. `delFlag`
  256. FROM
  257. `cm_coupon_club`
  258. WHERE
  259. couponId = #{couponId}
  260. AND delFlag = 0
  261. LIMIT
  262. 1
  263. </select>
  264. <select id="findUserList" resultType="com.caimei.modules.user.entity.CmUser">
  265. SELECT
  266. u.clubID,
  267. u.userID,
  268. u.userName,
  269. u.bindMobile,
  270. u.name,
  271. u.userIdentity,
  272. c.sname AS shortName
  273. FROM
  274. club c
  275. LEFT JOIN USER u ON c.userID = u.userID
  276. WHERE
  277. c.status IN (1, 90)
  278. <if test="userID != null">
  279. AND u.userID = #{userID}
  280. </if>
  281. <if test="name != null and name != ''">
  282. AND u.name LIKE CONCAT('%',#{name},'%')
  283. </if>
  284. <if test="shortName != null and shortName != ''">
  285. AND c.sname LIKE CONCAT('%',#{shortName},'%')
  286. </if>
  287. ORDER BY
  288. userID ASC
  289. </select>
  290. <select id="findShopList" resultType="com.caimei.modules.user.entity.NewCmShop">
  291. SELECT
  292. s.shopID,
  293. s.userID,
  294. IFNULL(s.name, u.name) AS name,
  295. IFNULL(s.sname, u.realName) AS sname,
  296. IFNULL(s.contractMobile, u.bindMobile) AS contractMobile,
  297. IFNULL(s.linkMan, u.userName) AS linkMan
  298. FROM
  299. shop s
  300. LEFT JOIN USER u ON u.`shopID` = s.`shopID`
  301. WHERE
  302. s.status = 90
  303. <if test="shopID != null">
  304. AND s.shopID = #{shopID}
  305. </if>
  306. <if test="name != null and name != ''">
  307. AND (s.name LIKE CONCAT('%',#{name},'%') OR u.name LIKE CONCAT('%',#{name},'%'))
  308. </if>
  309. <if test="sname != null and sname != ''">
  310. AND (s.sname LIKE CONCAT('%',#{sname},'%') OR u.realName LIKE CONCAT('%',#{sname},'%'))
  311. </if>
  312. ORDER BY
  313. s.shopID
  314. </select>
  315. <select id="findRedemptionCodeNum" resultType="integer">
  316. SELECT COUNT(id) FROM cm_coupon_redemption_code WHERE couponId = #{couponId}
  317. </select>
  318. <select id="findByRedemptionCode" resultType="com.caimei.modules.coupon.entity.CmCouponRedemptionCode">
  319. SELECT
  320. `id`,
  321. `couponId`,
  322. `userId`,
  323. `redemptionCode`,
  324. `status`,
  325. `redemptionTime`,
  326. `addTime`
  327. FROM
  328. cm_coupon_redemption_code
  329. WHERE
  330. redemptionCode = #{redemptionCode}
  331. </select>
  332. <insert id="insertRedemptionCode">
  333. INSERT INTO `cm_coupon_redemption_code` (
  334. `couponId`,
  335. `userId`,
  336. `redemptionCode`,
  337. `status`,
  338. `redemptionTime`,
  339. `addTime`
  340. )
  341. VALUES
  342. (
  343. #{couponId},
  344. #{userId},
  345. #{redemptionCode},
  346. #{status},
  347. #{redemptionTime},
  348. #{addTime}
  349. )
  350. </insert>
  351. <select id="findRedemptionCode" resultType="com.caimei.modules.coupon.entity.CmCouponRedemptionCode">
  352. SELECT
  353. `id`,
  354. `couponId`,
  355. `userId`,
  356. `redemptionCode`,
  357. `status`,
  358. `redemptionTime`,
  359. `addTime`
  360. FROM
  361. cm_coupon_redemption_code
  362. WHERE
  363. couponId = #{couponId}
  364. <if test="status != null and status != ''">
  365. AND status = #{status}
  366. </if>
  367. ORDER BY
  368. addTime DESC
  369. </select>
  370. <select id="findQuantityRedeemed" resultType="integer">
  371. SELECT COUNT(id) FROM cm_coupon_redemption_code WHERE couponId = #{couponId} AND status = 2
  372. </select>
  373. </mapper>