| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?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 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'
- 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
- <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>
- and cu.status != 'used'
- where cu.user_id = #{userId}
- and cu.channel != 'exCode'
- <if test="couponId == null">
- order by isAvailable desc
- </if>
- <if test="couponId != null">
- order by case when cp.id = #{couponId} then 2 else isAvailable end desc
- </if>
- </select>
- <select id="countAvailableCouponList" resultType="java.lang.Integer">
- select count(distinct cu.id)
- 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
- 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'
- <if test="isRenew != null and isRenew">
- and cp.is_renew = #{isRenew}
- </if>
- </select>
- <select id="couponCenterList" resultType="com.cyksj.model.views.CouponActiveView">
- 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'
- end) as couponStatus,
- (case
- when remain_num <= 0 then 2
- when cu.id is null then 0
- end) as `order`
- 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 ca.expiry_status != 0
- and ca.`status` != 0
- and cu.id is null
- order by `order`
- </select>
- </mapper>
|