|
|
@@ -129,19 +129,19 @@
|
|
|
cu.valid_end_time,
|
|
|
c.is_renew,
|
|
|
(case
|
|
|
- when cu.valid_end_time < now() then 'expired'
|
|
|
- when ca.status = 0 then 'invalid'
|
|
|
+ when cu.status != 'used' and cu.valid_end_time < now() then 'expired'
|
|
|
+ when cu.status != 'used' and ca.status = 0 then 'invalid'
|
|
|
else cu.status end) as couponUserStatus,
|
|
|
(case
|
|
|
- when cu.status = 'unused' then 0
|
|
|
+ when cu.status = 'used' then 4
|
|
|
+ when ca.status = 0 then 3
|
|
|
when cu.valid_start_time < now() then 1
|
|
|
when cu.valid_end_time < now() then 2
|
|
|
- when ca.status = 0 then 3
|
|
|
- when cu.status = 'used' then 4
|
|
|
+ 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.coupon_id = c.id
|
|
|
+ left join `coupon_active` ca on ca.id = cu.coupon_active_id
|
|
|
where cu.user_id = #{userId}
|
|
|
and cu.channel != 'exCode'
|
|
|
and ca.id is not null
|