xuhy
2025-01-09 712f70b2936079a131ecb1e63c6d337171618cad
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<?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.stylefeng.guns.modular.system.dao.MerchantActivityMapper">
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.system.model.MerchantActivity">
        <id column="id" property="id"/>
        <result column="merchantId" property="merchantId"/>
        <result column="companyType" property="companyType"/>
        <result column="companyId" property="companyId"/>
        <result column="activityType" property="activityType"/>
        <result column="name" property="name"/>
        <result column="orderType" property="orderType"/>
        <result column="type" property="type"/>
        <result column="orderAmountFull" property="orderAmountFull"/>
        <result column="orderNumber" property="orderNumber"/>
        <result column="effectiveDays" property="effectiveDays"/>
        <result column="auditStatus" property="auditStatus"/>
        <result column="auditNote" property="auditNote"/>
        <result column="auditUserId" property="auditUserId"/>
        <result column="auditTime" property="auditTime"/>
        <result column="status" property="status"/>
        <result column="state" property="state"/>
        <result column="createTime" property="createTime"/>
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, merchantId, companyType ,companyId, `name`, auditStatus, fullAmount, status, state,createTime
    </sql>
 
 
    <select id="list" resultType="map">
        SELECT a.* ,b.name merchantName,
        (SELECT IFNULL(COUNT(1),0) total FROM t_user_merchant_coupon WHERE state=1 AND merchantActivityId=a.id ) number
        FROM t_merchant_activity a
        LEFT JOIN t_merchant b ON a.merchantId = b.id
        WHERE a.state = 1 AND a.auditStatus = 2 AND a.activityType=1
 
        <if test="startTime!=null and startTime!='' and endTime!=null and endTime!=''">
            AND a.createTime &gt;= CONCAT(#{startTime},' 00:00:00')
            AND a.createTime &lt;= CONCAT(#{endTime},' 23:59:59')
        </if>
 
        <if test="companyId!=null">
            AND a.companyId=#{companyId}
        </if>
 
        <if test="type!=null">
            AND a.type = #{type}
        </if>
 
        <if test="merchantName!=null and merchantName!=''">
            AND b.name LIKE CONCAT('%',#{merchantName},'%')
        </if>
 
        <if test="status!=null ">
            AND a.status =#{status}
        </if>
 
        ORDER BY a.createTime DESC
    </select>
 
 
    <select id="getReceiveList" resultType="map">
        SELECT * FROM(
        SELECT
        a.*,
        b.nickName,
        b.phone,
        c.type
        FROM
        t_user_merchant_coupon a
        LEFT JOIN t_user b ON ( a.userId = b.id AND a.userType = 1 )
        LEFT JOIN t_merchant_coupon c ON a.merchantCouponId = c.id
        WHERE
        a.state = 1 AND a.userType = 1
        <if test="merchantActivityId!=null">
            AND a.merchantActivityId=#{merchantActivityId}
        </if>
 
        <if test="userName!=null and userName!=''">
            AND b.nickName LIKE CONCAT('%',#{userName},'%')
        </if>
 
        <if test="phone!=null and phone!=''">
            AND b.phone LIKE CONCAT('%',#{phone},'%')
        </if>
 
        <if test="startTime!=null and startTime!='' and endTime!=null and endTime!=''">
            AND a.createTime &gt;= CONCAT(#{startTime},' 00:00:00')
            AND a.createTime &lt;= CONCAT(#{endTime},' 23:59:59')
        </if>
 
        <if test="status!=null">
            AND a.status = #{status}
        </if>
        UNION ALL
        SELECT
        a.*,
        b.`name` nickName,
        b.phone,
        c.type
        FROM
        t_user_merchant_coupon a
        LEFT JOIN t_driver b ON ( a.userId = b.id AND a.userType = 2 )
        LEFT JOIN t_merchant_coupon c ON a.merchantCouponId = c.id
        WHERE
        a.state = 1 AND a. userType = 2
        <if test="merchantActivityId!=null">
            AND a.merchantActivityId=#{merchantActivityId}
        </if>
 
        <if test="userName!=null and userName!=''">
            AND b.name LIKE CONCAT('%',#{userName},'%')
        </if>
 
        <if test="phone!=null and phone!=''">
            AND b.phone LIKE CONCAT('%',#{phone},'%')
        </if>
 
        <if test="startTime!=null and startTime!='' and endTime!=null and endTime!=''">
            AND a.createTime &gt;= CONCAT(#{startTime},' 00:00:00')
            AND a.createTime &lt;= CONCAT(#{endTime},' 23:59:59')
        </if>
 
        <if test="status!=null">
            AND a.status = #{status}
        </if>
        ) tt ORDER BY tt.createTime DESC
    </select>
 
    <select id="activityExamineList" resultType="map">
        SELECT a.* ,b.name merchantName,
        (SELECT IFNULL(COUNT(1),0) total FROM t_user_merchant_coupon WHERE state=1 AND merchantActivityId=a.id ) number
        FROM t_merchant_activity a
        LEFT JOIN t_merchant b ON a.merchantId = b.id
 
        WHERE a.state = 1 AND a.activityType = 1
 
        <if test="startTime!=null and startTime!='' and endTime!=null and endTime!=''">
            AND a.createTime &gt;= CONCAT(#{startTime},' 00:00:00')
            AND a.createTime &lt;= CONCAT(#{endTime},' 23:59:59')
        </if>
 
        <if test="type!=null">
            AND a.type = #{type}
        </if>
 
        <if test="companyId!=null">
            AND a.companyId  NOT  IN (#{companyId})
        </if>
 
        <if test="auditStatus!=null ">
            AND a.auditStatus =#{auditStatus}
        </if>
        ORDER BY a.createTime DESC
    </select>
 
    <select id="getMerchantActivityGiveList" resultType="map">
        SELECT a.* ,b.name merchantName,
        (SELECT IFNULL(COUNT(1),0) total FROM t_user_merchant_coupon WHERE state=1 AND merchantActivityId=a.id ) number
        FROM t_merchant_activity a
        LEFT JOIN t_merchant b ON a.merchantId = b.id
        WHERE a.state = 1  AND a.activityType=2
 
        <if test="startTime!=null and startTime!='' and endTime!=null and endTime!=''">
            AND a.createTime &gt;= CONCAT(#{startTime},' 00:00:00')
            AND a.createTime &lt;= CONCAT(#{endTime},' 23:59:59')
        </if>
 
        <if test="type!=null">
            AND a.type = #{type}
        </if>
 
        <if test="merchantName!=null and merchantName!=''">
            AND b.name LIKE CONCAT('%',#{merchantName},'%')
        </if>
 
        <if test="status!=null ">
            AND a.status =#{status}
        </if>
 
        <if test="companyId!=null">
            AND a.companyId =#{companyId}
        </if>
        ORDER BY a.createTime DESC
    </select>
 
    <!--获取用户信息-->
    <select id="getUserList" resultType="map">
        SELECT
        *
        FROM
        (SELECT ci.`name` AS companyName,
        ui.id,
        ui.insertTime,
        ui.nickName,
        ui.phone ,
        1 as type,
        ui.flag
        FROM
        t_user AS ui
        LEFT JOIN ( SELECT * FROM t_company WHERE flag != 3 ) AS ci ON ci.id = ui.companyId
        LEFT JOIN ( SELECT COUNT( id ) AS num, userId FROM t_order_taxi WHERE FIND_IN_SET( state, '8,9' ) GROUP BY
        userId ) AS ot ON ot.userId = ui.id
        LEFT JOIN ( SELECT sum( money ) AS num, userId FROM t_pub_transaction_details WHERE userType = 1 AND type = 1
        AND state = 2 GROUP BY userId ) AS td ON td.userId = ui.id
        ) AS o
        WHERE
        o.flag != 3
        <if test="phone != null and phone != ''">
            and o.phone LIKE CONCAT('%',#{phone},'%')
        </if>
        <if test="nickName != null and nickName != ''">
            and o.nickName LIKE CONCAT('%',#{nickName},'%')
        </if>
        <if test="startTime!=null and startTime!='' and endTime!=null and endTime!=''">
            AND o.insertTime &gt;= CONCAT(#{startTime},' 00:00:00')
            AND o.insertTime &lt;= CONCAT(#{endTime},' 23:59:59')
        </if>
        order by o.id desc
    </select>
 
    <select id="getDriverList" resultType="map">
        SELECT
        a.id,
        a.insertTime,
        a.`name` nickName,
        a.phone,
        2 as type,
        b.`name` companyName ,
        a.flag
        FROM
        t_driver a
        LEFT JOIN t_company b ON a.companyId = b.id
        WHERE
        a.flag != 3
        <if test="phone != null and phone != ''">
            and a.phone LIKE CONCAT('%',#{phone},'%')
        </if>
        <if test="nickName != null and nickName != ''">
            and a.name LIKE CONCAT('%',#{nickName},'%')
        </if>
        <if test="companyName != null and companyName != ''">
            and b.`name`  LIKE CONCAT('%',#{companyName},'%')
        </if>
        <if test="startTime!=null and startTime!='' and endTime!=null and endTime!=''">
            AND a.insertTime &gt;= CONCAT(#{startTime},' 00:00:00')
            AND a.insertTime &lt;= CONCAT(#{endTime},' 23:59:59')
        </if>
        order by a.id desc
    </select>
</mapper>