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
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
<?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.IncomeMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.system.model.Income">
        <id column="id" property="id"/>
        <result column="userType" property="userType"/>
        <result column="objectId" property="objectId"/>
        <result column="type" property="type"/>
        <result column="incomeId" property="incomeId"/>
        <result column="orderType" property="orderType"/>
        <result column="money" property="money"/>
        <result column="insertTime" property="insertTime"/>
    </resultMap>
 
 
    <select id="summaryOfIncomeDetailsList" resultType="map">
        select * from (
        select
        DATE_FORMAT(insertTime, '%Y/%m/%d') as  insertTime
        from t_income where userType = 1 and money > 0
        <if test="null != companyId">
            and objectId = #{companyId}
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
        group by DATE_FORMAT(insertTime, '%Y/%m/%d')
        ) as aa order by aa.insertTime desc
        <if test="null != offset and null != limit">
            limit #{offset}, #{limit}
        </if>
    </select>
 
 
    <select id="summaryOfIncomeDetailsListCount" resultType="int">
        select count(1) from (
        select
        DATE_FORMAT(insertTime, '%Y/%m/%d') as  insertTime
        from t_income where userType = 1 and money > 0
        <if test="null != companyId">
            and objectId = #{companyId}
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
        group by DATE_FORMAT(insertTime, '%Y/%m/%d')
        ) as aa
    </select>
 
 
    <select id="summaryOfIncomeDetailsListSum" resultType="map">
        select
        '合计' as insertTime,
        ifnull(ROUND(sum(aa.orderPayMoney), 2), 0) as orderPayMoney,
        ifnull(ROUND(sum(aa.orderRevenue), 2), 0) as orderRevenue,
        ifnull(ROUND(sum(aa.taxiCardRevenue), 2), 0) as taxiCardRevenue,
        ifnull(ROUND(sum(aa.overtimeDeduction), 2), 0) as overtimeDeduction,
        ifnull(ROUND(sum(aa.complaintDeductionProceeds), 2), 0) as complaintDeductionProceeds,
        ifnull(ROUND(sum(aa.other), 2), 0) as other
        from (
        select a.money as orderRevenue, 0 as taxiCardRevenue, 0 as overtimeDeduction, 0 as complaintDeductionProceeds, 0 as other,
        if(a.orderType = 1, u1.nickName, if(a.orderType = 2, u2.nickName, if(a.orderType = 3, u3.nickName, if(a.orderType = 4, u4.nickName, if(a.orderType = 5, u5.nickName, if(a.orderType = 6, u6.nickName, if(a.orderType = 2, u7.nickName, ''))))))) as nickName,
        if(a.orderType = 1, u1.phone, if(a.orderType = 2, u2.phone, if(a.orderType = 3, u3.phone, if(a.orderType = 4, u4.phone, if(a.orderType = 5, u5.phone, if(a.orderType = 6, u6.phone, if(a.orderType = 2, u7.phone, ''))))))) as phone
        from t_income a
        left join t_order_private_car b on (a.orderType = 1 and a.incomeId = b.id)
        left join t_order_taxi c on (a.orderType = 2 and a.incomeId = c.id)
        left join t_order_cross_city d on (a.orderType = 3 and a.incomeId = d.id)
        left join t_order_logistics e on (a.orderType = 4 and a.incomeId = e.id)
        left join t_order_logistics f on (a.orderType = 5 and a.incomeId = f.id)
        left join t_order_chartered_car g on (a.orderType = 6 and a.incomeId = g.id)
        left join t_order_call h on (a.orderType = 7 and a.incomeId = h.id)
        left join t_user u1 on (b.userId = u1.id)
        left join t_user u2 on (c.userId = u2.id)
        left join t_user u3 on (d.userId = u3.id)
        left join t_user u4 on (e.userId = u4.id)
        left join t_user u5 on (f.userId = u5.id)
        left join t_user u6 on (g.userId = u6.id)
        left join t_user u7 on (h.userId = u7.id)
        where a.userType = 1 and a.money != 0 and a.type = 2
        <if test="null != companyId">
            and a.objectId = #{companyId}
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
 
        <if test="null != orderType">
            and a.orderType = #{orderType}
        </if>
        <if test="null != incomeType">
            and a.type = #{incomeType}
        </if>
 
        union all
 
        select 0 as orderRevenue, a.money as taxiCardRevenue, 0 as overtimeDeduction, 0 as complaintDeductionProceeds, 0 as other,
        if(a.orderType = 1, u1.nickName, if(a.orderType = 2, u2.nickName, if(a.orderType = 3, u3.nickName, if(a.orderType = 4, u4.nickName, if(a.orderType = 5, u5.nickName, if(a.orderType = 6, u6.nickName, if(a.orderType = 2, u7.nickName, ''))))))) as nickName,
        if(a.orderType = 1, u1.phone, if(a.orderType = 2, u2.phone, if(a.orderType = 3, u3.phone, if(a.orderType = 4, u4.phone, if(a.orderType = 5, u5.phone, if(a.orderType = 6, u6.phone, if(a.orderType = 2, u7.phone, ''))))))) as phone
        from t_income a
        left join t_order_private_car b on (a.orderType = 1 and a.incomeId = b.id)
        left join t_order_taxi c on (a.orderType = 2 and a.incomeId = c.id)
        left join t_order_cross_city d on (a.orderType = 3 and a.incomeId = d.id)
        left join t_order_logistics e on (a.orderType = 4 and a.incomeId = e.id)
        left join t_order_logistics f on (a.orderType = 5 and a.incomeId = f.id)
        left join t_order_chartered_car g on (a.orderType = 6 and a.incomeId = g.id)
        left join t_order_call h on (a.orderType = 7 and a.incomeId = h.id)
        left join t_user u1 on (b.userId = u1.id)
        left join t_user u2 on (c.userId = u2.id)
        left join t_user u3 on (d.userId = u3.id)
        left join t_user u4 on (e.userId = u4.id)
        left join t_user u5 on (f.userId = u5.id)
        left join t_user u6 on (g.userId = u6.id)
        left join t_user u7 on (h.userId = u7.id)
        where a.userType = 1 and a.money != 0 and a.type = 5
        <if test="null != companyId">
            and a.objectId = #{companyId}
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
        <if test="null != orderType">
            and a.orderType = #{orderType}
        </if>
        <if test="null != incomeType">
            and a.type = #{incomeType}
        </if>
 
        union all
 
        select 0 as orderRevenue, 0 as taxiCardRevenue, a.money as overtimeDeduction, 0 as complaintDeductionProceeds, 0 as other,
        if(a.orderType = 1, u1.nickName, if(a.orderType = 2, u2.nickName, if(a.orderType = 3, u3.nickName, if(a.orderType = 4, u4.nickName, if(a.orderType = 5, u5.nickName, if(a.orderType = 6, u6.nickName, if(a.orderType = 2, u7.nickName, ''))))))) as nickName,
        if(a.orderType = 1, u1.phone, if(a.orderType = 2, u2.phone, if(a.orderType = 3, u3.phone, if(a.orderType = 4, u4.phone, if(a.orderType = 5, u5.phone, if(a.orderType = 6, u6.phone, if(a.orderType = 2, u7.phone, ''))))))) as phone
        from t_income a
        left join t_order_private_car b on (a.orderType = 1 and a.incomeId = b.id)
        left join t_order_taxi c on (a.orderType = 2 and a.incomeId = c.id)
        left join t_order_cross_city d on (a.orderType = 3 and a.incomeId = d.id)
        left join t_order_logistics e on (a.orderType = 4 and a.incomeId = e.id)
        left join t_order_logistics f on (a.orderType = 5 and a.incomeId = f.id)
        left join t_order_chartered_car g on (a.orderType = 6 and a.incomeId = g.id)
        left join t_order_call h on (a.orderType = 7 and a.incomeId = h.id)
        left join t_user u1 on (b.userId = u1.id)
        left join t_user u2 on (c.userId = u2.id)
        left join t_user u3 on (d.userId = u3.id)
        left join t_user u4 on (e.userId = u4.id)
        left join t_user u5 on (f.userId = u5.id)
        left join t_user u6 on (g.userId = u6.id)
        left join t_user u7 on (h.userId = u7.id)
        where a.userType = 1 and a.money != 0 and a.type in (7, 9)
        <if test="null != companyId">
            and a.objectId = #{companyId}
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
        <if test="null != orderType">
            and a.orderType = #{orderType}
        </if>
        <if test="null != incomeType">
            and a.type = #{incomeType}
        </if>
 
        union all
 
        select 0 as orderRevenue, 0 as taxiCardRevenue, 0 as overtimeDeduction, a.money as complaintDeductionProceeds, 0 as other,
        if(a.orderType = 1, u1.nickName, if(a.orderType = 2, u2.nickName, if(a.orderType = 3, u3.nickName, if(a.orderType = 4, u4.nickName, if(a.orderType = 5, u5.nickName, if(a.orderType = 6, u6.nickName, if(a.orderType = 2, u7.nickName, ''))))))) as nickName,
        if(a.orderType = 1, u1.phone, if(a.orderType = 2, u2.phone, if(a.orderType = 3, u3.phone, if(a.orderType = 4, u4.phone, if(a.orderType = 5, u5.phone, if(a.orderType = 6, u6.phone, if(a.orderType = 2, u7.phone, ''))))))) as phone
        from t_income a
        left join t_order_private_car b on (a.orderType = 1 and a.incomeId = b.id)
        left join t_order_taxi c on (a.orderType = 2 and a.incomeId = c.id)
        left join t_order_cross_city d on (a.orderType = 3 and a.incomeId = d.id)
        left join t_order_logistics e on (a.orderType = 4 and a.incomeId = e.id)
        left join t_order_logistics f on (a.orderType = 5 and a.incomeId = f.id)
        left join t_order_chartered_car g on (a.orderType = 6 and a.incomeId = g.id)
        left join t_order_call h on (a.orderType = 7 and a.incomeId = h.id)
        left join t_user u1 on (b.userId = u1.id)
        left join t_user u2 on (c.userId = u2.id)
        left join t_user u3 on (d.userId = u3.id)
        left join t_user u4 on (e.userId = u4.id)
        left join t_user u5 on (f.userId = u5.id)
        left join t_user u6 on (g.userId = u6.id)
        left join t_user u7 on (h.userId = u7.id)
        where a.userType = 1 and a.money != 0 and a.type = 8
        <if test="null != companyId">
            and a.objectId = #{companyId}
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
        <if test="null != orderType">
            and a.orderType = #{orderType}
        </if>
        <if test="null != incomeType">
            and a.type = #{incomeType}
        </if>
 
        union all
 
        select 0 as orderRevenue, 0 as taxiCardRevenue, 0 as overtimeDeduction, 0 as complaintDeductionProceeds, a.money as other,
        if(a.orderType = 1, u1.nickName, if(a.orderType = 2, u2.nickName, if(a.orderType = 3, u3.nickName, if(a.orderType = 4, u4.nickName, if(a.orderType = 5, u5.nickName, if(a.orderType = 6, u6.nickName, if(a.orderType = 2, u7.nickName, ''))))))) as nickName,
        if(a.orderType = 1, u1.phone, if(a.orderType = 2, u2.phone, if(a.orderType = 3, u3.phone, if(a.orderType = 4, u4.phone, if(a.orderType = 5, u5.phone, if(a.orderType = 6, u6.phone, if(a.orderType = 2, u7.phone, ''))))))) as phone
        from t_income a
        left join t_order_private_car b on (a.orderType = 1 and a.incomeId = b.id)
        left join t_order_taxi c on (a.orderType = 2 and a.incomeId = c.id)
        left join t_order_cross_city d on (a.orderType = 3 and a.incomeId = d.id)
        left join t_order_logistics e on (a.orderType = 4 and a.incomeId = e.id)
        left join t_order_logistics f on (a.orderType = 5 and a.incomeId = f.id)
        left join t_order_chartered_car g on (a.orderType = 6 and a.incomeId = g.id)
        left join t_order_call h on (a.orderType = 7 and a.incomeId = h.id)
        left join t_user u1 on (b.userId = u1.id)
        left join t_user u2 on (c.userId = u2.id)
        left join t_user u3 on (d.userId = u3.id)
        left join t_user u4 on (e.userId = u4.id)
        left join t_user u5 on (f.userId = u5.id)
        left join t_user u6 on (g.userId = u6.id)
        left join t_user u7 on (h.userId = u7.id)
        where a.userType = 1 and a.money != 0 and a.type in (1, 3, 4, 6)
        <if test="null != companyId">
            and a.objectId = #{companyId}
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
        <if test="null != orderType">
            and a.orderType = #{orderType}
        </if>
        <if test="null != incomeType">
            and a.type = #{incomeType}
        </if>
 
        ) as aa where 1 = 1
        <if test="null != name and '' != name">
            and aa.nickName like CONCAT('%', #{name}, '%')
        </if>
        <if test="null != phone and '' != phone">
            and aa.phone like CONCAT('%', #{phone}, '%')
        </if>
    </select>
 
 
 
    <select id="summaryOfIncomeDetailsListGroupSum" resultType="map">
        select * from (
        select
        aa.userType,
        aa.objectId,
        aa.type,
        aa.orderType,
        aa.insertTime,
        ifnull(sum(aa.payMoney), 0) as payMoney,
        aa.nickName,
        aa.phone,
        ifnull(sum(aa.overtimeDeduction), 0) as overtimeDeduction,
        ifnull(sum(aa.money), 0) as money,
        ifnull(sum(aa.complaint), 0) as complaint
        from (
            select
            a.userType,
            a.objectId,
            a.type,
            a.orderType,
            DATE_FORMAT(a.insertTime, '%Y/%m/%d') as insertTime,
            if(a.orderType = 1, b.payMoney, if(a.orderType = 2, c.payMoney, if(a.orderType = 3, d.payMoney, if(a.orderType = 4, e.payMoney, if(a.orderType = 5, f.payMoney, if(a.orderType = 6, 0, if(a.orderType = 7, h.payMoney, 0))))))) as payMoney,
            if(a.orderType = 1, u1.nickName, if(a.orderType = 2, u2.nickName, if(a.orderType = 3, u3.nickName, if(a.orderType = 4, u4.nickName, if(a.orderType = 5, u5.nickName, if(a.orderType = 6, u6.nickName, if(a.orderType = 2, u7.nickName, ''))))))) as nickName,
            if(a.orderType = 1, u1.phone, if(a.orderType = 2, u2.phone, if(a.orderType = 3, u3.phone, if(a.orderType = 4, u4.phone, if(a.orderType = 5, u5.phone, if(a.orderType = 6, u6.phone, if(a.orderType = 2, u7.phone, ''))))))) as phone,
            0 as overtimeDeduction,
            if(a.orderType = 1 and a.incomeId = b.id, a.money, if(a.orderType = 2 and a.incomeId = c.id, a.money, if(a.orderType = 3 and a.incomeId = d.id, a.money, if(a.orderType = 4 and a.incomeId = e.id, a.money, if(a.orderType = 5 and a.incomeId = f.id, a.money, if(a.orderType = 6 and a.incomeId = g.id, a.money, if(a.orderType = 7 and a.incomeId = h.id, a.money, 0))))))) as money,
            0 as complaint
            from t_income a
            left join t_order_private_car b on (a.orderType = 1 and a.incomeId = b.id)
            left join t_order_taxi c on (a.orderType = 2 and a.incomeId = c.id)
            left join t_order_cross_city d on (a.orderType = 3 and a.incomeId = d.id)
            left join t_order_logistics e on (a.orderType = 4 and a.incomeId = e.id)
            left join t_order_logistics f on (a.orderType = 5 and a.incomeId = f.id)
            left join t_order_chartered_car g on (a.orderType = 6 and a.incomeId = g.id)
            left join t_order_call h on (a.orderType = 7 and a.incomeId = h.id)
            left join t_user u1 on (b.userId = u1.id)
            left join t_user u2 on (c.userId = u2.id)
            left join t_user u3 on (d.userId = u3.id)
            left join t_user u4 on (e.userId = u4.id)
            left join t_user u5 on (f.userId = u5.id)
            left join t_user u6 on (g.userId = u6.id)
            left join t_user u7 on (h.userId = u7.id)
            where a.type = 2
 
            union all
 
            select
            a.userType,
            a.objectId,
            a.type,
            a.orderType,
            DATE_FORMAT(a.insertTime, '%Y/%m/%d') as insertTime,
            0 as payMoney,
            if(a.orderType = 1, u1.nickName, if(a.orderType = 2, u2.nickName, if(a.orderType = 3, u3.nickName, if(a.orderType = 4, u4.nickName, if(a.orderType = 5, u5.nickName, if(a.orderType = 6, u6.nickName, if(a.orderType = 2, u7.nickName, ''))))))) as nickName,
            if(a.orderType = 1, u1.phone, if(a.orderType = 2, u2.phone, if(a.orderType = 3, u3.phone, if(a.orderType = 4, u4.phone, if(a.orderType = 5, u5.phone, if(a.orderType = 6, u6.phone, if(a.orderType = 2, u7.phone, ''))))))) as phone,
            if(a.orderType = 1 and a.incomeId = b.id, a.money, if(a.orderType = 2 and a.incomeId = c.id, a.money, if(a.orderType = 3 and a.incomeId = d.id, a.money, if(a.orderType = 4 and a.incomeId = e.id, a.money, if(a.orderType = 5 and a.incomeId = f.id, a.money, if(a.orderType = 6 and a.incomeId = g.id, a.money, if(a.orderType = 7 and a.incomeId = h.id, a.money, 0))))))) as overtimeDeduction,
            0 as money,
            0 as complaint
            from t_income a
            left join t_order_private_car b on (a.orderType = 1 and a.incomeId = b.id)
            left join t_order_taxi c on (a.orderType = 2 and a.incomeId = c.id)
            left join t_order_cross_city d on (a.orderType = 3 and a.incomeId = d.id)
            left join t_order_logistics e on (a.orderType = 4 and a.incomeId = e.id)
            left join t_order_logistics f on (a.orderType = 5 and a.incomeId = f.id)
            left join t_order_chartered_car g on (a.orderType = 6 and a.incomeId = g.id)
            left join t_order_call h on (a.orderType = 7 and a.incomeId = h.id)
            left join t_user u1 on (b.userId = u1.id)
            left join t_user u2 on (c.userId = u2.id)
            left join t_user u3 on (d.userId = u3.id)
            left join t_user u4 on (e.userId = u4.id)
            left join t_user u5 on (f.userId = u5.id)
            left join t_user u6 on (g.userId = u6.id)
            left join t_user u7 on (h.userId = u7.id)
            where a.type = 7
 
            union all
 
            select
            a.userType,
            a.objectId,
            a.type,
            a.orderType,
            DATE_FORMAT(a.insertTime, '%Y/%m/%d') as insertTime,
            0 as payMoney,
            '' as nickName,
            '' as phone,
            0 as overtimeDeduction,
            0 as money,
            a.money as complaint
            from t_income a
            where a.type = 8
            ) as aa group by aa.userType, aa.objectId, aa.type, aa.orderType, aa.insertTime, aa.nickName, aa.phone
        ) as datas where 1 = 1
        <if test="null != userType">
            and datas.userType = #{userType}
        </if>
        <if test="null != objectId">
            and datas.objectId = #{objectId}
        </if>
        <if test="null != insertTime">
            and datas.insertTime = #{insertTime}
        </if>
        order by datas.insertTime desc,datas.phone
    </select>
 
 
 
    <select id="summaryOfIncomeDetailsListGroupSum1" resultType="map">
        select * from (
        select
        aa.userType,
        aa.objectId,
        aa.type,
        aa.orderType,
        aa.insertTime,
        ifnull(sum(aa.orderMoney), 0) as orderMoney,
        ifnull(sum(aa.payMoney), 0) as payMoney,
        aa.nickName,
        aa.phone,
        ifnull(sum(aa.overtimeDeduction), 0) as overtimeDeduction,
        ifnull(sum(aa.money), 0) as money,
        ifnull(sum(aa.complaint), 0) as complaint,
        ifnull(sum(aa.taxiCardRevenue), 0) as taxiCardRevenue,
        ifnull(sum(aa.other), 0) as other
        from (
        select
        b.userType,
        b.objectId,
        b.type,
        b.orderType,
        DATE_FORMAT(a.insertTime, '%Y/%m/%d') as insertTime,
        a.orderMoney as orderMoney,
        a.payMoney as payMoney,
        u1.nickName as nickName,
        u1.phone as phone,
        0 as overtimeDeduction,
        c.money as money,
        0 as complaint,
        0 as taxiCardRevenue,
        0 as other
        from (
        select id, 1 as orderType, payMoney, userId, orderMoney,insertTime from t_order_private_car where state in (8, 9)
        union all
        select id, 2 as orderType, payMoney, userId, orderMoney,insertTime from t_order_taxi where state in (8, 9)
        union all
        select id, 3 as orderType, payMoney, userId, orderMoney,insertTime from t_order_cross_city where state in (8, 9)
        union all
        select id, type as orderType, payMoney, userId, orderMoney,insertTime from t_order_logistics where state in (6, 9)
        ) as a
        left join t_income b on (a.orderType = b.orderType and a.id = b.incomeId and b.type = 2 and b.userType = 1)
        left join t_income c on (c.type = b.type and c.incomeId = b.incomeId and b.orderType = c.orderType and c.userType = 2)
        left join t_user u1 on (a.userId = u1.id)
        where 1=1
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
        group by a.id, a.orderType
 
        union all
 
        select
        a.userType,
        a.objectId,
        a.type,
        a.orderType,
        DATE_FORMAT(a.insertTime, '%Y/%m/%d') as insertTime,
        0 as orderMoney,
        0 as payMoney,
        if(a.orderType = 1, u1.nickName, if(a.orderType = 2, u2.nickName, if(a.orderType = 3, u3.nickName, if(a.orderType = 4, u4.nickName, if(a.orderType = 5, u5.nickName, if(a.orderType = 6, u6.nickName, if(a.orderType = 2, u7.nickName, ''))))))) as nickName,
        if(a.orderType = 1, u1.phone, if(a.orderType = 2, u2.phone, if(a.orderType = 3, u3.phone, if(a.orderType = 4, u4.phone, if(a.orderType = 5, u5.phone, if(a.orderType = 6, u6.phone, if(a.orderType = 2, u7.phone, ''))))))) as phone,
        if(a.orderType = 1 and a.incomeId = b.id, a.money, if(a.orderType = 2 and a.incomeId = c.id, a.money, if(a.orderType = 3 and a.incomeId = d.id, a.money, if(a.orderType = 4 and a.incomeId = e.id, a.money, if(a.orderType = 5 and a.incomeId = f.id, a.money, if(a.orderType = 6 and a.incomeId = g.id, a.money, if(a.orderType = 7 and a.incomeId = h.id, a.money, 0))))))) as overtimeDeduction,
        0 as money,
        0 as complaint,
        0 as taxiCardRevenue,
        0 as other
        from t_income a
        left join t_order_private_car b on (a.orderType = 1 and a.incomeId = b.id)
        left join t_order_taxi c on (a.orderType = 2 and a.incomeId = c.id)
        left join t_order_cross_city d on (a.orderType = 3 and a.incomeId = d.id)
        left join t_order_logistics e on (a.orderType = 4 and a.incomeId = e.id)
        left join t_order_logistics f on (a.orderType = 5 and a.incomeId = f.id)
        left join t_order_chartered_car g on (a.orderType = 6 and a.incomeId = g.id)
        left join t_order_call h on (a.orderType = 7 and a.incomeId = h.id)
        left join t_user u1 on (b.userId = u1.id)
        left join t_user u2 on (c.userId = u2.id)
        left join t_user u3 on (d.userId = u3.id)
        left join t_user u4 on (e.userId = u4.id)
        left join t_user u5 on (f.userId = u5.id)
        left join t_user u6 on (g.userId = u6.id)
        left join t_user u7 on (h.userId = u7.id)
        where a.type = 7 and a.money != 0
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
 
        union all
 
        select
        a.userType,
        a.objectId,
        a.type,
        a.orderType,
        DATE_FORMAT(a.insertTime, '%Y/%m/%d') as insertTime,
        0 as orderMoney,
        0 as payMoney,
        '' as nickName,
        '' as phone,
        0 as overtimeDeduction,
        0 as money,
        a.money as complaint,
        0 as taxiCardRevenue,
        0 as other
        from t_income a
        where a.type = 8 and a.money != 0
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
 
        union all
 
        select
        a.userType,
        a.objectId,
        a.type,
        a.orderType,
        DATE_FORMAT(a.insertTime, '%Y/%m/%d') as insertTime,
        0 as orderMoney,
        0 as payMoney,
        '' as nickName,
        '' as phone,
        0 as overtimeDeduction,
        0 as money,
        0 as complaint,
        a.money as taxiCardRevenue,
        0 as other
        from t_income a
        where a.type = 5 and a.money != 0
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
 
        union all
 
        select
        a.userType,
        a.objectId,
        a.type,
        a.orderType,
        DATE_FORMAT(a.insertTime, '%Y/%m/%d') as insertTime,
        0 as orderMoney,
        0 as payMoney,
        if(a.orderType = 1, u1.nickName, if(a.orderType = 2, u2.nickName, if(a.orderType = 3, u3.nickName, if(a.orderType = 4, u4.nickName, if(a.orderType = 5, u5.nickName, if(a.orderType = 6, u6.nickName, if(a.orderType = 2, u7.nickName, ''))))))) as nickName,
        if(a.orderType = 1, u1.phone, if(a.orderType = 2, u2.phone, if(a.orderType = 3, u3.phone, if(a.orderType = 4, u4.phone, if(a.orderType = 5, u5.phone, if(a.orderType = 6, u6.phone, if(a.orderType = 2, u7.phone, ''))))))) as phone,
        0 as overtimeDeduction,
        0 as money,
        0 as complaint,
        0 as taxiCardRevenue,
        a.money as other
        from t_income a
        left join t_order_private_car b on (a.orderType = 1 and a.incomeId = b.id)
        left join t_order_taxi c on (a.orderType = 2 and a.incomeId = c.id)
        left join t_order_cross_city d on (a.orderType = 3 and a.incomeId = d.id)
        left join t_order_logistics e on (a.orderType = 4 and a.incomeId = e.id)
        left join t_order_logistics f on (a.orderType = 5 and a.incomeId = f.id)
        left join t_order_chartered_car g on (a.orderType = 6 and a.incomeId = g.id)
        left join t_order_call h on (a.orderType = 7 and a.incomeId = h.id)
        left join t_user u1 on (b.userId = u1.id)
        left join t_user u2 on (c.userId = u2.id)
        left join t_user u3 on (d.userId = u3.id)
        left join t_user u4 on (e.userId = u4.id)
        left join t_user u5 on (f.userId = u5.id)
        left join t_user u6 on (g.userId = u6.id)
        left join t_user u7 on (h.userId = u7.id)
        where a.type in (3, 4) and a.money != 0
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
 
        union all
 
        select
        a.userType,
        a.objectId,
        a.type,
        a.orderType,
        DATE_FORMAT(a.insertTime, '%Y/%m/%d') as insertTime,
        0 as orderMoney,
        0 as payMoney,
        '' as nickName,
        '' as phone,
        0 as overtimeDeduction,
        0 as money,
        0 as complaint,
        0 as taxiCardRevenue,
        a.money as other
        from t_income a
        where a.type in (1, 6, 9) and a.money != 0
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
 
        ) as aa group by aa.userType, aa.objectId, aa.type, aa.orderType, aa.insertTime, aa.nickName, aa.phone
        ) as datas where 1 = 1
        <if test="null != userType">
            and datas.userType = #{userType}
        </if>
        <if test="null != objectId">
            and datas.objectId = #{objectId}
        </if>
        <if test="null != orderType">
            and datas.orderType = #{orderType}
        </if>
        <if test="null != incomeType">
            and datas.type = #{incomeType}
        </if>
        <if test="null != name and '' != name">
            and datas.nickName like CONCAT('%', #{name}, '%')
        </if>
        <if test="null != phone and '' != phone">
            and datas.phone like CONCAT('%', #{phone}, '%')
        </if>
        order by datas.insertTime desc,datas.phone
        <if test="null != offset and null != limit">
            limit #{offset}, #{limit}
        </if>
    </select>
 
 
 
 
    <select id="getSumData" resultType="double">
        select
        ifnull(sum(aa.money), 0) as money
        from (
        select money,userType,objectId,DATE_FORMAT(insertTime, '%Y/%m/%d') as insertTime
        from t_income where 1 = 1
        <if test="null != userType">
            and userType = #{userType}
        </if>
        <if test="null != objectId">
            and objectId = #{objectId}
        </if>
        <if test="null != insertTime">
            and DATE_FORMAT(insertTime, '%Y/%m/%d') = #{insertTime}
        </if>
        <if test="null != types">
            and type in
            <foreach collection="types" item="item" index="index" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        ) as aa group by aa.userType,aa.objectId,aa.insertTime
    </select>
 
 
    <select id="summaryOfSpendingDetailsList" resultType="map">
        select * from (
        select
        DATE_FORMAT(insertTime, '%Y/%m/%d') as  insertTime
        from t_income where userType = 2 and money > 0
        <if test="null != companyId">
            and objectId in (select id from t_driver where authState = 2 and flag != 3 and companyId = #{companyId})
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
        group by DATE_FORMAT(insertTime, '%Y/%m/%d')
        ) as aa order by aa.insertTime desc
        <if test="null != offset and null != limit">
            limit #{offset}, #{limit}
        </if>
    </select>
 
 
    <select id="summaryOfSpendingDetailsListCount" resultType="int">
        select count(1) from (
        select
        DATE_FORMAT(insertTime, '%Y/%m/%d') as  insertTime
        from t_income where userType = 1 and money > 0
        <if test="null != companyId">
            and objectId in (select id from t_driver where authState = 2 and flag != 3 and companyId = #{companyId})
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
        group by DATE_FORMAT(insertTime, '%Y/%m/%d')
        ) as aa
    </select>
 
    <select id="summaryOfSpendingDetailsListSum" resultType="map">
        select
        ifnull(ROUND(sum(aa.orderRevenue), 2), 0) as orderRevenue,
        ifnull(ROUND(sum(aa.activityAward), 2), 0) as activityAward,
        ifnull(ROUND(sum(aa.other), 2), 0) as other,
        ROUND(ifnull(sum(aa.orderRevenue), 0) + ifnull(sum(aa.activityAward), 0) + ifnull(sum(aa.other), 0), 2) as `all`
        from (
        select objectId, money as orderRevenue, 0 as activityAward, 0 as other from t_income where userType = 2 and money > 0 and type = 2
        <if test="null != companyId">
            and objectId in (select id from t_driver where authState = 2 and flag != 3 and companyId = #{companyId})
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
        <if test="null != orderType">
            and orderType = #{orderType}
        </if>
        <if test="null != incomeType">
            and type = #{incomeType}
        </if>
 
        union all
 
        select objectId, 0 as orderRevenue, money as activityAward, 0 as other from t_income where userType = 2 and money > 0 and type = 1
        <if test="null != companyId">
            and objectId in (select id from t_driver where authState = 2 and flag != 3 and companyId = #{companyId})
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
        <if test="null != orderType">
            and orderType = #{orderType}
        </if>
        <if test="null != incomeType">
            and type = #{incomeType}
        </if>
 
        union all
 
        select objectId, 0 as orderRevenue, 0 as activityAward, money as other from t_income where userType = 2 and money > 0 and type in (6, 9)
        <if test="null != companyId">
            and objectId in (select id from t_driver where authState = 2 and flag != 3 and companyId = #{companyId})
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
        <if test="null != orderType">
            and orderType = #{orderType}
        </if>
        <if test="null != incomeType">
            and type = #{incomeType}
        </if>
 
        ) as aa
        left join t_driver bb on (aa.objectId = bb.id)
        where 1 = 1
        <if test="null != name and '' != name">
            and bb.name like CONCAT('%', #{name}, '%')
        </if>
        <if test="null != phone and '' != phone">
            and bb.phone like CONCAT('%', #{phone}, '%')
        </if>
    </select>
 
 
    <select id="summaryOfSpendingDetailsList1" resultType="map">
        select * from (
        select
        aa.insertTime,
        aa.orderType,
        aa.type,
        aa.incomeType,
        bb.`name`,
        bb.phone,
        aa.objectId,
        ROUND(sum(aa.orderRevenue), 2) as orderRevenue,
        ROUND(sum(aa.activityAward), 2) as activityAward,
        ROUND(sum(aa.other), 2) as other,
        ROUND((sum(aa.orderRevenue) + sum(aa.activityAward) + sum(aa.other)), 2) as `all`
        from (
        select
        DATE_FORMAT(insertTime, '%Y/%m/%d') as insertTime,
        orderType,
        '跑单收入' as type,
        type as incomeType,
        objectId,
        money as orderRevenue,
        0 as activityAward,
        0 as other
        from t_income where userType = 2 and type = 2
        <if test="null != companyId">
            and objectId in (select id from t_driver where authState = 2 and flag != 3 and companyId = #{companyId})
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
        group by  DATE_FORMAT(insertTime, '%Y/%m/%d'), orderType,incomeId, objectId
 
        union all
 
        select
        DATE_FORMAT(insertTime, '%Y/%m/%d') as insertTime,
        orderType,
        '活动收入' as type,
        type as incomeType,
        objectId,
        0 as orderRevenue,
        sum(money) as activityAward,
        0 as other
        from t_income where userType = 2 and type = 1
        <if test="null != companyId">
            and objectId in (select id from t_driver where authState = 2 and flag != 3 and companyId = #{companyId})
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
        group by  DATE_FORMAT(insertTime, '%Y/%m/%d'), orderType, objectId
 
        union all
 
        select
        DATE_FORMAT(insertTime, '%Y/%m/%d') as insertTime,
        orderType,
        '感谢费' as type,
        type as incomeType,
        objectId,
        0 as orderRevenue,
        0 as activityAward,
        sum(money) as other
        from t_income where userType = 2 and type = 6
        <if test="null != companyId">
            and objectId in (select id from t_driver where authState = 2 and flag != 3 and companyId = #{companyId})
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
        group by  DATE_FORMAT(insertTime, '%Y/%m/%d'), orderType, objectId
 
        union all
 
        select
        DATE_FORMAT(insertTime, '%Y/%m/%d') as insertTime,
        orderType,
        '小件物流超时退款' as type,
        type as incomeType,
        objectId,
        0 as orderRevenue,
        0 as activityAward,
        sum(money) as other
        from t_income where userType = 2 and type = 9
        <if test="null != companyId">
            and objectId in (select id from t_driver where authState = 2 and flag != 3 and companyId = #{companyId})
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
        group by  DATE_FORMAT(insertTime, '%Y/%m/%d'), orderType, objectId
        ) as aa
        left join t_driver bb on (aa.objectId = bb.id)
        group by aa.insertTime, aa.orderType, aa.type, aa.objectId
        ) as bb where 1 = 1
        <if test="null != orderType">
            and bb.orderType = #{orderType}
        </if>
        <if test="null != incomeType">
            and bb.incomeType = #{incomeType}
        </if>
        <if test="null != name and '' != name">
            and bb.name like CONCAT('%', #{name}, '%')
        </if>
        <if test="null != phone and '' != phone">
            and bb.phone like CONCAT('%', #{phone}, '%')
        </if>
        order by bb.insertTime desc
        <if test="null != offset and null != limit">
            limit #{offset}, #{limit}
        </if>
    </select>
</mapper>