123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678 |
- <?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.coupon.dao.CmCouponDao">
- <sql id="cmCouponColumns">
- a.id AS "id",
- a.name AS "name",
- a.couponAmount AS "couponAmount",
- a.touchPrice AS "touchPrice",
- a.startDate AS "startDate",
- a.endDate AS "endDate",
- a.receivePeriod,
- a.receiveFlag,
- a.usePeriod,
- a.useTimeFlag,
- a.status AS "status",
- a.couponType AS "couponType",
- a.vipFlag AS "vipFlag",
- a.userId AS "userId",
- a.shopId AS "shopId",
- a.productType AS "productType",
- a.pcBanner AS "pcBanner",
- a.appletsBanner AS "appletsBanner",
- a.categoryType AS "categoryType",
- a.couponsMode AS "couponsMode",
- a.moneyCouponPrice AS "moneyCouponPrice",
- a.moneyCouponFlag AS "moneyCouponFlag",
- a.moneyCouponType as "moneyCouponType",
- a.createDate AS "createDate",
- a.couponPayWay as "couponPayWay",
- a.shareCouponImage as "shareCouponImage",
- a.shareCouponTopic as "shareCouponTopic",
- a.delFlag AS "delFlag"
- </sql>
- <sql id="cmCouponJoins">
- </sql>
- <select id="get" resultType="CmCoupon">
- SELECT
- <include refid="cmCouponColumns"/>
- FROM cm_coupon a
- <include refid="cmCouponJoins"/>
- WHERE a.id = #{id}
- </select>
- <select id="findList" resultType="CmCoupon">
- SELECT
- <include refid="cmCouponColumns"/>,
- u.name AS "clubName",
- s.name AS "shopName"
- FROM cm_coupon a
- LEFT JOIN cm_coupon_club ccc ON ccc.couponId = a.id
- LEFT JOIN USER u ON u.userID = a.userId
- LEFT JOIN shop s ON s.shopID = a.shopId
- <include refid="cmCouponJoins"/>
- <where>
- AND a.delFlag = 0 AND a.vipFlag != '1'
- <if test="couponType != null and couponType != 5">
- AND a.couponType = #{couponType}
- </if>
- <if test="moneyCouponFlag != null and moneyCouponFlag > 0">
- AND a.moneyCouponFlag = #{moneyCouponFlag}
- </if>
- <if test="couponPayWay != null">
- AND a.couponPayWay = #{couponPayWay}
- </if>
- <if test="name != null and name != ''">
- AND a.name LIKE
- <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
- <if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
- <if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
- </if>
- <if test="startDate != null and startDate != ''">
- AND a.startDate <![CDATA[ >= ]]> #{startDate}
- </if>
- <if test="endDate != null and endDate != ''">
- AND a.endDate <![CDATA[ <= ]]> #{endDate}
- </if>
- <if test='status == "0"'>
- AND a.startDate <![CDATA[ > ]]> NOW()
- </if>
- <if test='status == "1"'>
- AND a.startDate <![CDATA[ <= ]]> NOW()
- AND a.endDate <![CDATA[ >= ]]> NOW()
- AND a.status != '2'
- </if>
- <if test='status == "2"'>
- AND a.status = '2'
- </if>
- <if test='status == "3"'>
- AND a.endDate <![CDATA[ < ]]> NOW()
- </if>
- <if test="clubName != null and clubName != ''">
- AND u.name LIKE concat('%',#{clubName},'%')
- </if>
- <if test='claimStatus == "1"'>
- AND ccc.id IS NULL
- </if>
- <if test='claimStatus == "2"'>
- AND ccc.id IS NOT NULL
- </if>
- <if test='useStatus == "1"'>
- AND (ccc.status IS NULL OR ccc.status = #{useStatus})
- </if>
- <if test='useStatus == "2"'>
- AND ccc.status = #{useStatus}
- </if>
- <if test="source != null and source != ''">
- AND ccc.source = #{source}
- </if>
- <if test="shopName != null and shopName != ''">
- AND s.name LIKE concat('%',#{shopName},'%')
- </if>
- <if test="couponsMode != null and couponsMode != ''">
- AND a.couponsMode = #{couponsMode}
- </if>
- </where>
- GROUP BY a.id
- <choose>
- <when test="page !=null and page.orderBy != null and page.orderBy != ''">
- ORDER BY ${page.orderBy}
- </when>
- <otherwise>
- ORDER BY createDate DESC
- </otherwise>
- </choose>
- </select>
- <select id="findAllList" resultType="CmCoupon">
- SELECT
- <include refid="cmCouponColumns"/>
- FROM cm_coupon a
- <include refid="cmCouponJoins"/>
- <where>
- </where>
- <choose>
- <when test="page !=null and page.orderBy != null and page.orderBy != ''">
- ORDER BY ${page.orderBy}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- </select>
- <insert id="insert" parameterType="CmCoupon" keyProperty="id" useGeneratedKeys="true">
- INSERT INTO cm_coupon(
- name,
- couponPayWay,
- couponAmount,
- touchPrice,
- startDate,
- endDate,
- receivePeriod,
- receiveFlag,
- useTimeFlag,
- usePeriod,
- status,
- couponType,
- vipFlag,
- userId,
- shopId,
- productType,
- pcBanner,
- appletsBanner,
- categoryType,
- couponsMode,
- createDate,
- moneyCouponPrice,
- moneyCouponFlag,
- moneyCouponType,
- delFlag,
- configure,
- shareCouponImage,
- shareCouponTopic
- ) VALUES (
- #{name},
- #{couponPayWay},
- #{couponAmount},
- #{touchPrice},
- #{startDate},
- #{endDate},
- #{receivePeriod},
- #{receiveFlag},
- #{useTimeFlag},
- #{usePeriod},
- #{status},
- #{couponType},
- #{vipFlag},
- #{userId},
- #{shopId},
- #{productType},
- #{pcBanner},
- #{appletsBanner},
- #{categoryType},
- #{couponsMode},
- #{createDate},
- #{moneyCouponPrice},
- #{moneyCouponFlag},
- #{moneyCouponType},
- #{delFlag},
- #{configure},
- #{shareCouponImage},
- #{shareCouponTopic}
- )
- </insert>
- <update id="update">
- UPDATE cm_coupon SET
- name = #{name},
- couponPayWay = #{couponPayWay},
- couponAmount = #{couponAmount},
- touchPrice = #{touchPrice},
- startDate = #{startDate},
- endDate = #{endDate},
- receivePeriod = #{receivePeriod},
- receiveFlag = #{receiveFlag},
- useTimeFlag = #{useTimeFlag},
- usePeriod = #{usePeriod},
- status = #{status},
- couponType = #{couponType},
- vipFlag = #{vipFlag},
- userId = #{userId},
- shopId = #{shopId},
- productType = #{productType},
- pcBanner = #{pcBanner},
- appletsBanner = #{appletsBanner},
- categoryType = #{categoryType},
- couponsMode = #{couponsMode},
- moneyCouponPrice = #{moneyCouponPrice},
- moneyCouponType = #{moneyCouponType},
- configure = #{configure},
- shareCouponImage = #{shareCouponImage},
- shareCouponTopic = #{shareCouponTopic}
- WHERE id = #{id}
- </update>
- <delete id="delete">
- DELETE FROM cm_coupon
- WHERE id = #{id}
- </delete>
- <select id="findByProductType" resultType="com.caimei.modules.coupon.entity.CmCouponAssociate">
- SELECT
- cca.id,
- cca.couponId,
- cca.productId,
- cca.pcStatus,
- cca.appletsStatus,
- cca.sort,
- cca.addTime,
- cca.delFlag,
- s.name AS shopName,
- p.name AS productName,
- p.mainImage AS image
- FROM
- cm_coupon_product cca
- LEFT JOIN product p ON cca.productId = p.productID
- LEFT JOIN shop s ON p.shopID = s.shopID
- WHERE
- cca.couponId = #{couponId}
- AND delFlag = 0
- ORDER BY
- - sort DESC
- </select>
- <insert id="insertCouponAssociate">
- INSERT INTO `cm_coupon_product` (
- `couponId`, `productId`, `pcStatus`,
- `appletsStatus`,
- `sort`, `addTime`, `delFlag`
- )
- VALUES
- (
- #{couponId}, #{productId}, #{pcStatus},
- #{appletsStatus},
- #{sort}, #{addTime}, #{delFlag}
- )
- </insert>
- <select id="findByCouponId" resultType="integer">
- SELECT id FROM cm_coupon_product WHERE couponId = #{couponId} AND delFlag = 0
- </select>
- <update id="updateCouponAssociate">
- UPDATE
- `cm_coupon_product`
- <set>
- <if test="pcStatus != null and pcStatus != ''">
- `pcStatus` = #{pcStatus},
- </if>
- <if test="appletsStatus != null and appletsStatus != ''">
- `appletsStatus` = #{appletsStatus},
- </if>
- <if test="sort != null">
- `sort` = #{sort},
- </if>
- </set>
- WHERE
- `id` = #{id}
- </update>
- <update id="logicDeleteCouponAssociate">
- UPDATE cm_coupon_product SET delFlag = 1 WHERE id = #{id}
- </update>
- <update id="updateByDelFlag">
- UPDATE cm_coupon SET delFlag = 1 WHERE id = #{couponId}
- </update>
- <update id="updateAssociateByDelFlag">
- UPDATE cm_coupon_product SET delFlag = 1 WHERE couponId = #{couponId}
- </update>
- <select id="findCouponClub" resultType="com.caimei.modules.coupon.entity.CmCouponClub">
- SELECT
- `userId`,
- `couponId`,
- orderId,
- `source`,
- `status`,
- `createDate`,
- `useDate`,
- `delFlag`
- FROM
- `cm_coupon_club`
- WHERE
- couponId = #{couponId}
- AND delFlag = 0
- LIMIT
- 1
- </select>
- <select id="findUserList" resultType="com.caimei.modules.user.entity.CmUser">
- SELECT
- c.clubID,
- c.userID,
- u.userName,
- u.bindMobile,
- u.name,
- u.userIdentity,
- c.sname AS shortName
- FROM
- club c
- LEFT JOIN USER u ON c.userID = u.userID
- WHERE
- c.status IN (1, 90)
- <if test="userID != null">
- AND u.userID = #{userID}
- </if>
- <if test="name != null and name != ''">
- AND u.name LIKE CONCAT('%',#{name},'%')
- </if>
- <if test="shortName != null and shortName != ''">
- AND c.sname LIKE CONCAT('%',#{shortName},'%')
- </if>
- ORDER BY
- userID ASC
- </select>
- <select id="findShopList" resultType="com.caimei.modules.user.entity.NewCmShop">
- SELECT
- s.shopID,
- s.userID,
- IFNULL(s.name, u.name) AS name,
- IFNULL(s.sname, u.realName) AS sname,
- IFNULL(s.contractMobile, u.bindMobile) AS contractMobile,
- IFNULL(s.linkMan, u.userName) AS linkMan
- FROM
- shop s
- LEFT JOIN USER u ON u.`shopID` = s.`shopID`
- WHERE
- s.status = 90
- <if test="shopID != null">
- AND s.shopID = #{shopID}
- </if>
- <if test="name != null and name != ''">
- AND (s.name LIKE CONCAT('%',#{name},'%') OR u.name LIKE CONCAT('%',#{name},'%'))
- </if>
- <if test="sname != null and sname != ''">
- AND (s.sname LIKE CONCAT('%',#{sname},'%') OR u.realName LIKE CONCAT('%',#{sname},'%'))
- </if>
- ORDER BY
- s.shopID
- </select>
- <select id="findRedemptionCodeNum" resultType="integer">
- SELECT COUNT(id) FROM cm_coupon_redemption_code WHERE couponId = #{couponId}
- </select>
- <select id="findByRedemptionCode" resultType="com.caimei.modules.coupon.entity.CmCouponRedemptionCode">
- SELECT
- `id`,
- `couponId`,
- `clubCouponId`,
- `redemptionCode`,
- `status`,
- `redemptionTime`,
- `addTime`
- FROM
- cm_coupon_redemption_code
- WHERE
- redemptionCode = #{redemptionCode}
- </select>
- <insert id="insertRedemptionCode">
- INSERT INTO `cm_coupon_redemption_code` (
- `couponId`,
- `clubCouponId`,
- `redemptionCode`,
- `status`,
- `redemptionTime`,
- `addTime`
- )
- VALUES
- (
- #{couponId},
- #{clubCouponId},
- #{redemptionCode},
- #{status},
- #{redemptionTime},
- #{addTime}
- )
- </insert>
- <select id="findRedemptionCode" resultType="com.caimei.modules.coupon.entity.CmCouponRedemptionCode">
- SELECT
- `id`,
- `couponId`,
- `clubCouponId`,
- `redemptionCode`,
- `status`,
- `redemptionTime`,
- `addTime`
- FROM
- cm_coupon_redemption_code
- WHERE
- couponId = #{couponId}
- <if test="status != null and status != ''">
- AND status = #{status}
- </if>
- ORDER BY
- addTime DESC
- </select>
- <select id="findQuantityRedeemed" resultType="integer">
- SELECT COUNT(id) FROM cm_coupon_redemption_code WHERE couponId = #{couponId} AND status = 2
- </select>
- <select id="findClubCouponList" resultType="com.caimei.modules.coupon.entity.CmCoupon">
- SELECT
- cc.`id`,
- cc.`name`,
- cc.`couponAmount`,
- cc.`touchPrice`,
- cc.`startDate`,
- cc.`endDate`,
- a.`createDate` as `receiveDate`,
- if(useTimeFlag = 1, cc.endDate,date_add(a.createDate,interval cc.usePeriod DAY)) as `useEndDate`,
- cc.`status`,
- cc.`couponType`,
- cc.`userId`,
- cc.`shopId`,
- cc.`productType`,
- cc.`pcBanner`,
- cc.`appletsBanner`,
- cc.`categoryType`,
- cc.`couponsMode`,
- cc.`createDate`,
- cc.`delFlag`,
- a.id AS clubCouponId,
- ccrc.redemptionCode
- FROM
- cm_coupon_club a
- LEFT JOIN cm_coupon cc ON a.couponId = cc.id
- LEFT JOIN cm_coupon_redemption_code ccrc ON a.id = ccrc.clubCouponId
- WHERE
- if(moneyCouponFlag=2,cc.delFlag = 0,cc.id>0)
- AND a.delFlag = 0
- AND a.userId = #{userId}
- AND a.status = 1
- AND NOW() <![CDATA[ < ]]> if(cc.usePeriod is null,cc.endDate,date_add(a.createDate,interval cc.usePeriod DAY))
- AND cc.status != 2
- ORDER BY
- a.createDate DESC
- </select>
- <select id="findAllProductId" resultType="integer">
- SELECT
- productId
- FROM
- cm_coupon_product
- WHERE
- couponId = #{couponId}
- AND (
- pcStatus = 1
- OR appletsStatus = 1
- )
- </select>
- <select id="findNotRedeemedCoupon" resultType="com.caimei.modules.coupon.entity.CmCoupon">
- SELECT
- a.`id`,
- a.`name`,
- a.`couponAmount`,
- a.`touchPrice`,
- a.`startDate`,
- a.`endDate`,
- a.`status`,
- a.`couponType`,
- a.`userId`,
- a.`shopId`,
- a.`productType`,
- a.`pcBanner`,
- a.`appletsBanner`,
- a.`categoryType`,
- a.`couponsMode`,
- a.`createDate`,
- a.`delFlag`,
- ccrc.redemptionCode
- FROM
- cm_coupon a
- LEFT JOIN cm_coupon_redemption_code ccrc ON a.id = ccrc.couponId
- WHERE
- a.status != 2
- AND a.moneyCouponFlag = 2
- AND a.delFlag = 0
- AND NOW() BETWEEN a.startDate
- AND a.endDate
- AND a.couponsMode = 1
- AND ccrc.status = 1
- </select>
- <select id="findCouponList" resultType="com.caimei.modules.coupon.entity.CmCoupon">
- SELECT
- cc.`id`,
- cc.`name`,
- cc.`couponAmount`,
- cc.`touchPrice`,
- cc.`startDate`,
- cc.`endDate`,
- cc.`status`,
- cc.`couponType`,
- cc.`userId`,
- cc.`shopId`,
- cc.`productType`,
- cc.`pcBanner`,
- cc.`appletsBanner`,
- cc.`categoryType`,
- cc.`couponsMode`,
- cc.`createDate`,
- cc.moneyCouponPrice,
- cc.`delFlag`
- FROM
- cm_coupon cc
- WHERE
- cc.id > 0
- AND cc.delFlag = 0
- AND cc.moneyCouponFlag = #{moneyCouponFlag}
- AND cc.status != 2
- AND cc.couponsMode = 0
- AND (couponType IN (0,1,3)
- OR (couponType = 2 AND userId = #{userId})
- OR ((SELECT registerTime FROM USER WHERE userID = #{userId}) <![CDATA[ >= ]]> startDate
- AND couponType = 4))
- AND NOW() <![CDATA[ < ]]> if(useTimeFlag = 1 or receiveFlag = 1,endDate,
- date_add(if((SELECT registerTime FROM USER WHERE userID = #{userId}) <![CDATA[ > ]]> startDate and (SELECT registerTime FROM USER WHERE userID = #{userId}) <![CDATA[ < ]]> endDate,(SELECT registerTime FROM USER WHERE userID = #{userId}),startDate),
- interval receivePeriod day))
- ORDER BY
- cc.couponAmount DESC
- </select>
- <update id="updateClubCoupon">
- UPDATE
- cm_coupon_club
- SET
- STATUS = 2,
- orderId = #{orderId},
- useDate = NOW()
- WHERE
- id = #{clubCouponId}
- </update>
- <select id="selconfigure" resultType="com.caimei.modules.coupon.entity.CmCoupon">
- SELECT <include refid="cmCouponColumns"/> FROM cm_coupon a WHERE configure = 1
- </select>
- <select id="selMonthTime" resultType="java.lang.String">
- SELECT cscm.useTime
- FROM cm_coupon a
- LEFT JOIN cm_svip_coupon csc ON a.id = csc.couponId
- LEFT JOIN cm_svip_coupon_month cscm ON csc.montId = cscm.id WHERE a.delFlag = 0 AND a.configure = 1 LIMIT 1
- </select>
- <select id="selCouponId" resultType="integer">
- SELECT cscm.id as id FROM cm_svip_coupon_month cscm LEFT JOIN cm_svip_coupon csc ON csc.montId = cscm.id WHERE csc.couponId = #{couponId}
- </select>
- <!--<insert id="insertConfigure">
- INSERT INTO cm_coupon_configure(
- name,
- couponPayWay,
- couponAmount,
- touchPrice,
- startDate,
- endDate,
- receivePeriod,
- receiveFlag,
- useTimeFlag,
- usePeriod,
- status,
- couponType,
- vipFlag,
- userId,
- shopId,
- productType,
- pcBanner,
- appletsBanner,
- categoryType,
- couponsMode,
- createDate,
- moneyCouponPrice,
- moneyCouponFlag,
- moneyCouponType,
- delFlag
- ) VALUES (
- #{name},
- #{couponPayWay},
- #{couponAmount},
- #{touchPrice},
- #{startDate},
- #{endDate},
- #{receivePeriod},
- #{receiveFlag},
- #{useTimeFlag},
- #{usePeriod},
- #{status},
- #{couponType},
- #{vipFlag},
- #{userId},
- #{shopId},
- #{productType},
- #{pcBanner},
- #{appletsBanner},
- #{categoryType},
- #{couponsMode},
- #{createDate},
- #{moneyCouponPrice},
- #{moneyCouponFlag},
- #{moneyCouponType},
- #{delFlag}
- )
- </insert>
- <update id="updateConfigure">
- UPDATE cm_coupon_configure SET
- name = #{name},
- couponPayWay = #{couponPayWay},
- couponAmount = #{couponAmount},
- touchPrice = #{touchPrice},
- startDate = #{startDate},
- endDate = #{endDate},
- receivePeriod = #{receivePeriod},
- receiveFlag = #{receiveFlag},
- useTimeFlag = #{useTimeFlag},
- usePeriod = #{usePeriod},
- status = #{status},
- couponType = #{couponType},
- vipFlag = #{vipFlag},
- userId = #{userId},
- shopId = #{shopId},
- productType = #{productType},
- pcBanner = #{pcBanner},
- appletsBanner = #{appletsBanner},
- categoryType = #{categoryType},
- couponsMode = #{couponsMode},
- moneyCouponPrice = #{moneyCouponPrice},
- moneyCouponType = #{moneyCouponType}
- WHERE id = #{id}
- </update>-->
- </mapper>
|