|
@@ -8,12 +8,13 @@
|
|
|
values (#{userId}, #{couponId}, NOW())
|
|
|
</insert>
|
|
|
<insert id="insertReceiveCoupon">
|
|
|
- insert into cm_hehe_receive_coupon (userId, couponId, source, status, receiveTime, delFlag)
|
|
|
- values (#{userId}, #{couponId}, #{source}, #{status}, #{receiveTime}, #{delFlag})
|
|
|
+ insert into cm_hehe_receive_coupon (userId, couponId, couponShareId, source, status, receiveTime, delFlag)
|
|
|
+ values (#{userId}, #{couponId}, #{couponShareId}, #{source}, #{status}, #{receiveTime}, #{delFlag})
|
|
|
+ </insert>
|
|
|
+ <insert id="insertCouponShare">
|
|
|
+ insert into cm_hehe_coupon_share (shareUserId, receiveUserId, type, shareCouponId, createTime)
|
|
|
+ values (#{shareUserId}, #{receiveUserId}, 2, #{shareCouponId}, NOW())
|
|
|
</insert>
|
|
|
- <update id="updateCouponShareRecord">
|
|
|
- update cm_hehe_coupon_share set consumeFlag = 1 and consumeCouponIds = #{consumeCouponIds}
|
|
|
- </update>
|
|
|
<select id="getCouponCount" resultType="java.lang.Integer">
|
|
|
select count(*) from cm_hehe_coupon
|
|
|
where couponType = #{couponType}
|
|
@@ -36,7 +37,8 @@
|
|
|
and userId = #{userId}
|
|
|
</select>
|
|
|
<select id="findCouponList" resultType="com.caimei.model.vo.CouponVo">
|
|
|
- select distinct chc.id as couponId,
|
|
|
+ select chc.id as couponId,
|
|
|
+ chcs.id as couponShareId,
|
|
|
name as couponName,
|
|
|
couponType,
|
|
|
productType,
|
|
@@ -50,56 +52,67 @@
|
|
|
date_add(startTime,interval receivePeriod DAY)
|
|
|
</if>
|
|
|
<if test="userId > 0">
|
|
|
- date_add(if(#{registerTime} <![CDATA[ >= ]]> startTime,
|
|
|
- #{registerTime},startTime),interval receivePeriod DAY)
|
|
|
+ date_add(
|
|
|
+ if(couponType <![CDATA[ <= ]]> 3,
|
|
|
+ if(#{registerTime} <![CDATA[ >= ]]> startTime,#{registerTime},startTime),
|
|
|
+ chcs.createTime
|
|
|
+ )
|
|
|
+ ,interval receivePeriod DAY)
|
|
|
</if>
|
|
|
) as receivePeriod,
|
|
|
- chc.createDate,
|
|
|
- if(productType = 2,group_concat(chcp.productId),null) as productIds
|
|
|
+ if(productType = 2,chcp.productIds,null) as productIds,
|
|
|
+ chc.createDate
|
|
|
from cm_hehe_coupon chc
|
|
|
- left join cm_hehe_coupon_product chcp on chc.id = chcp.couponId
|
|
|
+ left join cm_hehe_coupon_share chcs on chc.id = chcs.shareCouponId
|
|
|
+ left join (select couponId as couponId, group_concat(productId) as productIds
|
|
|
+ from cm_hehe_coupon_product
|
|
|
+ group by couponId
|
|
|
+ ) as chcp on chc.id = chcp.couponId
|
|
|
where chc.delFlag = 0
|
|
|
and if(startNowFlag = 1, true, NOW() <![CDATA[ >= ]]> startTime)
|
|
|
+ <if test="productIdArr != null and productIdArr.length > 0">
|
|
|
+ and (chc.productType = 1
|
|
|
+ <foreach item="productId" index="index" collection="productIdArr" open="" separator=" " close="">
|
|
|
+ or find_in_set(#{productId},productIds)
|
|
|
+ </foreach>)
|
|
|
+ </if>
|
|
|
<if test="userId == null or userId == 0">
|
|
|
AND couponType not in (2,4,5)
|
|
|
and if(receiveFlag = 1,
|
|
|
if(permanentFlag = 1,true,NOW() <![CDATA[ < ]]> endTime),
|
|
|
NOW() <![CDATA[ < ]]> date_add(startTime,interval receivePeriod DAY))
|
|
|
</if>
|
|
|
- <if test="productIdArr != null and productIdArr.length > 0">
|
|
|
- and (chc.productType = 1 or chcp.productId in
|
|
|
- <foreach item="productId" index="index" collection="productIdArr" open="(" separator="," close=")">
|
|
|
- #{productId}
|
|
|
- </foreach>
|
|
|
- )
|
|
|
- </if>
|
|
|
<if test="userId > 0">
|
|
|
- and chc.id not in (select couponId from cm_hehe_receive_coupon where userId = #{userId})
|
|
|
+ and if(couponType <![CDATA[ <= ]]> 3,
|
|
|
+ chc.id not in (select couponId from cm_hehe_receive_coupon where userId = #{userId} and couponId is not null),
|
|
|
+ chcs.id not in (select couponShareId from cm_hehe_receive_coupon where userId = #{userId} and couponShareId is not null)
|
|
|
+ )
|
|
|
and (
|
|
|
(couponType = 1
|
|
|
- or (couponType = 2 and chc.id in (select distinct couponId from cm_hehe_coupon_user where userId = #{userId}))
|
|
|
+ or (couponType = 2 and chc.id in (select distinct couponId from cm_hehe_coupon_user where userId = #{userId} and couponId is not null))
|
|
|
or (couponType = 3 and #{registerTime} <![CDATA[ >= ]]> startTime)
|
|
|
- or (couponType = 4 and FIND_IN_SET(chc.id , (select group_concat(shareCouponIds) from cm_hehe_coupon_share where shareUserId = #{userId})))
|
|
|
- or (couponType = 5 and FIND_IN_SET(chc.id , (select group_concat(consumeCouponIds) from cm_hehe_coupon_share where shareUserId = #{userId} and consumeFlag = 1)))
|
|
|
+ or (couponType = 4 and chcs.shareUserId = #{userId})
|
|
|
+ or (couponType = 5 and chcs.shareUserId = #{userId})
|
|
|
)
|
|
|
and if(receiveFlag = 1,
|
|
|
- if(permanentFlag = 1,true,NOW() <![CDATA[ < ]]> endTime),
|
|
|
- NOW() <![CDATA[ < ]]> date_add(
|
|
|
- if(couponType <![CDATA[ <= ]]> 3,
|
|
|
+ if(permanentFlag = 1,true,NOW() <![CDATA[ < ]]> endTime),
|
|
|
+ NOW() <![CDATA[ < ]]> date_add(
|
|
|
+ if(couponType <![CDATA[ <= ]]> 3,
|
|
|
if(#{registerTime} <![CDATA[ >= ]]> startTime,#{registerTime},startTime),
|
|
|
- (select if(couponType = 4,createTime,updateTime) from cm_hehe_coupon_share where FIND_IN_SET(chc.id,if(couponType = 4,shareCouponIds,consumeCouponIds)))),
|
|
|
- interval receivePeriod DAY)
|
|
|
- )
|
|
|
+ chcs.createTime
|
|
|
+ )
|
|
|
+ ,interval receivePeriod DAY))
|
|
|
+ )
|
|
|
</if>
|
|
|
<if test="couponType != null">
|
|
|
and couponType = #{couponType}
|
|
|
</if>
|
|
|
- group by chc.id
|
|
|
order by chc.createDate desc
|
|
|
</select>
|
|
|
<select id="findReceiveCouponList" resultType="com.caimei.model.vo.CouponVo">
|
|
|
select distinct
|
|
|
chrc.couponId as couponId,
|
|
|
+ chrc.couponShareId,
|
|
|
name as couponName,
|
|
|
couponType,
|
|
|
productType,
|
|
@@ -108,35 +121,33 @@
|
|
|
noThresholdFlag,
|
|
|
date_add(chrc.receiveTime, interval chc.usePeriod DAY) as usePeriod,
|
|
|
createDate,
|
|
|
- if(productType = 2,group_concat(chcp.productId),null) as productIds
|
|
|
+ if(productType = 2,chcp.productIds,null) as productIds
|
|
|
from cm_hehe_receive_coupon chrc left join cm_hehe_coupon chc on chrc.couponId = chc.id
|
|
|
- left join cm_hehe_coupon_product chcp on chrc.couponId = chcp.couponId
|
|
|
+ left join (select couponId as couponId, group_concat(productId) as productIds
|
|
|
+ from cm_hehe_coupon_product
|
|
|
+ group by couponId) chcp on chrc.couponId = chcp.couponId
|
|
|
where chrc.delFlag = 0 and chc.delFlag = 0 and chrc.userId = #{userId}
|
|
|
<if test="receiveCouponId != null and receiveCouponId>0">
|
|
|
and chrc.id = #{receiveCouponId}
|
|
|
</if>
|
|
|
<if test="productIdArr != null and productIdArr.length > 0">
|
|
|
- and (chc.productType = 1 or chcp.productId in
|
|
|
- <foreach item="productId" index="index" collection="productIdArr" open="(" separator="," close=")">
|
|
|
- #{productId}
|
|
|
- </foreach>
|
|
|
- )
|
|
|
+ and (chc.productType = 1
|
|
|
+ <foreach item="productId" index="index" collection="productIdArr" open="" separator=" " close="">
|
|
|
+ or find_in_set(#{productId},productIds)
|
|
|
+ </foreach>)
|
|
|
</if>
|
|
|
<if test="status == 1">
|
|
|
and chrc.status = 1
|
|
|
and NOW() <![CDATA[ <= ]]> date_add(chrc.receiveTime, interval chc.usePeriod DAY)
|
|
|
- group by chrc.couponId
|
|
|
order by chrc.receiveTime desc
|
|
|
</if>
|
|
|
<if test="status == 2">
|
|
|
and chrc.status = 2
|
|
|
- group by chrc.couponId
|
|
|
order by chrc.useTime desc
|
|
|
</if>
|
|
|
<if test="status == 3">
|
|
|
and chrc.status = 1
|
|
|
and NOW() <![CDATA[ > ]]> date_add(chrc.receiveTime, interval chc.usePeriod DAY)
|
|
|
- group by chrc.couponId
|
|
|
order by date_add(chrc.receiveTime, interval chc.usePeriod DAY) desc
|
|
|
</if>
|
|
|
</select>
|
|
@@ -188,17 +199,20 @@
|
|
|
select id
|
|
|
from cm_hehe_receive_coupon
|
|
|
where userId = #{userId}
|
|
|
- and couponId = #{couponId}
|
|
|
+ and couponId = #{couponId}
|
|
|
+ <if test="couponShareId != null">
|
|
|
+ and couponShareId = #{couponShareId}
|
|
|
+ </if>
|
|
|
</select>
|
|
|
- <select id="getCurrentCouponIds" resultType="java.lang.String">
|
|
|
- select group_concat(id)
|
|
|
+ <select id="getCurrentCouponIds" resultType="java.lang.Integer">
|
|
|
+ select id
|
|
|
from cm_hehe_coupon
|
|
|
where couponType = #{couponType} and if(startNowFlag = 1,true, NOW() <![CDATA[ >= ]]> startTime )
|
|
|
and if(permanentFlag = 1,true,NOW() <![CDATA[ <= ]]> endTime) and delFlag = 0
|
|
|
- group by couponType
|
|
|
</select>
|
|
|
- <select id="getCouponShareId" resultType="java.lang.Integer">
|
|
|
- select id from cm_hehe_coupon_share where receiveUserId = #{receiveUserId} and consumeFlag != 1
|
|
|
+ <select id="getCouponShareId" resultType="com.caimei.model.po.CouponSharePo">
|
|
|
+ select id, shareUserId, receiveUserId, shareCouponId
|
|
|
+ from cm_hehe_coupon_share where receiveUserId = #{receiveUserId} and type = 1
|
|
|
</select>
|
|
|
|
|
|
</mapper>
|