couponItemMapper.xml 8.7 KB

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