| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?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.CouponRecommendMapper">
- <select id="getRecommendCouponViewList" resultType="com.cyksj.model.views.CouponRecommendView">
- select * from (select cr.id,
- cr.coupon_id,
- c.name,
- c.goods_type,
- c.type,
- c.reduce_money,
- c.discount,
- c.goods_sku_ids,
- c.is_valid_time,
- c.valid_start_time,
- c.valid_end_time,
- cu.valid_start_time as userValidStartTime,
- cu.valid_end_time as userValidEndTime,
- c.valid_days,
- c.valid_hours,
- c.is_renew,
- c.scope,
- (case
- 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.valid_end_time < now() then 'expired'
- when cu.id is not null and cu.valid_start_time > now() then 'noEffective'
- when cu.id is not null and cu.status = 'unused' then 'received'
- end) as couponStatus,
- (case
- 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_recommend cr left join coupon c on c.id = cr.coupon_id and c.deleted and c.is_available
- left join coupon_user cu on cu.coupon_id = c.id and cu.user_id = #{userId}
- where cr.deleted is true and c.deleted is true and cr.status = 1
- and (cr.up_time is null or cr.up_time <= now()) and (cr.down_time is null or cr.down_time > now())
- <if test="couponId != null">
- and c.id = #{couponId}
- </if>
- <if test='!isNewUser'>
- and c.scope !='newUser'
- </if>)s where couponStatus not in ('used','expired','noEffective') and flag is true order by `order`
- </select>
- <select id="getRecommendCouponList" resultType="com.cyksj.model.views.CouponAvailableRecommendView">
- select * from (select c.id as couponId,
- c.scope,
- cr.id as recommendId,
- if(c.is_valid_time is true and c.valid_end_time < now(),false,true) as flag
- from coupon_recommend cr left join coupon c on c.id = cr.coupon_id and c.deleted and c.is_available
- left join coupon_user cu on cu.coupon_id = c.id and cu.user_id = #{userId}
- where cr.deleted is true and c.deleted is true and cr.status is true and cu.coupon_id is null
- and (cr.up_time is null or cr.up_time <= now()) and (cr.down_time is null or cr.down_time > now())
- <if test='!isNewUser'>
- and c.scope !='newUser'
- </if>)s where flag is true
- </select>
- <select id="checkPresentRecommendByCouponId" resultType="java.lang.Integer">
- select count(1)
- from coupon_recommend cr
- inner join coupon c on c.id = cr.coupon_id
- where cr.coupon_id = #{couponId}
- and cr.deleted is true
- and c.deleted is true
- and cr.status = 1
- and (cr.up_time is null or cr.up_time <= now())
- and (cr.down_time is null or cr.down_time > now())
- </select>
- <select id="getRecommendCouponByGoodsId" resultType="com.cyksj.model.entity.Coupon">
- select c.*
- from coupon_recommend cr inner join coupon c on c.id = cr.coupon_id
- where cr.deleted is true and c.deleted is true and cr.status is true
- and (cr.up_time is null or cr.up_time <= now()) and (cr.down_time is null or cr.down_time > now())
- and (select count(1) from coupon_sku cs where cs.coupon_id = cr.coupon_id and cs.goods_id = #{goodsId}) > 0
- order by c.discount asc,c.reduce_money desc
- limit 1
- </select>
- </mapper>
|