123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- <?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.caimei365.commodity.mapper.CouponMapper">
- <select id="findCouponClub" resultType="com.caimei365.commodity.model.vo.CouponVo">
- SELECT
- cc.`id` AS "couponId",
- cc.`couponAmount`,
- cc.`touchPrice`,
- if(cc.vipFlag = 1,cc.startDate,a.createDate) as startDate,
- if(cc.vipFlag = 1 or cc.useTimeFlag = 1,cc.endDate,date_add(a.createDate,interval cc.usePeriod day)) as endDate,
- cc.`couponType`,
- cc.`userId`,
- cc.`shopId`,
- cc.`productType`,
- cc.moneyCouponPrice,
- cc.moneyCouponFlag,
- cc.moneyCouponType,
- cc.`categoryType`,
- cc.couponPayWay
- FROM
- cm_coupon_club a
- LEFT JOIN cm_coupon cc ON a.couponId = cc.id
- WHERE
- IF(cc.moneyCouponFlag=2,cc.delflag = 0,cc.id>0)
- AND a.delFlag = 0
- AND a.userId = #{userId}
- <if test="status == 1">
- AND a.status = 1
- AND if(cc.vipFlag = 1,
- NOW() BETWEEN cc.startDate AND cc.endDate,
- NOW() <![CDATA[ < ]]> IF(cc.usePeriod IS NULL,cc.endDate,DATE_ADD(a.createDate,INTERVAL cc.usePeriod DAY)))
- </if>
- <if test="status == 2">
- AND a.status = 2
- </if>
- <if test="status == 3">
- AND a.status = 1
- AND if(cc.vipFlag = 1,
- NOW() > cc.endDate,
- NOW() <![CDATA[ < ]]> IF(cc.usePeriod IS NULL,cc.endDate,DATE_ADD(a.createDate,INTERVAL cc.usePeriod DAY)))
- </if>
- AND cc.status != 2
- ORDER BY
- a.createDate DESC
- </select>
- <select id="findCouponById" resultType="com.caimei365.commodity.model.vo.ActivityCouponVo">
- SELECT id AS "couponId",
- NAME,
- pcBanner,
- appletsBanner,
- productType
- FROM cm_coupon
- WHERE productType = 2
- AND delFlag = 0
- AND couponType = 0
- AND NOW() BETWEEN startDate
- AND endDate
- AND status != 2
- AND id = #{couponId}
- </select>
- <select id="findCouponProduct" resultType="com.caimei365.commodity.model.vo.ProductItemVo">
- SELECT
- p.productID AS productId,
- p.actStatus,
- p.name,
- p.aliasName,
- p.mainImage AS image,
- (select unit from cm_sku where productId=p.productID and organizeId = 0 order by price asc limit 1)as unit,
- p.productCode AS CODE,
- p.priceFlag,
- (select price from cm_sku where productId=p.productID and organizeId = 0 order by price asc limit 1)as price,
- (select costPrice from cm_sku where productId=p.productID and organizeId = 0 order by price asc limit 1)as costPrice,
- (select costCheckFlag from cm_sku where productId=p.productID and organizeId = 0 order by price asc limit 1)as costCheckFlag,
- p.shopID AS shopId,
- p.searchKey AS keyword,
- (select minBuyNumber from cm_sku where productId=p.productID and organizeId = 0 order by price asc limit 1) AS minBuyNumber,
- (select ladderPriceFlag from cm_sku where productId=p.productID and organizeId = 0 order by price asc limit 1)as ladderPriceFlag,
- (select normalPrice from cm_sku where productId=p.productID and organizeId = 0 order by price asc limit 1)as normalPrice,
- p.step,
- p.shopID AS shopId,
- p.taxPoint AS taxRate,
- p.includedTax,
- p.invoiceType,
- p.productCategory AS productCategory,
- IFNULL((SELECT validFlag FROM cm_organize_product_info WHERE productId = p.productID AND organizeId = 0), 999) AS validFlag,
- p.featuredFlag,
- p.commodityType,
- p.bigTypeID AS bigTypeId,
- p.smallTypeID AS smallTypeId,
- p.tinyTypeID AS tinyTypeId,
- p.productType
- FROM
- cm_coupon_product a
- LEFT JOIN product p ON a.productId = p.productID
- left join cm_organize_product_info copi on copi.productId = p.productID and copi.organizeId = 0
- WHERE
- a.delFlag = 0
- AND a.couponId = #{couponId}
- <if test="source == 1">
- AND a.pcStatus = 1
- </if>
- <if test="source == 2">
- AND a.appletsStatus = 1
- </if>
- <choose>
- <when test="identity == 1">
- AND copi.validFlag IN (2,3,9)
- </when>
- <when test="identity == 5">
- AND copi.validFlag = 2
- </when>
- <when test="identity == 2">
- AND p.visibility IN (1,2,3) AND copi.validFlag = 2
- </when>
- <when test="identity == 4">
- AND p.visibility IN (2,3) AND copi.validFlag = 2
- </when>
- <otherwise>
- AND p.visibility = 3 AND copi.validFlag = 2
- </otherwise>
- </choose>
- ORDER BY
- -a.sort DESC
- </select>
- <select id="findCouponList" resultType="com.caimei365.commodity.model.vo.CouponVo">
- SELECT
- `id` AS "couponId",
- `couponAmount`,
- `touchPrice`,
- <if test="userId == null || userId == 0">
- startDate,
- endDate,
- </if>
- <if test="userId != null and userId > 0">
- if(#{registerTime} <![CDATA[ > ]]> startDate and #{registerTime} <![CDATA[ < ]]>
- endDate,#{registerTime},startDate) as startDate,
- if(useTimeFlag = 1 or receiveFlag = 1,endDate,
- date_add(if(#{registerTime} <![CDATA[ > ]]> startDate and #{registerTime} <![CDATA[ < ]]> endDate,
- #{registerTime},startDate),interval receivePeriod day)) as endDate,
- </if>
- moneyCouponPrice,
- moneyCouponFlag,
- moneyCouponType,
- `couponType`,
- `userId`,
- `shopId`,
- `productType`,
- `categoryType`,
- couponPayWay
- FROM
- cm_coupon
- WHERE
- delFlag = 0 AND vipFlag != 1
- AND status != 2
- AND couponsMode = 0
- <if test="userId == null or userId == 0">
- AND couponType != 2
- AND NOW() <![CDATA[ > ]]> startDate
- AND NOW() <![CDATA[ < ]]> if(useTimeFlag = 1 or receiveFlag = 1,endDate,date_add(startDate,interval
- receivePeriod day))
- </if>
- <if test="userId != null and userId > 0">
- AND id NOT IN(SELECT couponId FROM cm_coupon_club WHERE userId = #{userId})
- AND (couponType IN (0,1,3)
- OR (couponType = 2 AND userId = #{userId})
- OR (#{registerTime} <![CDATA[ >= ]]> startDate and #{registerTime} <![CDATA[ < ]]> endDate AND couponType =
- 4))
- and NOW() <![CDATA[ > ]]> startDate
- and NOW() <![CDATA[ < ]]> if(useTimeFlag = 1 or receiveFlag = 1,endDate,
- date_add(if(#{registerTime} <![CDATA[ > ]]> startDate and #{registerTime} <![CDATA[ < ]]>
- endDate,#{registerTime},startDate),interval receivePeriod day)
- )
- </if>
- ORDER BY
- createDate DESC
- </select>
- <select id="getCoupons" resultType="com.caimei365.commodity.model.vo.CouponVo">
- SELECT `id` AS "couponId",
- `couponAmount`,
- `touchPrice`,
- if(#{registerTime} <![CDATA[ > ]]> startDate and #{registerTime} <![CDATA[ < ]]> endDate, #{registerTime}, startDate) as startDate,
- if(useTimeFlag = 1 or receiveFlag = 1, endDate,
- date_add(if(#{registerTime} <![CDATA[ > ]]> startDate and #{registerTime} <![CDATA[ < ]]> endDate, #{registerTime}, startDate),
- interval receivePeriod day)) as endDate,
- if(usePeriod is null, endDate, date_add(NOW(), interval usePeriod day)) as usePeriod,
- -- `endDate`,
- `couponType`,
- `userId`,
- `shopId`,
- `productType`,
- `categoryType`
- FROM cm_coupon
- WHERE delFlag = 0
- AND status != 2
- AND id = #{couponId}
- </select>
- <select id="findCouponRedemptionCode" resultType="com.caimei365.commodity.model.po.CouponRedemptionCodePo">
- SELECT `id`,
- `couponId`,
- `clubCouponId`,
- `redemptionCode`,
- `status`,
- `redemptionTime`,
- `addTime`
- FROM `cm_coupon_redemption_code`
- WHERE redemptionCode = #{redemptionCode}
- </select>
- <select id="findCouponClubByUserId" resultType="integer">
- SELECT `id`
- FROM `cm_coupon_club`
- WHERE userId = #{userId}
- AND couponId = #{couponId}
- </select>
- <insert id="insertCouponClub" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
- INSERT INTO `cm_coupon_club` (`userId`,
- `couponId`,
- `orderId`,
- `source`,
- `status`,
- `createDate`,
- `useDate`,
- `delFlag`)
- VALUES (#{userId},
- #{couponId},
- #{orderId},
- #{source},
- #{status},
- #{createDate},
- #{useDate},
- #{delFlag})
- </insert>
- <update id="updateRedemptionCode">
- UPDATE
- cm_coupon_redemption_code
- SET STATUS = 2,
- redemptionTime = NOW(),
- clubCouponId = #{clubCouponId}
- WHERE id = #{id}
- </update>
- <select id="findUserRegisterTime" resultType="date">
- SELECT registerTime
- FROM user
- WHERE userID = #{userId}
- </select>
- <select id="findVip" resultType="java.lang.Integer">
- select userId
- from cm_svip_user
- where userId = #{userId}
- AND delFlag = 0
- AND endtime > now()
- </select>
- <select id="findVipCoupon" resultType="java.lang.Integer">
- select couponId
- from cm_svip_coupon
- </select>
- <select id="findMoneyCoupons" resultType="com.caimei365.commodity.model.vo.CouponVo">
- SELECT cc.`id` AS "couponId",
- cc.`couponAmount`,
- cc.`touchPrice`,
- if(#{registerTime} <![CDATA[ > ]]> cc.startDate and #{registerTime} <![CDATA[ < ]]> cc.endDate, #{registerTime},
- cc.startDate) as startDate,
- if(useTimeFlag = 1 or receiveFlag = 1, cc.endDate, date_add(
- if(#{registerTime} <![CDATA[ > ]]> cc.startDate and #{registerTime} <![CDATA[ < ]]> cc.endDate, #{registerTime},
- cc.startDate),
- interval receivePeriod day)) as endDate,
- cc.moneyCouponPrice,
- cc.moneyCouponFlag,
- cc.moneyCouponType,
- cc.`couponType`,
- cc.`userId`,
- cc.`shopId`,
- cc.`productType`,
- cc.`categoryType`,
- cc.couponPayWay,
- s.name as shopName
- FROM cm_coupon cc
- LEFT JOIN shop s ON cc.shopId = s.shopId
- WHERE cc.delFlag = 0
- AND cc.vipFlag != 1
- AND cc.id != 49
- AND cc.status != 2
- AND cc.couponsMode = 0
- AND cc.moneyCouponFlag = 1
- AND (cc.couponType IN (0,1,3)
- OR (cc.couponType = 2 AND cc.userId = #{userId})
- OR (#{registerTime} <![CDATA[ >= ]]> cc.startDate
- and #{registerTime} <![CDATA[ < ]]> cc.endDate
- AND cc.couponType = 4))
- and NOW() <![CDATA[ > ]]> cc.startDate
- and NOW() <![CDATA[ < ]]> if(receiveFlag = 1
- , cc.endDate
- , date_add(if(#{registerTime} <![CDATA[ > ]]> cc.startDate
- and #{registerTime} <![CDATA[ < ]]> cc.endDate
- , #{registerTime}
- , cc.startDate)
- , interval receivePeriod day)
- )
- ORDER BY
- cc.createDate DESC
- </select>
- <select id="findCouponDetail" resultType="com.caimei365.commodity.model.vo.CouponVo">
- SELECT cc.`id` AS "couponId",
- cc.`couponAmount`,
- cc.`touchPrice`,
- cc.startDate,
- cc.endDate,
- cc.`couponType`,
- cc.`userId`,
- cc.`shopId`,
- cc.`productType`,
- cc.`categoryType`,
- cc.moneyCouponPrice,
- cc.moneyCouponFlag,
- s.name as shopName,
- cc.couponPayWay
- FROM cm_coupon cc
- LEFT JOIN shop s ON cc.shopId = s.shopId
- where id = #{couponId}
- </select>
- <select id="findUserPermission" resultType="java.lang.Integer">
- select userIdentity
- from user
- where userID = #{userId}
- </select>
- </mapper>
|