CmPromotionMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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.caimei.modules.product.dao.CmPromotionDao">
  4. <sql id="cmPromotionColumns">
  5. cp.id AS "id",
  6. cp.name AS "name",
  7. cp.description AS "description",
  8. cp.type AS "type",
  9. cp.mode AS "mode",
  10. cp.touchPrice AS "touchPrice",
  11. cp.reducedPrice AS "reducedPrice",
  12. cp.beginTime AS "beginTime",
  13. cp.endTime AS "endTime",
  14. cp.addTime AS "addTime",
  15. cp.updateTime AS "updateTime",
  16. cp.status AS "status",
  17. cp.delFlag AS "delFlag1"
  18. </sql>
  19. <select id="get" resultType="CmPromotion">
  20. SELECT
  21. <include refid="cmPromotionColumns"/>
  22. FROM cm_promotions cp
  23. WHERE cp.id = #{id}
  24. and cp.delFlag != '2'
  25. </select>
  26. <select id="findList" resultType="CmPromotion">
  27. SELECT
  28. <include refid="cmPromotionColumns"/>
  29. FROM cm_promotions cp
  30. LEFT JOIN cm_promotions_product cpp ON cp.id = cpp.promotionsId
  31. LEFT JOIN product p ON cpp.productId = p.productID
  32. LEFT JOIN shop s ON p.shopID = s.shopID OR cpp.supplierId=s.shopID
  33. <where>
  34. cp.delFlag != 2
  35. <if test="type != null and type != ''">
  36. AND cp.type = #{type,jdbcType=INTEGER}
  37. </if>
  38. <if test="name != null and name != ''">
  39. AND cp.name LIKE CONCAT('%',#{name,jdbcType=VARCHAR},'%')
  40. </if>
  41. <if test="description != null and description != ''">
  42. AND cp.description LIKE CONCAT('%',#{description,jdbcType=VARCHAR},'%')
  43. </if>
  44. <if test="productName != null and productName != ''">
  45. AND p.name LIKE CONCAT('%',#{productName,jdbcType=VARCHAR},'%')
  46. </if>
  47. <if test="shopName != null and shopName != ''">
  48. AND s.name LIKE CONCAT('%',#{shopName,jdbcType=VARCHAR},'%')
  49. </if>
  50. <if test="mode != null and mode != ''">
  51. AND cp.mode = #{mode,jdbcType=VARCHAR}
  52. </if>
  53. <if test="status != null and status != ''">
  54. AND cp.status = #{status,jdbcType=VARCHAR}
  55. </if>
  56. <if test="delFlag1 != null and delFlag1 != ''">
  57. <choose>
  58. <when test="delFlag1 == 1">
  59. AND NOW() <![CDATA[ < ]]> cp.beginTime
  60. AND cp.status != 1
  61. AND cp.delFlag != '1'
  62. </when>
  63. <when test="delFlag1 == 2">
  64. AND (NOW() between cp.beginTime AND cp.endTime
  65. OR cp.status = 1)
  66. AND cp.delFlag != '1'
  67. </when>
  68. <when test="delFlag1 == 3">
  69. AND NOW() <![CDATA[ > ]]> cp.endTime
  70. AND cp.status != 1
  71. AND cp.delFlag != '1'
  72. </when>
  73. <when test="delFlag1 == 0">
  74. AND cp.delFlag = '1'
  75. </when>
  76. <otherwise>
  77. AND cp.delFlag = null
  78. </otherwise>
  79. </choose>
  80. </if>
  81. </where>
  82. group by cp.id
  83. <choose>
  84. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  85. ORDER BY ${page.orderBy,jdbcType=VARCHAR}
  86. </when>
  87. <otherwise>
  88. ORDER BY cp.addTime DESC
  89. </otherwise>
  90. </choose>
  91. </select>
  92. <select id="findPromotionProduct" resultType="com.caimei.modules.product.entity.Product">
  93. SELECT
  94. p.*,
  95. cp.reducedPrice AS "reducedPrice",
  96. s.name AS "shopName"
  97. FROM
  98. cm_promotions cp
  99. LEFT JOIN cm_promotions_product cpp ON cp.id = cpp.promotionsId
  100. LEFT JOIN product p ON cpp.productId = p.productID
  101. LEFT JOIN shop s ON s.shopID = p.shopID
  102. WHERE
  103. cp.id = #{id}
  104. and p.productCategory = 1
  105. </select>
  106. <select id="findGiftProduct" resultType="com.caimei.modules.product.entity.Product">
  107. SELECT
  108. p.*,
  109. s.name AS "shopName",
  110. cpg.number AS "giftNumber"
  111. FROM
  112. cm_promotions cp
  113. LEFT JOIN cm_promotions_gift cpg ON cp.id = cpg.promotionsId
  114. LEFT JOIN product p ON cpg.productId = p.productID
  115. LEFT JOIN shop s ON s.shopID = p.shopID
  116. WHERE
  117. cp.id = #{id}
  118. and p.productCategory = 1
  119. </select>
  120. <select id="findGiftPurchaseProduct" resultType="com.caimei.modules.bulkpurchase.entity.PurchaseProduct">
  121. SELECT p.name name,s.name shopName ,s.`shopID` shopId,p.name purchaseProductName,
  122. p.`price1` price,p.`productID` productId,p.productCode productNo,p.mainImage image
  123. ,p.costCheckFlag costCheckFlag,p.costPrice costPrice,p.costProportional costProportional, p.price0 AS normalPrice,
  124. cpg.number AS num
  125. FROM
  126. cm_promotions cp
  127. LEFT JOIN cm_promotions_gift cpg ON cp.id = cpg.promotionsId
  128. LEFT JOIN product p ON cpg.productId = p.productID
  129. LEFT JOIN shop s ON s.shopID = p.shopID
  130. WHERE
  131. cp.id = #{id}
  132. and p.productCategory = 1
  133. </select>
  134. <select id="findPromotionShops" resultType="com.caimei.modules.cibe.entity.Shop">
  135. SELECT
  136. s.*
  137. FROM
  138. cm_promotions_product cpp
  139. LEFT JOIN shop s ON cpp.supplierId = s.shopID
  140. WHERE
  141. cpp.promotionsId = #{id}
  142. </select>
  143. <select id="findAllProduct" resultType="com.caimei.modules.product.entity.Product">
  144. SELECT
  145. p.*,
  146. s.name AS "shopName"
  147. FROM
  148. product p
  149. LEFT JOIN shop s ON s.shopID = p.shopID
  150. <where>
  151. p.productCategory = 1
  152. and p.validFlag = 2
  153. and p.price1TextFlag != 1
  154. and p.stock <![CDATA[ > ]]> 0
  155. <if test="productID != null">
  156. AND p.productID = #{productID}
  157. </if>
  158. <if test="name != null and name != ''">
  159. AND p.name LIKE concat('%',#{name},'%')
  160. </if>
  161. <if test="shopName != null and shopName != ''">
  162. AND s.name LIKE concat('%',#{shopName},'%')
  163. </if>
  164. <if test="ids != null and ids.size > 0">
  165. AND p.productID NOT IN
  166. <foreach collection="ids" open="(" close=")" item="id" separator=",">
  167. #{id}
  168. </foreach>
  169. </if>
  170. <if test="promotionType == 1 or promotionType == 2">
  171. AND p.productID NOT IN
  172. (SELECT cpp.productId
  173. FROM cm_promotions_product cpp
  174. LEFT JOIN cm_promotions cp on cpp.promotionsId = cp.id
  175. <where>
  176. cp.type = #{promotionType}
  177. AND cp.delFlag != '2'
  178. AND cpp.productId != 0
  179. <if test="delIdList != null and delIdList.size > 0">
  180. AND cpp.productId NOT IN
  181. <foreach collection="delIdList" open="(" close=")" item="delId" separator=",">
  182. #{delId}
  183. </foreach>
  184. </if>
  185. </where>
  186. )
  187. AND p.productID NOT IN (select productId from cm_svip_product)
  188. </if>
  189. </where>
  190. </select>
  191. <select id="findAllShop" resultType="com.caimei.modules.cibe.entity.Shop">
  192. SELECT
  193. s.*
  194. FROM
  195. shop s
  196. <where>
  197. s.status = 90
  198. AND s.shopID NOT IN
  199. (SELECT supplierId
  200. FROM cm_promotions_product cpp
  201. LEFT JOIN cm_promotions cp on cpp.promotionsId = cp.id
  202. <where>
  203. supplierId != 0
  204. AND cp.delFlag != '2'
  205. <if test="delShopIdList!=null and delShopIdList.size > 0">
  206. AND cpp.supplierId NOT IN
  207. <foreach collection="delShopIdList" open="(" close=")" item="delShopId" separator=",">
  208. #{delShopId}
  209. </foreach>
  210. </if>
  211. </where>
  212. )
  213. <if test="shopID != null">
  214. AND s.shopID = #{shopID}
  215. </if>
  216. <if test="name != null and name != ''">
  217. AND s.name LIKE concat('%',#{name},'%')
  218. </if>
  219. <if test="sname != null and sname != ''">
  220. AND s.sname LIKE concat('%',#{sname},'%')
  221. </if>
  222. <if test="ids != null and ids.size > 0">
  223. AND s.shopID NOT IN
  224. <foreach collection="ids" open="(" close=")" item="id" separator=",">
  225. #{id}
  226. </foreach>
  227. </if>
  228. </where>
  229. </select>
  230. <delete id="deleteAllPromotionProductsAndShops">
  231. DELETE FROM cm_promotions_product
  232. WHERE promotionsId = #{id}
  233. </delete>
  234. <delete id="deleteAllPromotionGifts">
  235. DELETE FROM cm_promotions_gift
  236. WHERE promotionsId = #{id}
  237. </delete>
  238. <insert id="insertPromotionProduct">
  239. INSERT INTO cm_promotions_product(
  240. promotionsId,
  241. productId,
  242. addTime
  243. ) VALUES (
  244. #{promotionId},
  245. #{productId},
  246. now()
  247. )
  248. </insert>
  249. <insert id="insertGiftProduct">
  250. INSERT INTO cm_promotions_gift(
  251. promotionsId,
  252. productId,
  253. number,
  254. addTime
  255. ) VALUES (
  256. #{promotionId},
  257. #{giftId},
  258. #{number},
  259. now()
  260. )
  261. </insert>
  262. <insert id="insertPromotionShop">
  263. INSERT INTO cm_promotions_product(
  264. promotionsId,
  265. supplierId,
  266. productId,
  267. addTime
  268. ) VALUES (
  269. #{promotionId},
  270. #{shopId},
  271. 0,
  272. now()
  273. )
  274. </insert>
  275. <insert id="insert" parameterType="CmPromotion" keyProperty="id" useGeneratedKeys="true">
  276. INSERT INTO cm_promotions(
  277. name,
  278. description,
  279. type,
  280. mode,
  281. touchPrice,
  282. reducedPrice,
  283. beginTime,
  284. endTime,
  285. addTime,
  286. updateTime,
  287. status,
  288. delFlag,
  289. discount,
  290. seen
  291. ) VALUES (
  292. #{name},
  293. #{description},
  294. #{type},
  295. #{mode},
  296. #{touchPrice},
  297. #{reducedPrice},
  298. #{beginTime},
  299. #{endTime},
  300. #{addTime},
  301. #{updateTime},
  302. #{status},
  303. #{delFlag1},
  304. #{discount},
  305. #{seen}
  306. )
  307. </insert>
  308. <update id="update">
  309. UPDATE cm_promotions
  310. SET name = #{name},
  311. description = #{description},
  312. type = #{type},
  313. mode = #{mode},
  314. touchPrice = #{touchPrice},
  315. reducedPrice = #{reducedPrice},
  316. beginTime = #{beginTime},
  317. endTime = #{endTime},
  318. updateTime = #{updateTime},
  319. status = #{status},
  320. delFlag = #{delFlag1}
  321. WHERE id = #{id}
  322. </update>
  323. <select id="findShop" resultType="com.caimei.modules.cibe.entity.Shop">
  324. SELECT * from shop where shopID = #{id}
  325. </select>
  326. <select id="findProductPromotion" resultType="com.caimei.modules.product.entity.CmPromotion">
  327. select pr.id,
  328. pr.name,
  329. pr.type,
  330. pr.mode,
  331. pr.touchPrice,
  332. pr.reducedPrice,
  333. pr.beginTime,
  334. pr.endTime,
  335. pr.status,
  336. prp.productId,
  337. prp.supplierId
  338. from cm_promotions pr
  339. left join cm_promotions_product prp on pr.id = prp.promotionsId
  340. where (prp.productId = #{productId}
  341. or prp.supplierId = #{shopId})
  342. and (pr.status = 1 or ( pr.status = 2 and (NOW() between pr.beginTime and pr.endTime)))
  343. and pr.delFlag not in ('1','2')
  344. order by pr.type desc
  345. limit 1
  346. </select>
  347. <select id="findProductPromotionsGift" resultType="com.caimei.modules.product.entity.CmPromotion">
  348. SELECT DISTINCT pr.id,
  349. pr.name,
  350. pr.type,
  351. pr.mode,
  352. pr.touchPrice,
  353. pr.reducedPrice,
  354. pr.beginTime,
  355. pr.endTime,
  356. pr.status
  357. FROM cm_promotions_gift cpg
  358. LEFT JOIN cm_promotions pr ON pr.id = cpg.promotionsId
  359. WHERE cpg.productId = #{productId}
  360. AND (pr.status = 1 OR ( pr.status = 2 AND (NOW() BETWEEN pr.beginTime AND pr.endTime)))
  361. AND pr.mode = 3
  362. AND pr.delFlag not in ('1','2')
  363. ORDER BY pr.type DESC
  364. LIMIT 1
  365. </select>
  366. <select id="findOrderPromotions" resultType="com.caimei.modules.product.entity.CmPromotion">
  367. SELECT * FROM cm_promotions_order WHERE id = #{orderPromotionsId}
  368. </select>
  369. <select id="findPromotionsByProductId" resultType="com.caimei.modules.product.entity.CmPromotion">
  370. select pr.id,
  371. pr.name,
  372. pr.description,
  373. pr.type,
  374. pr.mode,
  375. pr.touchPrice,
  376. pr.reducedPrice,
  377. pr.beginTime,
  378. pr.endTime,
  379. pr.status,
  380. prp.productId,
  381. prp.supplierId
  382. from cm_promotions pr
  383. left join cm_promotions_product prp on pr.id = prp.promotionsId
  384. where (prp.productId = #{productId} or
  385. prp.supplierId = (select p.shopID from product p where p.productID = #{productId})
  386. )
  387. and (pr.status = 1 or (pr.status = 2 and (NOW() between pr.beginTime and pr.endTime)))
  388. and pr.delFlag not in (1,2)
  389. order by pr.type desc
  390. limit 1
  391. </select>
  392. <select id="getPresentPriceById" resultType="java.lang.Double">
  393. select price1 from product where productID=#{productId}
  394. </select>
  395. </mapper>