CmHeheCouponMapper.xml 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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.hehe.dao.CmHeheCouponDao">
  4. <sql id="cmHeheCouponColumns">
  5. a.id AS "id",
  6. a.name AS "name",
  7. a.couponAmount AS "couponAmount",
  8. a.touchPrice AS "touchPrice",
  9. a.noThresholdFlag AS "noThresholdFlag",
  10. a.startTime AS "startTime",
  11. a.endTime AS "endTime",
  12. a.startNowFlag AS "startNowFlag",
  13. a.permanentFlag AS "permanentFlag",
  14. a.couponType AS "couponType",
  15. a.productType AS "productType",
  16. a.receivePeriod AS "receivePeriod",
  17. a.receiveFlag AS "receiveFlag",
  18. a.usePeriod AS "usePeriod",
  19. a.createDate AS "createDate",
  20. a.delFlag AS "delFlag"
  21. </sql>
  22. <sql id="cmHeheCouponJoins">
  23. </sql>
  24. <select id="get" resultType="CmHeheCoupon">
  25. SELECT
  26. <include refid="cmHeheCouponColumns"/>
  27. FROM cm_hehe_coupon a
  28. <include refid="cmHeheCouponJoins"/>
  29. WHERE a.id = #{id}
  30. </select>
  31. <select id="findList" resultType="CmHeheCoupon">
  32. SELECT
  33. <include refid="cmHeheCouponColumns"/>
  34. FROM cm_hehe_coupon a
  35. <include refid="cmHeheCouponJoins"/>
  36. <where>
  37. AND a.delFlag = 0
  38. <if test="couponType != null">
  39. AND a.couponType = #{couponType}
  40. </if>
  41. <if test="name != null and name != ''">
  42. AND a.name LIKE
  43. <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
  44. <if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
  45. <if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
  46. </if>
  47. <if test='status == "1"'>
  48. AND (NOW() <![CDATA[ < ]]> a.startTime and a.startNowFlag = 0)
  49. </if>
  50. <if test='status == "2"'>
  51. AND (NOW() <![CDATA[ >= ]]> a.startTime OR a.startNowFlag = 1)
  52. AND (NOW() <![CDATA[ <= ]]> a.endTime OR a.permanentFlag = 1)
  53. </if>
  54. <if test='status == "3"'>
  55. AND (NOW() <![CDATA[ > ]]> a.endTime and a.permanentFlag = 0)
  56. </if>
  57. </where>
  58. <choose>
  59. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  60. ORDER BY ${page.orderBy}
  61. </when>
  62. <otherwise>
  63. order by a.createDate desc
  64. </otherwise>
  65. </choose>
  66. </select>
  67. <select id="findAllList" resultType="CmHeheCoupon">
  68. SELECT
  69. <include refid="cmHeheCouponColumns"/>
  70. FROM cm_hehe_coupon a
  71. <include refid="cmHeheCouponJoins"/>
  72. <where>
  73. </where>
  74. <choose>
  75. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  76. ORDER BY ${page.orderBy}
  77. </when>
  78. <otherwise>
  79. </otherwise>
  80. </choose>
  81. </select>
  82. <select id="findCouponProductIds" resultType="java.lang.Integer">
  83. SELECT id FROM cm_hehe_coupon_product WHERE couponId = #{couponId}
  84. </select>
  85. <select id="findCouponProductList" resultType="com.caimei.modules.hehe.entity.CmHeheCouponProduct">
  86. SELECT
  87. cca.id,
  88. cca.couponId,
  89. cca.productId,
  90. cca.status,
  91. cca.sort,
  92. cca.addTime,
  93. s.name AS shopName,
  94. p.name AS productName,
  95. p.mainImage AS image
  96. FROM
  97. cm_hehe_coupon_product cca
  98. left join cm_hehe_product chp on cca.productId = chp.productId
  99. LEFT JOIN product p ON chp.productId = p.productID
  100. LEFT JOIN shop s ON p.shopID = s.shopID
  101. WHERE
  102. cca.couponId = #{couponId}
  103. ORDER BY
  104. - cca.sort DESC
  105. </select>
  106. <select id="findAllUser" resultType="com.caimei.modules.user.entity.CmUser">
  107. select id,userId as userID, nickName,mobile,userIdentity,openId as openID
  108. from cm_hehe_user
  109. <where>
  110. <if test="mobile != null and mobile != ''">
  111. AND mobile = #{mobile}
  112. </if>
  113. <if test="userIdentity != null and userIdentity != ''">
  114. AND userIdentity = #{userIdentity}
  115. </if>
  116. <if test="nickName != null and nickName != ''">
  117. AND nickName LIKE concat('%',#{nickName},'%')
  118. </if>
  119. </where>
  120. ORDER BY addTime DESC
  121. </select>
  122. <select id="findCouponUserIds" resultType="java.lang.Integer">
  123. SELECT id FROM cm_hehe_coupon_user WHERE couponId = #{couponId}
  124. </select>
  125. <select id="findCouponUserList" resultType="com.caimei.modules.hehe.entity.CmHeheCouponUser">
  126. select chu.id, chu.userId, chu.couponId, chu.addTime, u.nickName, u.mobile, u.userIdentity
  127. from cm_hehe_coupon_user chu
  128. left join cm_hehe_user u on chu.userId = u.userId
  129. where chu.couponId = #{id}
  130. order by chu.addTime desc
  131. </select>
  132. <select id="allUserList" resultType="com.caimei.modules.hehe.entity.CmHeheReceiveUser">
  133. select u.userId as userId,u.nickName,u.mobile,u.userIdentity,count(rc.id) as receiveNum, count(chc.id) as ableNum
  134. from cm_hehe_user u
  135. left join cm_hehe_receive_coupon rc on u.userId = rc.userId and rc.delFlag = 0 and rc.couponId in (select id from cm_hehe_coupon where delFlag = 0)
  136. left join cm_hehe_coupon chc on rc.couponId = chc.id
  137. and NOW() <![CDATA[ < ]]> DATE_ADD(rc.receiveTime ,interval chc.usePeriod DAY) and rc.status = 1
  138. and chc.delFlag = 0
  139. <where>
  140. <if test="nickName != null and nickName != ''">
  141. and u.nickName like concat('%',#{nickName},'%')
  142. </if>
  143. <if test="mobile != null and mobile != ''">
  144. and u.mobile like concat('%',#{mobile},'%')
  145. </if>
  146. <if test="userIdentity != null">
  147. and u.userIdentity = #{userIdentity}
  148. </if>
  149. </where>
  150. group by u.id
  151. having receiveNum >0
  152. order by count(chc.id) desc,u.id desc
  153. </select>
  154. <select id="receiveUserList" resultType="com.caimei.modules.hehe.entity.CmHeheReceiveUser">
  155. select chu.id as userId,
  156. chu.nickName,
  157. chu.mobile,
  158. chrc.source,
  159. chrc.receiveTime,
  160. date_add(chrc.receiveTime, interval chc.usePeriod DAY) as validPeriod,
  161. chrc.status,
  162. if(NOW() <![CDATA[ > ]]> date_add(chrc.receiveTime, interval chc.usePeriod DAY), 0, 1) as validFlag,
  163. chrc.useTime,
  164. chrc.orderId
  165. from cm_hehe_user chu
  166. left join cm_hehe_receive_coupon chrc on chu.userId = chrc.userId
  167. left join cm_hehe_coupon chc on chrc.couponId = chc.id
  168. <where>
  169. chrc.couponId = #{couponId}
  170. <if test="nickName != null and nickName != ''">
  171. and chu.nickName like concat('%',#{nickName},'%')
  172. </if>
  173. <if test="mobile != null and mobile != ''">
  174. and chu.mobile like concat('%',#{mobile},'%')
  175. </if>
  176. <if test="status != null">
  177. <if test="status == 2">
  178. and chrc.status = 2
  179. </if>
  180. <if test="status == 1">
  181. and chrc.status = 1 and NOW() <![CDATA[ <= ]]> date_add(chrc.receiveTime, interval chc.usePeriod DAY)
  182. </if>
  183. <if test="status == 3">
  184. and chrc.status = 1 and NOW() <![CDATA[ > ]]> date_add(chrc.receiveTime, interval chc.usePeriod DAY)
  185. </if>
  186. </if>
  187. </where>
  188. order by chrc.receiveTime desc
  189. </select>
  190. <select id="receiveCouponList" resultType="com.caimei.modules.hehe.entity.CmHeheCoupon">
  191. select chc.name,chc.couponType,chc.couponAmount,chc.touchPrice,chrc.receiveTime,
  192. date_add(chrc.receiveTime,interval chc.usePeriod DAY) as validPeriod,chrc.status as useStatus,
  193. if(NOW() <![CDATA[ > ]]> date_add(chrc.receiveTime, interval chc.usePeriod DAY), 0, 1) as validFlag,
  194. chrc.useTime,co.orderNo,co.orderID as orderId
  195. from cm_hehe_coupon chc
  196. left join cm_hehe_receive_coupon chrc on chc.id = chrc.couponId
  197. left join cm_hehe_user chu on chrc.userId = chu.userId
  198. left join cm_order co on chrc.orderId = co.orderID
  199. <where>
  200. <if test="userId != null">
  201. chrc.userId = #{userId}
  202. </if>
  203. and chrc.delFlag = 0
  204. and chc.delFlag = 0
  205. <if test="name != null and name !=''">
  206. and chc.name like concat('%',#{name},'%')
  207. </if>
  208. <if test="couponType != null">
  209. and chc.couponType = #{couponType}
  210. </if>
  211. <if test="useStatus != null">
  212. <if test="useStatus == 2">
  213. and chrc.status = 2
  214. </if>
  215. <if test="useStatus == 1">
  216. and chrc.status = 1 and NOW() <![CDATA[ <= ]]> date_add(chrc.receiveTime, interval chc.usePeriod DAY)
  217. </if>
  218. <if test="useStatus == 3">
  219. and chrc.status = 1 and NOW() <![CDATA[ > ]]> date_add(chrc.receiveTime, interval chc.usePeriod DAY)
  220. </if>
  221. </if>
  222. </where>
  223. order by chrc.receiveTime desc
  224. </select>
  225. <insert id="insert" parameterType="CmHeheCoupon" keyProperty="id" useGeneratedKeys="true">
  226. INSERT INTO cm_hehe_coupon(
  227. name,
  228. couponAmount,
  229. touchPrice,
  230. noThresholdFlag,
  231. startTime,
  232. endTime,
  233. startNowFlag,
  234. permanentFlag,
  235. couponType,
  236. productType,
  237. receivePeriod,
  238. receiveFlag,
  239. usePeriod,
  240. createDate,
  241. delFlag
  242. ) VALUES (
  243. #{name},
  244. #{couponAmount},
  245. #{touchPrice},
  246. #{noThresholdFlag},
  247. #{startTime},
  248. #{endTime},
  249. #{startNowFlag},
  250. #{permanentFlag},
  251. #{couponType},
  252. #{productType},
  253. #{receivePeriod},
  254. #{receiveFlag},
  255. #{usePeriod},
  256. #{createDate},
  257. #{delFlag}
  258. )
  259. </insert>
  260. <insert id="insertCouponProduct">
  261. INSERT INTO `cm_hehe_coupon_product` (
  262. `couponId`, `productId`, `status`,
  263. `sort`, `addTime`
  264. )
  265. VALUES
  266. (
  267. #{couponId}, #{productId}, #{status},
  268. #{sort}, #{addTime}
  269. )
  270. </insert>
  271. <insert id="insertCouponUser">
  272. insert into cm_hehe_coupon_user (couponId, userId, addTime) values (#{couponId}, #{userId}, #{addTime})
  273. </insert>
  274. <update id="update">
  275. UPDATE cm_hehe_coupon SET
  276. name = #{name},
  277. couponAmount = #{couponAmount},
  278. touchPrice = #{touchPrice},
  279. noThresholdFlag = #{noThresholdFlag},
  280. startTime = #{startTime},
  281. endTime = #{endTime},
  282. startNowFlag = #{startNowFlag},
  283. permanentFlag = #{permanentFlag},
  284. productType = #{productType},
  285. receivePeriod = #{receivePeriod},
  286. receiveFlag = #{receiveFlag},
  287. usePeriod = #{usePeriod}
  288. WHERE id = #{id}
  289. </update>
  290. <update id="updateCouponProduct">
  291. UPDATE
  292. `cm_hehe_coupon_product`
  293. <set>
  294. <if test="status != null">
  295. `status` = #{status},
  296. </if>
  297. <if test="sort != null">
  298. `sort` = #{sort},
  299. </if>
  300. </set>
  301. WHERE
  302. `id` = #{id}
  303. </update>
  304. <delete id="delete">
  305. DELETE FROM cm_hehe_coupon
  306. WHERE id = #{id}
  307. </delete>
  308. <delete id="deleteCouponProduct">
  309. delete from cm_hehe_coupon_product where id = #{id}
  310. </delete>
  311. <delete id="deleteCouponUser">
  312. delete from cm_hehe_coupon_user where id = #{id}
  313. </delete>
  314. <update id="deleteCoupon">
  315. update cm_hehe_coupon set delFlag = 1 where id = #{id}
  316. </update>
  317. </mapper>