Helius
2021-06-16 4e51778362c2130598a4c73ec4cebe6629dbc53f
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
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
<?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.xzx.gc.order.mapper.OrderMapper">
 
    <resultMap id="OrderMap" type="com.xzx.gc.model.order.OrderInfoVo">
        <result column="address_id" jdbcType="INTEGER" property="addressId"/>
        <result column="order_id" jdbcType="VARCHAR" property="orderId"/>
        <result column="order_status" jdbcType="VARCHAR" property="orderStatus"/>
        <result column="order_second_status" jdbcType="VARCHAR" property="orderSecondStatus"/>
        <result column="order_type" jdbcType="VARCHAR" property="orderType"/>
        <result column="reserve_time" jdbcType="VARCHAR" property="reserveTime"/>
        <result column="create_user_id" jdbcType="VARCHAR" property="createUserId"/>
        <result column="cancel_user_id" jdbcType="VARCHAR" property="cancelUserId"/>
        <result column="create_time" jdbcType="VARCHAR" property="createTime"/>
        <result column="create_user_name" jdbcType="VARCHAR" property="createUserName"/>
        <result column="receive_time" jdbcType="VARCHAR" property="receiveTime"/>
        <result column="order_pic" jdbcType="VARCHAR" property="orderPic"/>
        <result column="storage_money" jdbcType="VARCHAR" property="storageMoney"/>
        <result column="receiver_name" jdbcType="VARCHAR" property="receiverName"/>
        <result column="receiver_phone" jdbcType="VARCHAR" property="receiverPhone"/>
        <result column="take_phone_pic" jdbcType="VARCHAR" property="takePhonePic"/>
        <result column="cancel_user_phone" jdbcType="VARCHAR" property="cancelUserPhone"/>
        <result column="cancel_user_name" jdbcType="VARCHAR" property="cancelUserName"/>
        <result column="storage_user_id" jdbcType="VARCHAR" property="storageUserId"/>
        <result column="storage_user_name" jdbcType="VARCHAR" property="storageUserName"/>
        <result column="storage_user_phone" jdbcType="VARCHAR" property="storageUserPhone"/>
        <result column="rela_phone" jdbcType="VARCHAR" property="relaPhone"/>
        <result column="rela_name" jdbcType="VARCHAR" property="relaName"/>
        <result column="cancel_reason_code" jdbcType="VARCHAR" property="cancelReasonCode"/>
        <result column="cancel_reason_name" jdbcType="VARCHAR" property="cancelReasonName"/>
        <result column="item_type" jdbcType="VARCHAR" property="itemType"/>
        <result column="item_type_name" jdbcType="VARCHAR" property="itemTypeName"/>
        <result column="address_area" jdbcType="VARCHAR" property="addressArea"/>
        <result column="second_price" jdbcType="VARCHAR" property="secondPrice"/>
        <result column="create_type"  property="type"/>
        <result column="store_id"  property="storeId"/>
        <result column="receive_time"  property="receiveTime"/>
        <result column="complete_time"  property="completeTime"/>
        <result column="address_id"  property="addressId"/>
        <result column="town_id"  property="townId"/>
        <result column="home_service_id"  property="homeServiceId"/>
        <result column="order_fast_flag"  property="orderFastFlag"/>
        <result column="home_appliance_id"  property="homeApplianceId"/>
        <result column="change_receiver_flag"  property="changeReceiverFlag"/>
    </resultMap>
 
    <resultMap id="StorageInfoMap" type="com.xzx.gc.model.order.OrderStorageVo">
        <result column="storage_id" jdbcType="INTEGER" property="storageId"/>
        <result column="order_id" jdbcType="VARCHAR" property="orderId"/>
        <result column="storage_money" jdbcType="VARCHAR" property="storageMoney"/>
        <result column="recycle_money" jdbcType="VARCHAR" property="recycleMoney"/>
        <result column="receiver_name" jdbcType="VARCHAR" property="receiverName"/>
        <result column="receiver_phone" jdbcType="VARCHAR" property="receiverPhone"/>
        <result column="storage_user_id" jdbcType="VARCHAR" property="storageUserId"/>
        <result column="storage_user_name" jdbcType="VARCHAR" property="storageUserName"/>
        <result column="storage_user_phone" jdbcType="VARCHAR" property="storageUserPhone"/>
        <result column="storage_time" jdbcType="VARCHAR" property="storageTime"/>
        <result column="receiver_avatar" jdbcType="VARCHAR" property="receiverAvatar"/>
        <result column="sys_storage_id"  property="sysStorageId"/>
        <result column="sys_storage_type" property="sysStorageType"/>
    </resultMap>
 
    <resultMap id="OrderItemMap" type="com.xzx.gc.model.order.OrderItemVo">
        <result column="order_id" jdbcType="VARCHAR" property="orderId"/>
        <result column="item_type" jdbcType="VARCHAR" property="itemType"/>
        <result column="item_type_name" jdbcType="VARCHAR" property="itemTypeName"/>
        <result column="second_price" jdbcType="VARCHAR" property="secondPrice"/>
    </resultMap>
 
    <resultMap id="reserveTimeMap" type="com.xzx.gc.model.order.OrderReserveTimeVo">
        <result column="start_time" jdbcType="VARCHAR" property="startTime"/>
        <result column="end_time" jdbcType="VARCHAR" property="endTime"/>
        <result column="time_interval" jdbcType="VARCHAR" property="timeInterval"/>
    </resultMap>
 
    <resultMap id="UserInfoMap" type="com.xzx.gc.model.user.UserInfoVo">
        <result column="nick_name" jdbcType="VARCHAR" property="nickName"/>
        <result column="user_type" jdbcType="VARCHAR" property="userType"/>
        <result column="user_id" jdbcType="INTEGER" property="userId"/>
        <result column="mobile_phone" jdbcType="VARCHAR" property="mobilePhone"/>
    </resultMap>
    <resultMap id="ConfigInfoMap" type="com.xzx.gc.model.system.ConfigInfoVo">
        <result column="config_type_name" jdbcType="VARCHAR" property="configTypeName"/>
        <result column="config_value" jdbcType="VARCHAR" property="configValue"/>
        <result column="config_value_name" jdbcType="VARCHAR" property="configValueName"/>
    </resultMap>
 
    <!-- 订单基本信息增加 -->
    <insert id="orderInfoAdd" parameterType="java.util.Map">
        insert into xzx_order_info(order_id,address,order_status,order_type,reserve_time,
        create_user_id,create_time,rela_phone,longitude,latitude,address_area,rela_name,town_id,create_type,del_flag,store_id,receiver,house_number,unit_name,house_name)
        values (#{orderId},#{address},#{orderStatus},#{orderType},#{reserveTime},#{createUserId},
        #{createTime},#{relaPhone},#{longitude},#{latitude},#{addressArea},#{relaName},
          #{townId},#{createType},#{delFlag},#{storeId},#{receiver},#{houseNumber} ,#{unitName} ,#{houseName} )
    </insert>
 
    <!-- 订单详情增加 -->
    <insert id="orderDetailAdd" parameterType="java.util.Map">
        insert into xzx_order_detail_info(order_id,remark,create_user_name,mobile_phone,reserve_time,
        receive_time,order_pic,address_id,weight,amount,money,storage_money,receiver_name,take_phone_pic,receiver_phone,home_service_id,home_appliance_id)
        values (#{orderId},#{remark},#{createUserName},#{mobilePhone},#{reserveTime},#{receiveTime},
        #{orderPic},#{addressId},#{weight},#{amount},#{money},#{storageMoney},#{receiverName},#{takePhonePic},#{receiverPhone},#{homeServiceId} ,#{homeApplianceId} )
    </insert>
 
    <!-- 订单物品增加 -->
    <insert id="orderItemAdd" parameterType="java.util.Map">
        insert into xzx_order_item_info(order_id,item_type,weight,amount,money,price)
        values (#{orderId},#{itemType},#{weight},#{amount},#{money},#{price})
    </insert>
 
    <!-- 订单物品查询 -->
    <select id="orderItemQuery" parameterType="java.util.Map" resultMap="OrderItemMap">
        select a.order_id,a.item_type,a.weight,a.amount,a.money
        from xzx_order_item_info a
        where a.order_id=#{orderId}
        <if test="itemType!=null and itemType!=''">
            and a.item_type=#{itemType}
        </if>
    </select>
 
    <!-- 订单物品更新 -->
    <update id="orderItemUpdate" parameterType="java.util.Map">
        update xzx_order_item_info
        set weight=#{weight},amount=#{amount},money=#{money}
            <if test="price != null and price != ''">
                ,price=#{price}
            </if>
        where order_id=#{orderId} and item_type=#{itemType}
    </update>
 
 
    <!-- 订单列表查询 -->
    <select id="orderListQuery" parameterType="java.util.Map" resultMap="OrderMap">
        select distinct
        a.order_id,
        a.town_id,
        a.address,
        a.order_status,
        a.order_type,
        a.reserve_time,
        a.create_user_id,
        a.receiver,
        a.create_time,
        a.rela_phone,
        a.longitude,
        a.latitude,
        a.cancel_user_id,
        a.address_area,
        a.rela_name,
        a.order_second_status,
        a.create_type,
        a.store_id,
        d.take_phone_pic,
        d.storage_user_id,
        d.storage_user_name,
        d.storage_user_phone,
        d.remark,
        d.receiver_name,
        d.receiver_phone,
        d.complete_time,
        c.config_value_name "cancel_reason_name",
        d.receive_time,
        d.cancel_reason_name "cancelReason",
        d.address_id,
        d.order_fast_flag,
        d.home_service_id,
        d.note,
        d.home_appliance_id,
        d.change_receiver_flag
        <if test="latitude!=null and latitude!='' and longitude!=null and longitude!=''">
          ,ROUND(lat_lng_distance(#{latitude}, #{longitude}, a.latitude, a.longitude), 3) as distance
        </if>
        from xzx_order_info a
        left  join xzx_user_other_info b on a.receiver=b.user_id and b.del_flag=0 and b.is_prohibit=0
        inner join  xzx_order_detail_info d on a.order_id=d.order_id
        left join xzx_sys_config_info c on d.cancel_reason_code=c.config_value and c.config_type_code='CANCEL_REASON'
        where 1=1
        <if test="orderTypeList != null and orderTypeList.size()>0">
            and a.order_type in
            <foreach collection="orderTypeList" index="index" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="receiver == null || receiver == ''">
            <choose>
                <when test="fenceIds != null">
                    and ( b.partner_id=#{partnerId} or a.town_id in
                    <foreach collection="fenceIds" item="id" index="index" open="(" close=")" separator=",">
                        #{id}
                    </foreach>
                    )
                </when>
                <when test="townId != null and townId != ''  and orderStatus==1 and storeId==null">
                    and  find_in_set(a.town_id,#{townId})
                </when>
                <when test="townId != null and townId != ''  and orderStatus==1 and storeId!=null">
                    and  (find_in_set(a.town_id,#{townId}) or a.store_id=#{storeId})
                </when>
            </choose>
        </if>
 
        <choose>
            <when test="userType==1 and orderStatus==4">
                and (a.order_status=4 or a.order_status=5 or a.order_status=7)
            </when>
            <when test="userType==2 and orderStatus==4">
                and (a.order_status=4 or a.order_status=7)
            </when>
            <otherwise>
                <if test="orderStatus!=null and orderStatus!=''">
                    and a.order_status=#{orderStatus}
                </if>
            </otherwise>
        </choose>
 
        <if test="createUserId!=null and createUserId!=''">
            and a.create_user_id=#{createUserId}
        </if>
        <if test="receiver!=null and receiver!=''">
            and a.receiver=#{receiver}
        </if>
        <if test="isRecentThreeDays==1">
            and DATE_FORMAT(a.create_time,'%Y-%m-%d')>date_sub(CURRENT_DATE(), interval 3 day)
        </if>
 
        <if test="isRecentThreeDays==2">
            and DATE_FORMAT(a.create_time,'%Y-%m-%d')=CURRENT_DATE()
        </if>
 
        <if test="isRecentThreeDays==3">
            and DATE_FORMAT(a.create_time,'%Y-%m-%d')>date_sub(CURRENT_DATE(), interval 1 week)
        </if>
 
        <if test="isRecentThreeDays==4">
            and DATE_FORMAT(a.create_time,'%Y-%m-%d')>date_sub(CURRENT_DATE(), interval 1 month)
        </if>
 
        <if test="keyword != null and keyword != ''">
            and (a.rela_phone like concat('%',#{keyword},'%') or a.rela_name like concat('%',#{keyword},'%') or   b.name like concat('%',#{keyword},'%') or d.receiver_phone like concat('%',#{keyword},'%'))
        </if>
 
        <if test="orderMethod==1">
            and a.create_type=2
        </if>
        <if test="orderMethod==2">
            and a.create_type=3
        </if>
 
        <choose>
            <when test="latitude!=null and latitude!='' and longitude!=null and longitude!='' and orderStatus==1">
                order by  distance asc,a.create_time desc
            </when>
            <otherwise>
                order by  a.create_time desc
            </otherwise>
        </choose>
 
     </select>
 
 
    <select id="orderListQueryForAdmin" parameterType="java.util.Map" resultMap="OrderMap">
        select distinct
        a.order_id,
        a.town_id,
        a.address,
        a.order_status,
        a.order_type,
        a.reserve_time,
        a.create_user_id,
        a.receiver,
        a.create_time,
        a.rela_phone,
        a.longitude,
        a.latitude,
        a.cancel_user_id,
        a.address_area,
        a.rela_name,
        a.order_second_status,
        a.create_type,
        a.store_id,
        d.take_phone_pic,
        d.storage_user_id,
        d.storage_user_name,
        d.storage_user_phone,
        d.remark,
        d.receiver_name,
        d.receiver_phone,
        d.complete_time,
        c.config_value_name "cancel_reason_name",
        d.receive_time,
        d.cancel_reason_name "cancelReason",
        d.address_id,
        d.order_fast_flag,
        d.home_service_id,
        d.note,
        d.home_appliance_id,
        d.change_receiver_flag
        <if test="latitude!=null and latitude!='' and longitude!=null and longitude!=''">
            ,ROUND(lat_lng_distance(#{latitude}, #{longitude}, a.latitude, a.longitude), 3) as distance
        </if>
        from xzx_order_info a
        left  join xzx_user_other_info b on a.receiver=b.user_id and b.del_flag=0 and b.is_prohibit=0
        inner join  xzx_order_detail_info d on a.order_id=d.order_id
        left join xzx_sys_config_info c on d.cancel_reason_code=c.config_value and c.config_type_code='CANCEL_REASON'
        where 1=1
        <if test="orderTypeList != null and orderTypeList.size()>0">
            and a.order_type in
            <foreach collection="orderTypeList" index="index" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="receiver == null || receiver == ''">
            <choose>
                <when test="fenceIds != null">
                    and ( b.partner_id=#{partnerId} or a.town_id in
                    <foreach collection="fenceIds" item="id" index="index" open="(" close=")" separator=",">
                        #{id}
                    </foreach>
                    )
                </when>
                <when test="townId != null and townId != ''  and orderStatus==1 and storeId==null">
                    and  find_in_set(a.town_id,#{townId})
                </when>
                <when test="townId != null and townId != ''  and orderStatus==1 and storeId!=null">
                    and  (find_in_set(a.town_id,#{townId}) or a.store_id=#{storeId})
                </when>
            </choose>
        </if>
 
        <choose>
            <when test="userType==1 and orderStatus==4">
                and (a.order_status=4 or a.order_status=5 or a.order_status=7)
            </when>
            <when test="userType==2 and orderStatus==4">
                and (a.order_status=4 or a.order_status=7)
            </when>
            <otherwise>
                <if test="orderStatus!=null and orderStatus!=''">
                    and a.order_status=#{orderStatus}
                </if>
            </otherwise>
        </choose>
 
        <if test="createUserId!=null and createUserId!=''">
            and a.create_user_id=#{createUserId}
        </if>
        <if test="receiver!=null and receiver!=''">
            and a.receiver=#{receiver}
        </if>
        <if test="isRecentThreeDays==1">
            and DATE_FORMAT(a.create_time,'%Y-%m-%d')>date_sub(CURRENT_DATE(), interval 3 day)
        </if>
 
        <if test="isRecentThreeDays==2">
            and DATE_FORMAT(a.create_time,'%Y-%m-%d')=CURRENT_DATE()
        </if>
 
        <if test="isRecentThreeDays==3">
            and DATE_FORMAT(a.create_time,'%Y-%m-%d')>date_sub(CURRENT_DATE(), interval 1 week)
        </if>
 
        <if test="isRecentThreeDays==4">
            and DATE_FORMAT(a.create_time,'%Y-%m-%d')>date_sub(CURRENT_DATE(), interval 1 month)
        </if>
 
        <if test="keyword != null and keyword != ''">
            and (a.rela_phone like concat('%',#{keyword},'%') or a.rela_name like concat('%',#{keyword},'%') or   b.name like concat('%',#{keyword},'%') or d.receiver_phone like concat('%',#{keyword},'%'))
        </if>
 
        <if test="orderMethod==1">
            and a.create_type=2
        </if>
        <if test="orderMethod==2">
            and a.create_type=3
        </if>
 
        <choose>
            <when test="latitude!=null and latitude!='' and longitude!=null and longitude!='' and orderStatus==1">
                order by  distance asc,a.create_time desc
            </when>
            <otherwise>
                order by  a.create_time desc
            </otherwise>
        </choose>
 
    </select>
 
 
 
    <!-- 各个状态下的订单数 -->
    <select id="orderListCount" parameterType="java.util.Map" resultType="String">
        select count(*)
        from xzx_order_info
        where 1=1
        <if test="orderType!=null and orderType!=''">
            and order_type=#{orderType}
        </if>
        <if test="orderStatus!=null and orderStatus!='' and orderStatus=='4'">
                and (order_status='4' or order_status='5')
        </if>
        <if test="createUserId!=null and createUserId!=''">
            and create_user_id=#{createUserId}
        </if>
        <if test="receiver!=null and receiver!=''">
            and receiver=#{receiver}
        </if>
    </select>
 
    <!--统计普通用户订单信息-->
    <select id="statNormalUserOrder" parameterType="com.xzx.gc.model.order.OrderInfoReq" resultType="java.util.HashMap">
        select
        (
          case
            b.order_status
          when '1' then 'djdCount'
          when '2' then 'fwzCount'
          when '3' then 'dqrCount'
          when '4' then 'drkCount'
          when '5' then 'wcCount'
          when '6' then 'cancelCount'
              when  '7' then 'recyleingCount'
          else ''
          end) as orderStatus,
           b.orderNum
        from
        (
          select
            a.order_status,count(a.order_id) as orderNum
          from
            xzx_order_info a
          where
            a.create_user_id=#{createUserId}
          group by
            a.order_status
        ) b
    </select>
    <!--统计员工用户订单信息-->
    <select id="statStaffUserOrder" parameterType="com.xzx.gc.model.order.OrderInfoReq" resultType="java.util.HashMap">
        select
        (
          case
            b.order_status
          when '1' then 'djdCount'
          when '2' then 'fwzCount'
          when '3' then 'dqrCount'
          when '4' then 'drkCount'
          when '5' then 'wcCount'
          when '6' then 'cancelCount'
          when  '7' then 'recyleingCount'
          else ''
          end) as orderStatus,
           b.orderNum
        from
        (
          select
            a.order_status,count(a.order_id) as orderNum
          from
            xzx_order_info a
          where
            a.receiver=#{receiver}
 
          group by
            a.order_status
        ) b
 
    </select>
 
 
    <!--订单详情查询-->
    <select id="orderDetailQuery" parameterType="java.util.Map" resultMap="OrderMap">
       SELECT
    a.order_id,
    a.town_id,
    a.address,
    a.address_area,
    a.order_status,
    a.order_type,
    a.reserve_time,
    a.create_user_id,
    a.receiver,
    a.create_time,
    a.rela_phone,
    a.longitude,
    a.latitude,
    d.remark,
    d.create_user_name,
    d.receive_time,
    d.order_pic,
    d.amount,
    d.money,
    d.receiver_name,
    d.take_phone_pic,
    d.receiver_phone,
    d.cancel_user_name,
    d.cancel_user_phone,
    a.rela_name,
    a.order_second_status,
    d.cancel_reason_code,
    d.cancel_reason_name,
    a.store_id,
    d.address_id,
    d.home_service_id,
    d.note,
    d.home_appliance_id
FROM
    xzx_order_info a
    INNER JOIN xzx_order_detail_info d ON a.order_id = d.order_id
WHERE
    a.order_id = #{orderId}
    </select>
 
    <!-- 订单取消原因更新 -->
    <update id="updateOrderCancelReason" parameterType="java.util.Map">
        update xzx_order_detail_info
        set cancel_reason_code=#{cancelReasonCode}
            <if test="cancelReasonName != null and cancelReasonName != ''">
                ,cancel_reason_name=#{cancelReasonName}
            </if>
 
        where order_id=#{orderId}
    </update>
 
    <!-- 订单基本信息更新 -->
    <update id="updateOrderDetailInfo" parameterType="java.util.Map">
        update xzx_order_detail_info
        <trim prefix="set" suffixOverrides=",">
            <if test="remark!= null and remark!=''">remark=#{remark},</if>
            <if test="reserveTime!= null and reserveTime!=''">reserve_time=#{reserveTime},</if>
            <if test="receiveTime!= null and receiveTime!=''">receive_time=#{receiveTime},</if>
            <if test="addressId!= null and addressId!=''">address_id=#{addressId},</if>
            <if test="weight!=null and weight!=''">weight=#{weight},</if>
            <if test="amount!=null and amount!=''">amount=#{amount},</if>
            <if test="money!=null and money!=''">money=#{money},</if>
            <if test="storageMoney!=null and storageMoney!=''">storage_money=#{storageMoney},</if>
            <if test="receiverName!=null and receiverName!=''">receiver_name=#{receiverName},</if>
            <if test="receiverPhone!=null and receiverPhone!=''">receiver_phone=#{receiverPhone},</if>
            <if test="cancelUserName!=null and cancelUserName!=''">cancel_user_name=#{cancelUserName},</if>
            <if test="cancelUserPhone!=null and cancelUserPhone!=''">cancel_user_phone=#{cancelUserPhone},</if>
            <if test="storageUserId!=null and storageUserId!=''">storage_user_id=#{storageUserId},</if>
            <if test="storageUserName!=null and storageUserName!=''">storage_user_name=#{storageUserName},</if>
            <if test="storageUserPhone!=null and storageUserPhone!=''">storage_user_phone=#{storageUserPhone},</if>
            <if test="cancelReasonCode!=null and cancelReasonCode!=''">cancel_reason_code=#{cancelReasonCode},</if>
            <if test="cancelReasonName!=null and cancelReasonName!=''">cancel_reason_name=#{cancelReasonName},</if>
            <if test="completeTime!=null and completeTime!=''">complete_time=#{completeTime},</if>
            <if test="cancelTime != null and cancelTime != ''">cancel_time=#{cancelTime} ,</if>
        </trim>
        where order_id=#{orderId}
    </update>
 
 
    <!-- 订单详细信息更新 -->
    <update id="updateOrderInfo" parameterType="java.util.Map">
        update xzx_order_info
        <trim prefix="set" suffixOverrides=",">
            <if test="address!= null and address!=''">address=#{address},</if>
            <if test="orderStatus!= null and orderStatus!=''">order_status=#{orderStatus},</if>
            <if test="orderType!= null and orderType!=''">order_type=#{orderType},</if>
            <if test="reserveTime!= null and reserveTime!=''">reserve_time=#{reserveTime},</if>
            <if test="createUserId!=null and createUserId!=''">create_user_id=#{createUserId},</if>
            <if test="receiver!=null and receiver!='' ">receiver=#{receiver},</if>
            <if test="cancelUserId!=null and cancelUserId!=''">cancel_user_id=#{cancelUserId},</if>
            <if test="traceId != null and traceId != ''">trace_id=#{traceId} ,</if>
        </trim>
        where order_id=#{orderId}
    </update>
 
 
    <!--回收员的入库订单物品统计汇总-->
    <select id="prepareStorageOrderList" parameterType="java.util.Map" resultType="String">
        select a.order_id
        from xzx_order_info a
        where
        1=1
        <choose>
            <when test="clientType==2">
                and a.order_status=7
            </when>
            <when test="clientType==3">
                and a.order_status='4'
            </when>
        </choose>
              and a.receiver=(select receiver from xzx_order_info where order_id=#{orderId})
    </select>
 
    <!--回收员的服务中订单-->
    <select id="fwOrderList" parameterType="java.util.Map" resultType="String">
        select a.order_id
        from xzx_order_info a
        where
        1=1
                and a.order_status=2
        and a.receiver=(select receiver from xzx_order_info where order_id=#{orderId})
    </select>
 
    <select id="fwOrderListByUserId" parameterType="java.util.Map" resultType="String">
        select a.order_id
        from xzx_order_info a
        where
            1=1
            and a.order_status=2
            and a.receiver=#{receiver}
    </select>
 
 
    <!-- 查询接单员用户信息 -->
    <select id="queryUserInfo" parameterType="map" resultMap="UserInfoMap">
        select d.user_id,d.mobile_phone,d.avatar,d.nick_name,d.sex,d.birthday,d.user_type
        from xzx_user_info d
        where d.user_id=(select receiver from xzx_order_info where order_id=#{orderId})
    </select>
 
    <!-- 入库基本信息增加 -->
    <insert id="orderStorageInfoAdd" parameterType="java.util.Map">
        insert into xzx_order_storage_info(storage_id,order_id,storage_user_id,storage_user_name,
        storage_user_phone,storage_time,storage_money,recycle_money,receiver,receiver_name,receiver_phone,receiver_avatar,storage_status)
        values (#{storageId},#{orderId},#{storageUserId},#{storageUserName},#{storageUserPhone},#{storageTime},
        #{storageMoney},#{recycleMoney},#{receiver},#{receiverName},#{receiverPhone},#{receiverAvatar},#{storageStatus})
 
    </insert>
 
    <!-- 入库列表查询 -->
    <select id="orderStorageListQuery" parameterType="java.util.Map" resultMap="StorageInfoMap">
        select storage_id,order_id,storage_user_id,storage_user_name,
        storage_user_phone,storage_time,storage_money,recycle_money,
        receiver,receiver_name,receiver_phone,receiver_avatar,sys_storage_id,sys_storage_type
        from xzx_order_storage_info
        where 1=1
        <if test="storageUserId!=null and storageUserId!=''">
            and storage_user_id=#{storageUserId}
        </if>
        <if test="storageId!=null and storageId!=''">
            and storage_id=#{storageId}
        </if>
            and storage_status=#{storageStatus}
    </select>
 
    <!-- 入库明细查询 -->
    <select id="orderStorageDetailQuery" parameterType="java.util.Map" resultMap="OrderItemMap">
        select a.*,b.title item_type_name
        from xzx_order_storage_detail a
        <choose>
            <when test="type==0">
                left  JOIN xzx_sys_environmental_info b on a.item_type=b.item_type and b.del_flag=0 and b.parent_id is not null and b.city_id=#{townId}
            </when>
            <otherwise>
                left  JOIN xzx_package_goods_info b on a.item_type=b.item_type and b.del_flag=0 and b.parent_id is not null and b.package_id=#{townId}
            </otherwise>
        </choose>
        where storage_id=#{storageId}
        <if test="flag!=null and flag!=''">
            and flag=#{flag}
        </if>
    </select>
 
    <!-- 获取预约时间配置 -->
    <select id="reserveTimeConfigQuery" parameterType="java.util.Map" resultMap="reserveTimeMap">
        select a.start_time,a.end_time,a.time_interval
        from xzx_sys_service_time_config a
    </select>
 
    <!-- 配置信息查询 -->
    <select id="queryConfigInfo" parameterType="com.xzx.gc.model.system.ConfigInfoReq" resultMap="ConfigInfoMap">
        select config_type_name,config_value,config_value_name
        from xzx_sys_config_info
        where 1=1
        <if test="configTypeCode!=null and configTypeCode!=''">
            and  config_type_code=#{configTypeCode}
        </if>
        <if test="configValue!=null and configValue!=''">
            and  config_value=#{configValue}
        </if>
 
    </select>
    <select id="customerFind" resultType="com.xzx.gc.order.dto.OrderCustomDto">
            SELECT
        a.order_id "orderId",
        a.rela_name "relaName",
        a.rela_phone "relaPhone",
        a.address,
        a.address_area "addressArea",
        a.longitude,
        a.latitude,
        b.address_id "addressId",
        a.order_id "orderId"
        FROM
            xzx_order_info a
            INNER JOIN xzx_order_detail_info b ON a.order_id = b.order_id
        WHERE
            a.create_type = 2
            AND a.receiver=#{userId}
            AND a.del_flag =0
        AND a.order_id IN
        (SELECT max(order_id) FROM xzx_order_info group by create_user_id)
        ORDER BY a.create_time desc
 
    </select>
    <select id="findOrderWithCustome" resultType="com.xzx.gc.order.dto.CustomOrderDto">
        SELECT a.order_id "orderId",b.storage_money "storageMoney",a.receiver from xzx_order_info a
            inner JOIN xzx_order_detail_info b on a.order_id=b.order_id
        WHERE FIND_IN_SET(a.order_id,#{orderIdString}) and a.create_type=2
 
    </select>
    <select id="findSumWeight" resultType="java.math.BigDecimal">
        SELECT sum(CAST(IFNULL(b.weight,0) as DECIMAL(9,3))) from xzx_order_info a
            inner JOIN xzx_order_item_info b
                on a.order_id=b.order_id
        WHERE a.create_user_id=#{userId}  and a.order_status in('4','5','7');
    </select>
 
    <select id="findSumMoney" resultType="java.math.BigDecimal">
        SELECT sum(CAST(IFNULL(b.money,0) as DECIMAL(9,3))) from xzx_order_info a
            inner JOIN xzx_order_detail_info b
                on a.order_id=b.order_id
        WHERE a.create_user_id=#{userId}  and a.order_status in('4','5','7');
    </select>
 
 
 
 
 
    <select id="findDetailByReceiverAndStatus" resultType="com.xzx.gc.entity.OrderInfo">
           SELECT
        a.order_id "orderId",
        a.town_id "townId",
        a.create_user_id "createUserId",
        a.order_status "orderStatus",
        a.trace_id "traceId",
        b.money,
        b.complete_time "completeTime",
        a.create_time "createTime",
        a.store_id "storeId"
        FROM
            xzx_order_info a
            INNER JOIN xzx_order_detail_info b ON a.order_id = b.order_id
        WHERE
            a.order_type = '1'
            AND a.order_status = #{orderStatus}
            AND a.receiver = #{receiver}
        order by b.complete_time desc
    </select>
 
    <select id="findByAddressId" resultType="com.xzx.gc.order.dto.OrderCustomDto">
            SELECT
        a.order_id "orderId",
        a.rela_name "relaName",
        a.rela_phone "relaPhone",
        a.address,
        a.address_area "addressArea",
        a.longitude,
        a.latitude,
        b.address_id "addressId",
        a.order_id "orderId"
        FROM
            xzx_order_info a
            INNER JOIN xzx_order_detail_info b ON a.order_id = b.order_id
        WHERE
          b.address_id=#{addressId}
    </select>
    <select id="findWithLonNull" resultType="com.xzx.gc.order.dto.OrderCustomDto">
             SELECT
        a.order_id "orderId",
        a.rela_name "relaName",
        a.rela_phone "relaPhone",
        a.address,
        a.address_area "addressArea",
        a.longitude,
        a.latitude,
        b.address_id "addressId",
        a.order_id "orderId"
        FROM
            xzx_order_info a
            INNER JOIN xzx_order_detail_info b ON a.order_id = b.order_id
        WHERE
          a.longitude is null or a.longitude='0'
    </select>
    <select id="findOrderByTime" resultType="com.xzx.gc.entity.OrderInfo">
                SELECT
            a.order_id "orderId",
            b.complete_time "completeTime",
            CONCAT( c.address_area, c.detail_address ) "address",
            a.trace_id "traceId"
        FROM
            xzx_order_info a
            INNER JOIN xzx_order_detail_info b ON a.order_id = b.order_id
            INNER JOIN xzx_user_address_info c ON b.address_id = c.address_id
        WHERE
            a.receiver = #{receiverId}
            AND DATE_FORMAT( b.complete_time,'%Y-%m-%d')=#{time}
            AND a.order_status IN ( '4', '5', '7' )
            and a.create_type!=2
 
    </select>
    <select id="findByIds" resultType="com.xzx.gc.entity.OrderInfo">
   SELECT
        a.order_id "orderId",
        a.create_user_id "createUserId",
        b.complete_time "completeTime",
        c.regist_time "registTime",
        c.mobile_phone "createMobile",
        b.address_id "addressId"
        FROM
            xzx_order_info a
            inner join  xzx_user_info c on a.create_user_id=c.user_id and c.del_flag=0 and is_prohibit=0
            INNER JOIN xzx_order_detail_info b ON a.order_id = b.order_id
        WHERE
            a.order_id in
        <foreach collection="array" item="id" index="index" open="(" close=")" separator=",">
            #{id}
        </foreach>
 
         order by a.create_time asc
 
    </select>
    <select id="findWorkOrder" resultType="com.xzx.gc.entity.ReceiveClock">
        SELECT
            a.receiver "userId",c.`name` ,c.mobile_phone "mobile",min(b.complete_time) "workTime",max(b.complete_time) "closeTime"
        FROM
            xzx_order_info a
            inner JOIN xzx_order_detail_info b on a.order_id=b.order_id
            left join xzx_user_other_info c on a.receiver=c.user_id and c.del_flag=0
        WHERE
            a.order_status IN ( '4', '5', '7' ) and
            TO_DAYS( b.complete_time ) = TO_DAYS( NOW( ) )
        GROUP BY a.receiver
 
    </select>
 
    <select id="findPartnerId" resultType="com.xzx.gc.entity.OrderInfo">
        SELECT
            a.order_id "orderId",
            a.create_time "createTime",
            b.partner_id "partnerId",
            c.money
        FROM
            xzx_order_info a
            LEFT JOIN xzx_order_detail_info c on a.order_id=c.order_id
            LEFT JOIN xzx_partner_fence b ON a.town_id = b.fence_id
    </select>
    <select id="findPartnerIdByTime" resultType="com.xzx.gc.entity.OrderInfo">
        SELECT
            a.order_id "orderId",
            a.create_time "createTime",
            b.partner_id "partnerId",
            c.money
        FROM
            xzx_order_info a
            LEFT JOIN xzx_order_detail_info c on a.order_id=c.order_id
            LEFT JOIN xzx_partner_fence b ON a.town_id = b.fence_id
                                             AND b.del_flag = 0
            where
        DATE_FORMAT(a.create_time,'%Y-%m-%d')=date_sub(CURRENT_DATE(), interval 1 day)
    </select>
    <select id="queryMoneyByOrderId" resultType="java.lang.String">
        select IFNULL(sum(money),0) from xzx_order_item_info where order_id=#{orderId}
    </select>
    <select id="findById" resultType="com.xzx.gc.entity.OrderInfo">
        select * from xzx_order_info where order_id=#{orderId}
    </select>
    <select id="findSumWeightAndMoney" resultType="com.xzx.gc.model.order.OrderStatistic">
        SELECT
            sum( IFNULL( weight, 0 ) ) as sumWeight,
            sum( IFNULL( money, 0 ) ) as sumMoney
        FROM
            xzx_order_detail_info
        WHERE
            order_id IN
        <foreach collection="orderIds" index="index" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
    </select>
 
    <select id="queryStorageMoneyDetailApi" resultType="com.xzx.gc.model.admin.PayRequestInfoModel">
        select a.order_id as orderId,c.complete_time as completeTime,
        sum(b.money) as money,sum(b.weight) as weight,
        a.create_time as createTime,a.rela_phone as phone from xzx_order_info a
        left join xzx_order_detail_info c on a.order_id=c.order_id
        left join xzx_order_item_info b on a.order_id=b.order_id
        where a.del_flag=0
        and a.order_status in (4,5)
        and a.order_id=c.order_id
        and a.order_id in
        <foreach collection="orderIds" index="index" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
        group by a.order_id
    </select>
 
    <select id="queryMoneyAndWeightByOrderIds" resultType="java.util.HashMap" parameterType="java.util.List">
        select
        IFNULL(sum(b.money),0) as money,IFNULL(sum(b.weight),0) as weight
        from xzx_order_info a
        left join xzx_order_detail_info c on a.order_id=c.order_id
        left join xzx_order_item_info b on a.order_id=b.order_id
        where a.del_flag=0
        and a.order_status in (4,5)
        and a.order_id=c.order_id
        and a.order_id in
        <foreach collection="orderIds" index="index" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
        group by a.order_id
    </select>
 
    <select id="quotaDetail" parameterType="com.xzx.gc.model.admin.StorageUserModel" resultType="com.xzx.gc.model.admin.StorageUserModel">
        select IFNULL(sum(c.money),0) as money,IFNULL(sum(c.weight),0) as weight,b.receive_time as storageTime from xzx_order_info a
        left join xzx_order_detail_info b on a.order_id=b.order_id
        left join xzx_order_item_info c on a.order_id=c.order_id
        where a.receiver=#{userId} and c.order_id is not null
        <if test="startTime!= null and startTime!=''">
            and b.receive_time<![CDATA[>= ]]>#{startTime}
        </if>
        <if test="endTime!= null and endTime!=''">
            and b.receive_time<![CDATA[<= ]]>#{endTime}
        </if>
        group by a.order_id
    </select>
 
    <select id="queryOrderByPhone" resultType="com.xzx.gc.model.admin.OrderModel">
        select * from xzx_order_info where rela_phone=#{phone} and order_status in (1,2) and del_flag=0
    </select>
 
    <insert id="addOrderInfoApi">
 
        INSERT INTO `xzx_order_info`
        (`order_id`, `address`, `order_status`,
         `order_second_status`, `order_type`, `address_area`,
         `reserve_time`, `create_user_id`, `receiver`,
         `cancel_user_id`, `create_time`, `rela_phone`,
         `rela_name`, `longitude`, `latitude`, `town_id`,
         `create_type`, `del_flag`, `store_id`)
        VALUES (#{orderId}, #{detailAddress}, #{orderStatus},
                            NULL, '1', #{addressArea},
                            #{reserveTime}, #{createUserId}, NULL,
                            NULL, SYSDATE(), #{mobilePhone},
                #{nickName}, #{longitude}, #{latitude}, #{townshipId},
                '3', '0', #{storeId})
    </insert>
 
 
    <select id="queryUserOrderApiList" resultType="com.xzx.gc.model.admin.OrderModel">
        select a.order_id,a.create_time,sum(b.weight) ,sum(b.money) from xzx_order_info a
            left join xzx_order_item_info b on a.order_id=b.order_id
        where a.order_status in ('4','5','7')
              and a.create_user_id=#{userId}
        group by a.order_id
    </select>
 
    <select id="queryStaticDataToday" resultType="map">
        SELECT
        IFNULL(e.weight, 0) AS weight,
        IFNULL(e.money, 0) AS money,
        a.title as config_value_name
        FROM xzx_sys_environmental_info a
        LEFT JOIN (
        SELECT
        SUM(b.money) as money,
        SUM(b.weight) as weight,
        b.item_type,
        b.flag
        FROM xzx_order_storage_info c
        LEFT JOIN xzx_order_storage_detail b ON c.storage_id = b.storage_id
        WHERE b.flag = #{flag}
 
        <if test="startTime != null and startTime != ''">
            and c.storage_time BETWEEN #{startTime} AND #{endTime}
        </if>
 
        <if test="receiverphone != null and receiverphone != ''">
            and c.receiver_phone=#{receiverphone}
        </if>
        GROUP BY b.item_type
        ) e ON e.item_type = a.item_type
        WHERE a.del_flag = 0 and a.parent_id is NOT NULL;
    </select>
    <select id="queryOrderIdsByStorageId" resultType="java.lang.String">
        SELECT order_id
        FROM xzx_order_storage_info
        where storage_id = #{storageId}
    </select>
    <select id="queryCuserOrderByUserIdCount1" resultType="java.util.Map">
        SELECT
            count(a.order_id)                                           as count,
            (select count(b.order_id)
             from xzx_order_info b
             where b.order_status = 3 and b.create_user_id = #{userId}) as count1
        FROM xzx_order_info a
        WHERE a.create_user_id = #{userId} and a.order_status in (4, 5, 7)
    </select>
    <select id="queryOrderByOrderId" resultType="java.lang.String">
        select receiver
        from xzx_order_info
        WHERE order_id = #{orderId}
    </select>
    <select id="queryUserIdByOrderId" resultType="java.lang.String">
        select create_user_id
        from xzx_order_info
        WHERE order_id = #{orderId}
    </select>
    <select id="queryOrderPageByOrderno" resultType="map">
        SELECT a.address, a.address_area, a.order_type, a.order_status,a.create_time,
            a.rela_name as relaName,b.*,e.item_type, e.cweight AS cweight, e.camount as camount,
            e.cmoney as cmoney, e.title as title,a.reserve_time as reserveTime,b.address_id as addressId
        FROM xzx_order_info a
            LEFT JOIN xzx_order_detail_info b ON a.order_id=b.order_id
            LEFT JOIN(
                         select c.item_type, c.weight AS cweight, c.amount as camount,c.order_id,
                                             c.money as cmoney,d.title FROM xzx_order_item_info c
                             LEFT JOIN xzx_sys_environmental_info d ON c.item_type = d.item_type
                         WHERE c.money>0
                     )e on a.order_id = e.order_id
        WHERE a.order_id = #{orderNo}
        group by e.item_type
 
    </select>
    <select id="queryOrderList" resultType="map">
        SELECT
        a.order_id,
        a.create_time,
        a.reserve_time,
        a.order_type,
        a.order_status,
        c.nick_name,
        c.name,
        a.rela_name,
        b.money,
        SUM(f.weight) AS weight
        FROM xzx_order_info a
        LEFT JOIN xzx_order_detail_info b ON a.order_id = b.order_id
        LEFT JOIN xzx_user_other_info c ON a.receiver = c.user_id
        LEFT JOIN xzx_order_item_info f ON a.order_id = f.order_id
        WHERE 1 = 1
 
        <if test="orderStatus != null and orderStatus != ''">
            AND a.order_status=#{orderStatus}
        </if>
 
        <if test="startTime != null and startTime != ''">
            AND a.create_time BETWEEN #{startTime} AND #{endTime}
        </if>
 
        <if test="orderType != null and orderType != ''">
            AND a.order_type = #{orderType}
        </if>
 
        <if test="name != null and name != ''">
            AND c.name = #{name}
        </if>
 
        <if test="mobilePhone != null and mobilePhone != ''">
            AND c.mobile_phone = #{mobilePhone}
        </if>
        GROUP BY a.create_time desc
    </select>
    <select id="queryOrderApiList" resultType="com.xzx.gc.model.admin.OrderModel">
        SELECT
        a.order_id AS orderId,
        a.create_time AS createTime,
        a.reserve_time AS reserveTime,
        a.order_type AS orderType,
        a.rela_phone AS relaPhone,
        b.receive_time AS receiveTime,
        b.complete_time AS completeTime,
        b.cancel_reason_name AS cancelReasonName,
        a.order_status AS orderStatus,
        IFNULL( d.nick_name, c.nick_name ) AS nickName,
        c.NAME AS NAME,
        d.mobile_phone AS mobilePhone,
        a.rela_name AS relaName,
        b.money AS orderMoney,
        b.weight AS orderWeight,
        IFNULL( b.mark_read, 0 ) AS markRead,
        b.order_fast_flag AS orderFastFlag,
        b.mark_code AS markCode,
        d.partner_id AS partnerId,
        IFNULL( c.del_flag, 0 ) AS delFlag,
        b.home_service_id AS homeServiceId,
        b.note
        FROM
        xzx_order_info a
        LEFT JOIN xzx_order_detail_info b ON a.order_id = b.order_id
        LEFT JOIN xzx_user_info d ON a.create_user_id = d.user_id
        LEFT JOIN xzx_user_other_info c ON a.receiver = c.user_id
        LEFT JOIN xzx_user_info e ON a.receiver = e.user_id
        LEFT JOIN xzx_order_item_info f ON a.order_id = f.order_id
        LEFT JOIN xzx_user_address_info k ON b.address_id=k.address_id
        WHERE 1 = 1
        <if test="orderType != null and orderType != ''">
            and a.order_type=#{orderType}
        </if>
        <if test="orderStatus != null and orderStatus != ''">
            AND a.order_status=#{orderStatus}
        </if>
 
        <if test="startTime != null and startTime != ''">
            AND a.create_time BETWEEN #{startTime} AND #{endTime}
        </if>
 
        <if test="orderType != null and orderType != ''">
            AND a.order_type = #{orderType}
        </if>
 
        <if test="name != null and name != ''">
            <choose>
            <when test="orderType != null and orderType != '' and orderType==3">
                AND (e.name like concat('%',#{name} ,'%') or e.mobile_phone like concat('%',#{name} ,'%'))
            </when>
                <otherwise>
                    AND (c.name like concat('%',#{name} ,'%') or c.mobile_phone like concat('%',#{name} ,'%'))
                </otherwise>
            </choose>
        </if>
 
        <if test="mobilePhone != null and mobilePhone != ''">
            AND (d.mobile_phone like concat('%',#{mobilePhone} ,'%') or d.nick_name = #{nickName} or a.rela_phone like concat('%',#{mobilePhone} ,'%'))
        </if>
 
        <if test="orderId != null and orderId != ''">
            AND a.order_id like concat('%',#{orderId} ,'%')
        </if>
 
        <if test="createType != null and createType != ''">
            AND a.create_type = #{createType}
        </if>
 
 
        <if test="partnerId != null and partnerId != '' and townIds != null and townIds.size()>0">
            AND (c.partner_id=#{partnerId} or (a.town_id in
            <foreach collection="townIds" index="index" item="id" separator="," open="(" close=")">
                #{id}
            </foreach>
             and a.order_type in ('1','2')))
        </if>
 
        <if test="partnerId != null and partnerId != '' and (townIds == null or townIds.size()==0)">
            AND (c.partner_id=#{partnerId})
        </if>
 
        GROUP BY a.order_id
        order by a.create_time desc
    </select>
    <select id="queryTownIdsByPartnerIds" parameterType="java.util.List" resultType="java.lang.String">
        select distinct fence_id from xzx_partner_fence where 1=1
        <if test=" partnerIds != null and partnerIds.size() != 0">
            AND partner_id in
            <foreach collection="partnerIds" index="index" item="id" separator="," open="(" close=")">
                #{id}
            </foreach>
        </if>
    </select>
    <select id="queryStatusByCuserId" resultType="map">
        SELECT
            COUNT(*)       as count,
            a.order_status as orderStatus
        FROM xzx_order_info a
        WHERE a.receiver = #{userId}
        GROUP BY a.order_status
    </select>
    <select id="queryOrderByPartnerId" resultType="java.lang.String">
        select a.town_id
        from xzx_order_info a
        where a.order_id = #{orderId}
    </select>
    <update id="updateOrderStatus">
        update xzx_order_info
        <set>
            <if test="orderStatus != null and orderStatus != ''">
                order_status=#{orderStatus},
            </if>
 
            <if test="receiveId != null and receiveId != ''">
                receiver=#{receiveId},
            </if>
        </set>
        where order_id=#{orderId}
    </update>
    <update id="updateApirecByOrderId">
        update xzx_order_info
        set receiver = #{receiveId}, order_status = 2, trace_id = #{trid}
        where order_id = #{orderId}
    </update>
    <update id="updateApirecDetailByOrderId">
        update xzx_order_detail_info
        set receive_time = SYSDATE(), receiver_phone = #{mobilePhone}, receiver_name = #{name}
        where order_id = #{orderId}
    </update>
    <update id="updateOrderStatus1">
        update xzx_order_info
        set order_status = #{orderStatus}
        where order_id = #{orderId}
    </update>
    <update id="updateOrderDetailReData">
        update xzx_order_detail_info
        set cancel_reason_name = #{cancelReasonName}
        where order_id = #{orderId}
    </update>
    <select id="queryOrderReNum" resultType="java.lang.String">
        select count(order_id)
        from xzx_order_info
        where del_flag = 0 and receiver = #{userId} and order_status = 2
    </select>
    <select id="queryStorageApiList" resultType="map">
        select
        a.storage_id as storageId,
        IFNULL(x.name,a.storage_user_name) as storageName,
        a.storage_user_phone as storageUserPhone,
        (select user_type
        from xzx_user_other_info
        where user_id = receiver) as userType,
        receiver_name as receiverName,
        receiver as receiver,
        receiver_phone as receiverPhone,
        storage_time as storageTime,
        IFNULL(a.recycle_weight,'0') as recycleWeight,
        IFNULL(a.storage_weight,'0') as storageWeight,
        IFNULL(a.storage_money,'0') as storageMoney,
        IFNULL(a.recycle_money,'0') as recycleMoney,
        x.del_flag as delFlag,
        IFNULL(y.create_time,'-') as batchTime,
        y.vehicle_id as vehicleId,
        y.batch_no as batchNo,
        y.emptyWeight as emptyWeight,
        y.batchWeight as batchWeight,
        IFNULL((select z.storage_name
        from xzx_sys_storage z
        where a.sys_storage_id = z.id and a.sys_storage_type=1),(select m.partner_name from xzx_city_partner m where m.id=x.partner_id and a.sys_storage_type=2)) as sysStorageName,
        (select m.partner_name from xzx_city_partner m where m.id=x.partner_id) as partnerName
        from xzx_order_storage_info a
        LEFT JOIN (
        select f.create_time,b.order_id,b.vehicle_id,b.batch_no,b.weight as batchWeight,f.weight as emptyWeight from xzx_user_vehicle_info f
        LEFT JOIN  xzx_order_batch_info b ON f.id=b.vehicle_id
        WHERE  f.id=b.vehicle_id GROUP BY b.order_id
        )y ON y.order_id = a.order_id
        left join xzx_user_other_info x on x.user_id = a.storage_user_id
        where 1 = 1
        <if test="orderStatus != null and orderStatus != ''">
            AND a.storage_status = #{storageStatus}
        </if>
        <if test="storageStatus != null and storageStatus != ''">
            AND a.storage_status = #{storageStatus}
        </if>
        <if test="startTime != null and startTime != ''">
            AND a.storage_time >= #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
            AND a.storage_time &lt;= #{endTime}
        </if>
        <if test="name != null and name != ''">
            AND (a.receiver_name like concat('%',#{name} ,'%') or a.receiver_phone like concat('%',#{name} ,'%') or
            a.storage_id like concat('%',#{name} ,'%') )
        </if>
 
        <if test=" partnerIds != null and partnerIds.size() != 0">
            AND x.partner_id in
            <foreach collection="partnerIds" index="index" item="id" separator="," open="(" close=")">
                #{id}
            </foreach>
        </if>
        group by a.storage_id
        order by a.storage_time desc
    </select>
    <select id="queryStorageDetailApiList" resultType="map">
        SELECT a.order_id as orderid,a.create_time as createtime,
        c.name as name,c.mobile_phone as mobilephone,SUM(f.money) as ordermoney,SUM(f.weight) AS orderweight
        FROM xzx_order_info a
        LEFT JOIN xzx_order_detail_info b ON a.order_id = b.order_id
        LEFT JOIN xzx_user_other_info c ON a.receiver = c.user_id
        LEFT JOIN xzx_order_item_info f ON a.order_id = f.order_id
        WHERE 1=1
        <if test="orderIds != null and orderIds.size() != 0">
            AND a.order_id in
            <foreach collection="orderIds" index="index" item="id" separator="," open="(" close=")">
                #{id}
            </foreach>
        </if>
 
        GROUP BY a.order_id desc
    </select>
    <select id="queryStroageDetailPageByOrderno" resultType="map">
        select
        IFNULL(sum(a.money),0) as recyclemoney,
        IFNULL(sum(a.weight),0) as recycleweight,
        d.title,
        IFNULL((SELECT c.money
        from xzx_order_storage_detail c
        where a.item_type = c.item_type and c.flag=1
        <if test="storageId != null and storageId != ''">
            AND c.storage_id =#{storageId}
        </if>
        group by item_type),0) as storagemoney,
        IFNULL((SELECT c.weight
        from xzx_order_storage_detail c
        where a.item_type = c.item_type and c.flag=1
        <if test="storageId != null and storageId != ''">
            AND c.storage_id =#{storageId}
        </if>
        group by item_type),0) as storageweight
        from xzx_order_item_info a
        LEFT JOIN  (select f.township_id,e.order_id from  xzx_order_detail_info e
        LEFT JOIN xzx_user_address_info f on f.address_id=e.address_id
        )m  ON a.order_id=m.order_id
        LEFT JOIN xzx_sys_environmental_info d ON d.item_type = a.item_type and m.township_id=d.city_id
        where 1 = 1 AND a.money<![CDATA[> ]]>0 and a.weight<![CDATA[> ]]>0
        <if test="orderIds != null and orderIds.size() != 0">
            AND a.order_id in
            <foreach collection="orderIds" index="index" item="id" separator="," open="(" close=")">
                #{id}
            </foreach>
        </if>
        GROUP BY a.item_type
    </select>
    <select id="queryProvince" resultType="com.xzx.gc.model.admin.SysAddressLevelModel">
        select
            level_1_id   as level1Id,
            level_1_name as level1Name
        from xzx_sys_address_level_info
        where 1 = 1
        group by level_1_id
    </select>
    <select id="queryCityByProvinceId" resultType="com.xzx.gc.model.admin.SysAddressLevelModel">
        select
            level_2_id   as level2Id,
            level_2_name as level2Name
        from xzx_sys_address_level_info
        where 1 = 1 and level_1_id = #{provinceId}
        group by level_2_id
    </select>
    <select id="queryTownShipByCityId" resultType="com.xzx.gc.model.admin.SysAddressLevelModel">
        select
            level_3_id   as level3Id,
            level_3_name as level3Name
        from xzx_sys_address_level_info
        where 1 = 1 and level_2_id = #{cityId}
        group by level_3_id
    </select>
 
    <update id="updateOrderReserveTime">
        update xzx_order_detail_info
        set reserve_time = #{reserveDate},receive_time=null,receiver_name=null
        where order_id = #{orderId}
    </update>
 
    <update id="updateOrderInfoReserveTime">
        update xzx_order_info
        set reserve_time = #{reserveDate},order_status=1,receiver=null
        where order_id = #{orderId}
    </update>
 
    <delete id="updateOrderDetailByNo">
        update xzx_order_detail_info set mark_read='1' where  order_id=#{orderId}
    </delete>
 
    <select id="receiverStatsitic" resultType="com.xzx.gc.model.order.ReceiverStatsiticResDTO">
        SELECT
            c.NAME as name,
            date_format(a.create_time,'%Y-%m-%d') AS time,
            b.reserve_time AS reserveTime,
            b.receive_time AS receiveTime,
            a.order_status AS orderStatus,
            b.complete_time AS completeTime ,
            d.id as complaintId,
            b.weight,
            c.del_flag as "delFlag"
        FROM
            xzx_order_info a
            INNER JOIN xzx_order_detail_info b ON a.order_id = b.order_id
            LEFT JOIN xzx_order_complaint d ON b.order_id = d.order_id
            INNER JOIN xzx_user_other_info c ON a.receiver = c.user_id
        WHERE
            1 = 1
          <if test="key != null and key != ''">
              and (c.name like concat("%",#{key} ,"%") or c.mobile_phone like concat("%",#{key} ,"%"))
          </if>
          <if test="partnerId != null and partnerId != ''">
              and c.partner_id=#{partnerId}
          </if>
          <choose>
              <when test="type==1">
                  <if test="startTime != null and startTime != ''">
                      and date_format(a.create_time,'%Y-%m-%d') >= #{startTime}
                  </if>
                  <if test="endTime != null and endTime != ''">
                      and date_format(a.create_time,'%Y-%m-%d') &lt;= #{endTime}
                  </if>
              </when>
              <when test="type==2">
                    and  date_format(a.create_time,'%Y') = #{year}
              </when>
              <when test="type==3">
                  and  date_format(a.create_time,'%Y-%m') = concat(#{year},'-',#{month})
              </when>
              <otherwise>
 
              </otherwise>
          </choose>
    </select>
    <select id="ordergatherList" resultType="com.xzx.gc.model.user.UserGatherOrderRes">
        select
        a.order_id as "orderId",
        concat(ifnull(a.unit_name,''),ifnull(a.house_number,'')) as "detailAddress",
        a.address,
        a.rela_name as "name",
        a.create_user_id as "userId",
        a.create_time as "createTime",
        a.order_second_status "orderSecondStatus",
        c.complete_time as "completeTime",
        b.avatar
        from xzx_order_info a
        left join xzx_order_detail_info c on a.order_id=c.order_id
        inner join xzx_user_info b on a.create_user_id=b.user_id
        where a.order_type='3' and a.receiver=#{userId}
        <choose>
            <when test="orderStatus != null and orderStatus != ''">
                and a.order_status=#{orderStatus}
            </when>
        </choose>
 
        <if test="fliterType==1">
            and DATE_FORMAT(a.create_time,'%Y-%m-%d')=CURRENT_DATE()
        </if>
        <if test="latitude != null and latitude != ''">
          and ROUND(lat_lng_distance(#{latitude}, #{longitude}, a.latitude, a.longitude), 3)&lt;=0.5
        </if>
        order by  a.create_time desc
    </select>
 
 
    <select id="findServiceOrderByUserIdAndStatus" resultType="com.xzx.gc.entity.OrderInfo">
        SELECT
        a.order_id "orderId",
        a.create_user_id "createUserId",
        b.complete_time "completeTime",
        b.receive_time "receiveTime"
        FROM
        xzx_order_info a
        INNER JOIN xzx_order_detail_info b ON a.order_id = b.order_id
        where a.receiver=#{userId}  and a.order_status in
        <foreach collection="status" index="index" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
 
    </select>
 
    <!-- 订单列表查询 -->
    <select id="queryForHomeAppliance" parameterType="java.util.Map" resultMap="OrderMap">
        select distinct
        a.order_id,
        a.town_id,
        a.address,
        a.order_status,
        a.order_type,
        a.reserve_time,
        a.create_user_id,
        a.receiver,
        a.create_time,
        a.rela_phone,
        a.longitude,
        a.latitude,
        a.cancel_user_id,
        a.address_area,
        a.rela_name,
        a.order_second_status,
        a.create_type,
        a.store_id,
        d.take_phone_pic,
        d.storage_user_id,
        d.storage_user_name,
        d.storage_user_phone,
        d.remark,
        d.receiver_name,
        d.receiver_phone,
        d.complete_time,
        c.config_value_name "cancel_reason_name",
        d.receive_time,
        d.cancel_reason_name "cancelReason",
        d.address_id,
        d.order_fast_flag,
        d.home_service_id,
        d.note,
        d.home_appliance_id,
        d.change_receiver_flag
        <if test="latitude!=null and latitude!='' and longitude!=null and longitude!=''">
            ,ROUND(lat_lng_distance(#{latitude}, #{longitude}, a.latitude, a.longitude), 3) as distance
        </if>
        from xzx_order_info a
        left  join xzx_user_other_info b on a.receiver=b.user_id and b.del_flag=0 and b.is_prohibit=0
        inner join  xzx_order_detail_info d on a.order_id=d.order_id
        left join xzx_sys_config_info c on d.cancel_reason_code=c.config_value and c.config_type_code='CANCEL_REASON'
        where a.order_type='5' and a.town_id=#{townId}
        <choose>
            <when test="orderStatus==4">
                and (a.order_status=4 or a.order_status=7)
            </when>
            <otherwise>
                <if test="orderStatus!=null and orderStatus!=''">
                    and a.order_status=#{orderStatus}
                </if>
            </otherwise>
        </choose>
 
        <if test="orderStatus != null and orderStatus != '' and  orderStatus!=1">
          and a.receiver=#{receiver}
        </if>
 
        <choose>
            <when test="latitude!=null and latitude!='' and longitude!=null and longitude!='' and orderStatus==1">
                order by  distance asc,a.create_time desc
            </when>
            <otherwise>
                order by  a.create_time desc
            </otherwise>
        </choose>
 
    </select>
    <select id="findListOrderReceiveTime" resultType="com.xzx.gc.entity.OrderInfo">
        SELECT
            a.create_user_id as createUserId
        FROM
            xzx_order_info a
            INNER JOIN xzx_order_detail_info b ON a.order_id = b.order_id
        WHERE
            a.order_status = '2'  and a.receiver=#{receiver}
        ORDER BY
            b.receive_time ASC
    </select>
 
 
</mapper>