PromotionsMapper.xml 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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.caimei365.commodity.mapper.PromotionsMapper">
  4. <select id="getPromotionsById" resultType="com.caimei365.commodity.model.vo.PromotionsVo">
  5. select id,
  6. name,
  7. description,
  8. type,
  9. mode,
  10. touchPrice,
  11. reducedPrice,
  12. beginTime,
  13. endTime,
  14. status
  15. from cm_promotions
  16. where id = #{promotionsId}
  17. and (status = 1 or (status = 2 and (NOW() between beginTime and endTime)))
  18. and delFlag not in (1, 2)
  19. </select>
  20. <select id="getPromotionsByProductId" resultType="com.caimei365.commodity.model.vo.PromotionsVo">
  21. select pr.id,
  22. pr.name,
  23. pr.description,
  24. pr.type,
  25. pr.mode,
  26. pr.touchPrice,
  27. pr.reducedPrice,
  28. pr.beginTime,
  29. pr.endTime,
  30. pr.status,
  31. prp.productId,
  32. prp.supplierId as shopId,
  33. pr.seen as seen
  34. from cm_promotions pr
  35. left join cm_promotions_product prp on pr.id = prp.promotionsId
  36. where (prp.productId = #{productId} or
  37. prp.supplierId = (select p.shopID from product p where p.productID = #{productId})
  38. )
  39. and (pr.status = 1 or (pr.status = 2 and (NOW() between pr.beginTime and pr.endTime)))
  40. and pr.delFlag not in (1, 2)
  41. order by pr.type desc
  42. limit 1
  43. </select>
  44. <select id="getPricePromotions" resultType="com.caimei365.commodity.model.vo.PromotionsVo">
  45. select pr.id,
  46. pr.name,
  47. pr.description,
  48. pr.type,
  49. pr.mode,
  50. pr.touchPrice,
  51. pr.reducedPrice,
  52. pr.beginTime,
  53. pr.endTime,
  54. pr.status,
  55. prp.productId,
  56. prp.supplierId as shopId,
  57. pr.seen as seen
  58. from cm_promotions pr
  59. left join cm_promotions_product prp on pr.id = prp.promotionsId
  60. where (prp.productId = #{productId} or
  61. prp.supplierId = (select p.shopID from product p where p.productID = #{productId})
  62. )
  63. and (pr.status = 1 or (pr.status = 2 and (NOW() between pr.beginTime and pr.endTime)))
  64. <if test="identity != 2 and identity != 4">
  65. and pr.seen = 1
  66. </if>
  67. and pr.delFlag not in (1, 2)
  68. order by pr.type desc
  69. limit 1
  70. </select>
  71. <select id="getPromotionGifts" resultType="com.caimei365.commodity.model.vo.ProductItemVo">
  72. select cpg.id as id,
  73. p.productID as productId,
  74. p.actStatus,
  75. p.shopID as shopId,
  76. p.`name` as `name`,
  77. p.mainImage as image,
  78. cpg.number as number,
  79. 0 as price,
  80. 2 as productType,
  81. p.price as originalPrice,
  82. p.unit as unit,
  83. p.validFlag as validFlag,
  84. p.stock as stock,
  85. p.productType
  86. from product p
  87. left join cm_promotions_gift cpg on cpg.productId = p.productID
  88. where cpg.promotionsId = #{promotionsId}
  89. order by cpg.addTime desc
  90. </select>
  91. <select id="getPromotionsList" resultType="com.caimei365.commodity.model.vo.ImageLinkVo">
  92. select a.id as id,
  93. a.title as title,
  94. a.link as link,
  95. a.image as image,
  96. a.beginTime as beginTime,
  97. a.endTime as endTime,
  98. a.appletsImage as crmImage,
  99. a.appletsLink as crmLink,
  100. (case
  101. when a.beginTime>NOW() and <![CDATA[a.beginTime < a.endTime ]]> then 1
  102. when <![CDATA[a.beginTime<NOW()]]> and a.endTime >NOW() and <![CDATA[a.beginTime < a.endTime ]]> then 2
  103. else 3 end) as status,
  104. (case
  105. when a.beginTime>NOW() and <![CDATA[a.beginTime < a.endTime ]]> then
  106. concat(DATE_FORMAT(a.beginTime,'%Y-%m-%d'),'~',DATE_FORMAT(a.endTime,'%Y-%m-%d'))
  107. when <![CDATA[a.beginTime<NOW()]]> and a.endTime >NOW() and <![CDATA[a.beginTime < a.endTime ]]> then
  108. concat(DATE_FORMAT(a.beginTime,'%Y-%m-%d'),'~',DATE_FORMAT(a.endTime,'%Y-%m-%d'))
  109. else null end) as detail
  110. from cm_page_image a
  111. where a.type=4
  112. <choose>
  113. <when test="source == 2">
  114. and a.appletsEnabledStatus = 1
  115. </when>
  116. <otherwise>
  117. and a.enabledStatus = 1
  118. </otherwise>
  119. </choose>
  120. order by case when <![CDATA[status<3]]> then 0 when status>=3 then 1 end asc,a.sort desc,a.createDate desc
  121. </select>
  122. <select id="getProductListByPromotions" resultType="com.caimei365.commodity.model.search.ProductListVo">
  123. select
  124. p.productID as productId,
  125. p.`name` as `name`,
  126. p.mainImage as image,
  127. p.price,
  128. p.unit as unit,
  129. p.priceFlag,
  130. IFNULL(p.visibility,3) as visibility,
  131. p.productType
  132. from product p
  133. left join cm_promotions_product cpp on cpp.productId = p.productID
  134. where cpp.promotionsId = #{promotionsId}
  135. and p.visibility in
  136. <foreach collection="visibilityList" item="visibility" index="index" open="(" separator="," close=")">
  137. #{visibility}
  138. </foreach>
  139. and p.validFlag = 2
  140. order by p.productID desc
  141. </select>
  142. <select id="getPromotionGiftsByProductId" resultType="com.caimei365.commodity.model.vo.PromotionsVo">
  143. select pr.id,
  144. pr.name,
  145. pr.description,
  146. pr.type,
  147. pr.mode,
  148. pr.touchPrice,
  149. pr.reducedPrice,
  150. pr.beginTime,
  151. pr.endTime,
  152. pr.status,
  153. cpg.productId
  154. from cm_promotions pr
  155. left join cm_promotions_gift cpg on pr.id = cpg.promotionsId
  156. where cpg.productId = #{productId}
  157. and (pr.status = 1 or (pr.status = 2 and (NOW() between pr.beginTime and pr.endTime)))
  158. and pr.mode = 3
  159. and pr.delFlag not in (1, 2)
  160. order by pr.type desc
  161. limit 1
  162. </select>
  163. <select id="findUserIdentity" resultType="java.lang.Integer">
  164. select userIdentity
  165. from user
  166. where userID = #{userId}
  167. </select>
  168. </mapper>