CmCouponClubMapper.xml 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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.CmCouponClubDao">
  4. <sql id="cmCouponClubColumns">
  5. a.id AS "id",
  6. a.userId AS "userId",
  7. a.couponId AS "couponId",
  8. a.orderId AS "orderId",
  9. a.source AS "source",
  10. a.status AS "status",
  11. a.createDate AS "createDate",
  12. a.useDate AS "useDate",
  13. a.delFlag AS "delFlag",
  14. u.name AS "clubName"
  15. </sql>
  16. <sql id="cmCouponClubJoins">
  17. LEFT JOIN user u ON u.userID = a.userId
  18. </sql>
  19. <select id="get" resultType="CmCouponClub">
  20. SELECT
  21. <include refid="cmCouponClubColumns"/>
  22. FROM cm_coupon_club a
  23. <include refid="cmCouponClubJoins"/>
  24. WHERE a.id = #{id}
  25. </select>
  26. <select id="findList" resultType="CmCouponClub">
  27. SELECT
  28. <include refid="cmCouponClubColumns"/>
  29. FROM cm_coupon_club a
  30. <include refid="cmCouponClubJoins"/>
  31. <where>
  32. <if test="couponId != null">
  33. AND a.couponId = #{couponId}
  34. </if>
  35. <if test="userId != null">
  36. AND a.userId = #{userId}
  37. </if>
  38. <if test="source != null and source != ''">
  39. AND a.source = #{source}
  40. </if>
  41. <if test="status != null and status != ''">
  42. AND a.status = #{status}
  43. </if>
  44. <if test="createDate != null and createDate != ''">
  45. AND a.createDate > #{createDate}
  46. </if>
  47. <if test="useDate != null and useDate != ''">
  48. AND a.useDate > #{useDate}
  49. </if>
  50. <if test="clubName != null and clubName != ''">
  51. AND u.name LIKE CONCAT('%',#{clubName},'%')
  52. </if>
  53. </where>
  54. <choose>
  55. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  56. ORDER BY ${page.orderBy}
  57. </when>
  58. <otherwise>
  59. ORDER BY a.createDate DESC
  60. </otherwise>
  61. </choose>
  62. </select>
  63. <select id="findAllList" resultType="CmCouponClub">
  64. SELECT
  65. <include refid="cmCouponClubColumns"/>
  66. FROM cm_coupon_club a
  67. <include refid="cmCouponClubJoins"/>
  68. <where>
  69. </where>
  70. <choose>
  71. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  72. ORDER BY ${page.orderBy}
  73. </when>
  74. <otherwise>
  75. </otherwise>
  76. </choose>
  77. </select>
  78. <insert id="insert" parameterType="CmCouponClub" keyProperty="id" useGeneratedKeys="true">
  79. INSERT INTO cm_coupon_club(
  80. userId,
  81. couponId,
  82. orderId,
  83. returnedId,
  84. source,
  85. status,
  86. createDate,
  87. useDate,
  88. delFlag
  89. ) VALUES (
  90. #{userId},
  91. #{couponId},
  92. #{orderId},
  93. #{returnedId},
  94. #{source},
  95. #{status},
  96. #{createDate},
  97. #{useDate},
  98. #{delFlag}
  99. )
  100. </insert>
  101. <update id="update">
  102. UPDATE cm_coupon_club SET
  103. userId = #{userId},
  104. couponId = #{couponId},
  105. orderId = #{orderId},
  106. source = #{source},
  107. status = #{status},
  108. createDate = #{createDate},
  109. useDate = #{useDate},
  110. delFlag = #{delFlag}
  111. WHERE id = #{id}
  112. </update>
  113. <select id="receivingUserList" resultType="com.caimei.modules.coupon.entity.CmCouponClub">
  114. SELECT
  115. c.userID AS "userId",
  116. c.name AS "clubName",
  117. COUNT(cc.id) AS "num"
  118. FROM
  119. club c
  120. LEFT JOIN cm_coupon_club ccc ON c.userID = ccc.userId
  121. AND ccc.delFlag = 0
  122. AND ccc.status = 1
  123. LEFT JOIN cm_coupon cc ON ccc.couponId = cc.id
  124. AND cc.delFlag = 0
  125. AND NOW() BETWEEN cc.startDate
  126. AND cc.endDate
  127. AND cc.status != 2
  128. AND NOW() <![CDATA[ < ]]> DATE_ADD(ccc.createDate,INTERVAL cc.usePeriod DAY)
  129. WHERE
  130. c.status IN (1, 90)
  131. <if test="clubName != null and clubName != ''">
  132. AND c.name LIKE CONCAT('%',#{clubName},'%')
  133. </if>
  134. <if test="userId != null">
  135. AND c.userID = #{userId}
  136. </if>
  137. GROUP BY
  138. c.userID
  139. ORDER BY
  140. COUNT(cc.id) DESC
  141. </select>
  142. <select id="findClubCoupon" resultType="com.caimei.modules.coupon.entity.CmCouponClub">
  143. SELECT
  144. <include refid="cmCouponClubColumns"/>,
  145. cc.couponAmount,
  146. cc.touchPrice,
  147. cc.couponType,
  148. cc.status AS "couponStatus",
  149. cc.startDate,
  150. cc.endDate,
  151. co.orderNo
  152. FROM
  153. cm_coupon_club a
  154. <include refid="cmCouponClubJoins"/>
  155. LEFT JOIN cm_coupon cc ON a.couponId = cc.id
  156. LEFT JOIN cm_order co ON co.orderID = a.orderId
  157. WHERE
  158. a.delFlag = 0
  159. AND cc.delFlag = 0
  160. AND a.userId = #{userId}
  161. <if test="couponType != null">
  162. AND cc.couponType = #{couponType}
  163. </if>
  164. <if test="status != null and status != ''">
  165. AND a.status = #{status}
  166. </if>
  167. <if test='couponStatus == "0"'>
  168. AND cc.startDate <![CDATA[ > ]]> NOW()
  169. AND cc.status != '2'
  170. </if>
  171. <if test='couponStatus == "1"'>
  172. AND cc.startDate <![CDATA[ <= ]]> NOW()
  173. AND cc.endDate <![CDATA[ >= ]]> NOW()
  174. AND cc.status != '2'
  175. </if>
  176. <if test='couponStatus == "2"'>
  177. AND cc.status = '2'
  178. </if>
  179. <if test='couponStatus == "3"'>
  180. AND cc.endDate <![CDATA[ < ]]> NOW()
  181. AND cc.status != '2'
  182. </if>
  183. ORDER BY
  184. a.createDate DESC
  185. </select>
  186. <select id="findCouponRedemptionCode" resultType="com.caimei.modules.coupon.entity.CmCouponRedemptionCode">
  187. SELECT
  188. `id`,
  189. `couponId`,
  190. `clubCouponId`,
  191. `redemptionCode`,
  192. `status`,
  193. `redemptionTime`,
  194. `addTime`
  195. FROM
  196. `cm_coupon_redemption_code`
  197. WHERE
  198. redemptionCode = #{redemptionCode}
  199. </select>
  200. <select id="getCoupons" resultType="com.caimei.modules.coupon.entity.CmCoupon">
  201. SELECT
  202. `id` AS "couponId",
  203. `couponAmount`,
  204. `touchPrice`,
  205. `startDate`,
  206. `endDate`,
  207. `couponType`,
  208. `userId`,
  209. `shopId`,
  210. `productType`,
  211. `categoryType`
  212. FROM
  213. cm_coupon
  214. WHERE
  215. delFlag = 0
  216. AND status != 2
  217. AND id = #{couponId}
  218. </select>
  219. <update id="updateRedemptionCode">
  220. UPDATE
  221. cm_coupon_redemption_code
  222. SET
  223. status = 2,
  224. redemptionTime = NOW(),
  225. clubCouponId = #{clubCouponId}
  226. WHERE
  227. id = #{id}
  228. </update>
  229. <update id="deleteByReturnedId">
  230. UPDATE cm_coupon_club SET delFlag = 1 WHERE returnedId = #{returnedId} AND status = 1 AND source = 3
  231. </update>
  232. <select id="findRedemptionCode" resultType="com.caimei.modules.coupon.entity.CmCouponRedemptionCode">
  233. SELECT
  234. `id`,
  235. `couponId`,
  236. `clubCouponId`,
  237. `redemptionCode`,
  238. `status`,
  239. `redemptionTime`,
  240. `addTime`
  241. FROM
  242. cm_coupon_redemption_code
  243. WHERE
  244. couponId = #{couponId}
  245. AND STATUS = 1
  246. ORDER BY
  247. id
  248. LIMIT
  249. 1
  250. </select>
  251. </mapper>