couponItemMapper.xml 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. <!-- 命名,每一个映射对象不一样
  4. namespace:必须与对应的接口全类名一致
  5. -->
  6. <mapper namespace="com.iamberry.wechat.service.mapper.CouponItemMapper">
  7. <sql id="allField">
  8. CI.COUPON_ITEM_ID couponItemId,
  9. CI.COUPON_ID couponId,
  10. CI.COUPON_ITEM_USER_OPENID useropenid,
  11. CI.COUPON_USE_END_DATE couponUseEndDate,
  12. CI.COUPON_RECEIVE_DATE couponReceiveDate,
  13. CI.COUPON_USE_STATUS couponUseStatus,
  14. CI.COUPON_USE_DATE couponUseDate,
  15. CI.COUPON_ITEM_REMARK couponItemRemark,
  16. CI.coupon_item_current_user_openid couponItemCurrentUserOpenid,
  17. CT.coupon_is_new_people couponIsNewPeople,
  18. CT.coupon_is_give couponIsGive,
  19. CT.COUPON_NAME couponName,
  20. CT.coupon_type couponType,
  21. CT.COUPON_REDUCE couponReduce,
  22. CT.COUPON_IS_PURCHASE,
  23. CT.COUPON_CONSUME_ENOUGH couponConsumeEnough
  24. </sql>
  25. <!-- 查询优惠券详情列表 分页 -->
  26. <select id="getCouponItemDtoList" resultType="CouponItemDto" parameterType="CouponItemDto">
  27. SELECT
  28. <include refid="allField"></include>,
  29. CT.COUPON_TYPE couponType
  30. FROM TB_IAMBERRY_COUPON_ITEM CI
  31. JOIN TB_IAMBERRY_COUPON_TYPE CT ON CI.COUPON_ID=CT.COUPON_ID
  32. <where>
  33. <if test="couponId != null and couponId != ''">
  34. AND CI.COUPON_ID=#{couponId}
  35. </if>
  36. <if test="useropenid != null and useropenid != ''">
  37. AND CI.COUPON_ITEM_USER_OPENID=#{useropenid}
  38. </if>
  39. <!-- couponReduce 是将状态是7的优惠券 属于已使用的优惠券-->
  40. <if test="couponUseStatus != null and couponUseStatus != ''">
  41. AND CI.COUPON_USE_STATUS IN (#{couponUseStatus},#{couponReduce})
  42. </if>
  43. <if test="beginDate != null and beginDate != ''">
  44. AND date_format(CI.COUPON_USE_END_DATE,'%Y-%m-%d') >= date_format(#{beginDate},'%Y-%m-%d')
  45. </if>
  46. <if test="endDate != null and endDate != ''">
  47. AND CI.COUPON_USE_END_DATE<![CDATA[<]]>#{endDate}
  48. </if>
  49. <!-- 查已过期的优惠券时需去掉已经使用的优惠券 -->
  50. <if test="couponItemRemark != null and couponItemRemark != ''">
  51. AND CI.COUPON_USE_STATUS != 2
  52. </if>
  53. </where>
  54. ORDER BY CI.COUPON_RECEIVE_DATE DESC
  55. <if test="page!=null and page.recordBegin>0 and page.pageSize>0 ">
  56. LIMIT ${page.recordBegin},${page.pageSize}
  57. </if>
  58. <if test="page!=null and page.recordBegin==0 and page.pageSize>0 ">
  59. LIMIT ${page.pageSize}
  60. </if>
  61. </select>
  62. <!-- 查询优惠券详情总数 -->
  63. <select id="getCouponItemCount" resultType="Integer" parameterType="CouponItemDto">
  64. SELECT COUNT(COUPON_ITEM_ID) FROM TB_IAMBERRY_COUPON_ITEM
  65. <where>
  66. <if test="couponId != null and couponId != ''">
  67. COUPON_ID=#{couponId}
  68. </if>
  69. <if test="useropenid != null and useropenid != ''">
  70. AND COUPON_ITEM_USER_OPENID=#{useropenid}
  71. </if>
  72. <if test="couponUseStatus != null and couponUseStatus != ''">
  73. AND COUPON_USE_STATUS=#{couponUseStatus}
  74. </if>
  75. <if test="beginDate != null and beginDate != ''">
  76. AND COUPON_USE_END_DATE<![CDATA[>]]>#{beginDate}
  77. </if>
  78. <if test="endDate != null and endDate != ''">
  79. AND COUPON_USE_END_DATE<![CDATA[<]]>#{endDate}
  80. </if>
  81. </where>
  82. </select>
  83. <!--查询待用的优惠卷-->
  84. <select id="getStandByCoupon" resultType="CouponItem">
  85. SELECT CT.COUPON_NAME,CI.COUPON_USE_END_DATE ,CI.COUPON_RECEIVE_DATE
  86. FROM TB_IAMBERRY_COUPON_ITEM CI
  87. LEFT JOIN TB_IAMBERRY_COUPON_TYPE CT
  88. ON CI.COUPON_ID=CT.COUPON_ID
  89. WHERE CI.ITEM_CURRENT_USER_OPENID=#{openid} AND CI.COUPON_USE_STATUS=1
  90. ORDER BY CI.COUPON_ITEM_ID
  91. </select>
  92. <!--查询已使用的优惠卷-->
  93. <select id="getUseCoupon" resultType="CouponItem">
  94. SELECT CT.COUPON_NAME,CI.COUPON_USE_END_DATE ,CI.COUPON_RECEIVE_DATE
  95. FROM TB_IAMBERRY_COUPON_ITEM CI
  96. LEFT JOIN TB_IAMBERRY_COUPON_TYPE CT
  97. ON CI.COUPON_ID=CT.COUPON_ID
  98. WHERE CI.ITEM_CURRENT_USER_OPENID=#{openid} AND CI.COUPON_USE_STATUS=2
  99. ORDER BY CI.COUPON_ITEM_ID
  100. </select>
  101. <!--查询全部的优惠券-->
  102. <!-- 添加一张优惠券 -->
  103. <insert id="insertCouponItem" parameterType="CouponItem"
  104. useGeneratedKeys="true" keyProperty="couponItemId">
  105. INSERT INTO TB_IAMBERRY_COUPON_ITEM
  106. (
  107. COUPON_ITEM_ID ,
  108. COUPON_ID ,
  109. COUPON_ITEM_USER_OPENID ,
  110. COUPON_ITEM_CURRENT_USER_OPENID,
  111. COUPON_USE_END_DATE ,
  112. COUPON_RECEIVE_DATE ,
  113. COUPON_USE_STATUS ,
  114. COUPON_IS_DONATION ,
  115. COUPON_USE_DATE ,
  116. COUPON_ITEM_REMARK
  117. )
  118. VALUES
  119. (
  120. #{couponItemId},#{couponId},#{couponItemUseropenid},#{couponItemCurrentUserOpenid},#{couponUseEndDate},
  121. NOW(),#{couponUseStatus},#{couponIsDonation},#{couponUseDate},#{couponItemRemark}
  122. )
  123. </insert>
  124. <select id="getCouponItemById" resultType="CouponItemDto" parameterType="String">
  125. SELECT
  126. <include refid="allField"></include>
  127. FROM TB_IAMBERRY_COUPON_ITEM CI
  128. JOIN TB_IAMBERRY_COUPON_TYPE CT ON CI.COUPON_ID=CT.COUPON_ID
  129. WHERE CI.COUPON_ITEM_ID=#{couponItemId}
  130. </select>
  131. <!-- 根据id修改 -->
  132. <update id="updateCouponItemById" parameterType="CouponItem">
  133. UPDATE TB_IAMBERRY_COUPON_ITEM
  134. <set>
  135. <if test="couponUseEndDate!=null and couponUseEndDate!=''">
  136. COUPON_USE_END_DATE=#{couponUseEndDate},
  137. </if>
  138. <if test="couponUseStatus!=null and couponUseStatus!=''">
  139. COUPON_USE_STATUS=#{couponUseStatus},
  140. </if>
  141. <if test="couponUseDate!=null and couponUseDate!=''">
  142. COUPON_USE_DATE=#{couponUseDate},
  143. </if>
  144. <if test="couponItemRemark!=null and couponItemRemark!=''">
  145. COUPON_ITEM_REMARK=#{couponItemRemark},
  146. </if>
  147. </set>
  148. WHERE COUPON_ITEM_ID=#{couponItemId}
  149. <if test="couponItemUseropenid!=null and couponItemUseropenid!=''">
  150. AND COUPON_ITEM_USER_OPENID=#{couponItemUseropenid}
  151. </if>
  152. <if test="oldCouponUseStatus!=null and oldCouponUseStatus!=''">
  153. AND COUPON_USE_STATUS=#{oldCouponUseStatus}
  154. </if>
  155. </update>
  156. <update id="updateCouponItemList" parameterType="java.util.List">
  157. <foreach collection="list" item="item" index="index" separator=";" open="" close="">
  158. UPDATE TB_IAMBERRY_COUPON_ITEM
  159. <set>
  160. <if test="item.couponUseEndDate!=null and item.couponUseEndDate!=''">
  161. COUPON_USE_END_DATE=#{item.couponUseEndDate},
  162. </if>
  163. <if test="item.couponUseStatus!=null and item.couponUseStatus!=''">
  164. COUPON_USE_STATUS=#{item.couponUseStatus},
  165. </if>
  166. <if test="item.couponUseDate!=null and item.couponUseDate!=''">
  167. COUPON_USE_DATE=#{item.couponUseDate},
  168. </if>
  169. <if test="item.couponItemRemark!=null and item.couponItemRemark!=''">
  170. COUPON_ITEM_REMARK=#{item.couponItemRemark},
  171. </if>
  172. </set>
  173. WHERE COUPON_ITEM_ID=#{item.couponItemId}
  174. <if test="item.couponItemUseropenid!=null and item.couponItemUseropenid!=''">
  175. AND COUPON_ITEM_USER_OPENID=#{item.couponItemUseropenid}
  176. </if>
  177. <if test="item.oldCouponUseStatus!=null and item.oldCouponUseStatus!=''">
  178. AND COUPON_USE_STATUS=#{item.oldCouponUseStatus}
  179. </if>
  180. </foreach>
  181. </update>
  182. <!--根据openid查询是否已领取新人优惠券-->
  183. <select id="getIsReceive" parameterType="String" resultType="Integer">
  184. SELECT
  185. COUNT(1)
  186. FROM TB_IAMBERRY_COUPON_ITEM CI
  187. JOIN TB_IAMBERRY_COUPON_TYPE CT ON CI.COUPON_ID=CT.COUPON_ID
  188. where
  189. CI.COUPON_ITEM_USER_OPENID=#{openId}
  190. AND CT.COUPON_IS_NEW_PEOPLE = 1
  191. ORDER BY CI.COUPON_RECEIVE_DATE DESC
  192. </select>
  193. <!--根据openid和优惠券类型查询领取了多少张优惠券-->
  194. <select id="isReceive" parameterType="CouponItem" resultType="Integer">
  195. SELECT
  196. COUNT(CI.coupon_item_id)
  197. FROM
  198. TB_IAMBERRY_COUPON_ITEM CI
  199. WHERE
  200. CI.COUPON_ITEM_USER_OPENID = #{couponItemUseropenid}
  201. AND CI.coupon_id = #{couponId}
  202. </select>
  203. <!--根据openid查询领取了多少张优惠券-->
  204. <select id="userCouponNum" parameterType="CouponItem" resultType="Integer">
  205. SELECT
  206. COUNT(CI.coupon_item_id)
  207. FROM
  208. TB_IAMBERRY_COUPON_ITEM CI
  209. <where>
  210. CI.COUPON_ITEM_USER_OPENID = #{couponItemUseropenid}
  211. <if test="couponUseStatus != null and couponUseStatus != ''">
  212. AND COUPON_USE_STATUS=#{couponUseStatus}
  213. </if>
  214. </where>
  215. </select>
  216. <!--获取所有领取优惠券的人-->
  217. <select id="allCouponItemNumber" parameterType="CouponItem" resultType="Integer">
  218. SELECT
  219. COUNT(CI.coupon_item_id)
  220. FROM
  221. TB_IAMBERRY_COUPON_ITEM CI
  222. <where>
  223. <if test="couponId != null and couponId != ''">
  224. CI.COUPON_ID=#{couponId}
  225. </if>
  226. <if test="couponIds!=null and couponIds!=''">
  227. AND CI.COUPON_ID IN
  228. <foreach collection="couponIds" item="node" index="index" separator="," open="(" close=")">
  229. #{node}
  230. </foreach >
  231. </if>
  232. <if test="couponUseStatus != null and couponUseStatus != ''">
  233. AND CI.coupon_use_status = #{couponUseStatus}
  234. </if>
  235. </where>
  236. </select>
  237. </mapper>