liujie
2026-06-09 c96fbe6b0aeb413a17c429133ee6d81d138144b9
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?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, money2, money3 , 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="pageList" resultType="com.xiaopeng.account.model.vo.XpAppUserCouponListVo">
        select a.*
        from xp_app_user_coupon as a
        where a.is_deleted = 0 and a.app_user_id = #{query.appUserId}
        <if test="query.createTimeStart != null ">
            a.create_time >= #{query.createTimeStart}
        </if>
        <if test="query.createTimeEnd != null ">
            a.create_time &lt;= #{query.createTimeEnd}
        </if>
        <if test="query.status != null">
            and a.status = #{query.status}
        </if>
        <if test="query.couponType != null">
            and a.coupon_type = #{query.couponType}
        </if>
        <if test="query.acticityIds != null">
            and a.activity_id in
            <foreach item="item" collection="query.acticityIds" separator="," open="(" close=")" index="">
                #{item}
            </foreach>
        </if>
        order by a.create_time desc
    </select>
 
    <select id="userCouponList" resultType="com.xiaopeng.account.model.vo.XpAppUserCouponListVo">
        select t.*,t.status  from (
        SELECT id as couponId,
        coupon_id as operationCouponId,
        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 app_user_id = #{uid}
        ) 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>
 
 
    <select id="getCouponReceiptRecord" resultType="com.xiaopeng.api.model.account.XpAppUserCoupon">
        select * from xp_app_user_coupon
        where activity_id = #{query.activityId}
        <if test="null != query.startTime and '' != query.startTime and null != query.endTime and '' != query.endTime">
            and create_time between #{query.startTime} and #{query.endTime}
        </if>
        <if test="null != query.appUserIds and query.appUserIds.size() > 0">
            and app_user_id in
            <foreach collection="query.appUserIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="null != query.status">
            and status = #{query.status}
        </if>
        order by create_time desc
    </select>
</mapper>