liujie
2026-02-26 58cd3733911c4a9970a5daf219950582100f3db2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?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.xiaopeng.account.mapper.XpAppUserCouponMapper">
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, full_money, money, expiration_time, status, coupon_type, app_user_id, coupon_id, activity_id, activity_type, is_deleted, create_time, update_time, create_by, update_by
    </sql>
 
 
 
    <select id="userCouponList" resultType="com.xiaopeng.account.model.vo.XpAppUserCouponListVo">
        select t.*,t.status  from (
        SELECT id as couponId,
        coupon_name as title,
        money as discountAmount,
        use_time as useTime,
        create_time as createTime,
        expiration_time as expireTime,
        case
        when status = 1 and now() >= expiration_time then 3  -- 包含等于的情况
        when status = 1 and expiration_time > now() then 1
        else status
        end as `status`
        FROM xp_app_user_coupon
        WHERE phone = #{phone}
        ) as t
        where 1=1
        <if test="query.status != null">
            and t.status = #{query.status}
        </if>
 
        <if test="query.status != null and query.status == 1">
            order by t.expireTime ,t.discountAmount desc,t.createTime desc
        </if>
        <if test="query.status != null and query.status == 2">
            order by t.useTime desc
        </if>
        <if test="query.status != null and query.status == 3">
            order by t.expireTime desc
        </if>
 
    </select>
 
</mapper>