|
@@ -20,7 +20,11 @@
|
|
|
cp.is_renew,
|
|
cp.is_renew,
|
|
|
cu.status as couponUserStatus,
|
|
cu.status as couponUserStatus,
|
|
|
if(ck.id is null, 0, 1) as 'isAvailable',
|
|
if(ck.id is null, 0, 1) as 'isAvailable',
|
|
|
- if(ca.id is not null and ca.expiry_status = 0,false,true) flag
|
|
|
|
|
|
|
+ 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
|
|
from `coupon_user` cu
|
|
|
left join `coupon` cp on cp.id = cu.coupon_id
|
|
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_active` ca on ca.id = cu.coupon_active_id
|
|
@@ -38,10 +42,10 @@
|
|
|
and cu.channel != 'exCode'
|
|
and cu.channel != 'exCode'
|
|
|
and cu.valid_end_time > now()
|
|
and cu.valid_end_time > now()
|
|
|
<if test="couponId == null">
|
|
<if test="couponId == null">
|
|
|
- order by isAvailable desc
|
|
|
|
|
|
|
+ order by isAvailable desc,orderby
|
|
|
</if>
|
|
</if>
|
|
|
<if test="couponId != null">
|
|
<if test="couponId != null">
|
|
|
- order by case when cp.id = #{couponId} then 2 else isAvailable end desc
|
|
|
|
|
|
|
+ order by case when cp.id = #{couponId} then 2 else isAvailable end desc,orderby
|
|
|
</if>)s where flag = 1 and couponUserStatus != 'used'
|
|
</if>)s where flag = 1 and couponUserStatus != 'used'
|
|
|
</select>
|
|
</select>
|
|
|
|
|
|