PromotionsMapper.xml 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. cpg.skuId as giftSkuId,
  74. p.productID as productId,
  75. p.actStatus,
  76. p.shopID as shopId,
  77. p.`name` as `name`,
  78. p.mainImage as image,
  79. cpg.number as number,
  80. 0 as price,
  81. 2 as productType,
  82. cs.price as originalPrice,
  83. cs.unit as unit,
  84. p.validFlag as validFlag,
  85. cs.stock as stock,
  86. p.productType
  87. from product p
  88. left join cm_promotions_gift cpg on cpg.productId = p.productID
  89. left join cm_sku cs on cpg.skuId=cs.skuId
  90. where cpg.promotionsId = #{promotionsId}
  91. order by cpg.addTime desc
  92. </select>
  93. <select id="getPromotionsList" resultType="com.caimei365.commodity.model.vo.ImageLinkVo">
  94. select a.id as id,
  95. a.title as title,
  96. a.link as link,
  97. a.image as image,
  98. a.beginTime as beginTime,
  99. a.endTime as endTime,
  100. a.appletsImage as crmImage,
  101. a.appletsLink as crmLink,
  102. (case
  103. when a.beginTime>NOW() and <![CDATA[a.beginTime < a.endTime ]]> then 1
  104. when <![CDATA[a.beginTime<NOW()]]> and a.endTime >NOW() and <![CDATA[a.beginTime < a.endTime ]]> then 2
  105. else 3 end) as status,
  106. (case
  107. when a.beginTime>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. when <![CDATA[a.beginTime<NOW()]]> and a.endTime >NOW() and <![CDATA[a.beginTime < a.endTime ]]> then
  110. concat(DATE_FORMAT(a.beginTime,'%Y-%m-%d'),'~',DATE_FORMAT(a.endTime,'%Y-%m-%d'))
  111. else null end) as detail
  112. from cm_page_image a
  113. where a.type=4
  114. <choose>
  115. <when test="source == 2">
  116. and a.appletsEnabledStatus = 1
  117. </when>
  118. <otherwise>
  119. and a.enabledStatus = 1
  120. </otherwise>
  121. </choose>
  122. order by case when <![CDATA[status<3]]> then 0 when status>=3 then 1 end asc,a.sort desc,a.createDate desc
  123. </select>
  124. <select id="getProductListByPromotions" resultType="com.caimei365.commodity.model.search.ProductListVo">
  125. select
  126. p.productID as productId,
  127. p.`name` as `name`,
  128. p.mainImage as image,
  129. (select price from cm_sku where productID=p.productID order by price asc limit 1)as price,
  130. (select unit from cm_sku where productID=p.productID order by price asc limit 1)as unit,
  131. p.priceFlag,
  132. IFNULL(p.visibility,3) as visibility,
  133. p.productType
  134. from product p
  135. left join cm_promotions_product cpp on cpp.productId = p.productID
  136. where cpp.promotionsId = #{promotionsId}
  137. and p.visibility in
  138. <foreach collection="visibilityList" item="visibility" index="index" open="(" separator="," close=")">
  139. #{visibility}
  140. </foreach>
  141. and p.validFlag = 2
  142. order by p.productID desc
  143. </select>
  144. <select id="getPromotionGiftsByProductId" resultType="com.caimei365.commodity.model.vo.PromotionsVo">
  145. select pr.id,
  146. pr.name,
  147. pr.description,
  148. pr.type,
  149. pr.mode,
  150. pr.touchPrice,
  151. pr.reducedPrice,
  152. pr.beginTime,
  153. pr.endTime,
  154. pr.status,
  155. cpg.productId
  156. from cm_promotions pr
  157. left join cm_promotions_gift cpg on pr.id = cpg.promotionsId
  158. where cpg.productId = #{productId}
  159. and (pr.status = 1 or (pr.status = 2 and (NOW() between pr.beginTime and pr.endTime)))
  160. and pr.mode = 3
  161. and pr.delFlag not in (1, 2)
  162. order by pr.type desc
  163. limit 1
  164. </select>
  165. <select id="findUserIdentity" resultType="java.lang.Integer">
  166. select userIdentity
  167. from user
  168. where userID = #{userId}
  169. </select>
  170. </mapper>