PromotionsMapper.xml 5.1 KB

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