| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <?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.cyksj.mapper.manage.coupon.CouponUserMapper">
- <select id="getAvailableCouponList" resultType="com.cyksj.model.views.CouponUserView">
- select * from (select distinct cu.id,
- cp.id as coupon_id,
- cp.name,
- cp.goods_type,
- cp.type,
- cp.goods_sku_ids,
- cp.discount,
- cp.reduce_money,
- cp.is_valid_time,
- cu.valid_start_time,
- cu.valid_end_time,
- cp.valid_days,
- cu.created_time,
- cp.is_renew,
- cu.status as couponUserStatus,
- if(ck.id is null, 0, 1) as 'isAvailable',
- if(ca.id is not null and ca.expiry_status = 0,false,true) flag,
- (case
- when cu.valid_start_time > now() then 1
- when cu.status = 'unused' then 0
- end) as orderby
- from `coupon_user` cu
- left join `coupon` cp on cp.id = cu.coupon_id
- left join `coupon_active` ca on ca.id = cu.coupon_active_id
- left join `coupon_sku` ck on ck.coupon_id = cp.id
- <if test="goodsId != null">
- and ck.goods_id = #{goodsId}
- </if>
- <if test="goodsId == null">
- and ck.sku_id = #{skuId}
- </if>
- <if test="isRenew != null and isRenew">
- and cp.is_renew = #{isRenew}
- </if>
- where cu.user_id = #{userId}
- and cu.channel != 'exCode'
- and cu.valid_end_time > now()
- <if test="couponId == null">
- order by isAvailable desc,orderby
- </if>
- <if test="couponId != null">
- order by case when cp.id = #{couponId} then 2 else isAvailable end desc,orderby
- </if>)s where flag = 1 and couponUserStatus != 'used'
- </select>
- <select id="countAvailableCouponList" resultType="java.lang.Integer">
- select count(distinct id)
- from (select cu.id,ca.expiry_status as flag
- from `coupon_user` cu
- left join `coupon` cp on cp.id = cu.coupon_id
- left join `coupon_sku` ck on ck.coupon_id = cp.id
- left join `coupon_active` ca on ca.id = cu.coupon_active_id
- where
- <if test="goodsId != null">
- ck.goods_id = #{goodsId}
- </if>
- <if test="goodsId == null">
- ck.sku_id = #{skuId}
- </if>
- and cu.user_id = #{userId}
- and cu.status = 'unused'
- and cu.channel != 'exCode'
- and cu.valid_start_time < now()
- and cu.valid_end_time > now()
- <if test="isRenew != null and isRenew">
- and cp.is_renew = #{isRenew}
- </if>)s where flag != 0 or flag is null
- </select>
- <select id="couponCenterList" resultType="com.cyksj.model.views.CouponActiveView">
- select *
- from (select ca.id,
- c.id as coupon_id,
- c.name,
- c.goods_type,
- c.type,
- c.reduce_money,
- c.discount,
- c.scope,
- c.goods_sku_ids,
- c.is_valid_time,
- c.valid_start_time,
- c.valid_end_time,
- c.valid_days,
- c.is_renew,
- ca.num,
- ca.`status`,
- ca.expiry_status,
- ca.remain_num,
- (case
- when ca.remain_num <= 0 then 'over'
- when cu.id is null then 'collecting'
- when cu.id is not null and cu.status != 'unused' then 'used'
- when cu.id is not null and cu.status = 'unused' then 'received'
- end) as couponStatus,
- (case
- when remain_num <= 0 then 2
- when cu.id is null then 0
- when cu.id is not null and cu.status = 'unused' then 1
- end) as `order`,
- if(c.is_valid_time is true and c.valid_end_time < now(), false, true) as flag
- from coupon_active ca
- left join coupon c
- on c.id = ca.coupon_id
- left join coupon_user cu on cu.coupon_id = c.id and cu.user_id = #{userId}
- where ca.deleted is true
- and c.deleted is true
- and cu.id is null
- and ca.expiry_status != 0
- and ca.`status` != 0
- ) s
- where couponStatus in ('over', 'collecting')
- and flag = 1
- order by `order`
- </select>
- <select id="couponPersonalList" resultType="com.cyksj.model.views.CouponUserView">
- select cu.id,
- cu.channel,
- cu.user_id,
- c.id as couponId,
- ca.id as couponActiveId,
- c.name,
- c.goods_type,
- c.type,
- c.reduce_money,
- c.discount,
- c.goods_sku_ids,
- c.is_valid_time,
- cu.valid_start_time,
- c.valid_days,
- cu.valid_end_time,
- c.is_renew,
- (case
- when cu.status = 'used' then 'used'
- when cu.valid_end_time < now() then 'expired'
- when ca.id is not null and ca.expiry_status = 0 then 'invalid'
- when cu.valid_start_time > now() then 'notEffective'
- else cu.status end) as couponUserStatus,
- (case
- when cu.status = 'used' then 4
- when cu.valid_end_time < now() then 2
- when ca.id is not null and ca.expiry_status = 0 then 3
- when cu.valid_start_time > now() then 1
- when cu.status = 'unused' then 0
- end) as orderby
- from `coupon_user` cu
- left join `coupon` c on c.id = cu.coupon_id
- left join `coupon_active` ca on ca.id = cu.coupon_active_id
- where cu.user_id = #{userId}
- and cu.channel != 'exCode'
- order by `orderby`
- </select>
- </mapper>
|