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
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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
<?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.TDriverMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.system.model.TDriver">
        <id column="id" property="id" />
        <result column="account" property="account" />
        <result column="jobNumber" property="jobNumber" />
        <result column="phone" property="phone" />
        <result column="password" property="password" />
        <result column="name" property="name" />
        <result column="sex" property="sex" />
        <result column="idCard" property="idCard" />
        <result column="companyId" property="companyId" />
        <result column="headImgUrl" property="headImgUrl" />
        <result column="faceImgUrl" property="faceImgUrl" />
        <result column="idCardImgUrl1" property="idCardImgUrl1" />
        <result column="idCardImgUrl2" property="idCardImgUrl2" />
        <result column="placeOfEmployment" property="placeOfEmployment" />
        <result column="birthday" property="birthday" />
        <result column="bankCardNumber" property="bankCardNumber" />
        <result column="driverNationality" property="driverNationality" />
        <result column="driverNation" property="driverNation" />
        <result column="driverMaritalStatus" property="driverMaritalStatus" />
        <result column="driverLanguageLevel" property="driverLanguageLevel" />
        <result column="driverEducation" property="driverEducation" />
        <result column="driverCensus" property="driverCensus" />
        <result column="driverAddress" property="driverAddress" />
        <result column="driverContactAddress" property="driverContactAddress" />
        <result column="driverAge" property="driverAge" />
        <result column="driveCard" property="driveCard" />
        <result column="driveCardImgUrl" property="driveCardImgUrl" />
        <result column="driverType" property="driverType" />
        <result column="getDriverLicenseDate" property="getDriverLicenseDate" />
        <result column="driverLicenseOn" property="driverLicenseOn" />
        <result column="driverLicenseOff" property="driverLicenseOff" />
        <result column="taxiDriver" property="taxiDriver" />
        <result column="taxiAptitudeCard" property="taxiAptitudeCard" />
        <result column="networkCarlssueImg" property="networkCarlssueImg" />
        <result column="networkCarlssueOrganization" property="networkCarlssueOrganization" />
        <result column="networkCarlssueDate" property="networkCarlssueDate" />
        <result column="getNetworkCarProofDate" property="getNetworkCarProofDate" />
        <result column="networkCarProofOn" property="networkCarProofOn" />
        <result column="networkCarProofOff" property="networkCarProofOff" />
        <result column="registerDate" property="registerDate" />
        <result column="fullTimeDriver" property="fullTimeDriver" />
        <result column="inDriverBlacklist" property="inDriverBlacklist" />
        <result column="commercialType" property="commercialType" />
        <result column="contractCompany" property="contractCompany" />
        <result column="contractOn" property="contractOn" />
        <result column="contractOff" property="contractOff" />
        <result column="emergencyContact" property="emergencyContact" />
        <result column="emergencyContactPhone" property="emergencyContactPhone" />
        <result column="emergencyContactAddress" property="emergencyContactAddress" />
        <result column="remark" property="remark" />
        <result column="isPlatCar" property="isPlatCar" />
        <result column="carId" property="carId" />
        <result column="authState" property="authState" />
        <result column="state" property="state" />
        <result column="flag" property="flag" />
        <result column="insertTime" property="insertTime" />
        <result column="insertUser" property="insertUser" />
        <result column="updateTime" property="updateTime" />
        <result column="updateUser" property="updateUser" />
        <result column="addType" property="addType" />
        <result column="laveBusinessMoney" property="laveBusinessMoney"/>
        <result column="businessMoney" property="businessMoney"/>
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, account, jobNumber, phone, password, name, sex, idCard, companyId, headImgUrl, faceImgUrl, idCardImgUrl1, idCardImgUrl2, placeOfEmployment, birthday, bankCardNumber, driverNationality, driverNation, driverMaritalStatus, driverLanguageLevel, driverEducation, driverCensus, driverAddress, driverContactAddress, licenseCode, licenselImgUrl, driverAge, driveCard, driveCardImgUrl, driverType, getDriverLicenseDate, driverLicenseOn, driverLicenseOff, taxiDriver, taxiAptitudeCard, networkCarlssueImg, networkCarlssueOrganization, networkCarlssueDate, getNetworkCarProofDate, networkCarProofOn, networkCarProofOff, registerDate, fullTimeDriver, inDriverBlacklist, commercialType, contractCompany, contractOn, contractOff, emergencyContact, emergencyContactPhone, emergencyContactAddress, remark, isPlatCar, carId, authState, state, flag, insertTime, insertUser, updateTime, updateUser, addType
    </sql>
 
    <!--根据条件查询待审核司机列表-->
    <select id="getAuthDriverList" resultType="map" parameterType="com.baomidou.mybatisplus.plugins.Page">
        SELECT * FROM (SELECT cc1.`name` as companyName,cc2.`name` as franchiseeName,ds.serverStr,dd.* from t_driver as dd
        LEFT JOIN (select * from t_company where type = 2 and flag != 3) as cc1 on cc1.id = dd.companyId
        LEFT JOIN (select * from t_company where type = 3 and flag != 3) as cc2 on cc2.id = dd.franchiseeId
        LEFT JOIN (
        SELECT
        GROUP_CONCAT(case when type = 1 then '快车'
        when type = 2 then '出租车'
        when type = 3 then '跨城出行'
        when type = 4 then '小件物流-同城'
        when type = 5 then '小件物流-跨城'
        when type = 6 then '包车'
        else '' end ) as serverStr,driverId from t_driver_service GROUP BY driverId) as ds on ds.driverId = dd.id
        ) as o
        <where>
            FIND_IN_SET(o.authState,'1,4') and o.flag != 3
            <if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
                AND (o.insertTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
            </if>
            <if test="companyName != null and companyName != ''">
                and (o.companyName  LIKE CONCAT('%',#{companyName},'%') or o.franchiseeName  LIKE CONCAT('%',#{companyName},'%'))
            </if>
            <if test="phone != null and phone != ''">
                and o.phone  LIKE CONCAT('%',#{phone},'%')
            </if>
            <if test="account != null and account != ''">
                and o.account  LIKE CONCAT('%',#{account},'%')
            </if>
            <if test="addType != null and addType != ''">
                and o.addType = #{addType}
            </if>
            <if test="authState != null and authState != ''">
                and o.authState = #{authState}
            </if>
        </where>
        order by o.id desc
    </select>
 
    <!--根据用户ID获取用户详情-->
    <select id="getDriverById" resultType="map">
        SELECT cc.`name` as companyName,ds.serverStr,
        case when dd.addType = 1 then '司机注册' when dd.addType = 2 then '平台添加' when dd.addType = 3 then '分公司添加' when dd.addType = 4 then '加盟商添加' else '' end as addTypeStr,
        case when dd.sex = 1 then '男' when dd.sex = 2 then '女' else '' end as sexStr,
        case when dd.authState = 1 then '待审核' when dd.authState = 2 then '正常' when dd.authState = 3 then '冻结' when dd.authState = 4 then '已拒绝' end as authStateStr,
        dd.* from t_driver as dd
        LEFT JOIN (select * from t_company where flag != 3) as cc on cc.id = dd.companyId
        LEFT JOIN (
        SELECT
        GROUP_CONCAT(case when type = 1 then '快车'
        when type = 2 then '出租车'
        when type = 3 then '跨城出行'
        when type = 4 then '小件物流-同城'
        when type = 5 then '小件物流-跨城'
        when type = 6 then '包车'
        else '' end SEPARATOR '、') as serverStr,driverId from t_driver_service GROUP BY driverId) as ds on ds.driverId = dd.id
        where dd.id = #{driverId}
    </select>
 
    <!--根据审核通过的司机列表-->
    <select id="getDriverList" resultType="map" parameterType="com.baomidou.mybatisplus.plugins.Page">
        SELECT * FROM (SELECT cc1.`name` as companyName,cc2.`name` as franchiseeName,ci.carLicensePlate,ds.serverStr,IFNULL(oe.evaluateNum,0) as evaluateNum,
        (IFNULL(ot1.taxiNum, 0) + IFNULL(ot3.num, 0) + IFNULL(ot5.num, 0) + IFNULL(ot7.num, 0)) as historyNum,
        (IFNULL(ot2.taxiMoney, 0)+ IFNULL(ot4.money, 0) + IFNULL(ot6.money, 0) + IFNULL(ot8.money, 0)) as historyMoney,
        dd.* from t_driver as dd
        LEFT JOIN (select * from t_company where type = 2 and flag != 3) as cc1 on cc1.id = dd.companyId
        LEFT JOIN (select * from t_company where type = 3 and flag != 3) as cc2 on cc2.id = dd.franchiseeId
        LEFT JOIN (select * from t_car where state = 1) as ci on ci.id = dd.carId
        LEFT JOIN (
        SELECT
        GROUP_CONCAT(case when type = 1 then '快车'
        when type = 2 then '出租车'
        when type = 3 then '跨城出行'
        when type = 4 then '小件物流-同城'
        when type = 5 then '小件物流-跨城'
        when type = 6 then '包车'
        else '' end ) as serverStr,driverId from t_driver_service GROUP BY driverId) as ds on ds.driverId = dd.id
        LEFT JOIN (SELECT IFNULL(SUM(fraction)/COUNT(id),0) as evaluateNum,driverId FROM t_order_evaluate GROUP BY driverId) as oe on oe.driverId = dd.id
        LEFT JOIN (SELECT COUNT(id) as taxiNum,driverId FROM t_order_taxi where FIND_IN_SET(state,'7,8,9') GROUP BY driverId) as ot1 on ot1.driverId = dd.id
        LEFT JOIN (SELECT SUM(orderMoney) as taxiMoney,driverId FROM t_order_taxi where FIND_IN_SET(state,'7,8,9') GROUP BY driverId) as ot2 on ot2.driverId = dd.id
        LEFT JOIN (SELECT COUNT(id) as num,driverId FROM t_order_private_car where FIND_IN_SET(state,'7,8,9') GROUP BY driverId) as ot3 on ot3.driverId = dd.id
        LEFT JOIN (SELECT SUM(orderMoney) as money,driverId FROM t_order_private_car where FIND_IN_SET(state,'7,8,9') GROUP BY driverId) as ot4 on ot4.driverId = dd.id
        LEFT JOIN (SELECT COUNT(id) as num,driverId FROM t_order_cross_city where FIND_IN_SET(state,'6,8,9') GROUP BY driverId) as ot5 on ot5.driverId = dd.id
        LEFT JOIN (SELECT SUM(orderMoney) as money,driverId FROM t_order_cross_city where FIND_IN_SET(state,'6,8,9') GROUP BY driverId) as ot6 on ot6.driverId = dd.id
        LEFT JOIN (SELECT COUNT(id) as num,driverId FROM t_order_logistics where FIND_IN_SET(state,'6,9') GROUP BY driverId) as ot7 on ot7.driverId = dd.id
        LEFT JOIN (SELECT SUM(orderMoney) as money,driverId FROM t_order_logistics where FIND_IN_SET(state,'6,9') GROUP BY driverId) as ot8 on ot8.driverId = dd.id) as o
        <where>
            o.flag != 3
            <if test="roleType != null and roleType != '' and roleType == 1">
                and FIND_IN_SET(o.authState,'2,3')
            </if>
            <if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
                AND (o.insertTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
            </if>
            <if test="companyName != null and companyName != ''">
                and (o.companyName  LIKE CONCAT('%',#{companyName},'%') or o.franchiseeName  LIKE CONCAT('%',#{companyName},'%'))
            </if>
            <if test="phone != null and phone != ''">
                and o.phone  LIKE CONCAT('%',#{phone},'%')
            </if>
            <if test="name != null and name != ''">
                and o.name  LIKE CONCAT('%',#{name},'%')
            </if>
            <if test="addType != null and addType != ''">
                and o.addType = #{addType}
            </if>
            <if test="authState != null and authState != ''">
                and o.authState = #{authState}
            </if>
            <if test="roleType != null and roleType != '' and roleType == 2">
                and (o.companyId = #{nowUserId} or FIND_IN_SET(o.franchiseeId,(SELECT GROUP_CONCAT(id) as ids FROM t_company where superiorId = #{nowUserId} GROUP BY superiorId)))
            </if>
            <if test="roleType != null and roleType != '' and roleType == 3">
                and o.franchiseeId = #{nowUserId}
            </if>
        </where>
        order by o.id desc
    </select>
 
    <!--查询已被使用的车辆ID-->
    <select id="getUseCarIdStr" resultType="java.lang.String">
        SELECT GROUP_CONCAT(dd.carId) as carIdStr from t_driver as dd where dd.authState = 2 and dd.flag != 3
        <if test="carId != null and carId != '' and carId != 0">
            and dd.carId != #{carId}
        </if>
    </select>
 
    <!--查询当前可被选择的车辆列表-->
    <select id="getCanSelectCarList" resultType="map" parameterType="com.baomidou.mybatisplus.plugins.Page">
        SELECT * FROM (SELECT cm.`name` as modelName,cb.`name` as brandName,ds.serverStr,ci.* from t_car as ci
        LEFT JOIN (select * from t_car_model where state = 1) as cm on cm.id = ci.carModelId
        LEFT JOIN (select * from t_car_brand where state = 1) as cb on cb.id = ci.carBrandId
        LEFT JOIN (
        SELECT
        GROUP_CONCAT(case when type = 1 then '快车'
        when type = 2 then '出租车'
        when type = 3 then '跨城出行'
        when type = 4 then '小件物流-同城'
        when type = 5 then '小件物流-跨城'
        when type = 6 then '包车'
        else '' end ) as serverStr,carId from t_car_service GROUP BY carId) as ds on ds.carId = ci.id) as o
        <where>
            o.state = 1
            <if test="carIdStr != null and carIdStr != ''">
                and not FIND_IN_SET(o.id,#{carIdStr})
            </if>
            <if test="carLicensePlate != null and carLicensePlate != ''">
                and o.carLicensePlate  LIKE CONCAT('%',#{carLicensePlate},'%')
            </if>
            <if test="brandName != null and brandName != ''">
                and o.brandName  LIKE CONCAT('%',#{brandName},'%')
            </if>
            <if test="modelName != null and modelName != ''">
                and o.modelName  LIKE CONCAT('%',#{modelName},'%')
            </if>
            <if test="color != null and color != ''">
                and o.carColor  LIKE CONCAT('%',#{color},'%')
            </if>
            <if test="serverStr != null and serverStr != ''">
                and o.serverStr  LIKE CONCAT('%',#{serverStr},'%')
            </if>
            <if test="roleType != null and roleType != '' and roleType == 2">
                and (o.companyId = #{nowUserId} or FIND_IN_SET(o.franchiseeId,(SELECT GROUP_CONCAT(id) as ids FROM t_company where type = 3 and superiorId = #{nowUserId} GROUP BY superiorId)))
            </if>
            <if test="roleType != null and roleType != '' and roleType == 3">
                and o.franchiseeId = #{nowUserId}
            </if>
        </where>
        order by o.id desc
    </select>
 
    <!--修改分公司司机的状态-->
    <update id="updateCompanyDriverState" parameterType="java.lang.Integer">
        update t_driver
        <set>
            <if test="authState != null"> authState = #{authState} </if>
        </set>
        where companyId = #{companyId} and (franchiseeId = 0 or franchiseeId is null)
    </update>
 
    <!--修改加盟商司机的状态-->
    <update id="updateFranchiseeDriverState" parameterType="java.lang.Integer">
        update t_driver
        <set>
            <if test="authState != null"> authState = #{authState} </if>
        </set>
        where franchiseeId = #{franchiseeId}
    </update>
 
    <!--根据审核通过的司机列表无分页-->
    <select id="getDriverListNoPage" resultType="map">
        SELECT * FROM (SELECT cc1.`name` as companyName,cc2.`name` as franchiseeName,ci.carLicensePlate,ds.serverStr,IFNULL(oe.evaluateNum,0) as evaluateNum,
        (IFNULL(ot1.taxiNum, 0) + IFNULL(ot3.num, 0) + IFNULL(ot5.num, 0)) as historyNum,(IFNULL(ot2.taxiMoney, 0)+ IFNULL(ot4.money, 0) + IFNULL(ot6.money, 0)) as historyMoney,dd.* from t_driver as dd
        LEFT JOIN (select * from t_company where type = 2 and flag != 3) as cc1 on cc1.id = dd.companyId
        LEFT JOIN (select * from t_company where type = 3 and flag != 3) as cc2 on cc2.id = dd.franchiseeId
        LEFT JOIN (select * from t_car where state = 1) as ci on ci.id = dd.carId
        LEFT JOIN (
        SELECT
        GROUP_CONCAT(case when type = 1 then '快车'
        when type = 2 then '出租车'
        when type = 3 then '跨城出行'
        when type = 4 then '小件物流-同城'
        when type = 5 then '小件物流-跨城'
        when type = 6 then '包车'
        else '' end ) as serverStr,driverId from t_driver_service GROUP BY driverId) as ds on ds.driverId = dd.id
        LEFT JOIN (SELECT IFNULL(SUM(fraction)/COUNT(id),0) as evaluateNum,driverId FROM t_order_evaluate GROUP BY driverId) as oe on oe.driverId = dd.id
        LEFT JOIN (SELECT COUNT(id) as taxiNum,driverId FROM t_order_taxi where FIND_IN_SET(state,'7,8,9') GROUP BY driverId) as ot1 on ot1.driverId = dd.id
        LEFT JOIN (SELECT SUM(orderMoney) as taxiMoney,driverId FROM t_order_taxi where FIND_IN_SET(state,'8,9') GROUP BY driverId) as ot2 on ot2.driverId = dd.id
        LEFT JOIN (SELECT COUNT(id) as num,driverId FROM t_order_private_car where FIND_IN_SET(state,'7,8,9') GROUP BY driverId) as ot3 on ot3.driverId = dd.id
        LEFT JOIN (SELECT SUM(orderMoney) as money,driverId FROM t_order_private_car where FIND_IN_SET(state,'7,8,9') GROUP BY driverId) as ot4 on ot4.driverId = dd.id
        LEFT JOIN (SELECT COUNT(id) as num,driverId FROM t_order_cross_city where FIND_IN_SET(state,'6,7,8') GROUP BY driverId) as ot5 on ot5.driverId = dd.id
        LEFT JOIN (SELECT SUM(orderMoney) as money,driverId FROM t_order_cross_city where FIND_IN_SET(state,'6,7,8') GROUP BY driverId) as ot6 on ot6.driverId = dd.id
        ) as o
        <where>
            o.flag != 3
            <if test="roleType != null and roleType != '' and roleType == 1">
                and FIND_IN_SET(o.authState,'2,3')
            </if>
            <if test="roleType != null and roleType != '' and roleType == 2">
                and (o.companyId = #{nowUserId} or FIND_IN_SET(o.franchiseeId,(SELECT GROUP_CONCAT(id) as ids FROM t_company where superiorId = #{nowUserId} GROUP BY superiorId)))
            </if>
            <if test="roleType != null and roleType != '' and roleType == 3">
                and o.franchiseeId = #{nowUserId}
            </if>
        </where>
        order by o.id desc
    </select>
 
    <select id="orderRevenueDetailsList" resultType="map">
        select
        a.id,
        b.insertTime,
        a.`name`,
        a.phone as driverPhone,
        b.orderNum,
        b.orderType,
        c.money,
        c.type as incomeType,
        d.nickName,
        d.phone as userPhone,
        b.passengers,
        b.passengersPhone,
        b.startAddress,
        b.endAddress,
        e.carLicensePlate,
        b.payTypeName,
        b.orderMoney,
        b.payMoney
        from t_driver a
        left join (
        select id, orderNum, driverId, 1 as orderType, CASE WHEN payType=1 THEN '微信' WHEN payType=2 THEN '支付宝' WHEN payType=3 THEN '余额支付'  WHEN payType=4 THEN '云闪付'  ELSE '' END payTypeName, orderMoney,payMoney, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime, userId, passengers, passengersPhone, startAddress, endAddress, carId from t_order_private_car where state in (8, 9) and isDelete = 1
        union all
        select id, orderNum, driverId, 2 as orderType, CASE WHEN payType=1 THEN '微信' WHEN payType=2 THEN '支付宝' WHEN payType=3 THEN '余额支付' WHEN payType=4 THEN '云闪付' ELSE '' END payTypeName, orderMoney,payMoney, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime, userId, passengers, passengersPhone, startAddress, endAddress, carId from t_order_taxi where state in (8, 9) and isDelete = 1
        union all
        select id, orderNum, driverId, 3 as orderType, CASE WHEN payType=1 THEN '微信' WHEN payType=2 THEN '支付宝' WHEN payType=3 THEN '余额支付' WHEN payType=4 THEN '云闪付' ELSE '' END payTypeName, orderMoney,payMoney, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime, userId, passengers, passengersPhone, startAddress, endAddress, carId from t_order_cross_city where state in (8, 9) and isDelete = 1
        union all
        select id, orderNum, driverId, type as orderType, CASE WHEN payType=1 THEN '微信' WHEN payType=2 THEN '支付宝' WHEN payType=3 THEN '余额支付' WHEN payType=4 THEN '云闪付' ELSE '' END payTypeName, orderMoney,payMoney, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime, userId, recipient as passengers, recipientPhone as passengersPhone, startAddress, endAddress, carId from t_order_logistics where state in (6, 9) and isDelete = 1
        union all
        select id, orderNum, driverId, 7 as orderType, CASE WHEN payType=1 THEN '微信' WHEN payType=2 THEN '支付宝' WHEN payType=3 THEN '余额支付' WHEN payType=4 THEN '云闪付' ELSE '' END payTypeName, orderMoney,payMoney, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime, userId, passengers, passengersPhone, startAddress, endAddress, carId from t_order_call where state in (8, 9) and isDelete = 1
        ) b on (a.id = b.driverId)
        left join (select userType, objectId, type, incomeId, orderType, sum(money) as money from t_income where userType = 2 and type = 2 group by userType, objectId, type, incomeId, orderType) c on (b.id = c.incomeId and b.orderType = c.orderType)
        left join t_user d on (b.userId = d.id)
        left join t_car e on (b.carId = e.id)
        where a.flag != 3 and a.authState = 2
        <if test="null != companyId">
            and a.companyId = #{companyId}
        </if>
        <if test="null != driverName and '' != driverName">
            and a.`name` like CONCAT('%', #{driverName}, '%')
        </if>
        <if test="null != driverPhone and '' != driverPhone">
            and a.phone like CONCAT('%', #{driverPhone}, '%')
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(b.insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
        <if test="null != orderType">
            and b.orderType = #{orderType}
        </if>
        order by b.insertTime desc
    </select>
 
    <select id="orderRevenueDetailsListSum" resultType="double">
        select
        sum(c.money) as money
        from t_driver a
        left join (
        select id, orderNum, driverId, 1 as orderType, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime from t_order_private_car where state in (8, 9) and isDelete = 1
        union all
        select id, orderNum, driverId, 2 as orderType, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime from t_order_taxi where state in (8, 9) and isDelete = 1
        union all
        select id, orderNum, driverId, 3 as orderType, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime from t_order_cross_city where state in (8, 9) and isDelete = 1
        union all
        select id, orderNum, driverId, type as orderType, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime from t_order_logistics where state in (6, 9) and isDelete = 1
        union all
        select id, orderNum, driverId, 7 as orderType, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime from t_order_call where state in (8, 9) and isDelete = 1
        ) b on (a.id = b.driverId)
        left join (select * from t_income where userType = 2 and type = 2) c on (b.id = c.incomeId and b.orderType = c.orderType)
        where a.flag != 3 and a.authState = 2 and c.money > 0
        <if test="null != companyId">
            and a.companyId = #{companyId}
        </if>
        <if test="null != driverName and '' != driverName">
            and a.`name` like CONCAT('%', #{driverName}, '%')
        </if>
        <if test="null != driverPhone and '' != driverPhone">
            and a.phone like CONCAT('%', #{driverPhone}, '%')
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(b.insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
        <if test="null != orderType">
            and b.orderType = #{orderType}
        </if>
        order by b.insertTime desc
    </select>
 
 
 
 
    <select id="exportOrderRevenueDetails" resultType="map">
        select
        a.id,
        b.insertTime,
        a.`name`,
        a.phone as driverPhone,
        b.orderNum,
        b.orderType,
        c.money,
        c.type as incomeType,
        d.nickName,
        d.phone as userPhone,
        b.passengers,
        b.passengersPhone,
        b.startAddress,
        b.endAddress,
        e.carLicensePlate,
        b.payTypeName,
        b.orderMoney,
        b.payMoney
        from t_driver a
        left join (
        select id, orderNum, driverId, 1 as orderType, CASE WHEN payType=1 THEN '微信' WHEN payType=2 THEN '支付宝' WHEN payType=3 THEN '余额支付' ELSE '' END payTypeName, orderMoney,payMoney, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime, userId, passengers, passengersPhone, startAddress, endAddress, carId from t_order_private_car where state in (8, 9) and isDelete = 1
        union all
        select id, orderNum, driverId, 2 as orderType, CASE WHEN payType=1 THEN '微信' WHEN payType=2 THEN '支付宝' WHEN payType=3 THEN '余额支付' ELSE '' END payTypeName, orderMoney,payMoney, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime, userId, passengers, passengersPhone, startAddress, endAddress, carId from t_order_taxi where state in (8, 9) and isDelete = 1
        union all
        select id, orderNum, driverId, 3 as orderType, CASE WHEN payType=1 THEN '微信' WHEN payType=2 THEN '支付宝' WHEN payType=3 THEN '余额支付' ELSE '' END payTypeName, orderMoney,payMoney, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime, userId, passengers, passengersPhone, startAddress, endAddress, carId from t_order_cross_city where state in (8, 9) and isDelete = 1
        union all
        select id, orderNum, driverId, type as orderType, CASE WHEN payType=1 THEN '微信' WHEN payType=2 THEN '支付宝' WHEN payType=3 THEN '余额支付' ELSE '' END payTypeName, orderMoney,payMoney, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime, userId, recipient as passengers, recipientPhone as passengersPhone, startAddress, endAddress, carId from t_order_logistics where state in (6, 9) and isDelete = 1
        union all
        select id, orderNum, driverId, 7 as orderType, CASE WHEN payType=1 THEN '微信' WHEN payType=2 THEN '支付宝' WHEN payType=3 THEN '余额支付' ELSE '' END payTypeName, orderMoney,payMoney, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime, userId, passengers, passengersPhone, startAddress, endAddress, carId from t_order_call where state in (8, 9) and isDelete = 1
        ) b on (a.id = b.driverId)
        left join (select * from t_income where userType = 2 and type = 2) c on (b.id = c.incomeId and b.orderType = c.orderType)
        left join t_user d on (b.userId = d.id)
        left join t_car e on (b.carId = e.id)
        where a.flag != 3 and a.authState = 2 and c.money > 0
        <if test="null != companyId">
            and a.companyId = #{companyId}
        </if>
        <if test="null != driverName and '' != driverName">
            and a.`name` like CONCAT('%', #{driverName}, '%')
        </if>
        <if test="null != driverPhone and '' != driverPhone">
            and a.phone like CONCAT('%', #{driverPhone}, '%')
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(b.insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
        <if test="null != orderType">
            and b.orderType = #{orderType}
        </if>
        order by b.insertTime desc
    </select>
 
 
 
    <select id="otherSpendingDetailList" resultType="map">
        select
        da.travelTime,
        b.name,
        b.phone,
        da.type,
        da.thankYouFee
        from (
        select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, 1 as type, driverId, ifnull(thankYouFee, 0) as thankYouFee
        from t_order_private_car a
        where a.thankYouFee > 0
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(a.travelTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
 
        union all
 
        select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, 2 as type, driverId, ifnull(thankYouFee, 0) as thankYouFee
        from t_order_taxi a
        where a.thankYouFee > 0
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(a.travelTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
 
        union all
 
        select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, 3 as type, driverId, ifnull(thankYouFee, 0) as thankYouFee
        from t_order_cross_city a
        where a.thankYouFee > 0
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(a.travelTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
 
        union all
 
        select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, type as type, driverId, ifnull(thankYouFee, 0) as thankYouFee
        from t_order_logistics a
        where a.thankYouFee > 0
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(a.travelTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
 
        union all
 
        select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, 7 as type, driverId, ifnull(thankYouFee, 0) as thankYouFee
        from t_order_call a
        where a.thankYouFee > 0
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(a.travelTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
        ) as da
        left join t_driver b on (da.driverId = b.id)
        where 1 = 1
        <if test="null != driverName and '' != driverName">
            and b.name like CONCAT('%', #{driverName}, '%')
        </if>
        <if test="null != driverPhone and '' != driverPhone">
            and b.phone like CONCAT('%', #{driverPhone}, '%')
        </if>
        order by da.travelTime desc
        <if test="null != offset and null != limit">
            limit #{offset}, #{limit}
        </if>
    </select>
 
    <select id="otherSpendingDetailListCount" resultType="int">
        select count(1) from (
        select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, 1 as type, driverId, ifnull(thankYouFee, 0) as thankYouFee
        from t_order_private_car a
        where a.thankYouFee > 0
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(a.travelTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
 
        union all
 
        select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, 2 as type, driverId, ifnull(thankYouFee, 0) as thankYouFee
        from t_order_taxi a
        where a.thankYouFee > 0
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(a.travelTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
 
        union all
 
        select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, 3 as type, driverId, ifnull(thankYouFee, 0) as thankYouFee
        from t_order_cross_city a
        where a.thankYouFee > 0
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(a.travelTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
 
        union all
 
        select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, type as type, driverId, ifnull(thankYouFee, 0) as thankYouFee
        from t_order_logistics a
        where a.thankYouFee > 0
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(a.travelTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
 
        union all
 
        select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, 7 as type, driverId, ifnull(thankYouFee, 0) as thankYouFee
        from t_order_call a
        where a.thankYouFee > 0
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(a.travelTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
        ) as da
        left join t_driver b on (da.driverId = b.id)
        where 1 = 1
        <if test="null != driverName and '' != driverName">
            and b.name like CONCAT('%', #{driverName}, '%')
        </if>
        <if test="null != driverPhone and '' != driverPhone">
            and b.phone like CONCAT('%', #{driverPhone}, '%')
        </if>
    </select>
 
 
    <select id="otherSpendingDetailListSum" resultType="map">
        select '合计' as travelTime, ifnull(sum(thankYouFee), 0) as thankYouFee from (
        select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, 1 as type, driverId, ifnull(thankYouFee, 0) as thankYouFee
        from t_order_private_car a
        where a.thankYouFee > 0
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(a.travelTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
 
        union all
 
        select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, 2 as type, driverId, ifnull(thankYouFee, 0) as thankYouFee
        from t_order_taxi a
        where a.thankYouFee > 0
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(a.travelTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
 
        union all
 
        select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, 3 as type, driverId, ifnull(thankYouFee, 0) as thankYouFee
        from t_order_cross_city a
        where a.thankYouFee > 0
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(a.travelTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
 
        union all
 
        select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, type as type, driverId, ifnull(thankYouFee, 0) as thankYouFee
        from t_order_logistics a
        where a.thankYouFee > 0
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(a.travelTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
 
        union all
 
        select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, 7 as type, driverId, ifnull(thankYouFee, 0) as thankYouFee
        from t_order_call a
        where a.thankYouFee > 0
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(a.travelTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
        ) as da
        left join t_driver b on (da.driverId = b.id)
        where 1 = 1
        <if test="null != driverName and '' != driverName">
            and b.name like CONCAT('%', #{driverName}, '%')
        </if>
        <if test="null != driverPhone and '' != driverPhone">
            and b.phone like CONCAT('%', #{driverPhone}, '%')
        </if>
    </select>
 
 
    <select id="getAllBalance" resultType="double">
        <if test="1 == type"><!--活动余额-->
            select sum(laveActivityMoney) from t_driver where authState = 2 and flag != 3
            <if test="null != driverName and '' != driverName">
                and name like CONCAT('%', #{driverName}, '%')
            </if>
            <if test="null != driverPhone and '' != driverPhone">
                and phone like CONCAT('%', #{driverPhone}, '%')
            </if>
        </if>
        <if test="2 == type"><!--业务余额-->
            select sum(laveBusinessMoney) from t_driver where authState = 2 and flag != 3
            <if test="null != driverName and '' != driverName">
                and name like CONCAT('%', #{driverName}, '%')
            </if>
            <if test="null != driverPhone and '' != driverPhone">
                and phone like CONCAT('%', #{driverPhone}, '%')
            </if>
        </if>
    </select>
</mapper>