无关风月
2025-05-08 9486766c806fe1d9e082b2fd02ea1cc558f1b443
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?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.dsh.activity.mapper.PayHuiminMapper">
 
 
    <select id="selectSalesDetailPage" resultType="com.dsh.activity.model.response.SalesDetailVO">
        SELECT
        tph.id,
        thc.huiMinName,
        thc.huiMinType,
        thc.salesMoney,
        thc.operatorId,
        thc.storeIds,
        tph.appUserId,
        tph.paymentTime,
        tph.endTime,
        tph.studentId,
        thc.id as carId,
        tph.status
        FROM
        t_pay_huimin tph
        LEFT JOIN t_huimin_card thc ON tph.cardId = thc.id
        <where>
            tph.id IS NOT NULL
            <if test="query.huiMinName !=null and query.huiMinName != ''">
                AND thc.huiMinName LIKE CONCAT('%',#{query.huiMinName},'%')
            </if>
            <if test="query.huiMinType !=null and query.huiMinType != ''">
                AND thc.huiMinType = #{query.huiMinType}
            </if>
            <if test="query.operatorId !=null ">
                AND thc.operatorId = #{query.operatorId}
            </if>
            <if test="query.useId !=null and query.useId != ''">
                AND FIND_IN_SET(#{query.useId},thc.useIds)
            </if>
 
            <if test="query.appUserIds != null and query.appUserIds.size()>0">
                AND tph.appUserId IN
                <foreach collection="query.appUserIds" item="appUserId" open="(" separator="," close=")">
                    #{appUserId}
                </foreach>
            </if>
            <if test="query.paymentTimeStart != null and query.paymentTimeEnd!=null">
                AND tph.paymentTime BETWEEN #{query.paymentTimeStart} AND #{query.paymentTimeEnd}
            </if>
            <if test="query.endTimeStart != null and query.endTimeEnd!=null">
                AND tph.endTime BETWEEN #{query.endTimeStart} AND #{query.endTimeEnd}
            </if>
            <if test="query.status!=null and query.status !=''">
                <choose>
                    <when test="query.status == 1">
                        AND tph.status = 2
                    </when>
                    <when test="query.status == 2">
                        AND tph.status = 3
                    </when>
                </choose>
            </if>
        and tph.status!=1
        </where>
 
        ORDER BY tph.insertTime DESC
    </select>
    <select id="getStaticsData" resultType="java.util.Map"
            parameterType="com.dsh.activity.entity.HuiminPayQuery">
        SELECT
        COALESCE(SUM(CASE WHEN tph.status IN (2,3) THEN tph.salesMoney ELSE 0 END),0) AS totalAmount,
        COALESCE(SUM(CASE WHEN refundStatus IN (2, 3) THEN tph.salesMoney ELSE 0 END),0) AS refundAmount
        FROM t_pay_huimin tph
        LEFT JOIN t_huimin_card thc ON tph.cardId = thc.id
        <where>
            tph.id IS NOT NULL
            <if test="query.huiMinName !=null and query.huiMinName != ''">
                AND thc.huiMinName LIKE CONCAT('%',#{query.huiMinName},'%')
            </if>
            <if test="query.huiMinType !=null and query.huiMinType != ''">
                AND thc.huiMinType = #{query.huiMinType}
            </if>
            <if test="query.operatorId !=null and query.operatorId != ''">
                AND thc.huiMinType = #{query.huiMinType}
            </if>
            <if test="query.useId !=null and query.useId != ''">
                AND FIND_IN_SET(#{query.useId},thc.useIds)
            </if>
            <if test="query.useId !=null and query.useId != ''">
                AND FIND_IN_SET(#{query.useId},thc.useIds)
            </if>
            <if test="query.appUserIds != null and query.appUserIds.size()>0">
                AND tph.appUserId IN
                <foreach collection="query.appUserIds" item="appUserId" open="(" separator="," close=")">
                    #{appUserId}
                </foreach>
            </if>
            <if test="query.paymentTimeStart != null and query.paymentTimeEnd!=null">
                AND tph.paymentTime BETWEEN #{query.paymentTimeStart} AND #{query.paymentTimeEnd}
            </if>
            <if test="query.endTimeStart != null and query.endTimeEnd!=null">
                AND tph.endTime BETWEEN #{query.endTimeStart} AND #{query.endTimeEnd}
            </if>
            <if test="query.status!=null and query.status !=''">
                <choose>
                    <when test="query.status == 1">
                        AND tph.status = 2
                    </when>
                    <when test="query.status == 2">
                        AND tph.status = 3
                    </when>
                </choose>
            </if>
        </where>
    </select>
 
    <select id="exportData" resultType="com.dsh.activity.model.response.SalesDetailVO"
            parameterType="com.dsh.activity.entity.HuiminPayQuery">
        SELECT
        tph.id,
        thc.huiMinName,
        thc.huiMinType,
        thc.salesMoney,
        thc.operatorId,
        thc.storeIds,
        tph.appUserId,
        tph.paymentTime,
        thc.endTime,
        tph.studentId,
        tph.status,
        CASE
        WHEN tph.id IS NULL THEN NULL
        ELSE COALESCE(COUNT(thr.id), 0)
        END AS useTimes
        FROM
        t_pay_huimin tph
        LEFT JOIN t_huimin_card thc ON tph.cardId = thc.id
        LEFT JOIN t_huimin_record thr ON tph.appUserId= thr.appUserId AND tph.cardId= thr.huiminCardId
        <where>
            <if test="query.huiMinName !=null and query.huiMinName != ''">
                AND thc.huiMinName LIKE CONCAT('%',#{query.huiMinName},'%')
            </if>
            <if test="query.huiMinType !=null and query.huiMinType != ''">
                AND thc.huiMinType = #{query.huiMinType}
            </if>
            <if test="query.operatorId !=null and query.operatorId != ''">
                AND thc.huiMinType = #{query.huiMinType}
            </if>
            <if test="query.useId !=null and query.useId != ''">
                AND FIND_IN_SET(#{query.useId},thc.useIds)
            </if>
            <if test="query.useId !=null and query.useId != ''">
                AND FIND_IN_SET(#{query.useId},thc.useIds)
            </if>
            <if test="query.appUserIds != null and query.appUserIds.size()>0">
                AND tph.appUserId IN
                <foreach collection="query.appUserIds" item="appUserId" open="(" separator="," close=")">
                    #{appUserId}
                </foreach>
            </if>
            <if test="query.paymentTimeStart != null and query.paymentTimeEnd!=null">
                AND tph.paymentTime BETWEEN #{query.paymentTimeStart} AND #{query.paymentTimeEnd}
            </if>
            <if test="query.endTimeStart != null and query.endTimeEnd!=null">
                AND tph.endTime BETWEEN #{query.endTimeStart} AND #{query.endTimeEnd}
            </if>
            <if test="query.status!=null and query.status !=''">
                <choose>
                    <when test="query.status == 1">
                        AND tph.status = 2
                    </when>
                    <when test="query.status == 2">
                        AND tph.status = 3
                    </when>
                </choose>
            </if>
        and tph.paymentTime IS NOT NULL
        </where>
        GROUP BY tph.id
        ORDER BY tph.insertTime DESC
    </select>
</mapper>