huliguo
2 天以前 5d7b65670282a4fad015e37d567cfa171b162052
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
<?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.errand.mapper.OrderMapper">
 
 
    <select id="getAppUserOrderList" resultType="com.ruoyi.errand.object.vo.app.AppUserOrderListVO">
        select
            o.id,
            o.address_detail,
            o.recipient_name,
            o.recipient_phone,
            o.order_status,
            o.order_time,
            o.rating,
            o.courier_id,
            c.name,
            c.phone
            from t_order o
            left join t_courier c on o.courier_id = c.id
            where
                o.del_flag=0
              and o.pay_status=2
              and o.app_user_id = #{appUserId}
              <if test="orderStatus!=null and orderStatus!=0">
                  and o.order_status = #{orderStatus}
              </if>
    </select>
    <select id="getOrderDetail" resultType="com.ruoyi.errand.object.vo.app.OrderDetailVO">
        select
            o.id as id,
            o.community_id as communityId,
            o.community_name as communityName,
            o.address_detail as addressDetail,
            o.recipient_name as recipientName,
            o.recipient_phone as recipientPhone,
            o.agency_matters as agencyMatters,
            o.num as num,
            o.remark as remark,
            o.pics as pics,
            o.courier_pics as courierPics,
            o.order_status as orderStatus,
            o.order_number as orderNumber,
            o.order_time as orderTime,
            o.pay_method as payMethod,
            o.payment_amount as paymentAmount,
            c.courier_name as courierName,
            c.courier_phone as courierPhone,
            e.rating as rating,
            e.content as content
            from t_order o
        left join t_courier c on o.courier_id = c.id
        left join t_evaluation e on o.id = e.order_id
        where
            o.id=#{id}
            and o.del_flag=0
            and e.type = 0
    </select>
 
    <select id="getOrderTopInfoByDate" resultType="java.util.Map">
        select
            count(*) as num,
        COALESCE(SUM(payment_amount), 0.00) AS amount
        from
            t_order
        where
            del_flag=0
        and
            order_status in (4,5)
        <if test="communityId!=null and communityId!=0">
            and communityId =#{communityId}
        </if>
        <if test="start!=null and end!=null">
            and order_time BETWEEN #{start} AND #{end}
        </if>
 
 
    </select>
    <select id="countGroupByDate" resultType="java.util.Map">
        SELECT
            CASE #{datePattern}
                WHEN 'HH时' THEN DATE_FORMAT(order_time, '%H时')
                WHEN 'EEEE' THEN ELT(DAYOFWEEK(order_time), '星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六')
                WHEN 'dd日' THEN DATE_FORMAT(order_time, '%d日')
                WHEN 'MM月' THEN DATE_FORMAT(order_time, '%m月')
                WHEN 'yyyy-MM-dd' THEN DATE_FORMAT(order_time, '%Y-%m-%d')
                ELSE DATE_FORMAT(order_time, '%Y-%m-%d')
                END AS `date`,
            COUNT(*) AS `num`,
            COALESCE(SUM(payment_amount), 0.00) AS amount
        FROM t_order
        WHERE order_time BETWEEN #{start} AND #{end}
          and del_flag=0 and order_status in (4,5)
        GROUP BY
            CASE #{datePattern}
                WHEN 'HH时' THEN DATE_FORMAT(order_time, '%H时')
                WHEN 'EEEE' THEN ELT(DAYOFWEEK(order_time), '星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六')
                WHEN 'dd日' THEN DATE_FORMAT(order_time, '%d日')
                WHEN 'MM月' THEN DATE_FORMAT(order_time, '%m月')
                WHEN 'yyyy-MM-dd' THEN DATE_FORMAT(order_time, '%Y-%m-%d')
                ELSE DATE_FORMAT(order_time, '%Y-%m-%d')
                END
        ORDER BY order_time
    </select>
 
    <select id="selectPageTotal" resultType="java.lang.Long">
        SELECT COUNT(*) FROM (
            SELECT tau.id, 1 as type, t.order_status, t.order_time
            FROM t_order t
            INNER JOIN t_app_user tau ON t.app_user_id = tau.id
            WHERE
            t.del_flag=0
              and t.pay_status=2
            <if test="dto.appUserName!=null and  ''!=dto.appUserName">
                and tau.name like concat('%',#{dto.appUserName},'%')
            </if>
 
            <if test="dto.phone!=null and  ''!=dto.phone">
                and tau.phone like concat('%',#{dto.phone},'%')
            </if>
        <if test="dto.orderStatus!=null and 0!=dto.orderStatus and dto.orderStatus !=4">
            and t.order_status = #{dto.orderStatus}
        </if>
        <if test="dto.orderStatus ==4">
            and t.order_status in(4,5)
        </if>
            <if test="dto.startTime!=null and dto.endTime != null">
                and t.order_time between #{dto.startTime} and #{dto.endTime}
            </if>
        UNION ALL
            SELECT tau.id, 2 as type, t.order_status, t.order_time
            FROM t_vip_order t
            INNER JOIN t_app_user tau ON t.app_user_id = tau.id
            WHERE t.del_flag=0
        and t.pay_status=2
            <if test="dto.appUserName!=null and  ''!=dto.appUserName">
                and tau.name like concat('%',#{dto.appUserName},'%')
            </if>
 
            <if test="dto.phone!=null and  ''!=dto.phone">
                and tau.phone like concat('%',#{dto.phone},'%')
            </if>
 
        <if test="dto.orderStatus!=null and 0!=dto.orderStatus and dto.orderStatus !=4">
            and t.order_status = #{dto.orderStatus}
        </if>
        <if test="dto.orderStatus ==4">
            and t.order_status in(4,5)
        </if>
            <if test="dto.startTime!=null and dto.endTime != null">
                and t.order_time between #{dto.startTime} and #{dto.endTime}
            </if>
        ) t
        where
            1=1
        <if test="dto.type!=null and 0!=dto.type">
            and t.type = #{dto.type}
        </if>
    </select>
 
 
    <select id="financeStatistics" resultType="com.ruoyi.errand.object.vo.sys.FinanceStatisticsVO">
        select * from (
                SELECT t.id as id,
                       t.order_time as orderTime,
                       1 as type,
                       t.order_number as orderNumber,
                       tau.name as appUserName,
                       tau.phone as phone,
                       t.order_status as orderStatus
                FROM t_order t
                INNER JOIN t_app_user tau ON t.app_user_id = tau.id
                WHERE t.del_flag=0
        and t.pay_status=2
                <if test="dto.appUserName!=null and  ''!=dto.appUserName">
                    and tau.name like concat('%',#{dto.appUserName},'%')
                </if>
                <if test="dto.phone!=null and  ''!=dto.phone">
                    and tau.phone like concat('%',#{dto.phone},'%')
                </if>
                <if test="dto.orderStatus!=null and 0!=dto.orderStatus and dto.orderStatus !=4">
                    and t.order_status = #{dto.orderStatus}
                </if>
        <if test="dto.orderStatus ==4">
            and t.order_status in(4,5)
        </if>
                <if test="dto.startTime!=null and dto.endTime != null">
                    and t.order_time between #{dto.startTime} and #{dto.endTime}
                </if>
            UNION ALL
                SELECT t.id as id,
                t.order_time as orderTime,
                2 as type,
                t.order_number as orderNumber,
                tau.name as appUserName,
                tau.phone as phone,
                t.order_status as orderStatus
                FROM t_vip_order t
                INNER JOIN t_app_user tau ON t.app_user_id = tau.id
                WHERE t.del_flag=0
        and t.pay_status=2
                <if test="dto.appUserName!=null and  ''!=dto.appUserName">
                    and tau.name like concat('%',#{dto.appUserName},'%')
                </if>
 
                <if test="dto.phone!=null and  ''!=dto.phone">
                    and tau.phone like concat('%',#{dto.phone},'%')
                </if>
 
                <if test="dto.orderStatus!=null and 0!=dto.orderStatus and dto.orderStatus !=4">
                    and t.order_status = #{dto.orderStatus}
                </if>
                <if test="dto.orderStatus ==4">
                    and t.order_status in(4,5)
                </if>
 
                <if test="dto.startTime!=null and dto.endTime != null">
                    and t.order_time between #{dto.startTime} and #{dto.endTime}
                </if>
                ) t
            where
            1=1
            <if test="dto.type!=null and 0!=dto.type">
                and t.type = #{dto.type}
            </if>
            ORDER BY t.orderTime DESC
            LIMIT #{dto.pageNum}, #{dto.pageSize}
    </select>
    <select id="getOrderPageList" resultType="com.ruoyi.errand.object.vo.sys.OrderPageListVO">
        select
            o.id as id,
            o.order_number as orderNumber,
            o.order_time as orderTime,
            o.payment_amount as paymentAmount,
            o.finish_time as finishTime,
            o.order_status as orderStatus,
            o.community_name as communityName,
            tau.name as appUserName,
            tau.phone as appUserPhone,
            tc.name as courierName,
            tc.phone as courierPhone
        from t_order o
        inner join t_app_user tau on o.app_user_id = tau.id
        left join t_courier tc on o.courier_id = tc.id
        where
            o.del_flag=0
        and o.pay_status=2
        <if test="dto.orderNumber!=null and ''!=dto.orderNumber">
            and o.order_number like concat('%',#{dto.orderNumber},'%')
        </if>
        <if test="dto.communityName!=null and ''!=dto.communityName">
            and o.community_name like concat('%',#{dto.communityName},'%')
        </if>
        <if test="dto.appUserName!=null and ''!=dto.appUserName">
            and tau.name like concat('%',#{dto.appUserName},'%')
        </if>
        <if test="dto.appUserPhone!=null and ''!=dto.appUserPhone">
            and tau.phone like concat('%',#{dto.appUserPhone},'%')
        </if>
        <if test="dto.courierName!=null and ''!=dto.courierName">
            and tc.name like concat('%',#{dto.courierName},'%')
        </if>
        <if test="dto.courierPhone!=null and ''!=dto.courierPhone">
            and tc.phone like concat('%',#{dto.courierPhone},'%')
        </if>
        <if test="dto.orderStartTime!=null and dto.orderEndTime != null">
            and o.order_time between #{dto.orderStartTime} and #{dto.orderEndTime}
        </if>
        <if test="dto.finishStartTime!=null and dto.finishEndTime != null">
            and o.finishTime between #{dto.finishStartTime} and #{dto.finishEndTime}
        </if>
        <if test="dto.orderStatus!=null and 0!=dto.orderStatus and dto.orderStatus !=4">
            and o.order_status = #{dto.orderStatus}
        </if>
        <if test="dto.orderStatus ==4">
            and o.order_status in(4,5)
        </if>
    </select>
    <select id="detail" resultType="com.ruoyi.errand.object.vo.sys.OrderSysDetailVO">
        select
            o.order_status as orderStatus,
            tau.name as appUserName,
            tau.phone as appUserPhone,
            o.community_name as communityName,
            o.recipient_name as recipientName,
            o.recipient_phone as recipientPhone,
            o.address_detail as addressDetail,
            o.agency_matters as agencyMatters,
            o.num as  num,
            o.remark as  remark,
            o.pics as  pics,
            tc.name as  courierName,
            tc.phone as  courierPhone,
            o.courier_pics as  courierPics,
            o.order_number as  orderNumber,
            o.order_time as  orderTime,
            o.finish_time as  finishTime,
            o.payment_amount as  paymentAmount,
            teu.rating as  userRating,
            teu.content as  userContent,
            tec.rating as  courierRating,
            tec.content as courierContent
        from t_order o
        inner join t_app_user tau on o.app_user_id = tau.id
        left join t_courier tc on o.courier_id = tc.id
        left join t_evaluation teu on o.id = teu.order_id and teu.type=0
        left join t_evaluation tec on o.id = teu.order_id and teu.type=1
        where
            o.id=#{id}
    </select>
    <select id="export" resultType="com.ruoyi.errand.object.vo.sys.FinanceStatisticsVO">
        select * from (
        SELECT t.id as id,
        t.order_time as orderTime,
        1 as type,
        t.order_number as orderNumber,
        tau.name as appUserName,
        tau.phone as phone,
        t.order_status as orderStatus
        FROM t_order t
        INNER JOIN t_app_user tau ON t.app_user_id = tau.id
        WHERE t.del_flag=0
        and t.pay_status=2
        <if test="dto.appUserName!=null and  ''!=dto.appUserName">
            and tau.name like concat('%',#{dto.appUserName},'%')
        </if>
        <if test="dto.phone!=null and  ''!=dto.phone">
            and tau.phone like concat('%',#{dto.phone},'%')
        </if>
        <if test="dto.orderStatus!=null and 0!=dto.orderStatus and dto.orderStatus !=4">
            and t.order_status = #{dto.orderStatus}
        </if>
        <if test="dto.orderStatus ==4">
            and t.order_status in(4,5)
        </if>
        <if test="dto.startTime!=null and dto.endTime != null">
            and t.order_time between #{dto.startTime} and #{dto.endTime}
        </if>
        UNION ALL
        SELECT t.id as id,
        t.order_time as orderTime,
        2 as type,
        t.order_number as orderNumber,
        tau.name as appUserName,
        tau.phone as phone,
        t.order_status as orderStatus
        FROM t_vip_order t
        INNER JOIN t_app_user tau ON t.app_user_id = tau.id
        WHERE t.del_flag=0
        and t.pay_status=2
        <if test="dto.appUserName!=null and  ''!=dto.appUserName">
            and tau.name like concat('%',#{dto.appUserName},'%')
        </if>
 
        <if test="dto.phone!=null and  ''!=dto.phone">
            and tau.phone like concat('%',#{dto.phone},'%')
        </if>
 
        <if test="dto.orderStatus!=null and 0!=dto.orderStatus and dto.orderStatus !=4">
            and t.order_status = #{dto.orderStatus}
        </if>
        <if test="dto.orderStatus ==4">
            and t.order_status in(4,5)
        </if>
 
        <if test="dto.startTime!=null and dto.endTime != null">
            and t.order_time between #{dto.startTime} and #{dto.endTime}
        </if>
        ) t
        where
        1=1
        <if test="dto.type!=null and 0!=dto.type">
            and t.type = #{dto.type}
        </if>
        ORDER BY t.orderTime DESC
    </select>
    <select id="orderExport" resultType="com.ruoyi.errand.object.vo.sys.OrderPageListVO">
        select
        o.id as id,
        o.order_number as orderNumber,
        o.order_time as orderTime,
        o.payment_amount as paymentAmount,
        o.finish_time as finishTime,
        o.order_status as orderStatus,
        o.community_name as communityName,
        tau.name as appUserName,
        tau.phone as appUserPhone,
        tc.name as courierName,
        tc.phone as courierPhone
        from t_order o
        inner join t_app_user tau on o.app_user_id = tau.id
        left join t_courier tc on o.courier_id = tc.id
        where
        o.del_flag=0
        and o.pay_status=2
        <if test="dto.orderNumber!=null and ''!=dto.orderNumber">
            and o.order_number like concat('%',#{dto.orderNumber},'%')
        </if>
        <if test="dto.communityName!=null and ''!=dto.communityName">
            and o.community_name like concat('%',#{dto.communityName},'%')
        </if>
        <if test="dto.appUserName!=null and ''!=dto.appUserName">
            and tau.name like concat('%',#{dto.appUserName},'%')
        </if>
        <if test="dto.appUserPhone!=null and ''!=dto.appUserPhone">
            and tau.phone like concat('%',#{dto.appUserPhone},'%')
        </if>
        <if test="dto.courierName!=null and ''!=dto.courierName">
            and tc.name like concat('%',#{dto.courierName},'%')
        </if>
        <if test="dto.courierPhone!=null and ''!=dto.courierPhone">
            and tc.phone like concat('%',#{dto.courierPhone},'%')
        </if>
        <if test="dto.orderStartTime!=null and dto.orderEndTime != null">
            and o.order_time between #{dto.orderStartTime} and #{dto.orderEndTime}
        </if>
        <if test="dto.finishStartTime!=null and dto.finishEndTime != null">
            and o.finishTime between #{dto.finishStartTime} and #{dto.finishEndTime}
        </if>
        <if test="dto.orderStatus!=null and 0!=dto.orderStatus and dto.orderStatus !=4">
            and o.order_status = #{dto.orderStatus}
        </if>
        <if test="dto.orderStatus ==4">
            and o.order_status in(4,5)
        </if>
    </select>
</mapper>