Pu Zhibing
2024-10-16 c4664502dfdaffff555b532e65b51a57ac8b29c2
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
<?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.ruoyi.account.mapper.TAppCouponMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ruoyi.account.api.model.TAppCoupon">
        <id column="id" property="id" />
        <result column="app_user_id" property="appUserId" />
        <result column="coupon_id" property="couponId" />
        <result column="end_time" property="endTime" />
        <result column="ways_to_obtain" property="waysToObtain" />
        <result column="redeem_points" property="redeemPoints" />
        <result column="payment_amount" property="paymentAmount" />
        <result column="payment_type" property="paymentType" />
        <result column="serial_number" property="serialNumber" />
        <result column="payment_time" property="paymentTime" />
        <result column="status" property="status" />
        <result column="create_time" property="createTime" />
        <result column="del_flag" property="delFlag" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, app_user_id, coupon_id, end_time, ways_to_obtain, redeem_points, payment_amount, payment_type, serial_number, payment_time, status, create_time, del_flag
    </sql>
    <select id="pageList" resultType="com.ruoyi.account.api.vo.ExchangeRecordVO">
        select t1.id,t1.app_user_id as appUserId, t1.coupon_id as couponId,
               t1.end_time as endTime, t1.ways_to_obtain as waysToObtain,
               t1.redeem_points as redeemPoints,
               t1.payment_amount as paymentAmount,
               t1.payment_type as paymentType,
               t1.serial_number as serialNumber,
               t1.payment_time as paymentTime,
               t1.status,
               t1.create_time AS createTime,
               t1.del_flag AS delFlag,
               t2.phone
        from t_app_coupon t1
        left join t_app_user t2 on t1.app_user_id = t2.id
        <where>
            and t1.coupon_id = #{req.couponId}
            <if test="req.phone != null and req.phone != ''">
                AND  t2.phone LIKE concat('%',#{req.phone}, '%')
            </if>
            <if test="req.status != null and req.status = 1">
                AND t1.status =1 and t1.end_time &gt;= now()
            </if>
            <if test="req.status != null and req.status = 2">
                AND t1.status =2
            </if>
            <if test="req.status != null and req.status = 3">
                AND t1.status =1 and t1.end_time &lt;= now() and t1.del_flag = 0
            </if>
            <if test="req.status != null and req.status = 4">
                AND t1.del_flag = 0
            </if>
        </where>
        ORDER BY t1.create_time DESC
    </select>
    <select id="couponList" resultType="com.ruoyi.other.api.vo.CouponListVOVO">
        SELECT
            t1.app_user_id AS appUserId,
            t1.coupon_id AS couponId,
            MAX(t1.end_time) AS endTime,
            MAX(t1.create_time) AS createTime,
            MAX(t1.status) AS status,
            COUNT(*) AS couponCount
        FROM
            t_app_coupon t1
        WHERE
            t1.del_flag = 0
          AND t1.app_user_id = #{userId}
          AND t1.status = 1
        and t1.end_time &gt;= now()
        GROUP BY
            t1.app_user_id,
        t1.coupon_id
    </select>
 
</mapper>