123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441 |
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.caimei.modules.product.dao.CmPromotionDao">
- <sql id="cmPromotionColumns">
- cp.id AS "id",
- cp.name AS "name",
- cp.description AS "description",
- cp.type AS "type",
- cp.mode AS "mode",
- cp.touchPrice AS "touchPrice",
- cp.reducedPrice AS "reducedPrice",
- cp.beginTime AS "beginTime",
- cp.endTime AS "endTime",
- cp.addTime AS "addTime",
- cp.updateTime AS "updateTime",
- cp.status AS "status",
- cp.delFlag AS "delFlag1",
- cp.seen AS "seen",
- cp.discount AS "discount"
- </sql>
- <select id="get" resultType="CmPromotion">
- SELECT
- <include refid="cmPromotionColumns"/>
- FROM cm_promotions cp
- WHERE cp.id = #{id}
- and cp.delFlag != '2'
- </select>
- <select id="findList" resultType="CmPromotion">
- SELECT
- <include refid="cmPromotionColumns"/>
- FROM cm_promotions cp
- LEFT JOIN cm_promotions_product cpp ON cp.id = cpp.promotionsId
- LEFT JOIN product p ON cpp.productId = p.productID
- LEFT JOIN shop s ON p.shopID = s.shopID OR cpp.supplierId=s.shopID
- <where>
- cp.delFlag != 2
- <if test="type != null and type != ''">
- AND cp.type = #{type,jdbcType=INTEGER}
- </if>
- <if test="name != null and name != ''">
- AND cp.name LIKE CONCAT('%',#{name,jdbcType=VARCHAR},'%')
- </if>
- <if test="description != null and description != ''">
- AND cp.description LIKE CONCAT('%',#{description,jdbcType=VARCHAR},'%')
- </if>
- <if test="productName != null and productName != ''">
- AND p.name LIKE CONCAT('%',#{productName,jdbcType=VARCHAR},'%')
- </if>
- <if test="shopName != null and shopName != ''">
- AND s.name LIKE CONCAT('%',#{shopName,jdbcType=VARCHAR},'%')
- </if>
- <if test="mode != null and mode != ''">
- AND cp.mode = #{mode,jdbcType=VARCHAR}
- </if>
- <if test="status != null and status != ''">
- AND cp.status = #{status,jdbcType=VARCHAR}
- </if>
- <if test="delFlag1 != null and delFlag1 != ''">
- <choose>
- <when test="delFlag1 == 1">
- AND NOW() <![CDATA[ < ]]> cp.beginTime
- AND cp.status != 1
- AND cp.delFlag != '1'
- </when>
- <when test="delFlag1 == 2">
- AND (NOW() between cp.beginTime AND cp.endTime
- OR cp.status = 1)
- AND cp.delFlag != '1'
- </when>
- <when test="delFlag1 == 3">
- AND NOW() <![CDATA[ > ]]> cp.endTime
- AND cp.status != 1
- AND cp.delFlag != '1'
- </when>
- <when test="delFlag1 == 0">
- AND cp.delFlag = '1'
- </when>
- <otherwise>
- AND cp.delFlag = null
- </otherwise>
- </choose>
- </if>
- </where>
- group by cp.id
- <choose>
- <when test="page !=null and page.orderBy != null and page.orderBy != ''">
- ORDER BY ${page.orderBy,jdbcType=VARCHAR}
- </when>
- <otherwise>
- ORDER BY cp.addTime DESC
- </otherwise>
- </choose>
- </select>
- <select id="findPromotionProduct" resultType="com.caimei.modules.product.entity.Product">
- SELECT p.*,
- (select price from cm_sku where productId = p.productId order by price asc limit 1) as price,
- cp.reducedPrice AS "reducedPrice",
- s.name AS "shopName"
- FROM cm_promotions cp
- LEFT JOIN cm_promotions_product cpp ON cp.id = cpp.promotionsId
- LEFT JOIN product p ON cpp.productId = p.productID
- LEFT JOIN shop s ON s.shopID = p.shopID
- WHERE cp.id = #{id}
- and p.productCategory = 1
- </select>
- <select id="findGiftProduct" resultType="com.caimei.modules.product.entity.Product">
- SELECT cpg.skuId AS "skuId",
- cs.unit,
- p.name,
- p.mainImage,
- p.productID,
- s.name AS "shopName",
- cpg.number AS "giftNumber"
- FROM cm_promotions cp
- LEFT JOIN cm_promotions_gift cpg ON cp.id = cpg.promotionsId
- left join cm_sku cs on cpg.skuId = cs.skuId
- LEFT JOIN product p ON cpg.productId = p.productID
- LEFT JOIN shop s ON s.shopID = p.shopID
- WHERE cp.id = #{id}
- and p.productCategory = 1
- </select>
- <select id="findGiftPurchaseProduct" resultType="com.caimei.modules.bulkpurchase.entity.PurchaseProduct">
- SELECT p.name name,
- s.name shopName,
- s.`shopID` shopId,
- p.name purchaseProductName,
- cs.`price` price,
- p.`productID` productId,
- p.productCode productNo,
- p.mainImage image,
- cs.costCheckFlag costCheckFlag,
- cs.costPrice costPrice,
- cs.costProportional costProportional,
- cs.normalPrice AS normalPrice,
- cpg.number AS num,
- cp.discount as discounts
- FROM cm_promotions cp
- LEFT JOIN cm_promotions_gift cpg ON cp.id = cpg.promotionsId
- left join cm_sku cs on cpg.skuId = cs.skuId
- LEFT JOIN product p ON cpg.productId = p.productID
- LEFT JOIN shop s ON s.shopID = p.shopID
- WHERE cp.id = #{id}
- and p.productCategory = 1
- </select>
- <select id="findPromotionShops" resultType="com.caimei.modules.cibe.entity.Shop">
- SELECT s.*
- FROM cm_promotions_product cpp
- LEFT JOIN shop s ON cpp.supplierId = s.shopID
- WHERE cpp.promotionsId = #{id}
- </select>
- <select id="findAllProduct" resultType="com.caimei.modules.product.entity.Product">
- SELECT
- p.productId as productID,
- p.mainImage as mainImage,
- p.name as name,
- s.name AS shopName
- FROM
- product p
- LEFT JOIN shop s ON s.shopID = p.shopID
- <where>
- p.productCategory = 1
- and p.validFlag = 2
- and p.priceFlag != 1
- <if test="productID != null">
- AND p.productID = #{productID}
- </if>
- <if test="name != null and name != ''">
- AND p.name LIKE concat('%',#{name},'%')
- </if>
- <if test="shopName != null and shopName != ''">
- AND s.name LIKE concat('%',#{shopName},'%')
- </if>
- <if test="ids != null and ids.size > 0">
- AND p.productID NOT IN
- <foreach collection="ids" open="(" close=")" item="id" separator=",">
- #{id}
- </foreach>
- </if>
- <if test="promotionType == 1 or promotionType == 2">
- AND p.productID NOT IN
- (SELECT cpp.productId
- FROM cm_promotions_product cpp
- LEFT JOIN cm_promotions cp on cpp.promotionsId = cp.id
- <where>
- cp.type = #{promotionType}
- AND cp.delFlag != '2'
- AND cpp.productId != 0
- <if test="delIdList != null and delIdList.size > 0">
- AND cpp.productId NOT IN
- <foreach collection="delIdList" open="(" close=")" item="delId" separator=",">
- #{delId}
- </foreach>
- </if>
- </where>
- )
- AND p.productID NOT IN (select productId from cm_svip_product)
- </if>
- </where>
- </select>
- <select id="findAllShop" resultType="com.caimei.modules.cibe.entity.Shop">
- SELECT
- s.*
- FROM
- shop s
- <where>
- s.status = 90
- AND s.shopID NOT IN
- (SELECT supplierId
- FROM cm_promotions_product cpp
- LEFT JOIN cm_promotions cp on cpp.promotionsId = cp.id
- <where>
- supplierId != 0
- AND cp.delFlag != '2'
- <if test="delShopIdList!=null and delShopIdList.size > 0">
- AND cpp.supplierId NOT IN
- <foreach collection="delShopIdList" open="(" close=")" item="delShopId" separator=",">
- #{delShopId}
- </foreach>
- </if>
- </where>
- )
- <if test="shopID != null">
- AND s.shopID = #{shopID}
- </if>
- <if test="name != null and name != ''">
- AND s.name LIKE concat('%',#{name},'%')
- </if>
- <if test="sname != null and sname != ''">
- AND s.sname LIKE concat('%',#{sname},'%')
- </if>
- <if test="ids != null and ids.size > 0">
- AND s.shopID NOT IN
- <foreach collection="ids" open="(" close=")" item="id" separator=",">
- #{id}
- </foreach>
- </if>
- </where>
- </select>
- <delete id="deleteAllPromotionProductsAndShops">
- DELETE
- FROM cm_promotions_product
- WHERE promotionsId = #{id}
- </delete>
- <delete id="deleteAllPromotionGifts">
- DELETE
- FROM cm_promotions_gift
- WHERE promotionsId = #{id}
- </delete>
- <insert id="insertPromotionProduct">
- INSERT INTO cm_promotions_product(promotionsId,
- productId,
- addTime)
- VALUES (#{promotionId},
- #{productId},
- now())
- </insert>
- <insert id="insertGiftProduct">
- INSERT INTO cm_promotions_gift(promotionsId,
- skuId,
- productId,
- number,
- addTime)
- VALUES (#{promotionId},
- #{giftId},
- (select productId from cm_sku where skuId = #{giftId}),
- #{number},
- now())
- </insert>
- <insert id="insertPromotionShop">
- INSERT INTO cm_promotions_product(promotionsId,
- supplierId,
- productId,
- addTime)
- VALUES (#{promotionId},
- #{shopId},
- 0,
- now())
- </insert>
- <insert id="insert" parameterType="CmPromotion" keyProperty="id" useGeneratedKeys="true">
- INSERT INTO cm_promotions(name,
- description,
- type,
- mode,
- touchPrice,
- reducedPrice,
- beginTime,
- endTime,
- addTime,
- updateTime,
- status,
- delFlag,
- discount,
- seen)
- VALUES (#{name},
- #{description},
- #{type},
- #{mode},
- #{touchPrice},
- #{reducedPrice},
- #{beginTime},
- #{endTime},
- #{addTime},
- #{updateTime},
- #{status},
- #{delFlag1},
- #{discount},
- #{seen})
- </insert>
- <update id="update">
- UPDATE cm_promotions
- SET name = #{name},
- description = #{description},
- type = #{type},
- mode = #{mode},
- touchPrice = #{touchPrice},
- reducedPrice = #{reducedPrice},
- beginTime = #{beginTime},
- endTime = #{endTime},
- updateTime = #{updateTime},
- status = #{status},
- delFlag = #{delFlag1},
- discount = #{discount},
- seen = #{seen}
- WHERE id = #{id}
- </update>
- <select id="findShop" resultType="com.caimei.modules.cibe.entity.Shop">
- SELECT *
- from shop
- where shopID = #{id}
- </select>
- <select id="findProductPromotion" resultType="com.caimei.modules.product.entity.CmPromotion">
- select pr.id,
- pr.name,
- pr.type,
- pr.mode,
- pr.touchPrice,
- pr.reducedPrice,
- pr.beginTime,
- pr.endTime,
- pr.status,
- prp.productId,
- prp.supplierId,
- pr.discount,
- cpg.skuId
- from cm_promotions pr
- left join cm_promotions_product prp on pr.id = prp.promotionsId
- LEFT JOIN cm_promotions_gift cpg ON pr.id = cpg.promotionsId
- where (prp.productId = #{productId}
- or prp.supplierId = #{shopId})
- and (pr.status = 1 or (pr.status = 2 and (NOW() between pr.beginTime and pr.endTime)))
- and pr.delFlag not in ('1', '2')
- order by pr.type desc
- limit 1
- </select>
- <select id="findProductPromotionsGift" resultType="com.caimei.modules.product.entity.CmPromotion">
- SELECT DISTINCT pr.id,
- pr.name,
- pr.type,
- pr.mode,
- pr.touchPrice,
- pr.reducedPrice,
- pr.beginTime,
- pr.endTime,
- pr.status
- FROM cm_promotions_gift cpg
- LEFT JOIN cm_promotions pr ON pr.id = cpg.promotionsId
- WHERE cpg.productId = #{productId}
- AND (pr.status = 1 OR (pr.status = 2 AND (NOW() BETWEEN pr.beginTime AND pr.endTime)))
- AND pr.mode = 3
- AND pr.delFlag not in ('1', '2')
- ORDER BY pr.type DESC
- LIMIT 1
- </select>
- <select id="findOrderPromotions" resultType="com.caimei.modules.product.entity.CmPromotion">
- SELECT *
- FROM cm_promotions_order
- WHERE id = #{orderPromotionsId}
- </select>
- <select id="findPromotionsByProductId" resultType="com.caimei.modules.product.entity.CmPromotion">
- select pr.id,
- pr.name,
- pr.description,
- pr.type,
- pr.mode,
- pr.touchPrice,
- pr.reducedPrice,
- pr.beginTime,
- pr.endTime,
- pr.status,
- prp.productId,
- prp.supplierId
- from cm_promotions pr
- left join cm_promotions_product prp on pr.id = prp.promotionsId
- where (prp.productId = #{productId} or
- prp.supplierId = (select p.shopID from product p where p.productID = #{productId})
- )
- and (pr.status = 1 or (pr.status = 2 and (NOW() between pr.beginTime and pr.endTime)))
- and pr.delFlag not in (1, 2)
- order by pr.type desc
- limit 1
- </select>
- <select id="getPresentPriceById" resultType="java.lang.Double">
- select price
- from cm_sku
- where skuId = #{skuId}
- </select>
- <select id="findProductIdByPromotion" resultType="java.lang.Integer">
- select productId
- from cm_promotions_product
- where promotionsId = #{promotionsId}
- </select>
- <select id="findProductIdsByPromotion" resultType="java.lang.Integer">
- select productID
- from product
- where shopID in (select supplierId from cm_promotions_product where promotionsId = #{promotionsId})
- </select>
- </mapper>
|