123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- <?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.hehe.dao.CmHeheCouponDao">
-
- <sql id="cmHeheCouponColumns">
- a.id AS "id",
- a.name AS "name",
- a.couponAmount AS "couponAmount",
- a.touchPrice AS "touchPrice",
- a.noThresholdFlag AS "noThresholdFlag",
- a.startTime AS "startTime",
- a.endTime AS "endTime",
- a.startNowFlag AS "startNowFlag",
- a.permanentFlag AS "permanentFlag",
- a.couponType AS "couponType",
- a.productType AS "productType",
- a.receivePeriod AS "receivePeriod",
- a.receiveFlag AS "receiveFlag",
- a.usePeriod AS "usePeriod",
- a.createDate AS "createDate",
- a.delFlag AS "delFlag"
- </sql>
-
- <sql id="cmHeheCouponJoins">
- </sql>
-
- <select id="get" resultType="CmHeheCoupon">
- SELECT
- <include refid="cmHeheCouponColumns"/>
- FROM cm_hehe_coupon a
- <include refid="cmHeheCouponJoins"/>
- WHERE a.id = #{id}
- </select>
-
- <select id="findList" resultType="CmHeheCoupon">
- SELECT
- <include refid="cmHeheCouponColumns"/>
- FROM cm_hehe_coupon a
- <include refid="cmHeheCouponJoins"/>
- <where>
- AND a.delFlag = 0
- <if test="couponType != null">
- AND a.couponType = #{couponType}
- </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='status == "1"'>
- AND (NOW() <![CDATA[ < ]]> a.startTime and a.startNowFlag = 0)
- </if>
- <if test='status == "2"'>
- AND (NOW() <![CDATA[ >= ]]> a.startTime OR a.startNowFlag = 1)
- AND (NOW() <![CDATA[ <= ]]> a.endTime OR a.permanentFlag = 1)
- </if>
- <if test='status == "3"'>
- AND (NOW() <![CDATA[ > ]]> a.endTime and a.permanentFlag = 0)
- </if>
- </where>
- <choose>
- <when test="page !=null and page.orderBy != null and page.orderBy != ''">
- ORDER BY ${page.orderBy}
- </when>
- <otherwise>
- order by a.createDate desc
- </otherwise>
- </choose>
- </select>
-
- <select id="findAllList" resultType="CmHeheCoupon">
- SELECT
- <include refid="cmHeheCouponColumns"/>
- FROM cm_hehe_coupon a
- <include refid="cmHeheCouponJoins"/>
- <where>
-
- </where>
- <choose>
- <when test="page !=null and page.orderBy != null and page.orderBy != ''">
- ORDER BY ${page.orderBy}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- </select>
- <select id="findCouponProductIds" resultType="java.lang.Integer">
- SELECT id FROM cm_hehe_coupon_product WHERE couponId = #{couponId}
- </select>
- <select id="findCouponProductList" resultType="com.caimei.modules.hehe.entity.CmHeheCouponProduct">
- SELECT
- cca.id,
- cca.couponId,
- cca.productId,
- cca.status,
- cca.sort,
- cca.addTime,
- s.name AS shopName,
- p.name AS productName,
- p.mainImage AS image
- FROM
- cm_hehe_coupon_product cca
- left join cm_hehe_product chp on cca.productId = chp.productId
- LEFT JOIN product p ON chp.productId = p.productID
- LEFT JOIN shop s ON p.shopID = s.shopID
- WHERE
- cca.couponId = #{couponId}
- ORDER BY
- - cca.sort DESC
- </select>
- <select id="findAllUser" resultType="com.caimei.modules.user.entity.CmUser">
- select id,userId as userID, nickName,mobile,userIdentity,openId as openID
- from cm_hehe_user
- <where>
- <if test="mobile != null and mobile != ''">
- AND mobile = #{mobile}
- </if>
- <if test="userIdentity != null and userIdentity != ''">
- AND userIdentity = #{userIdentity}
- </if>
- <if test="nickName != null and nickName != ''">
- AND nickName LIKE concat('%',#{nickName},'%')
- </if>
- </where>
- ORDER BY addTime DESC
- </select>
- <select id="findCouponUserIds" resultType="java.lang.Integer">
- SELECT id FROM cm_hehe_coupon_user WHERE couponId = #{couponId}
- </select>
- <select id="findCouponUserList" resultType="com.caimei.modules.hehe.entity.CmHeheCouponUser">
- select chu.id, chu.userId, chu.couponId, chu.addTime, u.nickName, u.mobile, u.userIdentity
- from cm_hehe_coupon_user chu
- left join cm_hehe_user u on chu.userId = u.userId
- where chu.couponId = #{id}
- order by chu.addTime desc
- </select>
- <select id="allUserList" resultType="com.caimei.modules.hehe.entity.CmHeheReceiveUser">
- select u.userId as userId,u.nickName,u.mobile,u.userIdentity,count(rc.id) as receiveNum, count(chc.id) as ableNum
- from cm_hehe_user u
- left join cm_hehe_receive_coupon rc on u.userId = rc.userId and rc.delFlag = 0 and rc.couponId in (select id from cm_hehe_coupon where delFlag = 0)
- left join cm_hehe_coupon chc on rc.couponId = chc.id
- and NOW() <![CDATA[ < ]]> DATE_ADD(rc.receiveTime ,interval chc.usePeriod DAY) and rc.status = 1
- and chc.delFlag = 0
- <where>
- <if test="nickName != null and nickName != ''">
- and u.nickName like concat('%',#{nickName},'%')
- </if>
- <if test="mobile != null and mobile != ''">
- and u.mobile like concat('%',#{mobile},'%')
- </if>
- <if test="userIdentity != null">
- and u.userIdentity = #{userIdentity}
- </if>
- </where>
- group by u.id
- having receiveNum >0
- order by count(chc.id) desc,u.id desc
- </select>
- <select id="receiveUserList" resultType="com.caimei.modules.hehe.entity.CmHeheReceiveUser">
- select chu.id as userId,
- chu.nickName,
- chu.mobile,
- chrc.source,
- chrc.receiveTime,
- date_add(chrc.receiveTime, interval chc.usePeriod DAY) as validPeriod,
- chrc.status,
- if(NOW() <![CDATA[ > ]]> date_add(chrc.receiveTime, interval chc.usePeriod DAY), 0, 1) as validFlag,
- chrc.useTime,
- chrc.orderId
- from cm_hehe_user chu
- left join cm_hehe_receive_coupon chrc on chu.userId = chrc.userId
- left join cm_hehe_coupon chc on chrc.couponId = chc.id
- <where>
- chrc.couponId = #{couponId}
- <if test="nickName != null and nickName != ''">
- and chu.nickName like concat('%',#{nickName},'%')
- </if>
- <if test="mobile != null and mobile != ''">
- and chu.mobile like concat('%',#{mobile},'%')
- </if>
- <if test="status != null">
- <if test="status == 2">
- and chrc.status = 2
- </if>
- <if test="status == 1">
- and chrc.status = 1 and NOW() <![CDATA[ <= ]]> date_add(chrc.receiveTime, interval chc.usePeriod DAY)
- </if>
- <if test="status == 3">
- and chrc.status = 1 and NOW() <![CDATA[ > ]]> date_add(chrc.receiveTime, interval chc.usePeriod DAY)
- </if>
- </if>
- </where>
- order by chrc.receiveTime desc
- </select>
- <select id="receiveCouponList" resultType="com.caimei.modules.hehe.entity.CmHeheCoupon">
- select chc.name,chc.couponType,chc.couponAmount,chc.touchPrice,chrc.receiveTime,
- date_add(chrc.receiveTime,interval chc.usePeriod DAY) as validPeriod,chrc.status as useStatus,
- if(NOW() <![CDATA[ > ]]> date_add(chrc.receiveTime, interval chc.usePeriod DAY), 0, 1) as validFlag,
- chrc.useTime,co.orderNo,co.orderID as orderId
- from cm_hehe_coupon chc
- left join cm_hehe_receive_coupon chrc on chc.id = chrc.couponId
- left join cm_hehe_user chu on chrc.userId = chu.userId
- left join cm_order co on chrc.orderId = co.orderID
- <where>
- <if test="userId != null">
- chrc.userId = #{userId}
- </if>
- and chrc.delFlag = 0
- and chc.delFlag = 0
- <if test="name != null and name !=''">
- and chc.name like concat('%',#{name},'%')
- </if>
- <if test="couponType != null">
- and chc.couponType = #{couponType}
- </if>
- <if test="useStatus != null">
- <if test="useStatus == 2">
- and chrc.status = 2
- </if>
- <if test="useStatus == 1">
- and chrc.status = 1 and NOW() <![CDATA[ <= ]]> date_add(chrc.receiveTime, interval chc.usePeriod DAY)
- </if>
- <if test="useStatus == 3">
- and chrc.status = 1 and NOW() <![CDATA[ > ]]> date_add(chrc.receiveTime, interval chc.usePeriod DAY)
- </if>
- </if>
- </where>
- order by chrc.receiveTime desc
- </select>
- <insert id="insert" parameterType="CmHeheCoupon" keyProperty="id" useGeneratedKeys="true">
- INSERT INTO cm_hehe_coupon(
- name,
- couponAmount,
- touchPrice,
- noThresholdFlag,
- startTime,
- endTime,
- startNowFlag,
- permanentFlag,
- couponType,
- productType,
- receivePeriod,
- receiveFlag,
- usePeriod,
- createDate,
- delFlag
- ) VALUES (
- #{name},
- #{couponAmount},
- #{touchPrice},
- #{noThresholdFlag},
- #{startTime},
- #{endTime},
- #{startNowFlag},
- #{permanentFlag},
- #{couponType},
- #{productType},
- #{receivePeriod},
- #{receiveFlag},
- #{usePeriod},
- #{createDate},
- #{delFlag}
- )
- </insert>
- <insert id="insertCouponProduct">
- INSERT INTO `cm_hehe_coupon_product` (
- `couponId`, `productId`, `status`,
- `sort`, `addTime`
- )
- VALUES
- (
- #{couponId}, #{productId}, #{status},
- #{sort}, #{addTime}
- )
- </insert>
- <insert id="insertCouponUser">
- insert into cm_hehe_coupon_user (couponId, userId, addTime) values (#{couponId}, #{userId}, #{addTime})
- </insert>
- <update id="update">
- UPDATE cm_hehe_coupon SET
- name = #{name},
- couponAmount = #{couponAmount},
- touchPrice = #{touchPrice},
- noThresholdFlag = #{noThresholdFlag},
- startTime = #{startTime},
- endTime = #{endTime},
- startNowFlag = #{startNowFlag},
- permanentFlag = #{permanentFlag},
- productType = #{productType},
- receivePeriod = #{receivePeriod},
- receiveFlag = #{receiveFlag},
- usePeriod = #{usePeriod}
- WHERE id = #{id}
- </update>
- <update id="updateCouponProduct">
- UPDATE
- `cm_hehe_coupon_product`
- <set>
- <if test="status != null">
- `status` = #{status},
- </if>
- <if test="sort != null">
- `sort` = #{sort},
- </if>
- </set>
- WHERE
- `id` = #{id}
- </update>
- <delete id="delete">
- DELETE FROM cm_hehe_coupon
- WHERE id = #{id}
- </delete>
- <delete id="deleteCouponProduct">
- delete from cm_hehe_coupon_product where id = #{id}
- </delete>
- <delete id="deleteCouponUser">
- delete from cm_hehe_coupon_user where id = #{id}
- </delete>
- <update id="deleteCoupon">
- update cm_hehe_coupon set delFlag = 1 where id = #{id}
- </update>
- </mapper>
|