Helius
2022-05-27 4351e71d782741143a98f86f6648acd16689165f
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
<?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.matrix.system.hive.dao.AchieveNewDao">
    <!-- 定义AchieveNew 的复杂关联map -->
    <resultMap type="com.matrix.system.hive.bean.AchieveNew" id="AchieveNewMap">
        <id property="id" column="id" />
        <result property="saleId" column="sale_id" />
        <result property="beaultId" column="beault_id" />
        <result property="shopId" column="shop_id" />
        <result property="datatime" column="datatime" />
        <result property="orderId" column="order_id" />
        <result property="orderItemId" column="order_item_id" />
        <result property="shoppingGoodsId" column="shopping_goods_id" />
        <result property="serviceOrderId" column="service_order_id" />
        <result property="vipId" column="vip_id" />
        <result property="freeConsume" column="free_consume" />
        <result property="hisConsume" column="his_consume" />
        <result property="goodsCash" column="goods_cash" />
        <result property="cardCash" column="card_cash" />
        <result property="projNum" column="proj_num" />
        <result property="numberOfPeople" column="number_of_people" />
        <result property="shopName" column="shop_name" />
        <result property="projTime" column="proj_time" />
        <result property="remark" column="remark" />
        <result property="orderType" column="order_type" />
        <result property="projPercentage" column="proj_percentage" />
        <result property="t1" column="t1" />
        <result property="t2" column="t2" />
        <result property="achieveType" column="achieveType" />
        <result property="t4" column="t4" />
        <result property="t5" column="t5" />
        <result property="t6" column="t6" />
        <result property="t8" column="t8" />
        <result property="t9" column="t9" />
        <result property="companyId" column="company_id" />
 
        <result property="year" column="year" />
        <result property="month" column="month" />
        <result property="orderNo" column="order_no" />
        <result property="levelName" column="level_name" />
        <result property="vipName" column="vip_name" />
        <result property="proName" column="pro_name" />
        <result property="guwen" column="guwen" />
        <result property="meiliao" column="meiliao" />
        <result property="zkTotal" column="zk_total" />
        <result property="payMethod" column="pay_method" />
        <result property="arriveCnt" column="arrive_cnt" />
 
        <result property="goodsNo" column="goodsNo" />
        <result property="goodsName" column="goodsName" />
 
        <result property="cateName" column="cateName" />
        <result property="achieveRuleName" column="achieveRuleName" />
 
    </resultMap>
 
    <select id="findDayFlow" resultMap="AchieveNewMap">
        select
        a.datatime,
        YEAR (a.datatime) year,
        MONTH (a.datatime) month,
        DAY(a.datatime)
        day,
        IFNULL(b.order_no,l.SERVICE_NO) as order_no,
        d.level_name,
        c.vip_name,
        e.name as pro_name,
        b.ZK_TOTAL as zk_total,
        a.his_consume,
        er.name as achieveRuleName,
        a.free_consume,
        f.su_name meiliao,
        g.su_name guwen,
        a.proj_percentage,
        a.number_of_people,
        a.proj_num,
        a.proj_time,
        i.name as cateName,
        h.shop_short_name shop_name,
        a.order_type,
        a.achieveType,
        case when a.pay_method = '现金' then goods_cash end goods_cash,
        case when a.pay_method = '划扣' then goods_cash end card_cash,
        j.pay_method
        from
        achieve_new a
        left join sys_order b on a.order_id=b.id
        left join sys_vip_info c on a.vip_id=c.id
        left join sys_vip_level d on c.LEVEL_ID=d.id
        left join shopping_goods e on a.shopping_goods_id=e.id
        left join achieve_rule er on e.achieve_rule_id=er.id
        LEFT JOIN sys_users f on a.beault_id=f.su_id
        LEFT JOIN sys_users g on a.sale_id = g.su_id
        LEFT JOIN sys_shop_info h ON a.SHOP_ID = h.ID
        LEFT JOIN shopping_goods_category i ON e.cate_id = i.id
        left join sys_proj_services l on a.service_order_id=l.id
        left join sys_order_item j on a.order_item_id=j.ID
        <where>
            and    a.company_id = #{record.companyId}
            <if test="record!=null">
                <if
                        test="(record.shopId!=null and record.shopId!='') or  (record.shopId!='' and record.shopId==0)  ">
                    and a.shop_id = #{record.shopId}
                </if>
                <if test="record.achieveRuleId != null  ">
                    and e.achieve_rule_id = #{record.achieveRuleId}
                </if>
                <if test="record.year != null and record.year !='' ">
                    and YEAR (a.datatime) = #{record.year}
                </if>
                <if test="record.month != null and record.month !='' ">
                    and MONTH (a.datatime) = #{record.month}
                </if>
                <if test="record.day != null  and record.day !=''  ">
                    and DAY(a.datatime) = #{record.day}
                </if>
                <if test="(record.beginTime!=null  )">
                    and a.datatime <![CDATA[ > ]]>  #{record.beginTime}
                </if>
                <if test="(record.endTime!=null  )">
                    and a.datatime <![CDATA[ < ]]> #{record.endTime}
                </if>
                <if test="record.beaultId != null and record.beaultId !='' ">
                    and    a.beault_id = #{record.beaultId}
                </if>
 
                <if test="record.beaultId != null and record.beaultId !='' ">
                    and    a.beault_id = #{record.beaultId}
                </if>
                <if test="record.vipQueryKey != null and record.vipQueryKey != ''  ">
                    and c.VIP_NAME like concat('%',#{record.vipQueryKey},'%')
                    or (c.VIP_NO like concat('%',#{record.vipQueryKey},'%')
                    or c.PHONE like concat('%',#{record.vipQueryKey},'%')
                    )
                </if>
            </if>
        </where>
        <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 -->
            <if test="pageVo.sort !=null  and pageVo.order !=null">
                order by
                ${pageVo.sort} ${pageVo.order}
            </if>
            <if test="pageVo.offset >=0  and pageVo.limit >0">
                limit
                #{pageVo.offset},#{pageVo.limit}
            </if>
        </if>
 
 
    </select>
    <select id="findDayFlowTotal"
            resultType="java.lang.Integer">
        select count(*)
        from
        achieve_new a
        left join sys_order b on a.order_id=b.id
        left join sys_vip_info c on a.vip_id=c.id
        left join sys_vip_level d on c.LEVEL_ID=d.id
        left join shopping_goods e on a.shopping_goods_id=e.id
        LEFT JOIN sys_users f on a.beault_id=f.su_id
        LEFT JOIN sys_users g on a.sale_id = g.su_id
        LEFT JOIN sys_shop_info h ON a.SHOP_ID = h.ID
        LEFT JOIN shopping_goods_category i ON e.cate_id = i.id
        left join sys_proj_services l on a.service_order_id=l.id
        <where>
 
            <if test="record!=null">
                <if
                        test="(record.shopId!=null and record.shopId!='') or  (record.shopId!='' and record.shopId==0)  ">
                    and a.shop_id = #{record.shopId}
                </if>
                <if test="record.year != null and record.year !='' ">
                    and YEAR (a.datatime) = #{record.year}
                </if>
                <if test="record.month != null and record.month !='' ">
                    and MONTH (a.datatime) = #{record.month}
                </if>
                <if test="record.day != null   and record.day !='' ">
                    and DAY(a.datatime) = #{record.day}
                </if>
                <if test="record.beginTime!=null ">
                    and a.datatime <![CDATA[ > ]]>  #{record.beginTime}
                </if>
                <if test="record.endTime!=null">
                    and a.datatime <![CDATA[ < ]]> #{record.endTime}
                </if>
                <if test="record.companyId != null and record.companyId !='' ">
                    and    a.company_id = #{record.companyId}
                </if>
                <if test="record.beaultId != null and record.beaultId !='' ">
                    and    a.beault_id = #{record.beaultId}
                </if>
                <if test="record.vipQueryKey != null and record.vipQueryKey != ''  ">
                    and c.VIP_NAME like concat('%',#{record.vipQueryKey},'%')
                    or (c.VIP_NO like concat('%',#{record.vipQueryKey},'%')
                    or c.PHONE like concat('%',#{record.vipQueryKey},'%')
                    )
                </if>
            </if>
        </where>
    </select>
 
    <!--
 
     统计员工业绩
 
    select
            u.name,
            g.su_name guwen,
            cast(SUM(b.ZK_TOTAL) AS decimal(15,2)) as zk_total,
            cast(SUM(a.his_consume) AS decimal(15,2)),
            cast(SUM(a.free_consume) AS decimal(15,2)),
            cast(SUM(a.proj_percentage) AS decimal(15,2)),
            cast(SUM(a.number_of_people) AS decimal(15,2)),
            cast(SUM(a.proj_num) AS decimal(15,2)),
            cast(SUM(a.proj_time) AS decimal(15,2)),
            h.shop_short_name shop_name,
            a.order_type,
            a.achieveType
            from
            achieve_new a
            left join sys_order b on a.order_id=b.id
            left join sys_vip_info c on a.vip_id=c.id
            left join sys_vip_level d on c.LEVEL_ID=d.id
            left join shopping_goods e on a.shopping_goods_id=e.id
            LEFT JOIN sys_users f on a.beault_id=f.su_id
            LEFT JOIN sys_users g on a.sale_id = g.su_id
            LEFT JOIN sys_shop_info h ON a.SHOP_ID = h.ID
            LEFT JOIN shopping_goods_category i ON e.cate_id = i.id
            left join sys_proj_services l on a.service_order_id=l.id
            left join sys_order_item j on a.order_item_id=j.ID
            left join achieve_rule u on u.id=e.achieve_rule_id
     where h.shop_short_name='龙华店'
        GROUP BY g.su_name , a.order_type, h.id,a.achieveType
        ORDER BY g.su_name
 
    -->
 
 
    <select id="findSumDailyInfoNew" resultMap="AchieveNewMap">
        select
        YEAR (a.datatime) year,
        MONTH (a.datatime) month,
        DAY(a.datatime) day,
        SUM( IFNULL(a.goods_cash,0)  )as zk_total,
        SUM(a.goods_cash) as goods_cash,
        SUM(a.his_consume) as his_consume,
        SUM(a.free_consume) as free_consume,
        SUM(a.proj_percentage) as proj_percentage,
        SUM(a.number_of_people) as number_of_people,
        SUM(a.proj_num) as proj_num,
        SUM(a.proj_time) as proj_time,
        h.SHOP_NAME shop_name,
        a.shop_id
        from
        achieve_new a
        left join sys_order b on a.order_id=b.id
        left join sys_vip_info c on a.vip_id=c.id
        left join sys_vip_level d on c.LEVEL_ID=d.id
        left join shopping_goods e on a.shopping_goods_id=e.id
        LEFT JOIN sys_users f on a.beault_id=f.su_id
        LEFT JOIN sys_users g on a.sale_id = g.su_id
        LEFT JOIN sys_shop_info h ON a.SHOP_ID = h.ID
        LEFT JOIN shopping_goods_category i ON e.cate_id = i.id
        LEFT JOIN shopping_goods_category j ON i.parent_id = j.id
        left join sys_proj_services l on a.service_order_id=l.id
        <where>
 
            <if test="record!=null">
                <if
                        test="(record.shopId!=null and record.shopId!='') or  (record.shopId!='' and record.shopId==0)  ">
                    and a.shop_id = #{record.shopId}
                </if>
                <if test="record.year != null and record.year !='' ">
                    and YEAR (a.datatime) = #{record.year}
                </if>
                <if test="record.month != null and record.month !='' ">
                    and MONTH (a.datatime) = #{record.month}
                </if>
                <if test="record.day != null   and record.day !='' ">
                    and DAY(a.datatime) = #{record.day}
                </if>
                <if test="record.beginTime!=null ">
                    and a.datatime <![CDATA[ > ]]>  #{record.beginTime}
                </if>
                <if test="record.endTime!=null">
                    and a.datatime <![CDATA[ < ]]> #{record.endTime}
                </if>
                <if test="record.companyId != null and record.companyId !='' ">
                    and    a.company_id = #{record.companyId}
                </if>
            </if>
        </where>
        group by a.shop_id , DATE_FORMAT(a.datatime, '%Y-%m-%d')
        <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 -->
            <if test="pageVo.sort !=null  and pageVo.order !=null">
                order by
                ${pageVo.sort} ${pageVo.order}
            </if>
        </if>
 
    </select>
 
 
 
 
 
 
    <!-- 定义AchieveNew 的简单map ,本map不添加其他的关联属性 -->
    <resultMap type="com.matrix.system.hive.bean.AchieveNew" id="AchieveNewSimpleMap">
        <id property="id" column="id" />
        <result property="saleId" column="sale_id" />
        <result property="beaultId" column="beault_id" />
        <result property="shopId" column="shop_id" />
        <result property="datatime" column="datatime" />
        <result property="orderId" column="order_id" />
        <result property="orderItemId" column="order_item_id" />
        <result property="shoppingGoodsId" column="shopping_goods_id" />
        <result property="serviceOrderId" column="service_order_id" />
        <result property="vipId" column="vip_id" />
        <result property="freeConsume" column="free_consume" />
        <result property="hisConsume" column="his_consume" />
        <result property="goodsCash" column="goods_cash" />
        <result property="projNum" column="proj_num" />
        <result property="numberOfPeople" column="number_of_people" />
        <result property="shopName" column="shop_name" />
        <result property="projTime" column="proj_time" />
        <result property="remark" column="remark" />
        <result property="orderType" column="order_type" />
        <result property="projPercentage" column="proj_percentage" />
        <result property="payMethod" column="pay_method" />
        <result property="t1" column="t1" />
        <result property="t2" column="t2" />
        <result property="achieveType" column="achieveType" />
        <result property="t4" column="t4" />
        <result property="t5" column="t5" />
        <result property="t6" column="t6" />
        <result property="t8" column="t8" />
        <result property="t9" column="t9" />
        <result property="companyId" column="company_id" />
    </resultMap>
 
    <!-- 字段sql -->
    <sql id="columns">
        id,
        sale_id,
        beault_id,
        shop_id,
        datatime,
        order_id,
        order_item_id,
        shopping_goods_id,
        service_order_id,
        vip_id,
        free_consume,
        his_consume,
        goods_cash,
        proj_num,
        number_of_people,
        shop_name,
        proj_time,
        remark,
        order_type,
        proj_percentage,
 
        t1,
        t2,
        achieveType,
        t4,
        t5,
        t6,
        t8,
        t9,
        company_id,
pay_method
    </sql>
 
    <!-- 属性sql -->
    <sql id="propertys">
        #{item.id},
        #{item.saleId},
        #{item.beaultId},
        #{item.shopId},
        #{item.datatime},
        #{item.orderId},
        #{item.orderItemId},
        #{item.shoppingGoodsId},
        #{item.serviceOrderId},
        #{item.vipId},
        #{item.freeConsume},
        #{item.hisConsume},
        #{item.goodsCash},
        #{item.projNum},
        #{item.numberOfPeople},
        #{item.shopName},
        #{item.projTime},
        #{item.remark},
        #{item.orderType},
        #{item.projPercentage},
 
        #{item.t1},
        #{item.t2},
        #{item.achieveType},
        #{item.t4},
        #{item.t5},
        #{item.t6},
        #{item.t8},
        #{item.t9},
        #{item.companyId},
        #{item.payMethod}
    </sql>
 
    <!-- where sql -->
    <sql id="where_sql">
 
        <if test="record!=null">
            <if
                    test="(record.id!=null and record.id!='') or  (record.id!='' and record.id==0)  ">
                and id = #{record.id}
            </if>
            <if test="record.companyId != null and record.companyId !='' ">
                and company_id = #{record.companyId}
            </if>
            <if
                    test="(record.saleId!=null and record.saleId!='') or  (record.saleId!='' and record.saleId==0)  ">
                and sale_id = #{record.saleId}
            </if>
            <if
                    test="(record.beaultId!=null and record.beaultId!='') or  (record.beaultId!='' and record.beaultId==0)  ">
                and beault_id = #{record.beaultId}
            </if>
            <if
                    test="(record.shopId!=null and record.shopId!='') or  (record.shopId!='' and record.shopId==0)  ">
                and shop_id = #{record.shopId}
            </if>
            <if
                    test="(record.datatime!=null and record.datatime!='') or  (record.datatime!='' and record.datatime==0)  ">
                and datatime = #{record.datatime}
            </if>
            <if
                    test="(record.orderId!=null and record.orderId!='') or  (record.orderId!='' and record.orderId==0)  ">
                and order_id = #{record.orderId}
            </if>
            <if
                    test="(record.orderItemId!=null and record.orderItemId!='') or  (record.orderItemId!='' and record.orderItemId==0)  ">
                and order_item_id = #{record.orderItemId}
            </if>
            <if
                    test="(record.shoppingGoodsId!=null and record.shoppingGoodsId!='') or  (record.shoppingGoodsId!='' and record.shoppingGoodsId==0)  ">
                and shopping_goods_id = #{record.shoppingGoodsId}
            </if>
            <if
                    test="(record.serviceOrderId!=null and record.serviceOrderId!='') or  (record.serviceOrderId!='' and record.serviceOrderId==0)  ">
                and service_order_id = #{record.serviceOrderId}
            </if>
            <if
                    test="(record.vipId!=null and record.vipId!='') or  (record.vipId!='' and record.vipId==0)  ">
                and vip_id = #{record.vipId}
            </if>
            <if
                    test="(record.freeConsume!=null and record.freeConsume!='') or  (record.freeConsume!='' and record.freeConsume==0)  ">
                and free_consume = #{record.freeConsume}
            </if>
            <if
                    test="(record.hisConsume!=null and record.hisConsume!='') or  (record.hisConsume!='' and record.hisConsume==0)  ">
                and his_consume = #{record.hisConsume}
            </if>
 
 
            <if
                    test="(record.goodsCash!=null and record.goodsCash!='') or  (record.goodsCash!='' and record.goodsCash==0)  ">
                and goods_cash = #{record.goodsCash}
            </if>
            <if
                    test="(record.projNum!=null and record.projNum!='') or  (record.projNum!='' and record.projNum==0)  ">
                and proj_num = #{record.projNum}
            </if>
            <if
                    test="(record.numberOfPeople!=null and record.numberOfPeople!='') or  (record.numberOfPeople!='' and record.numberOfPeople==0)  ">
                and number_of_people = #{record.numberOfPeople}
            </if>
            <if
                    test="(record.shopName!=null and record.shopName!='') or  (record.shopName!='' and record.shopName==0)  ">
                and shop_name = #{record.shopName}
            </if>
            <if
                    test="(record.projTime!=null and record.projTime!='') or  (record.projTime!='' and record.projTime==0)  ">
                and proj_time = #{record.projTime}
            </if>
            <if
                    test="(record.remark!=null and record.remark!='') or  (record.remark!='' and record.remark==0)  ">
                and remark = #{record.remark}
            </if>
            <if
                    test="(record.orderType!=null and record.orderType!='') or  (record.orderType!='' and record.orderType==0)  ">
                and order_type = #{record.orderType}
            </if>
            <if
                    test="(record.projPercentage!=null and record.projPercentage!='') or  (record.projPercentage!='' and record.projPercentage==0)  ">
                and proj_percentage = #{record.projPercentage}
            </if>
            <if
                    test="(record.t1!=null and record.t1!='') or  (record.t1!='' and record.t1==0)  ">
                and t1 = #{record.t1}
            </if>
            <if
                    test="(record.t2!=null and record.t2!='') or  (record.t2!='' and record.t2==0)  ">
                and t2 = #{record.t2}
            </if>
            <if
                    test="(record.achieveType!=null and record.achieveType!='') or  (record.achieveType!='' and record.achieveType==0)  ">
                and achieveType = #{record.achieveType}
            </if>
            <if
                    test="(record.t4!=null and record.t4!='') or  (record.t4!='' and record.t4==0)  ">
                and t4 = #{record.t4}
            </if>
            <if
                    test="(record.t5!=null and record.t5!='') or  (record.t5!='' and record.t5==0)  ">
                and t5 = #{record.t5}
            </if>
            <if
                    test="(record.t6!=null and record.t6!='') or  (record.t6!='' and record.t6==0)  ">
                and t6 = #{record.t6}
            </if>
            <if
                    test="(record.t8!=null and record.t8!='') or  (record.t8!='' and record.t8==0)  ">
                and t8 = #{record.t8}
            </if>
            <if
                    test="(record.t9!=null and record.t9!='') or  (record.t9!='' and record.t9==0)  ">
                and t9 = #{record.t9}
            </if>
        </if>
 
    </sql>
 
    <!-- 插入方法 -->
    <insert id="insert" parameterType="com.matrix.system.hive.bean.AchieveNew"
            useGeneratedKeys="true" keyProperty="item.id">
        INSERT INTO achieve_new (
        <include refid="columns"></include>
        )
        VALUES (
        <include refid="propertys"></include>
        )
    </insert>
 
 
 
    <!-- 批量插入 -->
    <insert id="batchInsert" parameterType="java.util.List">
        INSERT INTO achieve_new (
        <include refid="columns"></include>
        )
        VALUES
        <foreach collection="list" item="item" index="index"
                 separator=",">
            (
            <include refid="propertys"></include>
            )
        </foreach>
    </insert>
 
 
 
 
 
    <!-- 根据Map更新 部分更新 -->
    <update id="updateByMap" parameterType="java.util.HashMap">
        UPDATE achieve_new
        <set>
            <if test="_parameter.containsKey('saleId')">
                sale_id = #{saleId},
            </if>
            <if test="_parameter.containsKey('beaultId')">
                beault_id = #{beaultId},
            </if>
            <if test="_parameter.containsKey('shopId')">
                shop_id = #{shopId},
            </if>
            <if test="_parameter.containsKey('datatime')">
                datatime = #{datatime},
            </if>
            <if test="_parameter.containsKey('orderId')">
                order_id = #{orderId},
            </if>
            <if test="_parameter.containsKey('orderItemId')">
                order_item_id = #{orderItemId},
            </if>
            <if test="_parameter.containsKey('shoppingGoodsId')">
                shopping_goods_id = #{shoppingGoodsId},
            </if>
            <if test="_parameter.containsKey('serviceOrderId')">
                service_order_id = #{serviceOrderId},
            </if>
            <if test="_parameter.containsKey('vipId')">
                vip_id = #{vipId},
            </if>
            <if test="_parameter.containsKey('freeConsume')">
                free_consume = #{freeConsume},
            </if>
            <if test="_parameter.containsKey('hisConsume')">
                his_consume = #{hisConsume},
            </if>
 
 
 
            <if test="_parameter.containsKey('goodsCash')">
                goods_cash = #{goodsCash},
            </if>
            <if test="_parameter.containsKey('projNum')">
                proj_num = #{projNum},
            </if>
            <if test="_parameter.containsKey('numberOfPeople')">
                number_of_people = #{numberOfPeople},
            </if>
            <if test="_parameter.containsKey('shopName')">
                shop_name = #{shopName},
            </if>
            <if test="_parameter.containsKey('projTime')">
                proj_time = #{projTime},
            </if>
            <if test="_parameter.containsKey('remark')">
                remark = #{remark},
            </if>
            <if test="_parameter.containsKey('orderType')">
                order_type = #{orderType},
            </if>
            <if test="_parameter.containsKey('projPercentage')">
                proj_percentage = #{projPercentage},
            </if>
 
            <if test="_parameter.containsKey('t1')">
                t1 = #{t1},
            </if>
            <if test="_parameter.containsKey('t2')">
                t2 = #{t2},
            </if>
            <if test="_parameter.containsKey('achieveType')">
                achieveType = #{achieveType},
            </if>
            <if test="_parameter.containsKey('t4')">
                t4 = #{t4},
            </if>
            <if test="_parameter.containsKey('t5')">
                t5 = #{t5},
            </if>
            <if test="_parameter.containsKey('t6')">
                t6 = #{t6},
            </if>
            <if test="_parameter.containsKey('t8')">
                t8 = #{t8},
            </if>
            <if test="_parameter.containsKey('t9')">
                t9 = #{t9},
            </if>
            <if test="_parameter.containsKey('payMethod')">
                pay_method = #{payMethod},
            </if>
        </set>
        WHERE id=#{id}
    </update>
 
 
    <!-- 根据对象更新 部分更新 -->
    <update id="updateAchieveTime" >
        UPDATE achieve_new set datatime = #{record.datatime}
        <where>
            <if
                    test="(record.id!=null and record.id!='') or  (record.id!='' and record.id==0)  ">
                and id = #{record.id}
            </if>
            <if
                    test="(record.orderId!=null and record.orderId!='') or  (record.orderId!='' and record.orderId==0)  ">
                and order_id = #{record.orderId}
            </if>
            <if
                    test="(record.serviceOrderId!=null and record.serviceOrderId!='') or  (record.serviceOrderId!='' and record.serviceOrderId==0)  ">
                and service_order_id = #{record.serviceOrderId}
            </if>
        </where>
 
 
    </update>
    <update id="updateByModel" >
        UPDATE achieve_new
        <set>
            <if test="record.saleId != null ">
                sale_id = #{record.saleId},
            </if>
            <if test="record.beaultId != null ">
                beault_id = #{record.beaultId},
            </if>
            <if test="record.shopId != null ">
                shop_id = #{record.shopId},
            </if>
            <if test="record.datatime != null ">
                datatime = #{record.datatime},
            </if>
            <if test="record.orderId != null ">
                order_id = #{record.orderId},
            </if>
            <if test="record.orderItemId != null ">
                order_item_id = #{record.orderItemId},
            </if>
            <if test="record.shoppingGoodsId != null ">
                shopping_goods_id = #{record.shoppingGoodsId},
            </if>
            <if test="record.serviceOrderId != null ">
                service_order_id = #{record.serviceOrderId},
            </if>
            <if test="record.vipId != null ">
                vip_id = #{record.vipId},
            </if>
            <if
                    test="record.freeConsume != null and record.freeConsume != '' ">
                free_consume = #{record.freeConsume},
            </if>
            <if test="record.hisConsume != null ">
                his_consume = #{record.hisConsume},
            </if>
 
 
            <if test="record.goodsCash != null ">
                goods_cash = #{record.goodsCash},
            </if>
            <if test="record.projNum != null ">
                proj_num = #{record.projNum},
            </if>
            <if test="record.numberOfPeople != null ">
                number_of_people = #{record.numberOfPeople},
            </if>
            <if test="record.shopName != null and record.shopName != '' ">
                shop_name = #{record.shopName},
            </if>
            <if test="record.projTime != null ">
                proj_time = #{record.projTime},
            </if>
            <if test="record.remark != null and record.remark != '' ">
                remark = #{record.remark},
            </if>
            <if test="record.orderType != null and record.orderType != '' ">
                order_type = #{record.orderType},
            </if>
            <if test="record.projPercentage != null ">
                proj_percentage = #{record.projPercentage},
            </if>
 
            <if test="record.t1 != null and record.t1 != '' ">
                t1 = #{record.t1},
            </if>
            <if test="record.t2 != null and record.t2 != '' ">
                t2 = #{record.t2},
            </if>
            <if test="record.achieveType != null and record.achieveType != '' ">
                achieveType = #{record.achieveType},
            </if>
            <if test="record.t4 != null and record.t4 != '' ">
                t4 = #{record.t4},
            </if>
            <if test="record.t5 != null and record.t5 != '' ">
                t5 = #{record.t5},
            </if>
            <if test="record.t6 != null and record.t6 != '' ">
                t6 = #{record.t6},
            </if>
            <if test="record.t8 != null and record.t8 != '' ">
                t8 = #{record.t8},
            </if>
            <if test="record.t9 != null and record.t9 != '' ">
                t9 = #{record.t9},
            </if>
            <if test="record.payMethod != null and record.payMethod != '' ">
                pay_method = #{record.payMethod},
            </if>
        </set>
        WHERE id=#{record.id}
    </update>
 
    <!-- 批量删除 -->
    <delete id="deleteByIds" parameterType="java.util.List">
        delete from achieve_new where id in
        <foreach collection="list" index="index" item="item" open="("
                 separator="," close=")">
            #{item}
        </foreach>
    </delete>
 
    <!-- 根据id删除 -->
    <delete id="deleteById" >
        DELETE FROM achieve_new
        where id=#{id}
    </delete>
 
    <!-- 根据对象删除 -->
    <delete id="deleteByModel" >
        DELETE FROM achieve_new
        where 1=1
        <include refid="where_sql"></include>
    </delete>
 
 
    <delete id="deleteByOrderId">
        DELETE FROM achieve_new where order_id=#{orderId}
    </delete>
 
 
 
    <!-- 分页查询 -->
    <select id="selectInPage" resultMap="AchieveNewMap">
        select
        <include refid="columns"></include>
        from achieve_new
        where 1=1
        <include refid="where_sql"></include>
        <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 -->
            <if test="pageVo.sort !=null  and pageVo.order !=null">
                order by
                ${pageVo.sort} ${pageVo.order}
            </if>
            <if test="pageVo.offset >=0  and pageVo.limit >0">
                limit
                #{pageVo.offset},#{pageVo.limit}
            </if>
        </if>
    </select>
 
    <!-- 查询总条数 -->
    <select id="selectTotalRecord"
            resultType="java.lang.Integer">
        select count(*)
        from achieve_new
        where 1=1
        <include refid="where_sql"></include>
    </select>
 
    <!-- 根据id查询 -->
    <select id="selectById" resultMap="AchieveNewMap">
        select
        <include refid="columns"></include>
        from achieve_new
        where id=#{id}
    </select>
 
 
    <!-- 根据id 锁表查询 -->
    <select id="selectForUpdate" resultMap="AchieveNewMap">
        select
        <include refid="columns"></include>
        from achieve_new
        where id=#{id}
        for update
    </select>
 
 
 
    <!-- 根据对象查询 -->
    <select id="selectByModel" resultMap="AchieveNewMap">
        select
        <include refid="columns"></include>
        from achieve_new
        where 1=1
        <include refid="where_sql"></include>
    </select>
 
 
    <select id="selectVipConsumeStatisticsList" resultType="java.util.HashMap">
        select
        a.VIP_NAME vipName,
        a.PHONE t9,
        b.su_name meiliao,
        (SELECT  sum(IFNULL(goods_cash,0)) from achieve_new where  pay_method='现金' and  VIP_ID=a.id
        <if test="record.beginTime != null"> and date_format(datatime, '%Y-%m-%d') >= date_format(#{record.beginTime}, '%Y-%m-%d') </if>
        <if test="record.endTime != null"> <![CDATA[ and date_format(datatime, '%Y-%m-%d') < date_format(#{record.endTime}, '%Y-%m-%d') ]]>     </if> )  as 'goodsCash'  ,
        (SELECT  sum(IFNULL(goods_cash,0)) from achieve_new where  pay_method='划扣' and  VIP_ID=a.id
        <if test="record.beginTime != null"> and date_format(datatime, '%Y-%m-%d') >= date_format(#{record.beginTime}, '%Y-%m-%d') </if>
        <if test="record.endTime != null"> <![CDATA[ and date_format(datatime, '%Y-%m-%d') < date_format(#{record.endTime}, '%Y-%m-%d') ]]>     </if>)  as 'cardCash'  ,
        (SELECT  sum(IFNULL(free_consume,0)) from achieve_new where   VIP_ID=a.id
        <if test="record.beginTime != null"> and date_format(datatime, '%Y-%m-%d') >= date_format(#{record.beginTime}, '%Y-%m-%d') </if>
        <if test="record.endTime != null"> <![CDATA[ and date_format(datatime, '%Y-%m-%d') < date_format(#{record.endTime}, '%Y-%m-%d') ]]>     </if>  )  as 'freeConsume'  ,
        (SELECT  sum(IFNULL(number_of_people,0)) from achieve_new where   VIP_ID=a.id
        <if test="record.beginTime != null"> and date_format(datatime, '%Y-%m-%d') >= date_format(#{record.beginTime}, '%Y-%m-%d') </if>
        <if test="record.endTime != null"> <![CDATA[ and date_format(datatime, '%Y-%m-%d') < date_format(#{record.endTime}, '%Y-%m-%d') ]]>     </if>  )  as 'arriveCnt'  ,
        (SELECT  sum(IFNULL(his_consume,0)) from achieve_new where   VIP_ID=a.id
        <if test="record.beginTime != null"> and date_format(datatime, '%Y-%m-%d') >= date_format(#{record.beginTime}, '%Y-%m-%d') </if>
        <if test="record.endTime != null"> <![CDATA[ and date_format(datatime, '%Y-%m-%d') < date_format(#{record.endTime}, '%Y-%m-%d') ]]>     </if> )  as 'hisConsume'
        from sys_vip_info a
        left join sys_users b on a.BEATUY_ID=b.su_id
        inner join sys_shop_info c on c.id=a.SHOP_ID
        <where>
 
            <if test="record.vipName != null and record.vipName !=''">
                and (a.vip_name like CONCAT(CONCAT('%', #{record.vipName}), '%') or a.vip_no=#{record.vipName} or a.phone = #{record.vipName})
            </if>
            <if test="record.shopId != null">
                and a.shop_id=#{record.shopId}
            </if>
            <if test="record.beaultId != null and record.beaultId!=''">
                and FIND_IN_SET(#{record.beaultId}, a.BEATUY_ID)
            </if>
            <if test='record.t1 == "on"'>
                and a.BEATUY_ID is not null
            </if>
        </where>
        <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 -->
            <if test="pageVo.sort !=null  and pageVo.order !=null">
                order by
                ${pageVo.sort} ${pageVo.order}
            </if>
            <if test="pageVo.offset >=0  and pageVo.limit >0">
                limit
                #{pageVo.offset},#{pageVo.limit}
            </if>
        </if>
    </select>
 
    <select id="selectVipConsumeStatisticsTotal" resultType="java.lang.Integer">
        select count(1)
        from sys_vip_info a
        left join sys_users b on a.BEATUY_ID=b.su_id
        inner join sys_shop_info c on c.id=a.SHOP_ID
        <where>
 
            <if test="record.vipName != null and record.vipName !=''">
                and (a.vip_name like CONCAT(CONCAT('%', #{record.vipName}), '%') or a.vip_no=#{record.vipName} or a.phone = #{record.vipName})
            </if>
            <if test="record.shopId != null">
                and a.shop_id=#{record.shopId}
            </if>
            <if test="record.beaultId != null and record.beaultId!=''">
                and FIND_IN_SET(#{record.beaultId}, a.BEATUY_ID)
            </if>
            <if test='record.t1 == "on"'>
                and a.BEATUY_ID is not null
            </if>
        </where>
    </select>
 
 
    <select id="selectUserAchieveByTime" resultType="com.matrix.system.app.vo.UserAchieveVo">
        select
            sale_id id,
            (select ifnull(sum(case pay_method when '现金' then goods_cash else 0 end),0)
             from achieve_new a
             where a.beault_id=#{userId}
               and (date_format(datatime, '%Y-%m-%d') >= date_format(#{startTime}, '%Y-%m-%d') and date_format(#{endTime}, '%Y-%m-%d') >= date_format(datatime, '%Y-%m-%d'))
            ) orderCash,
            (select ifnull(sum(case pay_method when '划扣' then goods_cash else 0 end),0)
             from achieve_new a
             where  a.beault_id=#{userId}
               and (date_format(datatime, '%Y-%m-%d') >= date_format(#{startTime}, '%Y-%m-%d') and date_format(#{endTime}, '%Y-%m-%d') >= date_format(datatime, '%Y-%m-%d'))
            ) cash,
            sum(case order_type when '订单' then proj_percentage else 0 end) cardUse,
            sum(IFNULL(his_consume, 0)) hisConsume,
            sum(IFNULL(free_consume, 0)) freeConsume,
            sum(case order_type when '服务单' then proj_percentage else 0 end) projCommission
        from achieve_new a
        where a.beault_id=#{userId}
          and (date_format(datatime, '%Y-%m-%d') >= date_format(#{startTime}, '%Y-%m-%d') and date_format(#{endTime}, '%Y-%m-%d') >= date_format(datatime, '%Y-%m-%d'))
    </select>
 
    <select id="selectApiOrderItemAchieve" resultType="com.matrix.system.app.vo.OrderDetailAchieveItemVo">
        select
            b.su_name name,
            IFNULL(a.goods_cash, 0) achieve
        from achieve_new a
                 inner join sys_users b on (a.beault_id=b.su_id or a.sale_id = b.su_id)
        where a.order_item_id=#{itemId} and order_type = '订单'
    </select>
 
    <select id="selectShopConsumeAchieveRanking" resultType="com.matrix.system.app.vo.RankingVo">
        select
        b.shop_short_name name,
        b.SHOP_IMAG photo,
        sum(IFNULL(a.free_consume,0) + IFNULL(a.his_consume,0)) amount
        from achieve_new a
        left join sys_shop_info b on a.shop_id=b.ID and b.shop_type!=1
        <where>
            <if test="record.companyId != null">
                and a.company_id=#{record.companyId}
            </if>
            <if test='record.t1 == "1" and record.datatime != null'>
                and date_format(datatime, '%Y-%m-%d') = date_format(#{record.datatime}, '%Y-%m-%d')
            </if>
            <if test='record.t1 == "2" and record.datatime != null'>
                and date_format(datatime, '%Y-%m') = date_format(#{record.datatime}, '%Y-%m')
            </if>
            <if test='record.t1 == "3" and record.datatime != null'>
                and date_format(datatime, '%Y') = date_format(#{record.datatime}, '%Y')
            </if>
            <if test='record.t1 == "4" and record.datatime != null'>
                and date_format(datatime, '%Y-%m-%d %u') = date_format(#{record.datatime}, '%Y-%m-%d %u')
            </if>
        </where>
        group by a.shop_id
        order by amount desc, a.shop_id
    </select>
 
    <select id="selectBeauticianConsumeAchieveRanking" resultType="com.matrix.system.app.vo.RankingVo">
        select
        b.su_name name,
        b.su_id id,
        b.su_photo photo,
        sum(IFNULL(a.free_consume,0) + IFNULL(a.his_consume, 0) ) amount,
        c.shop_short_name shopName
        from achieve_new a
        inner join sys_users b on a.beault_id=b.su_id
        left join sys_shop_info c on a.shop_id=c.ID
        <where>
            a.order_type='服务单'
            <if test="record.companyId != null">
                and a.company_id=#{record.companyId}
            </if>
            <if test="record.shopId != null">
                and a.shop_id=#{record.shopId}
            </if>
            <if test='record.t1 == "1" and record.datatime != null'>
                and date_format(datatime, '%Y-%m-%d') = date_format(#{record.datatime}, '%Y-%m-%d')
            </if>
            <if test='record.t1 == "2" and record.datatime != null'>
                and date_format(datatime, '%Y-%m') = date_format(#{record.datatime}, '%Y-%m')
            </if>
            <if test='record.t1 == "3" and record.datatime != null'>
                and date_format(datatime, '%Y') = date_format(#{record.datatime}, '%Y')
            </if>
            <if test='record.t1 == "4" and record.datatime != null'>
                and date_format(datatime, '%Y-%m-%d %u') = date_format(#{record.datatime}, '%Y-%m-%d %u')
            </if>
        </where>
        group by a.beault_id
        order by amount desc
    </select>
 
    <select id="selectOrderItemAchieveByOrderId" resultMap="AchieveNewMap">
        select
            a.*,
            b.code goodsNo,
            b.name goodsName,
            c.su_name meiliao,
            TRUNCATE(d.count*d.zk_price,2) zk_total
        from achieve_new a
                 left join shopping_goods b on a.shopping_goods_id=b.id
                 left join sys_users c on a.beault_id=c.su_id
                 left join sys_order_item d on a.order_item_id=d.id
        where a.order_id=#{orderId}
    </select>
 
    <select id="selectStaffSaleAchieveRanking" resultType="com.matrix.system.app.vo.RankingVo">
        select
        b.su_name name,
        b.su_id id,
        b.su_photo photo,
        sum(ifnull(goods_cash,0)) amount,
        c.shop_short_name shopName
        from achieve_new a
        inner join sys_users b on a.beault_id=b.su_id
        inner join sys_shop_info c on a.SHOP_ID=c.ID
        <where>
            <if test="record.companyId != null">
                and b.company_id=#{record.companyId}
            </if>
            <if test="record.shopId != null">
                and b.shop_id=#{record.shopId}
            </if>
            <if test='record.type == "1" and record.datatime != null'>
                and date_format(datatime, '%Y-%m-%d') = date_format(#{record.datatime}, '%Y-%m-%d')
            </if>
            <if test='record.type == "2" and record.datatime != null'>
                and date_format(datatime, '%Y-%m') = date_format(#{record.datatime}, '%Y-%m')
            </if>
            <if test='record.type == "3" and record.datatime != null'>
                and date_format(datatime, '%Y') = date_format(#{record.datatime}, '%Y')
            </if>
            <if test='record.t1 == "4" and record.datatime != null'>
                and date_format(datatime, '%Y-%m-%d %u') = date_format(#{record.datatime}, '%Y-%m-%d %u')
            </if>
        </where>
        group by b.su_id
        order by amount desc, b.su_id
    </select>
 
    <select id="selectShopSaleAchieveRanking" resultType="com.matrix.system.app.vo.RankingVo">
        select
        b.shop_short_name name,
        b.SHOP_IMAG photo,
        sum(IFNULL(a.amount,0)) amount
        from sys_order_flow a
        inner join sys_order c on a.order_id=c.id and c.STATU != '已取消'
        inner join sys_shop_info b on a.shop_id=b.id and shop_type!=1
        <where>
            a.pay_method not in ('储值卡', '欠款')
            <if test="record.companyId != null">
                and a.company_id=#{record.companyId}
            </if>
            <if test='record.t1 == "1" and record.datatime != null'>
                and date_format(a.create_time, '%Y-%m-%d') = date_format(#{record.datatime}, '%Y-%m-%d')
            </if>
            <if test='record.t1 == "2" and record.datatime != null'>
                and date_format(a.create_time, '%Y-%m') = date_format(#{record.datatime}, '%Y-%m')
            </if>
            <if test='record.t1 == "3" and record.datatime != null'>
                and date_format(a.create_time, '%Y') = date_format(#{record.datatime}, '%Y')
            </if>
            <if test='record.t1 == "4" and record.datatime != null'>
                and date_format(a.create_time, '%Y-%m-%d %u') = date_format(#{record.datatime}, '%Y-%m-%d %u')
            </if>
        </where>
        group by a.shop_id
        order by amount desc, a.shop_id
    </select>
 
    <!-- 顾问当天下单列表 -->
    <select id="selectSaleManAchieveList" resultMap="AchieveNewMap">
        select * from achieve_new
        where sale_id=#{saleId} and vip_id=#{vipId} and sale_id=beault_id
          and date_format(datatime, '%Y-%m-%d') = date_format(#{date}, '%Y-%m-%d')
    </select>
 
    <select id="selectBeautyManAchieveList" resultMap="AchieveNewMap">
        select * from achieve_new
        where beault_id=#{beautyId} and vip_id=#{vipId}
          and date_format(datatime, '%Y-%m-%d') = date_format(#{date}, '%Y-%m-%d')
    </select>
 
    <select id="achieveNewStatistics" resultType="com.matrix.system.hive.vo.AchieveNewStatisticsVo">
 
        select
        u.name ruleName,
        f.su_name guwen,
        f.su_id gwid,
        g.su_name createBy,
        g.su_id createId,
        cast(SUM(b.ZK_TOTAL) AS decimal(15,2)) as zk_total,
        cast(SUM(a.his_consume) AS decimal(15,2)) his_consume,
        cast(SUM(a.free_consume) AS decimal(15,2)) free_consume,
        cast(SUM(a.proj_percentage) AS decimal(15,2)) proj_percentage,
        cast(SUM(a.number_of_people) AS decimal(15,2)) number_of_people,
        cast(SUM(a.proj_num) AS decimal(15,2)) proj_num,
        cast(SUM(case when a.pay_method = '划扣' then goods_cash end )AS decimal(15,2)) card_cash,
        cast(SUM(a.proj_time) AS decimal(15,2)) proj_time,
        cast(SUM(case when a.pay_method = '现金' then goods_cash end )AS decimal(15,2)) goods_cash,
        h.shop_short_name shop_name,
        a.order_type
        from
        achieve_new a
        left join sys_order b on a.order_id=b.id
        left join sys_vip_info c on a.vip_id=c.id
        left join sys_vip_level d on c.LEVEL_ID=d.id
        left join shopping_goods e on a.shopping_goods_id=e.id
        LEFT JOIN sys_users f on a.beault_id=f.su_id
        LEFT JOIN sys_users g on a.sale_id = g.su_id
        LEFT JOIN sys_shop_info h ON a.SHOP_ID = h.ID
        LEFT JOIN shopping_goods_category i ON e.cate_id = i.id
        left join sys_proj_services l on a.service_order_id=l.id
        left join sys_order_item j on a.order_item_id=j.ID
        left join achieve_rule u on u.id=e.achieve_rule_id
        <where>
            and a.company_id = #{record.companyId}
            <if test="record.shopId != null">
                and a.shop_id = #{record.shopId}
            </if>
            <if test="record.achieveRuleId != null">
                and u.id = #{record.achieveRuleId}
            </if>
 
            <if test="record.staffName != null and record.staffName!=''">
                <!-- 创建人和归属人都有业绩 -->
                and (f.su_name like concat('%',#{record.staffName},'%')  or g.su_name like concat('%',#{record.staffName},'%')  )
            </if>
 
            <if test="record.orderType != null and record.orderType != '' ">
                and a.order_type= #{record.orderType}
            </if>
            <if test="record.beginTime != null ">
                and a.datatime >= #{record.beginTime}
            </if>
            <if test="record.endTime != null   ">
                <![CDATA[and a.datatime <= #{record.endTime}]]>
            </if>
 
        </where>
        GROUP BY g.su_id , f.su_id, a.order_type, h.id,a.achieveType,u.name
        <if test="record.sort !=null and record.sort!=''"> order by ${record.sort} ${record.order}</if>
 
    </select>
 
 
    <update id="updateAchieveNumOfPeople">
        <foreach collection="list" item="item" index="index"
                 separator=";">
            update achieve_new set number_of_people=#{num} where id=#{item.id}
        </foreach>
    </update>
    <update id="setPayMethod">
 
 
        update  achieve_new
        set pay_method=#{paymethod}
        where id in
        <foreach collection="list" index="index" item="item" open="("
                 separator="," close=")">
            #{item}
        </foreach>
 
 
    </update>
 
    <select id="selectNumOfPeopleAchieveRanking" resultType="com.matrix.system.app.vo.RankingVo">
        select
        b.su_name name,
        b.su_id id,
        b.su_photo photo,
        sum(number_of_people) amount,
        c.shop_short_name shopName
        from achieve_new a
        inner join sys_users b on a.beault_id=b.su_id
        left join sys_shop_info c on a.shop_id=c.ID
        <where>
            <if test="record.companyId != null">
                and a.company_id=#{record.companyId}
            </if>
            <if test="record.shopId != null">
                and a.shop_id=#{record.shopId}
            </if>
            <if test='record.t1 == "1" and record.datatime != null'>
                and date_format(datatime, '%Y-%m-%d') = date_format(#{record.datatime}, '%Y-%m-%d')
            </if>
            <if test='record.t1 == "2" and record.datatime != null'>
                and date_format(datatime, '%Y-%m') = date_format(#{record.datatime}, '%Y-%m')
            </if>
            <if test='record.t1 == "3" and record.datatime != null'>
                and date_format(datatime, '%Y') = date_format(#{record.datatime}, '%Y')
            </if>
            <if test='record.t1 == "4" and record.datatime != null'>
                and date_format(datatime, '%Y-%m-%d %u') = date_format(#{record.datatime}, '%Y-%m-%d %u')
            </if>
        </where>
        group by a.beault_id
        order by amount desc
    </select>
 
    <select id="selectDailyBeautyList" resultType="com.matrix.system.hive.vo.DailyBeautyListVo">
        select
            date_format(b.datatime, '%Y-%m-%d') datatime,
            a.su_id,
            a.su_name beautyName,
            c.id vipId,
            c.VIP_NAME,
            c.arrival_way,
            case when c.BEATUY_ID=a.su_id then 1 else 0 end isAppoint,
            (select count(distinct date_format(n.datatime, '%Y-%m-%d')) from achieve_new n
             where date_format(b.datatime, '%Y-%m') = date_format(n.datatime, '%Y-%m') and n.vip_id=c.ID
             group by date_format(n.datatime, '%Y-%m'))arriveCnt,
            (select count(1) from sys_order o where o.statu in ('欠款', '已付款') and o.VIP_ID=c.id)  orderCnt,
            (select group_concat(distinct q.pay_method) payMethod from sys_order p
               inner join sys_order_flow q on p.ID=q.ORDER_ID
               inner join achieve_new o on o.order_id=p.id
             where date_format(pay_time, '%Y-%m-%d') = date_format(b.datatime, '%Y-%m-%d') and o.beault_id=a.su_id and c.ID=q.vip_id and p.STATU in ('欠款', '已付款')
             group by p.VIP_ID) payMethods,
            (select sum(amount) from sys_order_flow x
                 inner join achieve_new y on x.order_id=y.order_id
             where x.pay_method='团购' and date_format(x.create_time, '%Y-%m-%d') = date_format(b.datatime, '%Y-%m-%d')
               and y.beault_id=a.su_id and x.vip_id=c.id ) teamPay,
            (select sum(m.ZK_PRICE) from sys_order_item m
                 inner join achieve_new n on n.ORDER_ID=m.order_id
             where date_format(m.create_time, '%Y-%m-%d') = date_format(b.datatime, '%Y-%m-%d')
               and m.type in ('套餐', '项目') and n.beault_id=a.su_id) tcAndProjCash,
            (select sum(m.ZK_PRICE) from sys_order_item m
                 inner join achieve_new n on n.ORDER_ID=m.order_id
             where date_format(m.create_time, '%Y-%m-%d') = date_format(b.datatime, '%Y-%m-%d')
               and m.type in ('家居产品') and n.beault_id=a.su_id) productCash,
            (select sum(m.ZK_PRICE) from sys_order_item m
                 inner join achieve_new n on n.ORDER_ID=m.order_id
             where date_format(m.create_time, '%Y-%m-%d') = date_format(b.datatime, '%Y-%m-%d')
               and m.type in ('充值卡') and n.beault_id=a.su_id) cardCash,
            (select sum(amount) from sys_order_flow x
                 inner join achieve_new y on x.order_id=y.order_id
             where x.pay_method='储值卡' and date_format(x.create_time, '%Y-%m-%d') = date_format(b.datatime, '%Y-%m-%d')
               and y.beault_id=a.su_id and x.vip_id=c.id) cardPay,
            (select sum(amount) from sys_order_flow x
                inner join achieve_new y on x.order_id=y.order_id
             where x.pay_method not in ('储值卡','欠款') and date_format(x.create_time, '%Y-%m-%d') = date_format(b.datatime, '%Y-%m-%d')
                and y.beault_id=a.su_id and x.vip_id=c.id) cashPay,
            (select sum(e.goods_cash) from achieve_new e
                inner join shopping_goods f on e.shopping_goods_id=f.id and f.is_cooperate=1
             where e.order_type='订单' and date_format(e.datatime, '%Y-%m-%d') = date_format(b.datatime, '%Y-%m-%d')
                and e.beault_id=a.su_id and e.vip_id=c.id) cooperateProj,
            sum(proj_percentage) ticheng,
            sum(IFNULL(free_consume,0) + IFNULL(his_consume,0)) consume,
            (select count(1) from achieve_new z where z.beault_id=a.su_id and c.id=z.vip_id and z.order_type='服务单' group by z.beault_id,z.vip_id) projCnt
        from sys_users a
             left join achieve_new b on a.su_id=b.beault_id
             left join sys_vip_info c on b.vip_id=c.ID
        where 1=1
        <if test="record.companyId != null">
         and a.company_id=#{record.companyId}
        </if>
        <if test="record.shopId != null">
          and a.shop_id=#{record.shopId}
        </if>
        <if test="record.beginTime != null">
            and date_format(b.datatime, '%Y-%m-%d') > date_format(#{record.beginTime}, '%Y-%m-%d')
        </if>
        <if test="record.endTime != null">
            and date_format(#{record.endTime}, '%Y-%m-%d') > date_format(b.datatime, '%Y-%m-%d')
        </if>
        <if test="record.beaultId != null">
            and a.su_id=#{record.beaultId}
        </if>
        <if test="record.vipQueryKey != null and record.vipQueryKey != ''">
            and c.vip_name like concat('%', #{record.vipQueryKey}, '%')
        </if>
        <if test="record.beginTime == null and record.endTime == null">
            and date_format(b.datatime, '%Y-%m') = date_format(now(), '%Y-%m')
        </if>
        group by date_format(b.datatime, '%Y-%m-%d'), a.su_id, c.ID
        <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 -->
            order by date_format(b.datatime, '%Y-%m-%d') desc, a.su_id
            <if test="pageVo.offset >=0  and pageVo.limit >0">
                limit
                #{pageVo.offset},#{pageVo.limit}
            </if>
        </if>
    </select>
 
    <select id="selectDailyBeautyListTotal" resultType="java.lang.Integer">
        select count(1) from (
             select
                 date_format(b.datatime, '%Y-%m-%d') datatime,
                 a.su_id,
                 a.su_name,
                 c.id vipId,
                 c.VIP_NAME,
                 c.arrival_way,
                 sum(proj_percentage) ticheng,
                 sum(IFNULL(free_consume,0) + IFNULL(his_consume,0)) consume
             from sys_users a
                      left join achieve_new b on a.su_id=b.beault_id
                      left join sys_vip_info c on b.vip_id=c.ID
            where 1=1
            <if test="record.companyId != null">
                and a.company_id=#{record.companyId}
            </if>
            <if test="record.shopId != null">
                and a.shop_id=#{record.shopId}
            </if>
            <if test="record.beginTime != null">
                and date_format(b.datatime, '%Y-%m-%d') > date_format(#{record.beginTime}, '%Y-%m-%d')
            </if>
            <if test="record.endTime != null">
                and date_format(#{record.endTime}, '%Y-%m-%d') > date_format(b.datatime, '%Y-%m-%d')
            </if>
            <if test="record.beaultId != null">
                and a.su_id=#{record.beaultId}
            </if>
            <if test="record.vipQueryKey != null and record.vipQueryKey != ''">
                and c.vip_name like concat('%', #{record.vipQueryKey}, '%')
            </if>
            <if test="record.beginTime == null and record.endTime == null">
                and date_format(b.datatime, '%Y-%m') = date_format(now(), '%Y-%m')
            </if>
             group by date_format(b.datatime, '%Y-%m-%d'), a.su_id, c.ID
        ) a
    </select>
 
    <select id="selectPlInfoByVipIdAndDate" resultType="java.lang.String">
        select group_concat(concat(name,'*', bb))
        from (select l.name name, 0+CAST(sum(n.amount) as char) bb from sys_out_store m
         inner join sys_out_store_item n on m.id=n.OUT_STORE_ID
         inner join shopping_goods l on n.SKU_ID=l.id
       where m.SERVICE_ID in (select distinct service_order_id from achieve_new where date_format(datatime, '%Y-%m-%d') = date_format(#{datatime}, '%Y-%m-%d') and vip_id=#{vipId})
       group by l.id) a
    </select>
</mapper>