username@email.com
2021-09-10 83c4efe25b7b5ee027a34987f8ee508a379c1d47
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoMapper;
using AngleSharp.Html.Parser;
using DTO;
using IServices;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Net.Http;
using System.Threading.Tasks;
using zhengcaioa.Models;
using zhengcaioa.IService;
using CommonToolsCore;
using Services;
using System.Transactions;
using System.IdentityModel.Tokens.Jwt;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json.Linq;
using System.Net.Http.Headers;
 
namespace zhengcaioa.Controllers.BusinessOrder
{
   
    public class CooperOrderController : Controller
    {
        private readonly ILogger<CooperOrderController> _logger;
        private readonly ILiaotianService _liaotianService;
        private readonly IUserService _userService;
        private readonly ICooperOrderService _cooperOrderService;
        private readonly ICooperatecustomCustomerService _cooperatecustomCustomerService;
        private readonly IProjectService _projectService;
        private readonly IPltPageService _pltPageService;
        private readonly IFiBookService _fiBookService;
        private readonly IFiServiceService _fiServiceService;
        private readonly IFiMemberService _fiMemberService;
        private readonly IConfiguration _configuration;
        private readonly IHttpClientFactory _clientFactory;
        private readonly IAskService _askService; 
 
 
        public CooperOrderController(ILogger<CooperOrderController> logger, ILiaotianService liaotianService, IUserService userService, ICooperOrderService cooperOrderService
            , ICooperatecustomCustomerService cooperatecustomCustomerService, IProjectService projectService, IPltPageService pltPageService, IFiBookService fiBookService
            , IFiServiceService fiServiceService, IFiMemberService fiMemberService
            , IConfiguration configuration
            , IHttpClientFactory clientFactory
            , IAskService askService)
        {
            _logger = logger;
            _liaotianService = liaotianService;
            _userService = userService;
            _cooperOrderService = cooperOrderService;
            _cooperatecustomCustomerService = cooperatecustomCustomerService;
            _projectService = projectService;
            _pltPageService = pltPageService;
            _fiBookService = fiBookService;
            _fiServiceService = fiServiceService;
            _fiMemberService = fiMemberService;
            _configuration = configuration;
            _clientFactory = clientFactory;
            _askService = askService;
        }
 
        [CheckLogin]
        public IActionResult Index()
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            List<ActionEntity> actionlist = new List<ActionEntity>();
            ActionEntity actionEntity = new ActionEntity();
            actionEntity.OpenType = 0;
            actionEntity.ActionUrl = "";
            actionEntity.ActionFun = "Search";
            actionEntity.PageIco = "fa fa-search";
            actionEntity.ActionName = "查询";
            actionlist.Add(actionEntity);
            ActionEntity actionEntity1 = new ActionEntity();
            actionEntity1.OpenType = 0;
            actionEntity1.ActionUrl = "";
            actionEntity1.ActionFun = "Add";
            actionEntity1.PageIco = "fa fa-plus";
            actionEntity1.ActionName = "新增";
            actionlist.Add(actionEntity1);
 
            ActionEntity actionEntity3 = new ActionEntity();
            actionEntity3.OpenType = 0;
            actionEntity3.ActionUrl = "";
            actionEntity3.ActionFun = "Print";
            actionEntity3.PageIco = "fa fa-print";
            actionEntity3.ActionName = "打印";
            actionlist.Add(actionEntity3);
 
            ViewData["ActionInfo"] = actionlist;
 
            List<PageEntity> pageEntities = _pltPageService.GetUserPage(curentuser.Id, "/CooperOrder/Index/");
 
            ViewBag.pageEntities = pageEntities;
 
            ViewBag.OrderType = _liaotianService.GetSYScode("CooperVisit", "jtype").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
            ViewBag.users = _userService.GetList().Where(x => x.IsYwjl == "A").Select(x => new { code = x.Id, label = x.UserName }).ToList();
 
            ViewBag.Khlx = _liaotianService.GetSYScode("CooperatecustomCustomer", "khlx").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
 
            ViewBag.HuifangStatus = _liaotianService.GetSYScode("CooperOrder", "huifang_status").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
 
            ViewBag.PingjiaStatus = _liaotianService.GetSYScode("CooperOrder", "pingjia_status").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
 
            ViewBag.ShouliStatus = _liaotianService.GetSYScode("CooperOrder", "shouli_status").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
            return View();
 
        }
 
 
 
