| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?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,
- cp.valid_start_time,
- cp.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
- and ck.sku_id = #{skuId}
- <if test="isRenew != null">
- and cp.is_renew = #{isRenew}
- </if>
- and cu.status != 'used'
- where cu.user_id = #{userId}
- order by isAvailable desc
- </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 ck.sku_id = #{skuId} and cu.user_id = #{userId}
- and cu.status = 'unused'
- <if test="isRenew != null">
- 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.expiry_status = 0 then 'stop'
- when ca.`status` = 0 then 'stop'
- when ca.remain_num <= 0 then 'over'
- when cu.id is null then 'collecting'
- when cu.id is not null
- then 'received' end) as couponStatus,
- (case
- when ca.expiry_status = 0 then 2
- when ca.`status` = 0 then 2
- when remain_num <= 0 then 3
- when cu.id is null then 0
- when cu.id is not null
- then 1 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
- order by `order`
- </select>
- </mapper>
|