        [CheckLogin]
        public IActionResult GetList(CooperOrderDTOSearch search)
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            //search.Creater = curentuser.Id;
            //JsonResult jsonResult =   new JsonResult(_liaotianService.SearchByPaging(search), new Newtonsoft.Json.Serialization.DefaultContractResolver());
            return new JsonResult(_cooperOrderService.SearchByPaging(search));
        }
 
        [CheckLogin]
        public IActionResult ShouliList()
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            List<ActionEntity> actionlist = new List<ActionEntity>();
            ActionEntity actionEntity = new ActionEntity();
            actionEntity.OpenType = 0;
            actionEntity.ActionUrl = "";
            actionEntity.ActionFun = "Search";
            actionEntity.PageIco = "fa fa-search";
            actionEntity.ActionName = "查询";
            actionlist.Add(actionEntity);
 
            ViewData["ActionInfo"] = actionlist;
 
            ViewBag.OrderType = _liaotianService.GetSYScode("CooperVisit", "jtype").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
            ViewBag.users = _userService.GetList().Where(x => x.IsYwjl == "A").Select(x => new { code = x.Id, label = x.UserName }).ToList();
 
            ViewBag.Khlx = _liaotianService.GetSYScode("CooperatecustomCustomer", "khlx").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
 
            ViewBag.HuifangStatus = _liaotianService.GetSYScode("CooperOrder", "huifang_status").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
 
            ViewBag.PingjiaStatus = _liaotianService.GetSYScode("CooperOrder", "pingjia_status").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
 
            return View();
 
        }
        [CheckLogin]
        public IActionResult GetListshouli(CooperOrderDTOSearch search)
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            //search.ShouliStatus = "A";
            //JsonResult jsonResult =   new JsonResult(_liaotianService.SearchByPaging(search), new Newtonsoft.Json.Serialization.DefaultContractResolver());
            return new JsonResult(_cooperOrderService.SearchByPaging(search));
        }
 
 
        [CheckLogin]
        public IActionResult ChedanList()
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            List<ActionEntity> actionlist = new List<ActionEntity>();
            ActionEntity actionEntity = new ActionEntity();
            actionEntity.OpenType = 0;
            actionEntity.ActionUrl = "";
            actionEntity.ActionFun = "Search";
            actionEntity.PageIco = "fa fa-search";
            actionEntity.ActionName = "查询";
            actionlist.Add(actionEntity);
 
            ViewData["ActionInfo"] = actionlist;
 
            ViewBag.OrderType = _liaotianService.GetSYScode("CooperVisit", "jtype").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
            ViewBag.users = _userService.GetList().Where(x => x.IsYwjl == "A").Select(x => new { code = x.Id, label = x.UserName }).ToList();
 
            ViewBag.Khlx = _liaotianService.GetSYScode("CooperatecustomCustomer", "khlx").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
 
            ViewBag.HuifangStatus = _liaotianService.GetSYScode("CooperOrder", "huifang_status").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
 
            ViewBag.PingjiaStatus = _liaotianService.GetSYScode("CooperOrder", "pingjia_status").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
 
            return View();
 
        }
        [CheckLogin]
        public IActionResult GetListchedan(CooperOrderDTOSearch search)
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            //search.ShouliStatus = "A";
            //JsonResult jsonResult =   new JsonResult(_liaotianService.SearchByPaging(search), new Newtonsoft.Json.Serialization.DefaultContractResolver());
            return new JsonResult(_cooperOrderService.SearchByPaging(search));
        }
 
        [CheckLogin]
        public IActionResult WangongList()
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            List<ActionEntity> actionlist = new List<ActionEntity>();
            ActionEntity actionEntity = new ActionEntity();
            actionEntity.OpenType = 0;
            actionEntity.ActionUrl = "";
            actionEntity.ActionFun = "Search";
            actionEntity.PageIco = "fa fa-search";
            actionEntity.ActionName = "查询";
            actionlist.Add(actionEntity);
 
            ViewData["ActionInfo"] = actionlist;
 
            ViewBag.OrderType = _liaotianService.GetSYScode("CooperVisit", "jtype").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
            ViewBag.users = _userService.GetList().Where(x => x.IsYwjl == "A").Select(x => new { code = x.Id, label = x.UserName }).ToList();
 
            ViewBag.Khlx = _liaotianService.GetSYScode("CooperatecustomCustomer", "khlx").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
 
            ViewBag.HuifangStatus = _liaotianService.GetSYScode("CooperOrder", "huifang_status").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
 
            ViewBag.PingjiaStatus = _liaotianService.GetSYScode("CooperOrder", "pingjia_status").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
 
            return View();
 
        }
        [CheckLogin]
        public IActionResult GetListwangong(CooperOrderDTOSearch search)
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            search.ShouliStatus = "A";
            search.ChedanStatus = "D"; 
            //JsonResult jsonResult =   new JsonResult(_liaotianService.SearchByPaging(search), new Newtonsoft.Json.Serialization.DefaultContractResolver());
            return new JsonResult(_cooperOrderService.SearchByPaging(search));
        }
        [CheckLogin]
        public IActionResult SonghuoList()
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            List<ActionEntity> actionlist = new List<ActionEntity>();
            ActionEntity actionEntity = new ActionEntity();
            actionEntity.OpenType = 0;
            actionEntity.ActionUrl = "";
            actionEntity.ActionFun = "Search";
            actionEntity.PageIco = "fa fa-search";
            actionEntity.ActionName = "查询";
            actionlist.Add(actionEntity);
 
 
 
            ViewData["ActionInfo"] = actionlist;
 
            ViewBag.OrderType = _liaotianService.GetSYScode("CooperVisit", "jtype").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
            ViewBag.users = _userService.GetList().Where(x => x.IsYwjl == "A").Select(x => new { code = x.Id, label = x.UserName }).ToList();
 
            ViewBag.Khlx = _liaotianService.GetSYScode("CooperatecustomCustomer", "khlx").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
 
            ViewBag.HuifangStatus = _liaotianService.GetSYScode("CooperOrder", "huifang_status").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
 
            ViewBag.PingjiaStatus = _liaotianService.GetSYScode("CooperOrder", "pingjia_status").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
 
            return View();
 
        }
        [CheckLogin]
        public IActionResult GetListsonghuo(CooperOrderDTOSearch search)
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            search.WangongStatus = "A";
            search.ChedanStatus = "D";
            //JsonResult jsonResult =   new JsonResult(_liaotianService.SearchByPaging(search), new Newtonsoft.Json.Serialization.DefaultContractResolver());
            return new JsonResult(_cooperOrderService.SearchByPaging(search));
        }
        [CheckLogin]
        public IActionResult HuifangList()
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            List<ActionEntity> actionlist = new List<ActionEntity>();
            ActionEntity actionEntity = new ActionEntity();
            actionEntity.OpenType = 0;
            actionEntity.ActionUrl = "";
            actionEntity.ActionFun = "Search";
            actionEntity.PageIco = "fa fa-search";
            actionEntity.ActionName = "查询";
            actionlist.Add(actionEntity);
 
            ViewData["ActionInfo"] = actionlist;
 
            ViewBag.OrderType = _liaotianService.GetSYScode("CooperVisit", "jtype").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
            ViewBag.users = _userService.GetList().Where(x => x.IsYwjl == "A").Select(x => new { code = x.Id, label = x.UserName }).ToList();
 
            ViewBag.Khlx = _liaotianService.GetSYScode("CooperatecustomCustomer", "khlx").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
 
            ViewBag.HuifangStatus = _liaotianService.GetSYScode("CooperOrder", "huifang_status").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
 
            ViewBag.PingjiaStatus = _liaotianService.GetSYScode("CooperOrder", "pingjia_status").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
 
            return View();
 
        }
        [CheckLogin]
        public IActionResult GetListHuifang(CooperOrderDTOSearch search)
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            search.SonghuoStatus = "A";
            search.ChedanStatus = "D";
            //JsonResult jsonResult =   new JsonResult(_liaotianService.SearchByPaging(search), new Newtonsoft.Json.Serialization.DefaultContractResolver());
            return new JsonResult(_cooperOrderService.SearchByPaging(search));
        }
        [CheckLogin]
        public IActionResult PingjiaList()
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            List<ActionEntity> actionlist = new List<ActionEntity>();
            ActionEntity actionEntity = new ActionEntity();
            actionEntity.OpenType = 0;
            actionEntity.ActionUrl = "";
            actionEntity.ActionFun = "Search";
            actionEntity.PageIco = "fa fa-search";
            actionEntity.ActionName = "查询";
            actionlist.Add(actionEntity);
 
            ViewData["ActionInfo"] = actionlist;
 
            ViewBag.OrderType = _liaotianService.GetSYScode("CooperVisit", "jtype").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
            ViewBag.users = _userService.GetList().Where(x => x.IsYwjl == "A").Select(x => new { code = x.Id, label = x.UserName }).ToList();
 
            ViewBag.Khlx = _liaotianService.GetSYScode("CooperatecustomCustomer", "khlx").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
 
            ViewBag.HuifangStatus = _liaotianService.GetSYScode("CooperOrder", "huifang_status").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
 
            ViewBag.PingjiaStatus = _liaotianService.GetSYScode("CooperOrder", "pingjia_status").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
 
            return View();
 
        }
        [CheckLogin]
        public IActionResult GetListPingjia(CooperOrderDTOSearch search)
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            search.HuifangStatussss = "A";
            search.ChedanStatus = "D";
            //JsonResult jsonResult =   new JsonResult(_liaotianService.SearchByPaging(search), new Newtonsoft.Json.Serialization.DefaultContractResolver());
            return new JsonResult(_cooperOrderService.SearchByPaging(search));
        }
 
        public IActionResult YouhuiList()
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            List<ActionEntity> actionlist = new List<ActionEntity>();
            ActionEntity actionEntity = new ActionEntity();
            actionEntity.OpenType = 0;
            actionEntity.ActionUrl = "";
            actionEntity.ActionFun = "Search";
            actionEntity.PageIco = "fa fa-search";
            actionEntity.ActionName = "查询";
            actionlist.Add(actionEntity);
 
          
 
            ViewData["ActionInfo"] = actionlist;
 
            ViewBag.OrderType = _liaotianService.GetSYScode("CooperVisit", "jtype").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
            ViewBag.users = _userService.GetList().Where(x => x.IsYwjl == "A").Select(x => new { code = x.Id, label = x.UserName }).ToList();
 
            ViewBag.Khlx = _liaotianService.GetSYScode("CooperatecustomCustomer", "khlx").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
 
            ViewBag.HuifangStatus = _liaotianService.GetSYScode("CooperOrder", "huifang_status").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
 
            ViewBag.PingjiaStatus = _liaotianService.GetSYScode("CooperOrder", "pingjia_status").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
 
            return View();
 
        }
        [CheckLogin]
        public IActionResult GetListYouhui(CooperOrderDTOSearch search)
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            search.ShouliStatus = "A";
            search.ChedanStatus = "D";
            //JsonResult jsonResult =   new JsonResult(_liaotianService.SearchByPaging(search), new Newtonsoft.Json.Serialization.DefaultContractResolver());
            return new JsonResult(_cooperOrderService.SearchByPaging(search));
        }
        [CheckLogin]
        public IActionResult Edit(string id = null, string ShouliStatus = "1")
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
 
            CooperOrderDTO dto = new CooperOrderDTO();
            if (!String.IsNullOrEmpty(id))
            {
                dto = _cooperOrderService.Get(id);
                ViewBag.ShouliStatus = ShouliStatus;
                //ViewBag.YouHuiList = _askService.GetAskYouHuiList(dto.Khdw, dto.OrderType);
            }
            else
            {
                dto.XdTime = DateTime.Now;
                dto.OrderNum = 1;
                ViewBag.ShouliStatus = "1";
                //ViewBag.YouHuiList = new List<AdmAskYouHuiDTO>();
            }
 
 
 
 
 
            ViewBag.OrderType = _liaotianService.GetSYScode("CooperVisit", "jtype");
 
            ViewBag.customer = _cooperatecustomCustomerService.GetList();
 
            //ViewBag.project = _projectService.GetList();
 
          
 
 
            ViewData.Model = dto;
            return View();
        }
 
 
        /// <summary>
        /// 获取市
        /// </summary>
        /// <param name="shengid">省id</param>
        /// <returns></returns>
        /// 
        [CheckLogin]
        public string getProject()
        {
            var shi = _projectService.GetList().Select(x => new { Id = x.Id, Name = x.Name }).ToList(); ;
 
            return JsonConvert.SerializeObject(shi);
 
        }
 
 
 
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="data">岗位实体类对象</param>
        /// <returns></returns>
        /// 
        [CheckLogin]
        [HttpPost]
        public async Task<IActionResult> SaveAsync(CooperOrderDTO data)
        {
            ResultEntity resultEntity = new ResultEntity();
            //using (TransactionScope scope = new TransactionScope())
            //{
                var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
                ViewData["curentuser"] = curentuser;
                data.RecStatus = "A";
                if (String.IsNullOrEmpty(data.Id))
                {
                    data.Creater = curentuser.Id;
                    data.Createtime = DateTime.Now;
                    data.XdTime = data.Createtime;
                    if (data.OrderType == "03" || data.OrderType == "07" || (data.OrderType == "02" && (data.OrderType1 == "代拟投诉书" || data.OrderType1 == "代拟质疑函")))
                    {
                        var cooperatecustomCustomerDTO = _cooperatecustomCustomerService.Get(data.Khdw);
                        if (cooperatecustomCustomerDTO != null && !string.IsNullOrEmpty(cooperatecustomCustomerDTO.HuiyuanId))
                        {
                            string huiyuanurl = _configuration.GetSection("huiyuanurl").Value;
                            string SetCaseOrder = _configuration.GetSection("SetCaseOrder").Value;
 
                            Uri postUrl2 = new Uri(huiyuanurl + SetCaseOrder);
 
                            JObject questions2 = new JObject();
                            questions2.Add("UserID", cooperatecustomCustomerDTO.HuiyuanId);
                            if (data.OrderType == "03")
                            {
                                questions2.Add("CaseType", 0);
                            }
                            else if (data.OrderType == "07")
                            {
                                questions2.Add("CaseType", 1);
                            }
                            else if (data.OrderType == "07")
                            {
                                questions2.Add("CaseType", 1);
                            }
                            else if (data.OrderType == "02" && (data.OrderType1 == "代拟投诉书" || data.OrderType1 == "代拟质疑函"))
                            {
                                questions2.Add("CaseType", 2);
                            }
 
                            questions2.Add("count", Decimal.ToInt32(data.OrderNum.Value)  );
 
                            string requestJson2 = questions2.ToString();
                            string result2 = string.Empty;
 
                            using (HttpContent httpContent = new StringContent(requestJson2))
                            {
                                httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
 
                                var httpClient2 = _clientFactory.CreateClient();
                                httpClient2.Timeout = new TimeSpan(0, 0, 10);
                                var Result2 = await httpClient2.PostAsync(postUrl2, httpContent);
                                result2 = Result2.Content.ReadAsStringAsync().Result;
                            }
 
                            _logger.LogInformation("result2:" + result2);
                            JObject jobjectresult = (JObject)JsonConvert.DeserializeObject(result2);
 
                            if (jobjectresult["code"] != null && jobjectresult["code"].ToString() == "1")
                            {
                                resultEntity.Result = true;
                            }
                            else
                            {
                                resultEntity.Result = false;
                                resultEntity.Message = "写入会员订单失败";
                                return new JsonResult(resultEntity);
                            }
                        }
                    }
 
 
                
 
                    
                }
 
            var youHuiDTOs = _askService.GetAskYouHuiList(data.Khdw, data.OrderType).FirstOrDefault();
            if (youHuiDTOs != null)
            {
                data.Youhuier = youHuiDTOs.Id;
                if(youHuiDTOs.Youhuistandard == "01")
                {
                    data.Youhui = youHuiDTOs.YouHui.Value;
                    if(data.Money.Value < data.Youhui.Value)
                    {
                        data.Money = 0;
                    }
                    else
                    {
                        data.Money = data.Money.Value - data.Youhui.Value;
                    }
                   
                }
                else if (youHuiDTOs.Youhuistandard == "02")
                {
                    if (youHuiDTOs.YouHui.Value >= 100)
                    {
                        data.Youhui = data.Money.Value;
                        data.Money = 0;
                    }
                    else
                    {
                        data.Youhui =Math.Round(data.Money.Value * youHuiDTOs.YouHui.Value * new decimal(0.01),2);
                        data.Money = data.Money.Value - data.Youhui.Value;
                    }
                }
                  
                  
            }
            
            data.ShouliStatus = "1";
            data.Modifier = curentuser.Id;
            data.Modifytime = DateTime.Now;
 
            resultEntity = _cooperOrderService.save(data);
            //    scope.Complete();
            //}
 
 
            return new JsonResult(resultEntity);
        }
 
 
        /// <summary>
        /// 删除主信息
        /// </summary>
        /// <param name="info">实体</param>
        /// <returns></returns>
        /// 
        [CheckLogin]
        public IActionResult Nullify(string Id = "")
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            return new JsonResult(_cooperOrderService.ModifyStatus(Id, curentuser.Id));
        }
 
 
        /// <summary>
        /// 受理
        /// </summary>
        /// <param name="data">岗位实体类对象</param>
        /// <returns></returns>
        /// 
        [CheckLogin]
        public IActionResult Shouli(string id)
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            ResultEntity resultEntity = new ResultEntity();
            resultEntity.Result = false;
 
            CooperOrderDTO dto = _cooperOrderService.Get(id);
            if(dto.ShouliStatus != "1")
            {
                resultEntity.Result = false;
                resultEntity.Message = "只有已下单状态的订单才能受理";
                return new JsonResult(resultEntity);
            }
 
            dto.Shoulier = curentuser.Id;
            dto.Shoulitime = DateTime.Now;
            dto.ShouliStatus = "2";
 
              resultEntity = _cooperOrderService.shouli(dto);
 
            return new JsonResult(resultEntity);
        }
 
 
        /// <summary>
        /// 完工
        /// </summary>
        /// <param name="data">岗位实体类对象</param>
        /// <returns></returns>
        /// 
        [CheckLogin]
        public IActionResult Wangong(string id)
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            CooperOrderDTO dto = _cooperOrderService.Get(id);
            //dto.Id = id;
            dto.Wangonger = curentuser.Id;
            dto.Wangongtime = DateTime.Now;
            dto.ShouliStatus = "4";
 
            ResultEntity resultEntity = _cooperOrderService.save(dto);
 
            return new JsonResult(resultEntity);
        }
 
 
        [CheckLogin]
        public IActionResult Chedan(string id = null)
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            ViewData["Chedanid"] = id;
 
 
 
            return View();
        }
        [CheckLogin]
        public IActionResult chedantuihuan(decimal Price, string Chedanid)
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
 
            ResultEntity resultEntity = new ResultEntity();
            resultEntity.Result = false;
 
            CooperOrderDTO dto = _cooperOrderService.Get(Chedanid);
            if (dto.ShouliStatus != "2")
            {
                resultEntity.Result = false;
                resultEntity.Message = "只有受理状态的订单才能撤单";
                return new JsonResult(resultEntity);
            }
 
           
            dto.Chedaner = curentuser.Id;
            dto.Chedantime = DateTime.Now;
            dto.ChedanStatus = "A";
            dto.Chedan = Price;
            dto.ShouliStatus = "0";
 
            resultEntity = _cooperOrderService.chedan(dto);
 
            return new JsonResult(resultEntity);
        }
        [CheckLogin]
        public IActionResult Huifang(string id = null)
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            ViewData["Huifangid"] = id;
 
            ViewData["PingjiaStatus"] = _liaotianService.GetSYScode("CooperOrder", "pingjia_status");
            ViewData.Model = _cooperOrderService.Get(id); 
 
            return View();
        }
        [CheckLogin]
        public IActionResult Huifangtuihuan(CooperOrderDTO dto)
        {
            ResultEntity resultEntity = new ResultEntity();
            resultEntity.Result = true;
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
 
            
            
            dto.Huifanger = curentuser.Id;
            dto.Huifangtime = DateTime.Now;
            dto.HuifangStatus = "A";
             
 
            resultEntity = _cooperOrderService.huifang(dto);
 
            return new JsonResult(resultEntity);
        }
 
 
        /// <summary>
        /// 送货
        /// </summary>
        /// <param name="data">岗位实体类对象</param>
        /// <returns></returns>
        /// 
        [CheckLogin]
        public IActionResult Songhuo(string id)
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            ViewData["Huifangid"] = id;
 
            var cooperOrderDTO = _cooperOrderService.Get(id);
            if (!cooperOrderDTO.SonghuoTime1.HasValue)
            {
                cooperOrderDTO.SonghuoTime1 = DateTime.Now;
            }
 
            ViewData.Model = cooperOrderDTO;
 
            return View();
 
            
        }
 
        [CheckLogin]
        public IActionResult Songhuotuihuan(CooperOrderDTO dto)
        {
            ResultEntity resultEntity = new ResultEntity();
            resultEntity.Result = true;
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            var cooperOrderDTO  =  _cooperOrderService.Get(dto.Id);
            if (cooperOrderDTO.ShouliStatus != "2")
            {
                resultEntity.Result = false;
                resultEntity.Message = "只有受理状态的订单才能送货";
                return new JsonResult(resultEntity);
            }
 
            dto.Songhuoer = curentuser.Id;
            dto.Songhuotime = DateTime.Now;
            dto.ShouliStatus = "5";
 
            resultEntity = _cooperOrderService.Songhuo(dto);
 
            return new JsonResult(resultEntity);
        }
 
        [CheckLogin]
        public IActionResult Pingjia(string id = null)
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            ViewData["Pingjiaid"] = id;
            ViewData["PingjiaStatus"] = _liaotianService.GetSYScode("CooperOrder", "pingjia_status");
 
 
            return View();
        }
        [CheckLogin]
        public IActionResult Pingjiatuihuan(string PingjiaStatus, string Pingjiaid)
        {
            ResultEntity resultEntity = new ResultEntity();
            resultEntity.Result = true;
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
 
            CooperOrderDTO dto = new CooperOrderDTO();
            dto.Id = Pingjiaid;
            dto.Pingjiaer = curentuser.Id;
            dto.Pingjiatime = DateTime.Now;
            dto.PingjiaStatus = PingjiaStatus;
            
 
            resultEntity = _cooperOrderService.pingjia(dto);
 
            return new JsonResult(resultEntity);
        }
 
 
        [CheckLogin]
        public IActionResult Print(string id = null)
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
 
            CooperOrderDTO dto = new CooperOrderDTO();
            if (!String.IsNullOrEmpty(id))
            {
                dto = _cooperOrderService.Getprint(id);
                if (dto.OrderType == "01")
                {
                    dto.OrderType1 = _fiBookService.Get(dto.OrderType1).BookName;
                }
                if (dto.OrderType == "05")
                {
                    dto.OrderType1 = _fiMemberService.Get(dto.OrderType1).MemberType;  
                }
            }
            else
            {
                dto.XdTime = DateTime.Now;
               
            }
 
            ViewData.Model = dto;
            return View();
        }
 
        [CheckLogin]
        public IActionResult printList(CooperOrderDTOSearch search)
        {
            //JsonResult jsonResult =   new JsonResult(_liaotianService.SearchByPaging(search), new Newtonsoft.Json.Serialization.DefaultContractResolver());
            search.rows = 1000;
            search.page = 1;
            ViewBag.ListCooperOrderDTO = _cooperOrderService.SearchByPaging(search).DataList as List<CooperOrderDTO>;
 
 
 
            return View();
        }
 
 
 
 
        /// <summary>
        /// 获取物品
        /// </summary>
        /// <param name="shengid">省id</param>
        /// <returns></returns>
        /// 
        [CheckLogin]
        public string getOrderType(string OrderType)
        {
            string result = "";
            if(OrderType == "01")
            {
                var shi = _fiBookService.GetList().Select(x => new { code = x.Id, label = x.BookName }).ToList();
                result = JsonConvert.SerializeObject(shi);
            }
            if (OrderType == "02"  || OrderType == "04" || OrderType == "06"   || OrderType == "09")
            {
                var shi = _fiServiceService.GetList().Where(x=>x.ServiceTypeTop == OrderType).Select(x => new { code = x.ServiceType, label = x.ServiceType }).Distinct().ToList();
                result = JsonConvert.SerializeObject(shi);
            }
            if (  OrderType == "03"  || OrderType == "07"  )
            {
                var shi = _fiServiceService.GetList().Where(x => x.ServiceTypeTop == OrderType).Select(x => new { code = x.ServiceTypeTwo, label = x.ServiceTypeTwo }).ToList();
                result = JsonConvert.SerializeObject(shi);
            }
            if (OrderType == "05" )
            {
                var shi = _fiMemberService.GetList().Select(x => new { code = x.Id, label = x.MemberType }).ToList();
                result = JsonConvert.SerializeObject(shi);
            }
 
            if (OrderType == "08" || OrderType == "10" || OrderType == "11")
            {
               
                result = "[]";
            }
 
            return result;
 
        }
 
 
 
        /// <summary>
        /// 获取物品
        /// </summary>
        /// <param name="shengid">省id</param>
        /// <returns></returns>
        /// 
        [CheckLogin]
        public string getOrderType1(string OrderType,string OrderType1)
        {
            string result = "";
            if (OrderType == "01")
            {
                var shi = _fiBookService.Get(OrderType1);
                result = JsonConvert.SerializeObject(shi);
            }
            if (OrderType == "03" || OrderType == "07")
            {
                var shi = _fiServiceService.GetList().Where(x => x.ServiceTypeTop == OrderType && x.ServiceTypeTwo == OrderType1).FirstOrDefault();
                result = JsonConvert.SerializeObject(shi);
            }
            if (OrderType == "05")
            {
                var shi = _fiMemberService.Get(OrderType1);
                result = JsonConvert.SerializeObject(shi);
            }
            if (  OrderType == "04" || OrderType == "06" || OrderType == "09")
            {
                var shi = _fiServiceService.GetList().Where(x => x.ServiceTypeTop == OrderType && x.ServiceType == OrderType1).FirstOrDefault();
                result = JsonConvert.SerializeObject(shi);
            }
 
 
            if (OrderType == "02" )
            {
                if(OrderType1== "电话咨询" || OrderType1 == "当面咨询" || OrderType1 == "代拟质疑答复" || OrderType1 == "代拟投诉处理决定" || OrderType1 == "竞争对手和评审专家参加政府采购数据信息查询" || OrderType1 == "政采贷")
                {
                    var shi = _fiServiceService.GetList().Where(x => x.ServiceTypeTop == OrderType && x.ServiceType == OrderType1).FirstOrDefault();
                    result = JsonConvert.SerializeObject(shi);
                }
                else
                {
                    var shi = _fiServiceService.GetList().Where(x => x.ServiceTypeTop == OrderType && x.ServiceType == OrderType1).Select(x => new { code = x.ServiceTypeTwo, label = x.ServiceTypeTwo }).Distinct().ToList();
                    result = JsonConvert.SerializeObject(shi);
                }
 
               
            }
            if (result == "")
            {
                result = "[]";
            }
            return result;
 
        }
 
        /// <summary>
        /// 获取物品
        /// </summary>
        /// <param name="shengid">省id</param>
        /// <returns></returns>
        /// 
        [CheckLogin]
        public string getOrderType2(string OrderType, string OrderType1, string OrderType2)
        {
            string result = "";
           
           
                var shi = _fiServiceService.GetList().Where(x => x.ServiceTypeTop == OrderType && x.ServiceType == OrderType1 && x.ServiceTypeTwo == OrderType2).FirstOrDefault();
                result = JsonConvert.SerializeObject(shi);
            
 
            return result;
 
        }
 
 
 
        //提问
        public IActionResult GetHuiYuanOrder([FromBody]CooperOrderDTOSearch search)
        {
            ReturnMsg<List<UserOrders>> returnMsg = new ReturnMsg<List<UserOrders>>();
            returnMsg.code = 2;
            try
            {
                string userid = "";
                var headers = Request.Headers;
                if (headers != null)
                {
                    //string SecurityKey = _configuration.GetSection("SecurityKey").Value;
                    var keyId = headers["Authorization"].FirstOrDefault();
                    if (string.IsNullOrEmpty("keyId"))
                    {
                        returnMsg.code = 2;
                        returnMsg.error = "没有获取到token";
                        returnMsg.count = 0;
 
                        return new JsonResult(returnMsg);
                    }
 
 
                    JwtSecurityToken jwt = null;
                    var handler = new JwtSecurityTokenHandler();
                    var key1 = keyId.Replace("Bearer", "").Trim();
                    jwt = handler.ReadJwtToken(key1);
                    System.Security.Claims.Claim sss = jwt.Claims.Where(x => x.Type == "id").FirstOrDefault();
                    userid = sss.Value;
 
                }
                //LZhuanjiahuidumDTOSearch searchEntity = new LZhuanjiahuidumDTOSearch();
                //searchEntity.Userid = userid;
                ////searchEntity.HuidaStatus = "A";
                //searchEntity.page = 1;
                //searchEntity.rows = 1000;
                search.HuiyuanId = userid;
                ResultDataEntity<CooperOrderDTO> resultDataEntity = _cooperOrderService.SearchByPaging(search);
                List<CooperOrderDTO> cooperOrderDTOs  = resultDataEntity.DataList;
                List<UserOrders> userOrders = new List<UserOrders>();
                //封装订单
                foreach (var cooperOrderDTO in cooperOrderDTOs)
                {
                    UserOrders userOrder = new UserOrders();
                    userOrder.order_goods = new List<usercart_items>();
                    usercart_items usercart_Item = new usercart_items();
 
                    userOrder.order_type = "offline";
                    userOrder.order_no = cooperOrderDTO.OrderNo;
                    userOrder.accept_name = cooperOrderDTO.Shr;
                    userOrder.mobile = cooperOrderDTO.ShrTel;
                    userOrder.address = cooperOrderDTO.ShrAddress;
                    userOrder.order_amount = cooperOrderDTO.Money.HasValue ? cooperOrderDTO.Money.Value: 0; 
                    userOrder.statusChs = cooperOrderDTO.ShouliStatusName;
                    userOrder.add_time = cooperOrderDTO.Createtime;
 
                    usercart_Item.sell_price = cooperOrderDTO.Price.HasValue ? cooperOrderDTO.Price.Value : 0; 
                    usercart_Item.quantity = cooperOrderDTO.OrderNum.HasValue ? decimal.ToInt32(cooperOrderDTO.OrderNum.Value) : 0;
                    usercart_Item.name = cooperOrderDTO.OrderTypeName + "-" + cooperOrderDTO.OrderType1Name + (string.IsNullOrEmpty(cooperOrderDTO.OrderType2)?"": "-"+cooperOrderDTO.OrderType2);
 
 
 
                    userOrder.order_goods.Add(usercart_Item);
                    userOrders.Add(userOrder);
                }
                returnMsg.code = 1;
                returnMsg.returnObj = userOrders;
                returnMsg.count = resultDataEntity.DataList.Count;
            }
            catch (Exception ex)
            {
                returnMsg.code = 2;
                returnMsg.error = "没有获取到token";
                returnMsg.count = 0;
 
            }
            return new JsonResult(returnMsg);
        }
 
    }
}