From 67a0042c5f29e4bb0e0b82f6190f2bc51480b45c Mon Sep 17 00:00:00 2001
From: username@email.com <yzy2002yzy@163.com>
Date: 星期二, 28 二月 2023 13:25:09 +0800
Subject: [PATCH] 工资绩效改版

---
 zhengcaioa/zhengcaioa/Controllers/BusinessOrder/CooperOrderController.cs | 2538 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 2,383 insertions(+), 155 deletions(-)

diff --git a/zhengcaioa/zhengcaioa/Controllers/BusinessOrder/CooperOrderController.cs b/zhengcaioa/zhengcaioa/Controllers/BusinessOrder/CooperOrderController.cs
index ba62186..2040acd 100644
--- a/zhengcaioa/zhengcaioa/Controllers/BusinessOrder/CooperOrderController.cs
+++ b/zhengcaioa/zhengcaioa/Controllers/BusinessOrder/CooperOrderController.cs
@@ -40,7 +40,14 @@
         private readonly IFiMemberService _fiMemberService;
         private readonly IConfiguration _configuration;
         private readonly IHttpClientFactory _clientFactory;
-        private readonly IAskService _askService; 
+        private readonly IAskService _askService;
+        private readonly IAdmGoodsRecordService _admGoodsRecordService;
+
+        private readonly IAdmGoodsManageService _admGoodsManageService;
+        private readonly IFiOrderrecievemoneyService _fiOrderrecievemoneyService;
+        private readonly IFiAccountService _fiAccountService;
+        private readonly IFiAccountRecordService _iFiAccountRecordService;
+        private readonly ISysAttachmentService _sysAttachmentService;
 
 
         public CooperOrderController(ILogger<CooperOrderController> logger, ILiaotianService liaotianService, IUserService userService, ICooperOrderService cooperOrderService
@@ -48,7 +55,14 @@
             , IFiServiceService fiServiceService, IFiMemberService fiMemberService
             , IConfiguration configuration
             , IHttpClientFactory clientFactory
-            , IAskService askService)
+            , IAskService askService
+            , IAdmGoodsRecordService admGoodsRecordService
+            , IAdmGoodsManageService admGoodsManageService
+            , IFiOrderrecievemoneyService fiOrderrecievemoneyService
+            , IFiAccountService fiAccountService
+            , IFiAccountRecordService iFiAccountRecordService
+             , ISysAttachmentService sysAttachmentService
+            )
         {
             _logger = logger;
             _liaotianService = liaotianService;
@@ -63,6 +77,12 @@
             _configuration = configuration;
             _clientFactory = clientFactory;
             _askService = askService;
+            _admGoodsRecordService = admGoodsRecordService;
+            _admGoodsManageService = admGoodsManageService;
+            _fiOrderrecievemoneyService = fiOrderrecievemoneyService;
+            _fiAccountService = fiAccountService;
+            _iFiAccountRecordService = iFiAccountRecordService;
+            _sysAttachmentService = sysAttachmentService;
         }
 
         [CheckLogin]
@@ -71,34 +91,62 @@
             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 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);
+            //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;
+            //ViewData["ActionInfo"] = actionlist;
 
             List<PageEntity> pageEntities = _pltPageService.GetUserPage(curentuser.Id, "/CooperOrder/Index/");
 
             ViewBag.pageEntities = pageEntities;
+
+            var pageEntities1 = pageEntities.Where(x => x.PageMethod == "01").ToList();
+            if (pageEntities1.Count(x => x.PageShortcut == "Search") <= 0)
+            {
+                ActionEntity actionEntity = new ActionEntity();
+                actionEntity.OpenType = 0;
+                actionEntity.ActionUrl = "";
+                actionEntity.ActionFun = "Search";
+                actionEntity.PageIco = "fa fa-search";
+                actionEntity.ActionName = "鏌ヨ";
+                actionlist.Add(actionEntity);
+
+                ViewData["Creater"] = curentuser.Id;
+            }
+            var pageEntities2 = pageEntities.Where(x => x.PageMethod == "02").ToList();
+
+            foreach (var pageEntity in pageEntities1)
+            {
+                ActionEntity actionEntity1 = new ActionEntity();
+                actionEntity1.OpenType = pageEntity.OpenType;
+                actionEntity1.ActionUrl = "";
+                actionEntity1.ActionFun = pageEntity.PageShortcut;
+                actionEntity1.PageIco = pageEntity.PageIco;
+                actionEntity1.ActionName = pageEntity.PageName;
+                actionlist.Add(actionEntity1);
+            }
+            ViewData["ActionInfo"] = actionlist;
+            ViewData["ActionInfo2"] = pageEntities2;
 
             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();
@@ -398,37 +446,256 @@
             return new JsonResult(_cooperOrderService.SearchByPaging(search));
         }
         [CheckLogin]
-        public IActionResult Edit(string id = null, string ShouliStatus = "1")
+        public IActionResult Edit(string id = null, string ShouliStatus = "1",string dingdantype = "0")
         {
             var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
             ViewData["curentuser"] = curentuser;
-
+            var pageEntities = _pltPageService.GetUserPage(curentuser.Id, "/CooperOrder/Index/");
+            var pageEntities2 = pageEntities.Where(x => x.PageMethod == "02").ToList();
+            ViewData["ActionInfo2"] = pageEntities2;
             CooperOrderDTO dto = new CooperOrderDTO();
-            if (!String.IsNullOrEmpty(id))
+            if(dingdantype == "0")
+            {
+
+                if (!String.IsNullOrEmpty(id))
+                {
+                    dto = _cooperOrderService.Get(id);
+                    ViewBag.ShouliStatus = ShouliStatus;
+                    //ViewBag.YouHuiList = _askService.GetAskYouHuiList(dto.Khdw, dto.OrderType);
+                    //璐ㄧ枒鍑�
+                    List<TChallengeletterDTO> challengeletterDTOs = _cooperOrderService.GetListChallengeletter(id);
+                    TChallengeletterDTO challengeletterDTO = new TChallengeletterDTO();
+                    if (challengeletterDTOs != null && challengeletterDTOs.Count > 0)
+                    {
+                        challengeletterDTO = challengeletterDTOs[0];
+                        if (challengeletterDTO.DocumentsDate.HasValue)
+                        {
+                            challengeletterDTO.DocumentsDateName = challengeletterDTO.DocumentsDate.Value.ToString("yyyy-MM-dd");
+                        }
+                        List<TChallengeItemDTO> challengeItemDTOs = _cooperOrderService.GetListChallengeItem(challengeletterDTO.Id);
+                        if (challengeItemDTOs.Count > 0)
+                            challengeletterDTO.challengeItemDTOs = challengeItemDTOs;
+                        else
+                            challengeletterDTO.challengeItemDTOs = new List<TChallengeItemDTO>() { new TChallengeItemDTO() };
+                        List<TComplaintShouquandaibiaoDTO> complaintShouquandaibiaoDTOs = _cooperOrderService.GetListComplaintShouquandaibiao(challengeletterDTO.Id);
+                        if (complaintShouquandaibiaoDTOs.Count > 0)
+                            challengeletterDTO.complaintShouquandaibiaoDTOs = complaintShouquandaibiaoDTOs;
+                        else
+                            challengeletterDTO.complaintShouquandaibiaoDTOs = new List<TComplaintShouquandaibiaoDTO>() { new TComplaintShouquandaibiaoDTO() };
+
+                    }
+                    else
+                    {
+                        challengeletterDTO.challengeItemDTOs = new List<TChallengeItemDTO>() { new TChallengeItemDTO() };
+                        challengeletterDTO.complaintShouquandaibiaoDTOs = new List<TComplaintShouquandaibiaoDTO>() { new TComplaintShouquandaibiaoDTO() };
+                    }
+                    ViewBag.challengeletterDTO = challengeletterDTO;
+                    //鎶曡瘔涔�
+                    List<TComplaintletterDTO> complaintletterDTOs = _cooperOrderService.GetListComplaintletter(id);
+                    TComplaintletterDTO complaintletterDTO = new TComplaintletterDTO();
+                    if (complaintletterDTOs != null && complaintletterDTOs.Count > 0)
+                    {
+                        complaintletterDTO = complaintletterDTOs[0];
+
+                        if (complaintletterDTO.NoticeDate.HasValue)
+                        {
+                            complaintletterDTO.NoticeDateName = complaintletterDTO.NoticeDate.Value.ToString("yyyy-MM-dd");
+                        }
+
+                        if (complaintletterDTO.ResultnoticeDate.HasValue)
+                        {
+                            complaintletterDTO.ResultnoticeDateName = complaintletterDTO.ResultnoticeDate.Value.ToString("yyyy-MM-dd");
+                        }
+
+                        List<TComplaintItemDTO> complaintItemDTOs = _cooperOrderService.GetListComplaintItem(complaintletterDTO.Id);
+                        if (complaintItemDTOs.Count > 0)
+                            complaintletterDTO.complaintItemDTOs = complaintItemDTOs;
+                        else
+                            complaintletterDTO.complaintItemDTOs = new List<TComplaintItemDTO>() { new TComplaintItemDTO() };
+
+                        List<TComplaintRespondentDTO> complaintRespondentDTOs = _cooperOrderService.GetListComplaintRespondent(complaintletterDTO.Id);
+                        if (complaintRespondentDTOs.Count > 0)
+                            complaintletterDTO.complaintRespondentDTOs = complaintRespondentDTOs;
+                        else
+                            complaintletterDTO.complaintRespondentDTOs = new List<TComplaintRespondentDTO>() { new TComplaintRespondentDTO() };
+
+                        List<TComplaintShouquandaibiaoDTO> complaintShouquandaibiaoDTOs = _cooperOrderService.GetListComplaintShouquandaibiao(complaintletterDTO.Id);
+                        if (complaintShouquandaibiaoDTOs.Count > 0)
+                            complaintletterDTO.complaintShouquandaibiaoDTOs = complaintShouquandaibiaoDTOs;
+                        else
+                            complaintletterDTO.complaintShouquandaibiaoDTOs = new List<TComplaintShouquandaibiaoDTO>() { new TComplaintShouquandaibiaoDTO() };
+
+                        List<TComplaintGongyingshangDTO> complaintGongyingshangDTOs = _cooperOrderService.GetListComplaintGongyingshang(complaintletterDTO.Id);
+                        if (complaintGongyingshangDTOs.Count > 0)
+                            complaintletterDTO.complaintGongyingshangDTOs = complaintGongyingshangDTOs;
+                        else
+                            complaintletterDTO.complaintGongyingshangDTOs = new List<TComplaintGongyingshangDTO>()/* { new TComplaintGongyingshangDTO() }*/;
+
+                    }
+                    else
+                    {
+                        complaintletterDTO.complaintItemDTOs = new List<TComplaintItemDTO>() { new TComplaintItemDTO() };
+                        complaintletterDTO.complaintRespondentDTOs = new List<TComplaintRespondentDTO>() { new TComplaintRespondentDTO() };
+                        complaintletterDTO.complaintShouquandaibiaoDTOs = new List<TComplaintShouquandaibiaoDTO>() { new TComplaintShouquandaibiaoDTO() };
+                        complaintletterDTO.complaintGongyingshangDTOs = new List<TComplaintGongyingshangDTO>()/* { new TComplaintGongyingshangDTO() }*/;
+
+                    }
+                    ViewBag.complaintletterDTO = complaintletterDTO;
+                }
+                else
+                {
+                    dto.XdTime = DateTime.Now;
+                    dto.OrderNum = 1;
+                    ViewBag.ShouliStatus = "1";
+                    dto.OrderNo = _cooperOrderService.GetOrderNo();
+                    //ViewBag.YouHuiList = new List<AdmAskYouHuiDTO>();
+                    //璐ㄧ枒鍑�
+                    TChallengeletterDTO challengeletterDTO = new TChallengeletterDTO();
+                    challengeletterDTO.challengeItemDTOs = new List<TChallengeItemDTO>() { new TChallengeItemDTO() };
+                    challengeletterDTO.complaintShouquandaibiaoDTOs = new List<TComplaintShouquandaibiaoDTO>() { new TComplaintShouquandaibiaoDTO() };
+                    ViewBag.challengeletterDTO = challengeletterDTO;
+                    //鎶曡瘔涔�
+                    TComplaintletterDTO complaintletterDTO = new TComplaintletterDTO();
+                    complaintletterDTO.complaintItemDTOs = new List<TComplaintItemDTO>() { new TComplaintItemDTO() };
+                    complaintletterDTO.complaintRespondentDTOs = new List<TComplaintRespondentDTO>() { new TComplaintRespondentDTO() };
+                    complaintletterDTO.complaintShouquandaibiaoDTOs = new List<TComplaintShouquandaibiaoDTO>() { new TComplaintShouquandaibiaoDTO() };
+                    complaintletterDTO.complaintGongyingshangDTOs = new List<TComplaintGongyingshangDTO>() /*{ new TComplaintGongyingshangDTO() }*/;
+                    ViewBag.complaintletterDTO = complaintletterDTO;
+
+                }
+            }
+            else if (dingdantype == "1")
             {
                 dto = _cooperOrderService.Get(id);
                 ViewBag.ShouliStatus = ShouliStatus;
-                //ViewBag.YouHuiList = _askService.GetAskYouHuiList(dto.Khdw, dto.OrderType);
+
+
+
+
+
+                //璐ㄧ枒鍑�
+                TChallengeletterDTO challengeletterDTO = new TChallengeletterDTO();
+                challengeletterDTO.challengeItemDTOs = new List<TChallengeItemDTO>() { new TChallengeItemDTO() };
+                challengeletterDTO.complaintShouquandaibiaoDTOs = new List<TComplaintShouquandaibiaoDTO>() { new TComplaintShouquandaibiaoDTO() };
+                ViewBag.challengeletterDTO = challengeletterDTO;
+                //鎶曡瘔涔�
+              
+                TComplaintletterDTO complaintletterDTO = new TComplaintletterDTO();
+
+                complaintletterDTO.complaintItemDTOs = new List<TComplaintItemDTO>() { new TComplaintItemDTO() };
+                complaintletterDTO.complaintRespondentDTOs = new List<TComplaintRespondentDTO>() { new TComplaintRespondentDTO() };
+                //complaintletterDTO.complaintShouquandaibiaoDTOs = new List<TComplaintShouquandaibiaoDTO>() { new TComplaintShouquandaibiaoDTO() };
+                complaintletterDTO.complaintGongyingshangDTOs = new List<TComplaintGongyingshangDTO>()/* { new TComplaintGongyingshangDTO() }*/;
+                List<TChallengeletterDTO> challengeletterDTOs = _cooperOrderService.GetListChallengeletter(id);
+
+                if (challengeletterDTOs != null && challengeletterDTOs.Count > 0)
+                {
+                    complaintletterDTO.TsrName = challengeletterDTOs[0].GysName;
+                    complaintletterDTO.TsrAddress = challengeletterDTOs[0].GysAddress;
+                    complaintletterDTO.TsrPostcode = challengeletterDTOs[0].GysPostcode;
+                    complaintletterDTO.TsrCorporation = challengeletterDTOs[0].GysContacts;
+                    complaintletterDTO.TsrPhone = challengeletterDTOs[0].GysPhone;
+                    complaintletterDTO.XmName = challengeletterDTOs[0].XmName;
+                    complaintletterDTO.XmCode = challengeletterDTOs[0].XmCode;
+                    complaintletterDTO.XmPackage = challengeletterDTOs[0].XmPackage;
+                    complaintletterDTO.PurchaserName = challengeletterDTOs[0].PurchaserName;
+                    //complaintletterDTO.Agency = challengeletterDTOs[0].PurchaserName;
+
+
+
+
+                    complaintletterDTO.ChallengeDateName = challengeletterDTOs[0].DocumentsDate.HasValue ? challengeletterDTOs[0].DocumentsDate.Value.ToString("yyyy-MM-dd") : "";
+                    complaintletterDTO.RequestInfo = challengeletterDTOs[0].RequestInfo;
+                    complaintletterDTO.Questioned = challengeletterDTOs[0].PurchaserName;
+
+                    List<TComplaintShouquandaibiaoDTO> complaintShouquandaibiaoDTOs = _cooperOrderService.GetListComplaintShouquandaibiao(challengeletterDTOs[0].Id);
+                    if (complaintShouquandaibiaoDTOs.Count > 0)
+                        complaintletterDTO.complaintShouquandaibiaoDTOs = complaintShouquandaibiaoDTOs;
+                    else
+                        complaintletterDTO.complaintShouquandaibiaoDTOs = new List<TComplaintShouquandaibiaoDTO>() { new TComplaintShouquandaibiaoDTO() };
+                }
+
+
+                    ViewBag.complaintletterDTO = complaintletterDTO;
+
+
+                dto.Id = "";
+                dto.OrderType = "02";
+                dto.OrderType1 = "浠f嫙鎶曡瘔涔�";
+                //dto.OrderType2 = "";
             }
-            else
+            else if (dingdantype == "2")
             {
-                dto.XdTime = DateTime.Now;
-                dto.OrderNum = 1;
-                ViewBag.ShouliStatus = "1";
-                //ViewBag.YouHuiList = new List<AdmAskYouHuiDTO>();
+                dto = _cooperOrderService.Get(id);
+                ViewBag.ShouliStatus = ShouliStatus;
+                dto.Id = "";
+                dto.OrderType = "08";
+                dto.OrderType1 = "澶嶈璇夎";
+                dto.OrderType2 = "";
+
+                //璐ㄧ枒鍑�
+                TChallengeletterDTO challengeletterDTO = new TChallengeletterDTO();
+
+                challengeletterDTO.challengeItemDTOs = new List<TChallengeItemDTO>() { new TChallengeItemDTO() };
+                challengeletterDTO.complaintShouquandaibiaoDTOs = new List<TComplaintShouquandaibiaoDTO>() { new TComplaintShouquandaibiaoDTO() };
+
+                ViewBag.challengeletterDTO = challengeletterDTO;
+                //鎶曡瘔涔�
+                TComplaintletterDTO complaintletterDTO = new TComplaintletterDTO();
+
+                complaintletterDTO.complaintItemDTOs = new List<TComplaintItemDTO>() { new TComplaintItemDTO() };
+                complaintletterDTO.complaintRespondentDTOs = new List<TComplaintRespondentDTO>() { new TComplaintRespondentDTO() };
+                complaintletterDTO.complaintShouquandaibiaoDTOs = new List<TComplaintShouquandaibiaoDTO>() { new TComplaintShouquandaibiaoDTO() };
+                complaintletterDTO.complaintGongyingshangDTOs = new List<TComplaintGongyingshangDTO>()/* { new TComplaintGongyingshangDTO() }*/;
+
+
+                ViewBag.complaintletterDTO = complaintletterDTO;
+            }
+            else if (dingdantype == "3")
+            {
+                dto = _cooperOrderService.Get(id);
+                ViewBag.ShouliStatus = ShouliStatus;
+                dto.Id = "";
+
+
+                //璐ㄧ枒鍑�
+                TChallengeletterDTO challengeletterDTO = new TChallengeletterDTO();
+
+                challengeletterDTO.challengeItemDTOs = new List<TChallengeItemDTO>() { new TChallengeItemDTO() };
+                challengeletterDTO.complaintShouquandaibiaoDTOs = new List<TComplaintShouquandaibiaoDTO>() { new TComplaintShouquandaibiaoDTO() };
+
+                ViewBag.challengeletterDTO = challengeletterDTO;
+                //鎶曡瘔涔�
+                TComplaintletterDTO complaintletterDTO = new TComplaintletterDTO();
+
+                complaintletterDTO.complaintItemDTOs = new List<TComplaintItemDTO>() { new TComplaintItemDTO() };
+                complaintletterDTO.complaintRespondentDTOs = new List<TComplaintRespondentDTO>() { new TComplaintRespondentDTO() };
+                complaintletterDTO.complaintShouquandaibiaoDTOs = new List<TComplaintShouquandaibiaoDTO>() { new TComplaintShouquandaibiaoDTO() };
+                complaintletterDTO.complaintGongyingshangDTOs = new List<TComplaintGongyingshangDTO>()/* { new TComplaintGongyingshangDTO() }*/;
+
+
+                ViewBag.complaintletterDTO = complaintletterDTO;
             }
 
+
+
+            ViewBag.request_info = _liaotianService.GetSYScode("t_challengeletter", "request_info");//璐ㄧ枒璇锋眰
+            ViewBag.question = _liaotianService.GetSYScode("t_challenge_items", "question"); //	璐ㄧ枒浜嬮」
+            ViewBag.law = _liaotianService.GetSYScode("t_complaint_items", "law");//娉曞緥渚濇嵁
 
 
 
 
             ViewBag.OrderType = _liaotianService.GetSYScode("CooperVisit", "jtype");
 
+            ViewBag.shifou = _liaotianService.GetSYScode("system", "shifou");
+
             ViewBag.customer = _cooperatecustomCustomerService.GetList();
 
             //ViewBag.project = _projectService.GetList();
+            ViewBag.ChallengeletterChosen = _cooperOrderService.GetListChallengeletterChosen().Where(x => x.Createtime >= DateTime.Now.AddMonths(-2)).ToList(); ;
 
-          
+
 
 
             ViewData.Model = dto;
@@ -464,123 +731,409 @@
         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))
+
+            
+
+                bool youhui = true;
+
+            if (String.IsNullOrEmpty(data.Id))
+            {
+                var cooperatecustomCustomerDTO = _cooperatecustomCustomerService.Get(data.Khdw);
+                if (cooperatecustomCustomerDTO != null && !string.IsNullOrEmpty(cooperatecustomCustomerDTO.HuiyuanId))
                 {
-                    data.Creater = curentuser.Id;
-                    data.Createtime = DateTime.Now;
-                    data.XdTime = data.Createtime;
-                    if (data.OrderType == "03" || data.OrderType == "07" || (data.OrderType == "02" && (data.OrderType1 == "浠f嫙鎶曡瘔涔�" || data.OrderType1 == "浠f嫙璐ㄧ枒鍑�")))
+                    var cooperOrderDTOs = _cooperOrderService.GetListComplaintsDisputeCount(cooperatecustomCustomerDTO.HuiyuanId).FirstOrDefault();
+                    if(cooperOrderDTOs != null)
                     {
-                        var cooperatecustomCustomerDTO = _cooperatecustomCustomerService.Get(data.Khdw);
-                        if (cooperatecustomCustomerDTO != null && !string.IsNullOrEmpty(cooperatecustomCustomerDTO.HuiyuanId))
+                        if ((cooperOrderDTOs.ComplaintsDisputeCount - cooperOrderDTOs.ComplaintsDisputeCountused > 0) && (data.OrderType == "02" && (data.OrderType1 == "浠f嫙鎶曡瘔涔�" || data.OrderType1 == "浠f嫙璐ㄧ枒鍑�")))
                         {
-                            string huiyuanurl = _configuration.GetSection("huiyuanurl").Value;
-                            string SetCaseOrder = _configuration.GetSection("SetCaseOrder").Value;
+                            data.Youhui = data.Money.Value;
+                            data.Money = 0;
+                            youhui = false;
+                        }
+                        else if ((cooperOrderDTOs.BiddingDocumentsCount - cooperOrderDTOs.BiddingDocumentsCountused > 0) && data.OrderType == "03")
+                        {
+                            data.Youhui = data.Money.Value;
+                            data.Money = 0;
+                            youhui = false;
+                        }
+                        else if ((cooperOrderDTOs.PerformanceDisputeCount - cooperOrderDTOs.PerformanceDisputeCountused > 0) && data.OrderType == "07")
+                        {
+                            data.Youhui = data.Money.Value;
+                            data.Money = 0;
+                            youhui = false;
+                        }
+                    }
+                }
 
-                            Uri postUrl2 = new Uri(huiyuanurl + SetCaseOrder);
 
-                            JObject questions2 = new JObject();
-                            questions2.Add("UserID", cooperatecustomCustomerDTO.HuiyuanId);
-                            if (data.OrderType == "03")
+                data.Creater = curentuser.Id;
+                data.Createtime = DateTime.Now;
+                data.XdTime = data.Createtime;
+                if (data.OrderType == "03" || data.OrderType == "07" || (data.OrderType == "02" && (data.OrderType1 == "浠f嫙鎶曡瘔涔�" || data.OrderType1 == "浠f嫙璐ㄧ枒鍑�")))
+                {
+
+                    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 == "浠f嫙鎶曡瘔涔�" || data.OrderType1 == "浠f嫙璐ㄧ枒鍑�"))
+                        {
+                            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);
+                        }
+                    }
+                }
+
+
+
+
+
+            }
+
+
+            if(data.OrderType1 == "姘戜簨绾犵悍" || data.OrderType1 == "鍏朵粬绾犵悍")
+            {
+                data.OrderType2 = data.OrderType3;
+            }
+
+            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required,
+           new TransactionOptions
+           {
+               IsolationLevel = IsolationLevel.ReadCommitted,
+               Timeout = TransactionManager.MaximumTimeout
+           }
+           ))
+            {
+
+                if (youhui)
+                {
+                    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)
                             {
-                                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 == "浠f嫙鎶曡瘔涔�" || data.OrderType1 == "浠f嫙璐ㄧ枒鍑�"))
-                            {
-                                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;
+                                data.Money = 0;
                             }
                             else
                             {
-                                resultEntity.Result = false;
-                                resultEntity.Message = "鍐欏叆浼氬憳璁㈠崟澶辫触";
-                                return new JsonResult(resultEntity);
+                                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);
+
+                if (data.OrderType1 == "浠f嫙鎶曡瘔涔�")
+                {
+                    //鏌ヨ涓昏〃
+                    var complaintletterDTO = _cooperOrderService.GetListComplaintletter(data.Id).FirstOrDefault();
+                    var challengeletterDTO = _cooperOrderService.GetListChallengeletter(data.TsrId).FirstOrDefault();
+                    if (complaintletterDTO != null)
+                    {
+                        complaintletterDTO.TsrName = data.TsrName;
+                        complaintletterDTO.TsrAddress = data.TsrAddress;
+                        complaintletterDTO.TsrPostcode = data.TsrPostcode;
+                        complaintletterDTO.TsrCorporation = data.TsrCorporation;
+                        complaintletterDTO.TsrPhone = data.TsrPhone;
+                        complaintletterDTO.TsrId = data.TsrId;
+
+                        complaintletterDTO.XmName = data.tousuXmName;
+                        complaintletterDTO.XmCode = data.tousuXmCode;
+                        complaintletterDTO.XmPackage = data.tousuXmPackage;
+                        complaintletterDTO.PurchaserName = data.tousuPurchaserName;
+
+                        complaintletterDTO.Agency = data.tousuAgency;
+                        complaintletterDTO.IsNotice = data.tousuIsNotice;
+                        complaintletterDTO.NoticeDate = data.tousuNoticeDate;
+                        complaintletterDTO.IsResultnotice = data.tousuIsResultnotice;
+                        complaintletterDTO.ResultnoticeDate = data.tousuResultnoticeDate;
+                        complaintletterDTO.Modifier = curentuser.Id;
+                        complaintletterDTO.Modifytime = DateTime.Now;
+                        complaintletterDTO.Status = 1;
+                        if (challengeletterDTO != null)
+                        {
+                            complaintletterDTO.RequestInfo = challengeletterDTO.RequestInfo;
+                        }
+                        resultEntity = _cooperOrderService.saveComplaintletter(complaintletterDTO);
+                    }
+                    else
+                    {
+                        complaintletterDTO = new TComplaintletterDTO();
+                        complaintletterDTO.OrderId = data.Id;
+                        complaintletterDTO.TsrName = data.TsrName;
+                        complaintletterDTO.TsrAddress = data.TsrAddress;
+                        complaintletterDTO.TsrPostcode = data.TsrPostcode;
+                        complaintletterDTO.TsrCorporation = data.TsrCorporation;
+                        complaintletterDTO.TsrPhone = data.TsrPhone;
+                        complaintletterDTO.TsrId = data.TsrId;
+
+                        complaintletterDTO.XmName = data.tousuXmName;
+                        complaintletterDTO.XmCode = data.tousuXmCode;
+                        complaintletterDTO.XmPackage = data.tousuXmPackage;
+                        complaintletterDTO.PurchaserName = data.tousuPurchaserName;
+
+                        complaintletterDTO.Agency = data.tousuAgency;
+                        complaintletterDTO.IsNotice = data.tousuIsNotice;
+                        complaintletterDTO.NoticeDate = data.tousuNoticeDate;
+                        complaintletterDTO.IsResultnotice = data.tousuIsResultnotice;
+                        complaintletterDTO.ResultnoticeDate = data.tousuResultnoticeDate;
+                        complaintletterDTO.Modifier = curentuser.Id;
+                        complaintletterDTO.Modifytime = DateTime.Now;
+                        complaintletterDTO.Creater = curentuser.Id;
+                        complaintletterDTO.Createtime = complaintletterDTO.Modifytime;
+                        complaintletterDTO.Status = 1;
+                        if (challengeletterDTO != null)
+                        {
+                            complaintletterDTO.RequestInfo = challengeletterDTO.RequestInfo;
+                        }
+                        resultEntity = _cooperOrderService.saveComplaintletter(complaintletterDTO);
+                    }
+                    resultEntity = _cooperOrderService.deleteComplaintShouquandaibiao(complaintletterDTO.Id);
+                    if (data.tousuShouquandaibiao != null && data.tousuShouquandaibiao.Length > 0)
+                    {
+                        for (int i = 0; i < data.tousuShouquandaibiao.Length; i++)
+                        {
+                            if (!(string.IsNullOrEmpty(data.tousuShouquandaibiao[i])
+                             && string.IsNullOrEmpty(data.tousuLianxidianhua[i])
+                             && string.IsNullOrEmpty(data.tousuDizhi[i])
+                             && string.IsNullOrEmpty(data.tousuYoubian[i])))
+                            {
+                                var complaintShouquandaibiaoDTO = new TComplaintShouquandaibiaoDTO();
+                                complaintShouquandaibiaoDTO.ComplaintId = complaintletterDTO.Id;
+                                complaintShouquandaibiaoDTO.Shouquandaibiao = data.tousuShouquandaibiao[i];
+                                complaintShouquandaibiaoDTO.Lianxidianhua = data.tousuLianxidianhua[i];
+                                complaintShouquandaibiaoDTO.Dizhi = data.tousuDizhi[i];
+                                complaintShouquandaibiaoDTO.Youbian = data.tousuYoubian[i];
+                                complaintShouquandaibiaoDTO.Sort = i;
+                                resultEntity = _cooperOrderService.saveComplaintShouquandaibiao(complaintShouquandaibiaoDTO);
+                            }
+                              
                         }
                     }
 
 
-                
-
-                    
-                }
-
-            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)
+                    resultEntity = _cooperOrderService.deleteComplaintRespondent(complaintletterDTO.Id);
+                    if (data.tousuRespondent != null && data.tousuRespondent.Length > 0)
                     {
-                        data.Money = 0;
+                        for (int i = 0; i < data.tousuRespondent.Length; i++)
+                        {
+                            if (!(string.IsNullOrEmpty(data.tousuRespondent[i])
+                           && string.IsNullOrEmpty(data.tousuAddress[i])
+                           && string.IsNullOrEmpty(data.tousuPostcode[i])
+                           && string.IsNullOrEmpty(data.tousuContacts[i])
+                            && string.IsNullOrEmpty(data.tousuPhone[i])))
+                            {
+                                var complaintRespondentDTO = new TComplaintRespondentDTO();
+                                complaintRespondentDTO.ComplaintId = complaintletterDTO.Id;
+                                complaintRespondentDTO.Respondent = data.tousuRespondent[i];
+                                complaintRespondentDTO.Address = data.tousuAddress[i];
+                                complaintRespondentDTO.Postcode = data.tousuPostcode[i];
+                                complaintRespondentDTO.Contacts = data.tousuContacts[i];
+                                complaintRespondentDTO.Phone = data.tousuPhone[i];
+                                complaintRespondentDTO.Sort = i;
+                                resultEntity = _cooperOrderService.saveComplaintRespondent(complaintRespondentDTO);
+                            }
+                               
+                        }
                     }
-                    else
+
+                    resultEntity = _cooperOrderService.deleteComplaintGongyingshang(complaintletterDTO.Id);
+                    if (data.Gongytingshang != null && data.Gongytingshang.Length > 0)
                     {
-                        data.Money = data.Money.Value - data.Youhui.Value;
+                        for (int i = 0; i < data.Gongytingshang.Length; i++)
+                        {
+                            if (!(string.IsNullOrEmpty(data.Gongytingshang[i])
+                          && string.IsNullOrEmpty(data.gongyingshangYoubian[i])
+                          && string.IsNullOrEmpty(data.gongyingshangLianxiren[i])
+                          && string.IsNullOrEmpty(data.gongyingshangLianxidianhua[i])
+                           && string.IsNullOrEmpty(data.gongyingshangDizhi[i])))
+                            {
+                                var complaintGongyingshangDTO = new TComplaintGongyingshangDTO();
+                                complaintGongyingshangDTO.ComplaintId = complaintletterDTO.Id;
+                                complaintGongyingshangDTO.Gongytingshang = data.Gongytingshang[i];
+                                complaintGongyingshangDTO.Youbian = data.gongyingshangYoubian[i];
+                                complaintGongyingshangDTO.Lianxiren = data.gongyingshangLianxiren[i];
+                                complaintGongyingshangDTO.Lianxidianhua = data.gongyingshangLianxidianhua[i];
+                                complaintGongyingshangDTO.Dizhi = data.gongyingshangDizhi[i];
+                                complaintGongyingshangDTO.Sort = i;
+                                resultEntity = _cooperOrderService.saveComplaintGongyingshang(complaintGongyingshangDTO);
+                            }
+                               
+                        }
+                    }
+
+                    resultEntity = _cooperOrderService.deleteChallengeItem(complaintletterDTO.Id);
+                    if (challengeletterDTO!=null)
+                    {
+                        var challengeItemDTOs = _cooperOrderService.GetListChallengeItem(challengeletterDTO.Id);
+                        if (challengeItemDTOs != null && challengeItemDTOs.Count > 0)
+                        {
+                            for (int i = 0; i < challengeItemDTOs.Count; i++)
+                            {
+
+                                var complaintItemDTO = new TComplaintItemDTO();
+                                complaintItemDTO.ComplaintId = complaintletterDTO.Id;
+                                complaintItemDTO.Question = challengeItemDTOs[i].Question;
+                                complaintItemDTO.Evidential = challengeItemDTOs[i].Evidential;
+                                //complaintItemDTO.Law = data.Law[i];
+                                //complaintItemDTO.Lawcoment = data.Lawcoment[i];
+                                complaintItemDTO.Sort = i;
+                                resultEntity = _cooperOrderService.saveComplaintItem(complaintItemDTO);
+
+
+                            }
+                        }
                     }
                    
+
                 }
-                else if (youHuiDTOs.Youhuistandard == "02")
+                else if (data.OrderType1 == "浠f嫙璐ㄧ枒鍑�")
                 {
-                    if (youHuiDTOs.YouHui.Value >= 100)
+                    //鏌ヨ涓昏〃
+                    var challengeletterDTO = _cooperOrderService.GetListChallengeletter(data.Id).FirstOrDefault();
+                    if (challengeletterDTO != null)
                     {
-                        data.Youhui = data.Money.Value;
-                        data.Money = 0;
+                        challengeletterDTO.GysName = data.GysName;
+                        challengeletterDTO.GysAddress = data.GysAddress;
+                        challengeletterDTO.GysPostcode = data.GysPostcode;
+                        challengeletterDTO.GysContacts = data.GysContacts;
+                        challengeletterDTO.GysPhone = data.GysPhone;
+
+                        challengeletterDTO.XmName = data.zhiyiXmName;
+                        challengeletterDTO.XmCode = data.zhiyiXmCode;
+                        challengeletterDTO.XmPackage = data.zhiyiXmPackage;
+                        challengeletterDTO.PurchaserName = data.zhiyiPurchaserName;
+                        challengeletterDTO.DocumentsDate = data.zhiyiDocumentsDate;
+                        challengeletterDTO.Modifier = curentuser.Id;
+                        challengeletterDTO.Modifytime = DateTime.Now;
+                        challengeletterDTO.Status = 1;
+                        resultEntity = _cooperOrderService.saveChallengeletter(challengeletterDTO);
                     }
                     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;
+                        challengeletterDTO = new TChallengeletterDTO();
+                        challengeletterDTO.OrderId = data.Id;
+                        challengeletterDTO.GysName = data.GysName;
+                        challengeletterDTO.GysAddress = data.GysAddress;
+                        challengeletterDTO.GysPostcode = data.GysPostcode;
+                        challengeletterDTO.GysContacts = data.GysContacts;
+                        challengeletterDTO.GysPhone = data.GysPhone;
 
-            resultEntity = _cooperOrderService.save(data);
-            //    scope.Complete();
-            //}
+                        challengeletterDTO.XmName = data.zhiyiXmName;
+                        challengeletterDTO.XmCode = data.zhiyiXmCode;
+                        challengeletterDTO.XmPackage = data.zhiyiXmPackage;
+                        challengeletterDTO.PurchaserName = data.zhiyiPurchaserName;
+                        challengeletterDTO.DocumentsDate = data.zhiyiDocumentsDate;
+                        challengeletterDTO.Modifier = curentuser.Id;
+                        challengeletterDTO.Modifytime = DateTime.Now;
+                        challengeletterDTO.Creater = curentuser.Id;
+                        challengeletterDTO.Createtime = challengeletterDTO.Modifytime;
+                        challengeletterDTO.Status = 1;
+                        resultEntity = _cooperOrderService.saveChallengeletter(challengeletterDTO);
+                    }
+
+                    resultEntity = _cooperOrderService.deleteComplaintShouquandaibiao(challengeletterDTO.Id);
+                    if (data.zhiyiShouquandaibiao != null && data.zhiyiShouquandaibiao.Length > 0)
+                    {
+                        for (int i = 0; i < data.zhiyiShouquandaibiao.Length; i++)
+                        {
+                            if (!(string.IsNullOrEmpty(data.zhiyiShouquandaibiao[i])
+                           && string.IsNullOrEmpty(data.zhiyiLianxidianhua[i])
+                           && string.IsNullOrEmpty(data.zhiyiDizhi[i])
+                           && string.IsNullOrEmpty(data.zhiyiYoubian[i])))
+                            {
+                                var complaintShouquandaibiaoDTO = new TComplaintShouquandaibiaoDTO();
+                                complaintShouquandaibiaoDTO.ComplaintId = challengeletterDTO.Id;
+                                complaintShouquandaibiaoDTO.Shouquandaibiao = data.zhiyiShouquandaibiao[i];
+                                complaintShouquandaibiaoDTO.Lianxidianhua = data.zhiyiLianxidianhua[i];
+                                complaintShouquandaibiaoDTO.Dizhi = data.zhiyiDizhi[i];
+                                complaintShouquandaibiaoDTO.Youbian = data.zhiyiYoubian[i];
+                                complaintShouquandaibiaoDTO.Sort = i;
+                                resultEntity = _cooperOrderService.saveComplaintShouquandaibiao(complaintShouquandaibiaoDTO);
+                            }
+                                
+                        }
+                    }
+
+
+                }
+                scope.Complete();
+            }
 
 
             return new JsonResult(resultEntity);
@@ -616,19 +1169,141 @@
             ResultEntity resultEntity = new ResultEntity();
             resultEntity.Result = false;
 
-            CooperOrderDTO dto = _cooperOrderService.Get(id);
-            if(dto.ShouliStatus != "1")
+            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required,
+          new TransactionOptions
+          {
+              IsolationLevel = IsolationLevel.ReadCommitted,
+              Timeout = TransactionManager.MaximumTimeout
+          }
+          ))
             {
-                resultEntity.Result = false;
-                resultEntity.Message = "鍙湁宸蹭笅鍗曠姸鎬佺殑璁㈠崟鎵嶈兘鍙楃悊";
-                return new JsonResult(resultEntity);
+
+                CooperOrderDTO dto = _cooperOrderService.Get(id);
+                if (dto.ShouliStatus != "1")
+                {
+                    resultEntity.Result = false;
+                    resultEntity.Message = "鍙湁宸蹭笅鍗曠姸鎬佺殑璁㈠崟鎵嶈兘鍙楃悊";
+                    return new JsonResult(resultEntity);
+                }
+
+
+                if (dto.OrderType == "01")
+                {
+                    var shi = _fiBookService.Get(dto.OrderType1);
+                    if (string.IsNullOrEmpty(shi.Id))
+                    {
+                        resultEntity.Result = false;
+                        resultEntity.Message = "鏈壘鍒拌鍟嗗搧";
+                        return new JsonResult(resultEntity);
+                    }
+                    var admGoodsManageDTOs = _admGoodsManageService.GetList().Where(x => x.ISBN == shi.BookNo).FirstOrDefault();
+
+                    if (admGoodsManageDTOs == null)
+                    {
+
+
+                        resultEntity.Result = false;
+                        resultEntity.Message = "娌℃湁鎵惧埌璇ュ晢鍝�";
+                        return new JsonResult(resultEntity);
+
+                    }
+                    else if (!admGoodsManageDTOs.GoodsLeft.HasValue)
+                    {
+                        resultEntity.Result = false;
+                        resultEntity.Message = "璇ュ晢鍝佹病鏈夊簱瀛�";
+                        return new JsonResult(resultEntity);
+
+                    }
+                    else if (admGoodsManageDTOs.GoodsLeft.Value < dto.OrderNum)
+                    {
+                        resultEntity.Result = false;
+                        resultEntity.Message = "璇ュ晢鍝佸簱瀛樹笉瓒�";
+                        return new JsonResult(resultEntity);
+
+                    }
+                    var left = admGoodsManageDTOs.GoodsLeft - dto.OrderNum;
+                    admGoodsManageDTOs.GoodsLeft = left;
+
+                    resultEntity = _admGoodsManageService.save(admGoodsManageDTOs);
+
+                    AdmGoodsRecordDTO dto1 = new AdmGoodsRecordDTO();
+                    dto1.GoodsId = admGoodsManageDTOs.Id;
+                    dto1.GoodsNum = dto.OrderNum;
+                    dto1.GoodsLeft = admGoodsManageDTOs.GoodsLeft;
+                    dto1.RecordTypeId = "02";
+                    dto1.RecStatus = "A";
+                    dto1.Creater = curentuser.Id;
+                    dto1.Createtime = DateTime.Now;
+                    dto1.Modifier = curentuser.Id;
+                    dto1.Modifytime = DateTime.Now;
+                    dto1.OperationalMatters = "璁㈠崟锛�" + dto.OrderNo + " 璐拱涔︾睄";
+                    resultEntity = _admGoodsRecordService.save(dto1);
+
+                }
+
+
+                if(dto.Money<=0 && dto.OrderType == "05")
+                {
+                var cooperatecustomCustomerDTO = _cooperatecustomCustomerService.Get(dto.Khdw);
+                var fiMemberDTO = _fiMemberService.Get(dto.OrderType1);
+                //寮�閫氫細鍛�
+                string huiyuanurl = _configuration.GetSection("huiyuanurl").Value;
+                string OAWriteChangeAsync = _configuration.GetSection("OAWriteChangeAsync").Value;
+
+                Uri postUrl2 = new Uri(huiyuanurl + OAWriteChangeAsync);
+                JObject questions2 = new JObject();
+                questions2.Add("UserID", cooperatecustomCustomerDTO.HuiyuanId);
+                questions2.Add("PhoneNumber", cooperatecustomCustomerDTO.Tel);
+                questions2.Add("VIPName", fiMemberDTO.MemberType);
+                questions2.Add("FromName", "OA");
+                questions2.Add("UserName", cooperatecustomCustomerDTO.Name);
+
+
+
+
+
+                string requestJson2 = questions2.ToString();
+                    string result2 = string.Empty;
+
+                    using (HttpContent httpContent = new StringContent(requestJson2))
+                    {
+                        httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
+
+                        using (HttpClient httpClient = new HttpClient())
+                        {
+                            httpClient.Timeout = new TimeSpan(0, 0, 10);
+                            HttpResponseMessage responseMessage = httpClient.PostAsync(postUrl2, httpContent).Result;
+                            result2 = responseMessage.Content.ReadAsStringAsync().Result;
+                        }
+                           
+                    }
+
+                    _logger.LogInformation("result2:" + result2);
+                    JObject jobjectresult = (JObject)JsonConvert.DeserializeObject(result2);
+
+                    if (jobjectresult["code"] != null && jobjectresult["code"].ToString() == "1")
+                    {
+                        cooperatecustomCustomerDTO.HuiyuanId = jobjectresult["UserID"].ToString();
+                        _cooperatecustomCustomerService.save(cooperatecustomCustomerDTO);
+                        resultEntity.Result = true;
+                    }
+                    else
+                    {
+                        resultEntity.Result = false;
+                        resultEntity.Message = "鍐欏叆浼氬憳鏉冮檺澶辫触";
+                        return new JsonResult(resultEntity);
+                    }
+
+                }
+
+                dto.Shoulier = curentuser.Id;
+                dto.Shoulitime = DateTime.Now;
+                dto.ShouliStatus = "2";
+
+                resultEntity = _cooperOrderService.shouli(dto);
+
+                scope.Complete();
             }
-
-            dto.Shoulier = curentuser.Id;
-            dto.Shoulitime = DateTime.Now;
-            dto.ShouliStatus = "2";
-
-              resultEntity = _cooperOrderService.shouli(dto);
 
             return new JsonResult(resultEntity);
         }
@@ -649,9 +1324,10 @@
             //dto.Id = id;
             dto.Wangonger = curentuser.Id;
             dto.Wangongtime = DateTime.Now;
+            dto.WangongStatus = "A";
             dto.ShouliStatus = "4";
 
-            ResultEntity resultEntity = _cooperOrderService.save(dto);
+            ResultEntity resultEntity = _cooperOrderService.Wangong(dto);
 
             return new JsonResult(resultEntity);
         }
@@ -662,38 +1338,142 @@
         {
             var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
             ViewData["curentuser"] = curentuser;
+            var cooperOrderDTO = _cooperOrderService.Get(id);
             ViewData["Chedanid"] = id;
-
+            ViewData["Money"] = cooperOrderDTO.Money.Value.ToString();
 
 
             return View();
         }
         [CheckLogin]
-        public IActionResult chedantuihuan(decimal Price, string Chedanid)
+        public IActionResult chedantuihuan(string Chedanid, decimal Price=0,string Chedanyuany="")
         {
             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")
+            
+            using (TransactionScope scope = new TransactionScope())
             {
-                resultEntity.Result = false;
-                resultEntity.Message = "鍙湁鍙楃悊鐘舵�佺殑璁㈠崟鎵嶈兘鎾ゅ崟";
-                return new JsonResult(resultEntity);
+              
+                CooperOrderDTO dto = _cooperOrderService.Get(Chedanid);
+                if (dto.ShouliStatus != "2")
+                {
+                    resultEntity.Result = false;
+                    resultEntity.Message = "鍙湁鍙楃悊鐘舵�佺殑璁㈠崟鎵嶈兘鎾ゅ崟";
+                    return new JsonResult(resultEntity);
+                }
+
+
+                if (dto.OrderType == "01")
+                {
+                    var shi = _fiBookService.Get(dto.OrderType1);
+                    if (string.IsNullOrEmpty(shi.Id))
+                    {
+                        resultEntity.Result = false;
+                        resultEntity.Message = "鏈壘鍒拌鍟嗗搧";
+                        return new JsonResult(resultEntity);
+                    }
+                    var admGoodsManageDTOs = _admGoodsManageService.GetList().Where(x => x.ISBN == shi.BookNo).FirstOrDefault();
+
+                    if (admGoodsManageDTOs == null)
+                    {
+
+
+                        resultEntity.Result = false;
+                        resultEntity.Message = "娌℃湁鎵惧埌璇ュ晢鍝�";
+                        return new JsonResult(resultEntity);
+
+                    }
+
+                    var left = admGoodsManageDTOs.GoodsLeft + dto.OrderNum;
+                    admGoodsManageDTOs.GoodsLeft = left;
+
+                    resultEntity = _admGoodsManageService.save(admGoodsManageDTOs);
+
+                    AdmGoodsRecordDTO dto1 = new AdmGoodsRecordDTO();
+                    dto1.GoodsId = admGoodsManageDTOs.Id;
+                    dto1.GoodsNum = dto.OrderNum;
+                    dto1.GoodsLeft = admGoodsManageDTOs.GoodsLeft;
+                    dto1.RecordTypeId = "01";
+                    dto1.RecStatus = "A";
+                    dto1.Creater = curentuser.Id;
+                    dto1.Createtime = DateTime.Now;
+                    dto1.Modifier = curentuser.Id;
+                    dto1.Modifytime = DateTime.Now;
+                    dto1.OperationalMatters = "璁㈠崟锛�" + dto.OrderNo + " 鎾ゅ崟";
+                    resultEntity = _admGoodsRecordService.save(dto1);
+
+                }
+
+
+                dto.Chedaner = curentuser.Id;
+                dto.Chedantime = DateTime.Now;
+                dto.ChedanStatus = "A";
+                dto.Chedan = Price;
+                dto.ShouliStatus = "0";
+                if (!string.IsNullOrWhiteSpace(Chedanyuany))
+                    dto.Remark += "    " + Chedanyuany;
+                resultEntity = _cooperOrderService.chedan(dto);
+
+
+                var fiAccountRecordDTOs = _iFiAccountRecordService.GetList("璁㈠崟鏀舵"+dto.OrderNo, dto.OrderNo);
+                if ( Price>0 && fiAccountRecordDTOs != null && fiAccountRecordDTOs.Count > 0)
+                {
+                    var sysCodeDtls = _liaotianService.GetSYScode("CooperVisit", "jtype");
+                    //foreach (var fiAccountRecordDTO in fiAccountRecordDTOs)
+                    //{
+                       
+                        CooperatecustomCustomerDTO cooperatecustomCustomerDTO = _cooperatecustomCustomerService.Get(dto.Khdw);
+                        FiAccountRecordDTO data1 = new FiAccountRecordDTO();
+                        data1.RecStatus = "A";
+                        data1.Creater = curentuser.Id;
+                        data1.Createtime = DateTime.Now;
+                        data1.Modifier = curentuser.Id;
+                        data1.Modifytime = DateTime.Now;
+                        data1.SubjectId = fiAccountRecordDTOs[0].SubjectId;
+
+                        data1.AccountId = fiAccountRecordDTOs[0].AccountId;
+                        data1.Money = Price;
+                        data1.PaymentUnit = cooperatecustomCustomerDTO.Name;
+                        var ssss = sysCodeDtls.Where(x => x.CodeSn == dto.OrderType).FirstOrDefault();
+                        if (ssss!=null)
+                        {
+                            dto.OrderTypeName = ssss.Comments;
+                        }
+                        var book = _fiBookService.Get(dto.OrderType1);
+                        var member = _fiMemberService.Get(dto.OrderType1);
+                        if (book != null)
+                        {
+                            dto.OrderType1 = book.BookName;
+                        }
+                        if (member != null)
+                        {
+                            dto.OrderType1 = member.MemberType;
+                        }
+                        data1.OperationalMatters = dto.OrderTypeName + dto.OrderType1 + dto.OrderType2 + " 璁㈠崟鎾ゅ崟閫�娆�"  ;
+                        data1.Remark =  dto.OrderNo;
+
+
+                        FiAccountDTO firmAccount = _fiAccountService.Get(data1.AccountId);
+
+
+                        data1.RecordTypeId = "2";//閫�娆�
+                        data1.Department = "";
+
+
+
+                        firmAccount.AllIncome = (firmAccount.AllIncome ?? 0) - Price;
+                        firmAccount.Balance = (firmAccount.Balance ?? 0) - Price;
+
+                        data1.AccountMoney = firmAccount.Balance;
+                        resultEntity = _iFiAccountRecordService.save(data1);
+                        resultEntity = _fiAccountService.save(firmAccount);
+                    //}
+                }
+                scope.Complete();
             }
-
-           
-            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]
@@ -871,7 +1651,7 @@
                 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")
+            if (OrderType == "02"  || OrderType == "04" || OrderType == "06"   || OrderType == "09" || OrderType == "08")
             {
                 var shi = _fiServiceService.GetList().Where(x=>x.ServiceTypeTop == OrderType).Select(x => new { code = x.ServiceType, label = x.ServiceType }).Distinct().ToList();
                 result = JsonConvert.SerializeObject(shi);
@@ -887,7 +1667,7 @@
                 result = JsonConvert.SerializeObject(shi);
             }
 
-            if (OrderType == "08" || OrderType == "10" || OrderType == "11")
+            if (OrderType == "10" || OrderType == "11")
             {
                
                 result = "[]";
@@ -946,7 +1726,10 @@
 
                
             }
-           
+            if (result == "")
+            {
+                result = "[]";
+            }
             return result;
 
         }
@@ -1052,5 +1835,1450 @@
             return new JsonResult(returnMsg);
         }
 
+
+
+        [CheckLogin]
+        public IActionResult IndexWenshu()
+        {
+            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.status = _liaotianService.GetSYScode("t_challengeletter", "status").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
+
+
+
+            return View();
+
+        }
+
+
+
+        [CheckLogin]
+        public IActionResult GetListWenshu(CooperOrderDTOSearch search)
+        {
+            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
+            ViewData["curentuser"] = curentuser;
+            //search.Status = 1;
+            //search.Creater = curentuser.Id;
+            //JsonResult jsonResult =   new JsonResult(_liaotianService.SearchByPaging(search), new Newtonsoft.Json.Serialization.DefaultContractResolver());
+            return new JsonResult(_cooperOrderService.SearchByPagingWenshu(search));
+        }
+
+
+        [CheckLogin]
+        public IActionResult selectWenshu()
+        {
+            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;
+            var pageEntities = _pltPageService.GetUserPage(curentuser.Id, "/CooperOrder/selectWenshu");
+            var pageEntities2 = pageEntities.Where(x => x.PageMethod == "02").ToList();
+            ViewData["ActionInfo2"] = pageEntities2;
+
+            ViewBag.Wenshuleixing = _liaotianService.GetSYScode("t_challengeletter", "Wenshuleixing").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
+            ViewBag.status = _liaotianService.GetSYScode("t_challengeletter", "status").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
+
+            return View();
+
+        }
+
+
+
+        public IActionResult EditZhiyihan(string id = null, string ReturnID = null)
+        {
+            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
+            ViewData["curentuser"] = curentuser;
+            var sysCodeDtls = _liaotianService.GetSYScode("expert_test_topicjiexi", "falv").OrderBy(x => x.CodeSn).ToList();//娉曞緥
+            var sysCodeDtls1 = _liaotianService.GetSYScode("t_complaint_items", "law").OrderBy(x => x.CodeSn).ToList();//娉曞緥渚濇嵁
+            foreach (var sysCodeDtl in sysCodeDtls1)
+            {
+                var sysCodeDtl1 = sysCodeDtls.Where(x => x.CodeSn == sysCodeDtl.Comments).FirstOrDefault();
+                if (sysCodeDtl1 != null)
+                    sysCodeDtl.Classify3 = sysCodeDtl1.Comments;
+            }
+
+            //璐ㄧ枒鍑�
+            List<TChallengeletterDTO> challengeletterDTOs = _cooperOrderService.GetListChallengeletter(id);
+            TChallengeletterDTO challengeletterDTO = new TChallengeletterDTO();
+            if (challengeletterDTOs != null && challengeletterDTOs.Count > 0)
+            {
+                challengeletterDTO = challengeletterDTOs[0];
+                if (challengeletterDTO.DocumentsDate.HasValue)
+                {
+                    challengeletterDTO.DocumentsDateName = challengeletterDTO.DocumentsDate.Value.ToString("yyyy-MM-dd");
+                }
+                List<TChallengeItemDTO> challengeItemDTOs = _cooperOrderService.GetListChallengeItem(challengeletterDTO.Id);
+                if (challengeItemDTOs.Count > 0)
+                {
+                    challengeletterDTO.challengeItemDTOs = challengeItemDTOs;
+                    foreach (var challengeItemDTO in challengeletterDTO.challengeItemDTOs)
+                    {
+                      var sysCodeDtls2 =  sysCodeDtls1.Where(x => x.Classify1 == challengeItemDTO.Question).ToList();
+                        if (!string.IsNullOrEmpty(challengeItemDTO.Law) || !string.IsNullOrEmpty(ReturnID))
+                        {
+                            var law = "";
+                            if (!string.IsNullOrEmpty(challengeItemDTO.Law))
+                            {
+                                law = challengeItemDTO.Law;
+                                if (!string.IsNullOrEmpty(ReturnID))
+                                {
+                                    law += "," + ReturnID;
+                                }
+
+                            }
+                            else
+                            {
+                                law = ReturnID;
+                            }
+
+                            if (!string.IsNullOrEmpty(law))
+                            {
+                                sysCodeDtls2 = sysCodeDtls2.Where(x => law.Split(',').Contains(x.CodeSn)).ToList();
+                            }
+
+                           
+                        }
+                        challengeItemDTO.sysCodeDtls = sysCodeDtls2;
+                    }
+                }
+                else
+                {
+                    var challengeItemDTO = new TChallengeItemDTO();
+                    challengeItemDTO.Id = 1;
+                    challengeletterDTO.challengeItemDTOs = new List<TChallengeItemDTO>() { challengeItemDTO };
+                    challengeletterDTO.challengeItemDTOs[0].sysCodeDtls = new List<SysCodeDtl>() { new SysCodeDtl() };
+                }
+                  
+                List<TComplaintShouquandaibiaoDTO> complaintShouquandaibiaoDTOs = _cooperOrderService.GetListComplaintShouquandaibiao(challengeletterDTO.Id);
+
+                if (complaintShouquandaibiaoDTOs.Count > 0)
+                    challengeletterDTO.complaintShouquandaibiaoDTOs = complaintShouquandaibiaoDTOs;
+                else
+                    challengeletterDTO.complaintShouquandaibiaoDTOs = new List<TComplaintShouquandaibiaoDTO>() { new TComplaintShouquandaibiaoDTO() };
+
+                List<TChallengeRequestInfoDTO> challengeRequestInfoDTOs = _cooperOrderService.GetListChallengeRequestInfo(challengeletterDTO.Id);
+
+                if (challengeRequestInfoDTOs.Count > 0)
+                    challengeletterDTO.challengeRequestInfoDTOs = challengeRequestInfoDTOs;
+                else
+                    challengeletterDTO.challengeRequestInfoDTOs = new List<TChallengeRequestInfoDTO>() { new TChallengeRequestInfoDTO() };
+            }
+            else
+            {
+                var challengeItemDTO = new TChallengeItemDTO();
+                challengeItemDTO.Id = 1;
+                challengeletterDTO.challengeItemDTOs = new List<TChallengeItemDTO>() { challengeItemDTO };
+                challengeletterDTO.challengeItemDTOs[0].sysCodeDtls = new List<SysCodeDtl>() { new SysCodeDtl() };
+                challengeletterDTO.complaintShouquandaibiaoDTOs = new List<TComplaintShouquandaibiaoDTO>() { new TComplaintShouquandaibiaoDTO() };
+                challengeletterDTO.challengeRequestInfoDTOs = new List<TChallengeRequestInfoDTO>() { new TChallengeRequestInfoDTO() };
+            }
+            //ViewBag.challengeletterDTO = challengeletterDTO;
+
+
+
+
+            ViewBag.request_info = _liaotianService.GetSYScode("t_challengeletter", "request_info").OrderBy(x=>x.CodeSn).ToList();//璐ㄧ枒璇锋眰
+            ViewBag.question = _liaotianService.GetSYScode("t_challenge_items", "question").OrderBy(x => x.CodeSn).ToList(); //	璐ㄧ枒浜嬮」
+           
+            ViewBag.law = sysCodeDtls1;//娉曞緥渚濇嵁
+
+
+
+
+
+            ViewData.Model = challengeletterDTO;
+            return View();
+        }
+
+
+        public IActionResult getLaw(string id)
+        {
+            ResultEntity resultEntity = new ResultEntity();
+            resultEntity.Result = true;
+            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
+            ViewData["curentuser"] = curentuser;
+
+           var sysCodeDtl  = _liaotianService.GetSYScode("t_complaint_items", "law").Where(x=>x.CodeSn== id).FirstOrDefault();//娉曞緥渚濇嵁
+
+          
+            if (sysCodeDtl != null )
+            {
+                resultEntity.Message = sysCodeDtl.Contents;
+            }
+
+
+            return new JsonResult(resultEntity);
+        }
+
+        public IActionResult getQuestionLaw(string id, string no,string challengeItemId = "")
+        {
+            ResultEntity<SysCodeDtl> resultEntity = new ResultEntity<SysCodeDtl>();
+            resultEntity.Result = true;
+            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
+            ViewData["curentuser"] = curentuser;
+
+            var sysCodeDtls = _liaotianService.GetSYScode("t_complaint_items", "law").Where(x => x.Classify1 == id).OrderBy(x => x.CodeSn).ToList().ToList();//娉曞緥渚濇嵁
+            var sysCodeDtls1 = _liaotianService.GetSYScode("expert_test_topicjiexi", "falv");//娉曞緥
+            foreach (var sysCodeDtl in sysCodeDtls)
+            {
+                var sysCodeDtl1 = sysCodeDtls1.Where(x => x.CodeSn == sysCodeDtl.Comments).FirstOrDefault();
+                if (sysCodeDtl1 != null)
+                    sysCodeDtl.Classify3 = sysCodeDtl1.Comments;
+            }
+
+            //if (sysCodeDtl != null)
+            //{
+            //    resultEntity.Message = sysCodeDtl.Contents;
+            //}
+            resultEntity.Message = no;
+            resultEntity.Remark = challengeItemId;
+            resultEntity.Remark2 = id;
+            resultEntity.DataList = sysCodeDtls;
+
+            return new JsonResult(resultEntity);
+        }
+
+
+        public IActionResult getZhiyihan(string id = null)
+        {
+            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
+            ViewData["curentuser"] = curentuser;
+            var sysCodeDtls = _liaotianService.GetSYScode("expert_test_topicjiexi", "falv").OrderBy(x => x.CodeSn).ToList();//娉曞緥
+            var sysCodeDtls1 = _liaotianService.GetSYScode("t_complaint_items", "law").OrderBy(x => x.CodeSn).ToList();//娉曞緥渚濇嵁
+            foreach (var sysCodeDtl in sysCodeDtls1)
+            {
+                var sysCodeDtl1 = sysCodeDtls.Where(x => x.CodeSn == sysCodeDtl.Comments).FirstOrDefault();
+                if (sysCodeDtl1 != null)
+                    sysCodeDtl.Classify3 = sysCodeDtl1.Comments;
+            }
+
+            //璐ㄧ枒鍑�
+            List<TChallengeletterDTO> challengeletterDTOs = _cooperOrderService.GetListChallengeletter(id);
+            TChallengeletterDTO challengeletterDTO = new TChallengeletterDTO();
+            if (challengeletterDTOs != null && challengeletterDTOs.Count > 0)
+            {
+                challengeletterDTO = challengeletterDTOs[0];
+                if (challengeletterDTO.DocumentsDate.HasValue)
+                {
+                    challengeletterDTO.DocumentsDateName = challengeletterDTO.DocumentsDate.Value.ToString("yyyy-MM-dd");
+                }
+                List<TChallengeItemDTO> challengeItemDTOs = _cooperOrderService.GetListChallengeItem(challengeletterDTO.Id);
+                if (challengeItemDTOs.Count > 0)
+                {
+                    challengeletterDTO.challengeItemDTOs = challengeItemDTOs;
+                    foreach (var challengeItemDTO in challengeletterDTO.challengeItemDTOs)
+                    {
+                        var sysCodeDtls2 = sysCodeDtls1.Where(x => x.Classify1 == challengeItemDTO.Question).ToList();
+                        challengeItemDTO.sysCodeDtls = sysCodeDtls2;
+                    }
+                }
+                else
+                {
+                    challengeletterDTO.challengeItemDTOs = new List<TChallengeItemDTO>() { new TChallengeItemDTO() };
+                    challengeletterDTO.challengeItemDTOs[0].sysCodeDtls = new List<SysCodeDtl>() { new SysCodeDtl() };
+                }
+
+                List<TComplaintShouquandaibiaoDTO> complaintShouquandaibiaoDTOs = _cooperOrderService.GetListComplaintShouquandaibiao(challengeletterDTO.Id);
+
+                if (complaintShouquandaibiaoDTOs.Count > 0)
+                    challengeletterDTO.complaintShouquandaibiaoDTOs = complaintShouquandaibiaoDTOs;
+                else
+                    challengeletterDTO.complaintShouquandaibiaoDTOs = new List<TComplaintShouquandaibiaoDTO>() { new TComplaintShouquandaibiaoDTO() };
+            }
+            else
+            {
+                challengeletterDTO.challengeItemDTOs = new List<TChallengeItemDTO>() { new TChallengeItemDTO() };
+                challengeletterDTO.challengeItemDTOs[0].sysCodeDtls = new List<SysCodeDtl>() { new SysCodeDtl() };
+                challengeletterDTO.complaintShouquandaibiaoDTOs = new List<TComplaintShouquandaibiaoDTO>() { new TComplaintShouquandaibiaoDTO() };
+            }
+            var question = _liaotianService.GetSYScode("t_challenge_items", "question").OrderBy(x => x.CodeSn).ToList(); //	璐ㄧ枒浜嬮」
+            StringBuilder data = new StringBuilder();
+
+            for (int i = 0; i < challengeletterDTO.challengeItemDTOs.Count; i++)
+            {
+                if (challengeletterDTO.challengeItemDTOs.Count == 1)
+                {
+                    data.Append("<div class=\"clearfix layer-area\" style=\"padding-bottom:15px; \">");
+                    data.Append("<label grouptype=\"Vdata\"  id=\"Questionlabel\" class=\"text-right col-sm-1 col-md-1 control-label\">鎶曡瘔浜嬮」</label>");
+                    data.Append("<div class=\"col-sm-4 col-md-4\" grouptype =\"Vdata\" > ");
+                    data.Append(" <select class=\"form - control\" name=\"Question\" data-placeholder=\"閫夋嫨 搴忓垪...\" onchange=\"Questionchangge(" + i + "); \">");
+                    data.Append("<option value=\"\" hassubinfo=\"true\">璇烽�夋嫨</option>");
+                    foreach (var item in question)
+                    {
+                        if (!item.CodeSn.Equals(challengeletterDTO.challengeItemDTOs[i].Question))
+                        {
+                            data.Append("<option value=\"" + item.CodeSn + "\" hassubinfo=\"true\">" + item.Comments + "</option>");
+                        }
+                        else
+                        {
+                            data.Append("<option value=\"" + item.CodeSn + "\" hassubinfo=\"true\"  selected=\"selected\" >" + item.Comments + "</option>");
+                        }
+                    }
+                    data.Append("</select>");
+                    data.Append(" </div>");
+                    if (i == 0)
+                    {
+                        data.Append("<div class=\"col-sm-2 col-md-2\" grouptype=\"Vdata\">  <button type=\"button\" class=\"addBtn\" onclick =\"addzhiyishixiang(this)\" data-type=\"1\" > 鎶曡瘔浜嬮」</button>   </div>");
+                    }
+                    data.Append(" </div>");
+                    data.Append("<div class=\"clearfix layer-area\" style =\"padding-bottom:15px; \" > ");
+                    data.Append("<label grouptype=\"Vdata\" id=\"Evidentiallabel\"  class=\"text-right col-sm-1 col-md-1 control-label\" > 浜嬪疄渚濇嵁</label>");
+                    data.Append(" <div class=\"col-sm-8 col-md-8\" > ");
+                    data.Append("<textarea class=\"form-control bt\" name =\"Evidential\" title =\"浜嬪疄渚濇嵁\" isempty =\"\" maxlength =\"300\" length =\"long\" > " + challengeletterDTO.challengeItemDTOs[i].Evidential + "</textarea>");
+                    data.Append("</div>");
+                    data.Append("</div>");
+                    data.Append(" <div id=\"falvyiju" + i + "\">");
+                    for (int j = 0; j < challengeletterDTO.challengeItemDTOs[i].sysCodeDtls.Count; j++)
+                    {
+                        if (challengeletterDTO.challengeItemDTOs[i].sysCodeDtls.Count == 1)
+                        {
+                            data.Append("<div class=\"clearfix layer-area\" style=\"padding-bottom:15px; \">");
+                            data.Append("<label grouptype=\"Vdata\" class=\"text-right col-sm-1 col-md-1 control-label\" > 娉曞緥渚濇嵁</label>");
+                            data.Append("<div class=\"col-sm-8 col-md-8\" > 銆�" + challengeletterDTO.challengeItemDTOs[i].sysCodeDtls[j].CodeSn + "銆�"+ challengeletterDTO.challengeItemDTOs[i].sysCodeDtls[j].Classify2 + "锛�"+ challengeletterDTO.challengeItemDTOs[i].sysCodeDtls[j].Contents + "</div>");
+                            data.Append("</div>");
+
+                            
+                        }
+                        else
+                        {
+                            data.Append("<div class=\"clearfix layer-area\" style=\"padding-bottom:15px; \">");
+                            data.Append("<label grouptype=\"Vdata\" class=\"text-right col-sm-1 col-md-1 control-label\" > 娉曞緥渚濇嵁" + (i +1) + "</label>");
+                            data.Append("<div class=\"col-sm-8 col-md-8\" > 銆�" + challengeletterDTO.challengeItemDTOs[i].sysCodeDtls[j].CodeSn + "銆�" + challengeletterDTO.challengeItemDTOs[i].sysCodeDtls[j].Classify2 + "锛�" + challengeletterDTO.challengeItemDTOs[i].sysCodeDtls[j].Contents + "</div>");
+                            data.Append("</div>");
+
+                            
+                        }
+                       
+                    }
+
+
+                    data.Append("</div>");
+                }
+                else
+                {
+                    data.Append("<div class=\"clearfix layer-area\" style=\"padding-bottom:15px; \">");
+                    data.Append("<label grouptype=\"Vdata\" class=\"text-right col-sm-1 col-md-1 control-label\">鎶曡瘔浜嬮」" + (i +1) + "</label>");
+                    data.Append("<div class=\"col-sm-4 col-md-4\" grouptype =\"Vdata\" > ");
+                    data.Append(" <select class=\"form - control\" name=\"Question\" data-placeholder=\"閫夋嫨 搴忓垪...\" onchange=\"Questionchangge(" + i + "); \">");
+                    data.Append("<option value=\"\" hassubinfo=\"true\">璇烽�夋嫨</option>");
+                    foreach (var item in question)
+                    {
+                        if (!item.CodeSn.Equals(challengeletterDTO.challengeItemDTOs[i].Question))
+                        {
+                            data.Append("<option value=\"" + item.CodeSn + "\" hassubinfo=\"true\">" + item.Comments + "</option>");
+                        }
+                        else
+                        {
+                            data.Append("<option value=\"" + item.CodeSn + "\" hassubinfo=\"true\"  selected=\"selected\" >" + item.Comments + "</option>");
+                        }
+                    }
+                    data.Append("</select>");
+                    data.Append(" </div>");
+                    if (i == 0)
+                    {
+                        data.Append("<div class=\"col-sm-2 col-md-2\" grouptype=\"Vdata\">  <button type=\"button\" class=\"addBtn\" onclick =\"addzhiyishixiang(this)\" data-type=\"1\" > 鎶曡瘔浜嬮」</button>   </div>");
+                    }
+                    data.Append(" </div>");
+                    data.Append("<div class=\"clearfix layer-area\" style =\"padding-bottom:15px; \" > ");
+                    data.Append("<label grouptype=\"Vdata\" class=\"text-right col-sm-1 col-md-1 control-label\" > 浜嬪疄渚濇嵁" + (i + 1) + "</label>");
+                    data.Append(" <div class=\"col-sm-8 col-md-8\" > ");
+                    data.Append("<textarea class=\"form-control bt\" name =\"Evidential\" title =\"浜嬪疄渚濇嵁\" isempty =\"\" maxlength =\"300\" length =\"long\" > " + challengeletterDTO.challengeItemDTOs[i].Evidential + "</textarea>");
+                    data.Append("</div>");
+                    data.Append("</div>");
+                    data.Append(" <div id=\"falvyiju" + i + "\">");
+                    for (int j = 0; j < challengeletterDTO.challengeItemDTOs[i].sysCodeDtls.Count; j++)
+                    {
+                        if (challengeletterDTO.challengeItemDTOs[i].sysCodeDtls.Count == 1)
+                        {
+                            data.Append("<div class=\"clearfix layer-area\" style=\"padding-bottom:15px; \">");
+                            data.Append("<label grouptype=\"Vdata\" class=\"text-right col-sm-1 col-md-1 control-label\" > 娉曞緥渚濇嵁</label>");
+                            data.Append("<div class=\"col-sm-8 col-md-8\" > 銆�" + challengeletterDTO.challengeItemDTOs[i].sysCodeDtls[j].CodeSn + "銆�" + challengeletterDTO.challengeItemDTOs[i].sysCodeDtls[j].Classify2 + "锛�" + challengeletterDTO.challengeItemDTOs[i].sysCodeDtls[j].Contents + "</div>");
+                            data.Append("</div>");
+
+
+                        }
+                        else
+                        {
+                            data.Append("<div class=\"clearfix layer-area\" style=\"padding-bottom:15px; \">");
+                            data.Append("<label grouptype=\"Vdata\" class=\"text-right col-sm-1 col-md-1 control-label\" > 娉曞緥渚濇嵁" + (i + 1) + "</label>");
+                            data.Append("<div class=\"col-sm-8 col-md-8\" > 銆�" + challengeletterDTO.challengeItemDTOs[i].sysCodeDtls[j].CodeSn + "銆�" + challengeletterDTO.challengeItemDTOs[i].sysCodeDtls[j].Classify2 + "锛�" + challengeletterDTO.challengeItemDTOs[i].sysCodeDtls[j].Contents + "</div>");
+                            data.Append("</div>");
+
+
+                        }
+                    }
+
+
+                    data.Append("</div>");
+                }
+
+
+               
+            }
+
+            challengeletterDTO.GysId = data.ToString();
+
+            return new JsonResult(challengeletterDTO);
+
+ 
+        }
+
+        /// <summary>
+        /// 淇濆瓨
+        /// </summary>
+        /// <param name="data">宀椾綅瀹炰綋绫诲璞�</param>
+        /// <returns></returns>
+        /// 
+        [CheckLogin]
+        [HttpPost]
+        public IActionResult SaveChallengeletter(CooperOrderDTO data)
+        {
+            ResultEntity resultEntity = new ResultEntity();
+
+            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
+            ViewData["curentuser"] = curentuser;
+            
+
+            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required,
+                new TransactionOptions
+                {
+                    IsolationLevel = IsolationLevel.ReadCommitted,
+                    Timeout = TransactionManager.MaximumTimeout
+                }
+                ))
+            {
+
+
+
+
+                //鏌ヨ涓昏〃
+                var challengeletterDTO = _cooperOrderService.GetListChallengeletter(data.OrderId).FirstOrDefault();
+                if (challengeletterDTO != null)
+                {
+                    challengeletterDTO.GysName = data.GysName;
+                    challengeletterDTO.GysAddress = data.GysAddress;
+                    challengeletterDTO.GysPostcode = data.GysPostcode;
+                    challengeletterDTO.GysContacts = data.GysContacts;
+                    challengeletterDTO.GysPhone = data.GysPhone;
+
+                    challengeletterDTO.XmName = data.zhiyiXmName;
+                    challengeletterDTO.XmCode = data.zhiyiXmCode;
+                    challengeletterDTO.XmPackage = data.zhiyiXmPackage;
+                    challengeletterDTO.PurchaserName = data.zhiyiPurchaserName;
+                    challengeletterDTO.DocumentsDate = data.zhiyiDocumentsDate;
+                    challengeletterDTO.Modifier = curentuser.Id;
+                    challengeletterDTO.Modifytime = DateTime.Now;
+                    challengeletterDTO.Status = int.Parse(data.Status);
+                    challengeletterDTO.RequestInfo = data.RequestInfo;
+                    challengeletterDTO.PrintNum = data.PrintNum;
+                    resultEntity = _cooperOrderService.saveChallengeletter(challengeletterDTO);
+                }
+                else
+                {
+                    challengeletterDTO = new TChallengeletterDTO();
+                    challengeletterDTO.OrderId = data.Id;
+                    challengeletterDTO.GysName = data.GysName;
+                    challengeletterDTO.GysAddress = data.GysAddress;
+                    challengeletterDTO.GysPostcode = data.GysPostcode;
+                    challengeletterDTO.GysContacts = data.GysContacts;
+                    challengeletterDTO.GysPhone = data.GysPhone;
+
+                    challengeletterDTO.XmName = data.zhiyiXmName;
+                    challengeletterDTO.XmCode = data.zhiyiXmCode;
+                    challengeletterDTO.XmPackage = data.zhiyiXmPackage;
+                    challengeletterDTO.PurchaserName = data.zhiyiPurchaserName;
+                    challengeletterDTO.DocumentsDate = data.zhiyiDocumentsDate;
+                    challengeletterDTO.Modifier = curentuser.Id;
+                    challengeletterDTO.Modifytime = DateTime.Now;
+                    challengeletterDTO.Creater = curentuser.Id;
+                    challengeletterDTO.Createtime = challengeletterDTO.Modifytime;
+                    challengeletterDTO.Status =  int.Parse(data.Status); ;
+                    challengeletterDTO.RequestInfo = data.RequestInfo;
+                    challengeletterDTO.PrintNum = data.PrintNum;
+                    resultEntity = _cooperOrderService.saveChallengeletter(challengeletterDTO);
+                }
+
+                resultEntity = _cooperOrderService.deleteComplaintShouquandaibiao(challengeletterDTO.Id);
+                if (data.zhiyiShouquandaibiao != null && data.zhiyiShouquandaibiao.Length > 0)
+                {
+                    for (int i = 0; i < data.zhiyiShouquandaibiao.Length; i++)
+                    {
+                        if (!(string.IsNullOrEmpty(data.zhiyiShouquandaibiao[i])
+                              && string.IsNullOrEmpty(data.zhiyiLianxidianhua[i])
+                              && string.IsNullOrEmpty(data.zhiyiDizhi[i])
+                              && string.IsNullOrEmpty(data.zhiyiYoubian[i])))
+                        {
+                            var complaintShouquandaibiaoDTO = new TComplaintShouquandaibiaoDTO();
+                            complaintShouquandaibiaoDTO.ComplaintId = challengeletterDTO.Id;
+                            complaintShouquandaibiaoDTO.Shouquandaibiao = data.zhiyiShouquandaibiao[i];
+                            complaintShouquandaibiaoDTO.Lianxidianhua = data.zhiyiLianxidianhua[i];
+                            complaintShouquandaibiaoDTO.Dizhi = data.zhiyiDizhi[i];
+                            complaintShouquandaibiaoDTO.Youbian = data.zhiyiYoubian[i];
+                            complaintShouquandaibiaoDTO.Sort = i;
+                            resultEntity = _cooperOrderService.saveComplaintShouquandaibiao(complaintShouquandaibiaoDTO);
+                        }
+                           
+                    }
+                }
+
+
+                resultEntity = _cooperOrderService.deleteChallengeItem(challengeletterDTO.Id);
+                if (data.Question != null && data.Question.Length > 0)
+                {
+                    for (int i = 0; i < data.Question.Length; i++)
+                    {
+                        if (!(string.IsNullOrEmpty(data.Question[i])
+                            && string.IsNullOrEmpty(data.Evidential[i])
+                           ))
+                        {
+                            string Law = "";
+                            var challengeItemId = data.challengeItemId[i];
+                            var Laws = data.Law;
+                            var challengeItemIdlaw = data.challengeItemIdlaw;
+                            if(Laws != null&& Laws.Length > 0)
+                            {
+                                for (int j = 0; j < Laws.Length; j++)
+                                {
+                                    if(challengeItemId == challengeItemIdlaw[j])
+                                    {
+                                        Law += Laws[j] + ",";
+                                    }
+
+                                }
+                                if(!string.IsNullOrEmpty(Law))
+                                    Law = Law.TrimEnd(',');  //绉婚櫎鏈�鍚庣殑閫楀彿
+                            }
+
+                            var challengeItemDTO = new TChallengeItemDTO();
+                            challengeItemDTO.ChallengeId = challengeletterDTO.Id;
+                            challengeItemDTO.Question = data.Question[i];
+                            challengeItemDTO.Questionname = data.Questionname[i];
+                            challengeItemDTO.Evidential = data.Evidential[i];
+                            challengeItemDTO.Law = Law;
+                            //challengeItemDTO.Lawcoment = data.Lawcoment[i];
+                            challengeItemDTO.Sort = i;
+                            resultEntity = _cooperOrderService.saveChallengeItem(challengeItemDTO);
+                        }
+                       
+                    }
+                }
+
+                resultEntity = _cooperOrderService.deleteChallengeRequestInfo(challengeletterDTO.Id);
+                if (data.RequestInfos != null && data.RequestInfos.Length > 0)
+                {
+                    for (int i = 0; i < data.RequestInfos.Length; i++)
+                    {
+                        if (!string.IsNullOrEmpty(data.RequestInfos[i]))
+                           
+                        {
+                            var challengeRequestInfoDTO = new TChallengeRequestInfoDTO();
+                            challengeRequestInfoDTO.ChallengeId = challengeletterDTO.Id;
+                            challengeRequestInfoDTO.RequestInfo = data.RequestInfos[i];
+                            challengeRequestInfoDTO.RequestInfoname = data.RequestInfoname[i];
+                             
+                            resultEntity = _cooperOrderService.saveChallengeRequestInfo(challengeRequestInfoDTO);
+                        }
+
+                    }
+                }
+
+                scope.Complete();
+            }
+
+
+            return new JsonResult(resultEntity);
+        }
+
+
+        public IActionResult PrintZhiyihan(string id = null)
+        {
+            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
+            ViewData["curentuser"] = curentuser;
+            var sysCodeDtls = _liaotianService.GetSYScode("expert_test_topicjiexi", "falv").OrderBy(x => x.CodeSn).ToList();//娉曞緥
+            var sysCodeDtls1 = _liaotianService.GetSYScode("t_complaint_items", "law").OrderBy(x => x.CodeSn).ToList();//娉曞緥渚濇嵁
+            foreach (var sysCodeDtl in sysCodeDtls1)
+            {
+                var sysCodeDtl1 = sysCodeDtls.Where(x => x.CodeSn == sysCodeDtl.Comments).FirstOrDefault();
+                if (sysCodeDtl1 != null)
+                    sysCodeDtl.Classify3 = sysCodeDtl1.Comments;
+            }
+            //璐ㄧ枒鍑�
+            List<TChallengeletterDTO> challengeletterDTOs = _cooperOrderService.GetListChallengeletter(id);
+            TChallengeletterDTO challengeletterDTO = new TChallengeletterDTO();
+            if (challengeletterDTOs != null && challengeletterDTOs.Count > 0)
+            {
+                challengeletterDTO = challengeletterDTOs[0];
+                if (challengeletterDTO.DocumentsDate.HasValue)
+                {
+                    challengeletterDTO.DocumentsDateName = challengeletterDTO.DocumentsDate.Value.ToString("yyyy-MM-dd");
+                }
+                List<TChallengeItemDTO> challengeItemDTOs = _cooperOrderService.GetListChallengeItem(challengeletterDTO.Id);
+                if (challengeItemDTOs.Count > 0)
+                {
+                    challengeletterDTO.challengeItemDTOs = challengeItemDTOs;
+                    foreach (var challengeItemDTO in challengeletterDTO.challengeItemDTOs)
+                    {
+                        var sysCodeDtls2 = sysCodeDtls1.Where(x => x.Classify1 == challengeItemDTO.Question).ToList();
+                        if (!string.IsNullOrEmpty(challengeItemDTO.Law))
+                        {
+                            sysCodeDtls2 = sysCodeDtls2.Where(x => challengeItemDTO.Law.Split(',').Contains(x.CodeSn)).OrderBy(x=>x.Classify3).ToList();
+                        }
+                        challengeItemDTO.sysCodeDtls = sysCodeDtls2;
+                    }
+                }
+                  
+                else
+                {
+                    challengeletterDTO.challengeItemDTOs = new List<TChallengeItemDTO>() { new TChallengeItemDTO() };
+                    challengeletterDTO.challengeItemDTOs[0].sysCodeDtls = new List<SysCodeDtl>() { new SysCodeDtl() };
+                }
+                  
+                List<TComplaintShouquandaibiaoDTO> complaintShouquandaibiaoDTOs = _cooperOrderService.GetListComplaintShouquandaibiao(challengeletterDTO.Id);
+
+                if (complaintShouquandaibiaoDTOs.Count > 0)
+                    challengeletterDTO.complaintShouquandaibiaoDTOs = complaintShouquandaibiaoDTOs;
+                else
+                    challengeletterDTO.complaintShouquandaibiaoDTOs = new List<TComplaintShouquandaibiaoDTO>() /*{ new TComplaintShouquandaibiaoDTO() }*/;
+
+
+                List<TChallengeRequestInfoDTO> challengeRequestInfoDTOs = _cooperOrderService.GetListChallengeRequestInfo(challengeletterDTO.Id);
+
+                if (challengeRequestInfoDTOs.Count > 0)
+                    challengeletterDTO.challengeRequestInfoDTOs = challengeRequestInfoDTOs;
+                else
+                    challengeletterDTO.challengeRequestInfoDTOs = new List<TChallengeRequestInfoDTO>() /*{ new TChallengeRequestInfoDTO() }*/;
+            }
+            else
+            {
+                challengeletterDTO.challengeItemDTOs = new List<TChallengeItemDTO>() { new TChallengeItemDTO() };
+                challengeletterDTO.challengeItemDTOs[0].sysCodeDtls = new List<SysCodeDtl>() { new SysCodeDtl() };
+                challengeletterDTO.complaintShouquandaibiaoDTOs = new List<TComplaintShouquandaibiaoDTO>() /*{ new TComplaintShouquandaibiaoDTO() }*/;
+                challengeletterDTO.challengeRequestInfoDTOs = new List<TChallengeRequestInfoDTO>() /*{ new TChallengeRequestInfoDTO() }*/;
+            }
+            //ViewBag.challengeletterDTO = challengeletterDTO;
+
+
+
+
+            //ViewBag.request_info = _liaotianService.GetSYScode("t_challengeletter", "request_info");//璐ㄧ枒璇锋眰
+            //ViewBag.question = _liaotianService.GetSYScode("t_challenge_items", "question"); //	璐ㄧ枒浜嬮」
+            //var sysCodeDtls = _liaotianService.GetSYScode("expert_test_topicjiexi", "falv");//娉曞緥
+            //var sysCodeDtls1 = _liaotianService.GetSYScode("t_complaint_items", "law");//娉曞緥渚濇嵁
+            //foreach (var sysCodeDtl in sysCodeDtls1)
+            //{
+            //    var sysCodeDtl1 = sysCodeDtls.Where(x => x.CodeSn == sysCodeDtl.Comments).FirstOrDefault();
+            //    if (sysCodeDtl1 != null)
+            //        sysCodeDtl.Comments = sysCodeDtl1.Comments;
+            //}
+
+            //ViewBag.law = sysCodeDtls1;//娉曞緥渚濇嵁
+
+
+            var cooperOrderDTO = _cooperOrderService.Get(id);
+            var cooperatecustomCustomerDTO = _cooperatecustomCustomerService.Get(cooperOrderDTO.Khdw);
+            if (cooperatecustomCustomerDTO.Name.IndexOf("鑲′唤鏈夐檺鍏徃") >= 0)
+            {
+                cooperatecustomCustomerDTO.Zhiwu = "钁d簨闀�";
+            }
+            else if (cooperatecustomCustomerDTO.Name.IndexOf("鏈夐檺鍏徃") >= 0 || cooperatecustomCustomerDTO.Name.IndexOf("鏈夐檺璐d换鍏徃") >= 0)
+            {
+                cooperatecustomCustomerDTO.Zhiwu = "鎵ц钁d簨";
+            }
+            else if (cooperatecustomCustomerDTO.Name.IndexOf("鍗忎細") >= 0)
+            {
+                cooperatecustomCustomerDTO.Zhiwu = "浼氶暱";
+            }
+            else 
+            {
+                cooperatecustomCustomerDTO.Zhiwu = "鎬荤粡鐞�";
+            }
+
+
+            ResultDataEntity<SysAttachmentDTO> resultsyinyezhizhao = new ResultDataEntity<SysAttachmentDTO>();
+
+            SysAttachmentDTOSearch searchEntity = new SysAttachmentDTOSearch();
+            searchEntity.page = 1;
+            searchEntity.rows = 1000;
+            searchEntity.AttObj = "Cooperyinyezhizhao";
+            searchEntity.AttObjid = cooperOrderDTO.Khdw;
+            resultsyinyezhizhao = _sysAttachmentService.SearchByPaging(searchEntity);
+
+            ViewBag.yinyezhizhao = resultsyinyezhizhao;
+
+
+            ResultDataEntity<SysAttachmentDTO> resultshenfenzheng = new ResultDataEntity<SysAttachmentDTO>();
+
+            SysAttachmentDTOSearch searchEntity1 = new SysAttachmentDTOSearch();
+            searchEntity1.page = 1;
+            searchEntity1.rows = 1000;
+            searchEntity1.AttObj = "Cooperashenfenzheng";
+            searchEntity1.AttObjid = cooperOrderDTO.Khdw;
+            resultshenfenzheng = _sysAttachmentService.SearchByPaging(searchEntity1);
+            ViewBag.shenfenzheng = resultshenfenzheng;
+
+            ViewBag.cooperatecustomCustomerDTO = cooperatecustomCustomerDTO;
+
+            ViewData.Model = challengeletterDTO;
+
+            
+            return View();
+        }
+
+
+        public IActionResult EditTousushu(string id = null, string ReturnID = null)
+        {
+            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
+            ViewData["curentuser"] = curentuser;
+            var sysCodeDtls = _liaotianService.GetSYScode("expert_test_topicjiexi", "falv").OrderBy(x => x.CodeSn).ToList();//娉曞緥
+            var sysCodeDtls1 = _liaotianService.GetSYScode("t_complaint_items", "law").OrderBy(x => x.CodeSn).ToList();//娉曞緥渚濇嵁
+
+            foreach (var sysCodeDtl in sysCodeDtls1)
+            {
+                var sysCodeDtl1 = sysCodeDtls.Where(x => x.CodeSn == sysCodeDtl.Comments).FirstOrDefault();
+                if (sysCodeDtl1 != null)
+                    sysCodeDtl.Classify3 = sysCodeDtl1.Comments;
+            }
+            //鎶曡瘔涔�
+            List<TComplaintletterDTO> complaintletterDTOs = _cooperOrderService.GetListComplaintletter(id);
+            TComplaintletterDTO complaintletterDTO = new TComplaintletterDTO();
+            if (complaintletterDTOs != null && complaintletterDTOs.Count > 0)
+            {
+                complaintletterDTO = complaintletterDTOs[0];
+
+                if (complaintletterDTO.NoticeDate.HasValue)
+                {
+                    complaintletterDTO.NoticeDateName = complaintletterDTO.NoticeDate.Value.ToString("yyyy-MM-dd");
+                }
+
+                if (complaintletterDTO.ResultnoticeDate.HasValue)
+                {
+                    complaintletterDTO.ResultnoticeDateName = complaintletterDTO.ResultnoticeDate.Value.ToString("yyyy-MM-dd");
+                }
+
+                if (complaintletterDTO.ChallengeDate.HasValue)
+                {
+                    complaintletterDTO.ChallengeDateName = complaintletterDTO.ChallengeDate.Value.ToString("yyyy-MM-dd");
+                }
+                if (complaintletterDTO.RespondDate.HasValue)
+                {
+                    complaintletterDTO.RespondDateName = complaintletterDTO.RespondDate.Value.ToString("yyyy-MM-dd");
+                }
+                
+
+                List<TComplaintItemDTO> complaintItemDTOs = _cooperOrderService.GetListComplaintItem(complaintletterDTO.Id);
+                if (complaintItemDTOs.Count > 0)
+                {
+                    complaintletterDTO.complaintItemDTOs = complaintItemDTOs;
+                    foreach (var complaintItemDTO in complaintletterDTO.complaintItemDTOs)
+                    {
+                        var sysCodeDtls2 = sysCodeDtls1.Where(x => x.Classify1 == complaintItemDTO.Question).ToList();
+                       
+
+                        if (!string.IsNullOrEmpty(complaintItemDTO.Law) || !string.IsNullOrEmpty(ReturnID))
+                        {
+                            var law = "";
+                            if (!string.IsNullOrEmpty(complaintItemDTO.Law))
+                            {
+                                law = complaintItemDTO.Law;
+                                if (!string.IsNullOrEmpty(ReturnID))
+                                {
+                                    law += "," + ReturnID;
+                                }
+
+                            }
+                            else
+                            {
+                                law = ReturnID;
+                            }
+
+                            if (!string.IsNullOrEmpty(law))
+                            {
+                                sysCodeDtls2 = sysCodeDtls2.Where(x => law.Split(',').Contains(x.CodeSn)).ToList();
+                            }
+
+
+                        }
+
+                        complaintItemDTO.sysCodeDtls = sysCodeDtls2;
+                    }
+                }
+                else
+                {
+                    var complaintItemDTO = new TComplaintItemDTO();
+                    complaintItemDTO.Id = 1;
+                    complaintletterDTO.complaintItemDTOs = new List<TComplaintItemDTO>() { complaintItemDTO };
+                    complaintletterDTO.complaintItemDTOs[0].sysCodeDtls = new List<SysCodeDtl>() { new SysCodeDtl() };
+                }
+                   
+
+                List<TComplaintRespondentDTO> complaintRespondentDTOs = _cooperOrderService.GetListComplaintRespondent(complaintletterDTO.Id);
+                if (complaintRespondentDTOs.Count > 0)
+                    complaintletterDTO.complaintRespondentDTOs = complaintRespondentDTOs;
+                else
+                    complaintletterDTO.complaintRespondentDTOs = new List<TComplaintRespondentDTO>() { new TComplaintRespondentDTO() };
+
+                List<TComplaintShouquandaibiaoDTO> complaintShouquandaibiaoDTOs = _cooperOrderService.GetListComplaintShouquandaibiao(complaintletterDTO.Id);
+                if (complaintShouquandaibiaoDTOs.Count > 0)
+                    complaintletterDTO.complaintShouquandaibiaoDTOs = complaintShouquandaibiaoDTOs;
+                else
+                    complaintletterDTO.complaintShouquandaibiaoDTOs = new List<TComplaintShouquandaibiaoDTO>() { new TComplaintShouquandaibiaoDTO() };
+
+                List<TChallengeRequestInfoDTO> challengeRequestInfoDTOs = _cooperOrderService.GetListChallengeRequestInfo(complaintletterDTO.Id);
+                if (challengeRequestInfoDTOs.Count > 0)
+                    complaintletterDTO.challengeRequestInfoDTOs = challengeRequestInfoDTOs;
+                else
+                    complaintletterDTO.challengeRequestInfoDTOs = new List<TChallengeRequestInfoDTO>() { new TChallengeRequestInfoDTO() };
+
+                List<TComplaintGongyingshangDTO> complaintGongyingshangDTOs = _cooperOrderService.GetListComplaintGongyingshang(complaintletterDTO.Id);
+                if (complaintGongyingshangDTOs.Count > 0)
+                    complaintletterDTO.complaintGongyingshangDTOs = complaintGongyingshangDTOs;
+                else
+                    complaintletterDTO.complaintGongyingshangDTOs = new List<TComplaintGongyingshangDTO>() /*{ new TComplaintGongyingshangDTO() }*/;
+
+            }
+            else
+            {
+                var complaintItemDTO = new TComplaintItemDTO();
+                complaintItemDTO.Id = 1;
+                complaintletterDTO.complaintItemDTOs = new List<TComplaintItemDTO>() { complaintItemDTO };
+                complaintletterDTO.complaintItemDTOs[0].sysCodeDtls = new List<SysCodeDtl>() { new SysCodeDtl() };
+                complaintletterDTO.complaintRespondentDTOs = new List<TComplaintRespondentDTO>() { new TComplaintRespondentDTO() };
+                complaintletterDTO.complaintShouquandaibiaoDTOs = new List<TComplaintShouquandaibiaoDTO>() { new TComplaintShouquandaibiaoDTO() };
+                complaintletterDTO.complaintGongyingshangDTOs = new List<TComplaintGongyingshangDTO>()/* { new TComplaintGongyingshangDTO() }*/;
+                complaintletterDTO.challengeRequestInfoDTOs = new List<TChallengeRequestInfoDTO>() { new TChallengeRequestInfoDTO() };
+
+            }
+            //鍒ゆ柇鏄惁鏈夎川鐤戝嚱
+            if (complaintletterDTO.Status != 2 && string.IsNullOrEmpty(complaintletterDTO.complaintItemDTOs[0].Question))
+            {
+                CooperOrderDTO cooperOrderDTO = _cooperOrderService.Get(complaintletterDTO.OrderId);
+                List<TChallengeletterDTO> challengeletterDTOs = _cooperOrderService.GetListChallengelettertousu(cooperOrderDTO.Khdw, complaintletterDTO.XmCode);
+
+                if(challengeletterDTOs!=null&& challengeletterDTOs.Count > 0)
+                {
+                    TChallengeletterDTO challengeletterDTO = challengeletterDTOs[0];
+                    complaintletterDTO.PurchaserName = challengeletterDTO.PurchaserName;
+                    complaintletterDTO.ChallengeDateName = challengeletterDTO.DocumentsDate.HasValue ? challengeletterDTO.DocumentsDate.Value.ToString("yyyy-MM-dd") : "";
+                    complaintletterDTO.RequestInfo = challengeletterDTO.RequestInfo;
+                    complaintletterDTO.Questioned = challengeletterDTO.PurchaserName;
+                    complaintletterDTO.complaintShouquandaibiaoDTOs = _cooperOrderService.GetListComplaintShouquandaibiao(challengeletterDTO.Id);
+                    if (complaintletterDTO.complaintShouquandaibiaoDTOs.Count == 0)
+                        complaintletterDTO.complaintShouquandaibiaoDTOs = new List<TComplaintShouquandaibiaoDTO>() { new TComplaintShouquandaibiaoDTO() };
+
+
+                    complaintletterDTO.challengeRequestInfoDTOs = _cooperOrderService.GetListChallengeRequestInfo(challengeletterDTO.Id);
+                    if (complaintletterDTO.challengeRequestInfoDTOs.Count == 0)
+                        complaintletterDTO.challengeRequestInfoDTOs = new List<TChallengeRequestInfoDTO>() { new TChallengeRequestInfoDTO() };
+
+
+                    List<TChallengeItemDTO> challengeItemDTOs = _cooperOrderService.GetListChallengeItem(challengeletterDTO.Id);
+                    if (challengeItemDTOs.Count > 0)
+                    {
+                        List<TComplaintItemDTO> complaintItemDTOs = new List<TComplaintItemDTO>();
+                        foreach(var challengeItemDTO in challengeItemDTOs)
+                        {
+                            TComplaintItemDTO complaintItemDTO = new TComplaintItemDTO();
+                            complaintItemDTO.Id = challengeItemDTO.Id;
+                            complaintItemDTO.ComplaintId = challengeItemDTO.ChallengeId;
+                            complaintItemDTO.Question = challengeItemDTO.Question;
+                            complaintItemDTO.Questionname = challengeItemDTO.Questionname;
+                            complaintItemDTO.Evidential = challengeItemDTO.Evidential;
+                            complaintItemDTO.Law = challengeItemDTO.Law;
+                            complaintItemDTO.Lawcoment = challengeItemDTO.Lawcoment;
+                            complaintItemDTO.Sort = challengeItemDTO.Sort;
+
+                            complaintItemDTOs.Add(complaintItemDTO);
+                        }
+
+                        complaintletterDTO.complaintItemDTOs = complaintItemDTOs;
+                        foreach (var complaintItemDTO in complaintletterDTO.complaintItemDTOs)
+                        {
+                            var sysCodeDtls2 = sysCodeDtls1.Where(x => x.Classify1 == complaintItemDTO.Question).ToList();
+                            complaintItemDTO.sysCodeDtls = sysCodeDtls2;
+                        }
+                    }
+                    else
+                    {
+                        complaintletterDTO.complaintItemDTOs = new List<TComplaintItemDTO>() { new TComplaintItemDTO() };
+                        complaintletterDTO.complaintItemDTOs[0].sysCodeDtls = new List<SysCodeDtl>() { new SysCodeDtl() };
+                    }
+
+                }
+            }
+
+
+            ViewBag.request_info = _liaotianService.GetSYScode("t_challengeletter", "request_info").OrderBy(x => x.CodeSn).ToList();//璐ㄧ枒璇锋眰
+            ViewBag.question = _liaotianService.GetSYScode("t_challenge_items", "question").OrderBy(x => x.CodeSn).ToList(); //	璐ㄧ枒浜嬮」
+            
+
+            ViewBag.law = sysCodeDtls1;//娉曞緥渚濇嵁
+
+            ViewBag.shifou = _liaotianService.GetSYScode("system", "shifou");
+
+            ViewBag.ChallengeletterChosen = _cooperOrderService.GetListChallengeletterChosen().Where(x => x.Createtime >= DateTime.Now.AddMonths(-2)).ToList(); ;
+
+            ViewData.Model = complaintletterDTO;
+            return View();
+        }
+
+
+
+
+        /// <summary>
+        /// 淇濆瓨
+        /// </summary>
+        /// <param name="data">宀椾綅瀹炰綋绫诲璞�</param>
+        /// <returns></returns>
+        /// 
+        [CheckLogin]
+        [HttpPost]
+        public IActionResult SaveComplaintletter(CooperOrderDTO data)
+        {
+            ResultEntity resultEntity = new ResultEntity();
+
+            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
+            ViewData["curentuser"] = curentuser;
+
+
+            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required,
+                new TransactionOptions
+                {
+                    IsolationLevel = IsolationLevel.ReadCommitted,
+                    Timeout = TransactionManager.MaximumTimeout
+                }
+                ))
+            {
+
+
+
+
+                //鏌ヨ涓昏〃
+                var complaintletterDTO = _cooperOrderService.GetListComplaintletter(data.OrderId).FirstOrDefault();
+                if (complaintletterDTO != null)
+                {
+                    complaintletterDTO.TsrName = data.TsrName;
+                    complaintletterDTO.TsrAddress = data.TsrAddress;
+                    complaintletterDTO.TsrPostcode = data.TsrPostcode;
+                    complaintletterDTO.TsrCorporation = data.TsrCorporation;
+                    complaintletterDTO.TsrPhone = data.TsrPhone;
+
+ 
+
+                    complaintletterDTO.XmName = data.tousuXmName;
+                    complaintletterDTO.XmCode = data.tousuXmCode;
+                    complaintletterDTO.XmPackage = data.tousuXmPackage;
+                    complaintletterDTO.PurchaserName = data.tousuPurchaserName;
+                    complaintletterDTO.Agency = data.tousuAgency;
+
+                    complaintletterDTO.IsNotice = data.tousuIsNotice;
+                    complaintletterDTO.NoticeDate = data.tousuNoticeDate;
+                    complaintletterDTO.IsResultnotice = data.tousuIsResultnotice;
+                    complaintletterDTO.ResultnoticeDate = data.tousuResultnoticeDate;
+                    complaintletterDTO.ChallengeDate = data.tousuChallengeDate;
+                    complaintletterDTO.Questioned = data.tousuQuestioned;
+                    complaintletterDTO.Respondent = data.Respondent;
+                    complaintletterDTO.RespondDate = data.tousuRespondDate;
+
+
+                    complaintletterDTO.Modifier = curentuser.Id;
+                    complaintletterDTO.Modifytime = DateTime.Now;
+                    complaintletterDTO.Status = int.Parse(data.Status);
+                    complaintletterDTO.RequestInfo = data.RequestInfo;
+                    complaintletterDTO.PrintNum = data.PrintNum;
+                    complaintletterDTO.TsrId = data.TsrId;
+                    resultEntity = _cooperOrderService.saveComplaintletter(complaintletterDTO);
+                }
+                else
+                {
+                    complaintletterDTO = new TComplaintletterDTO();
+                    complaintletterDTO.OrderId = data.Id;
+
+                    complaintletterDTO.TsrName = data.TsrName;
+                    complaintletterDTO.TsrAddress = data.TsrAddress;
+                    complaintletterDTO.TsrPostcode = data.TsrPostcode;
+                    complaintletterDTO.TsrCorporation = data.TsrCorporation;
+                    complaintletterDTO.TsrPhone = data.TsrPhone;
+
+
+
+                    complaintletterDTO.XmName = data.tousuXmName;
+                    complaintletterDTO.XmCode = data.tousuXmCode;
+                    complaintletterDTO.XmPackage = data.tousuXmPackage;
+                    complaintletterDTO.PurchaserName = data.tousuPurchaserName;
+                    complaintletterDTO.Agency = data.tousuAgency;
+
+                    complaintletterDTO.IsNotice = data.tousuIsNotice;
+                    complaintletterDTO.NoticeDate = data.tousuNoticeDate;
+                    complaintletterDTO.IsResultnotice = data.tousuIsResultnotice;
+                    complaintletterDTO.ResultnoticeDate = data.tousuResultnoticeDate;
+                    complaintletterDTO.ChallengeDate = data.tousuChallengeDate;
+                    complaintletterDTO.Questioned = data.tousuQuestioned;
+                    complaintletterDTO.Respondent = data.Respondent;
+                    complaintletterDTO.RespondDate = data.tousuRespondDate;
+
+
+                    complaintletterDTO.Modifier = curentuser.Id;
+                    complaintletterDTO.Modifytime = DateTime.Now;
+                    complaintletterDTO.Creater = curentuser.Id;
+                    complaintletterDTO.Createtime = complaintletterDTO.Modifytime;
+                    complaintletterDTO.Status =  int.Parse(data.Status);
+                    complaintletterDTO.RequestInfo = data.RequestInfo;
+                    complaintletterDTO.PrintNum = data.PrintNum;
+                    complaintletterDTO.TsrId = data.TsrId;
+                    resultEntity = _cooperOrderService.saveComplaintletter(complaintletterDTO);
+                }
+
+
+
+                resultEntity = _cooperOrderService.deleteComplaintShouquandaibiao(complaintletterDTO.Id);
+                if (data.tousuShouquandaibiao != null && data.tousuShouquandaibiao.Length > 0)
+                {
+                    for (int i = 0; i < data.tousuShouquandaibiao.Length; i++)
+                    {
+                        if (!(string.IsNullOrEmpty(data.tousuShouquandaibiao[i])
+                              && string.IsNullOrEmpty(data.tousuLianxidianhua[i])
+                              && string.IsNullOrEmpty(data.tousuDizhi[i])
+                              && string.IsNullOrEmpty(data.tousuYoubian[i])))
+                        {
+                            var complaintShouquandaibiaoDTO = new TComplaintShouquandaibiaoDTO();
+                            complaintShouquandaibiaoDTO.ComplaintId = complaintletterDTO.Id;
+                            complaintShouquandaibiaoDTO.Shouquandaibiao = data.tousuShouquandaibiao[i];
+                            complaintShouquandaibiaoDTO.Lianxidianhua = data.tousuLianxidianhua[i];
+                            complaintShouquandaibiaoDTO.Dizhi = data.tousuDizhi[i];
+                            complaintShouquandaibiaoDTO.Youbian = data.tousuYoubian[i];
+                            complaintShouquandaibiaoDTO.Sort = i;
+                            resultEntity = _cooperOrderService.saveComplaintShouquandaibiao(complaintShouquandaibiaoDTO);
+                        }
+
+                    }
+                }
+
+
+                resultEntity = _cooperOrderService.deleteComplaintRespondent(complaintletterDTO.Id);
+                if (data.tousuRespondent != null && data.tousuRespondent.Length > 0)
+                {
+                    for (int i = 0; i < data.tousuRespondent.Length; i++)
+                    {
+                        if (!(string.IsNullOrEmpty(data.tousuRespondent[i])
+                       && string.IsNullOrEmpty(data.tousuAddress[i])
+                       && string.IsNullOrEmpty(data.tousuPostcode[i])
+                       && string.IsNullOrEmpty(data.tousuContacts[i])
+                        && string.IsNullOrEmpty(data.tousuPhone[i])))
+                        {
+                            var complaintRespondentDTO = new TComplaintRespondentDTO();
+                            complaintRespondentDTO.ComplaintId = complaintletterDTO.Id;
+                            complaintRespondentDTO.Respondent = data.tousuRespondent[i];
+                            complaintRespondentDTO.Address = data.tousuAddress[i];
+                            complaintRespondentDTO.Postcode = data.tousuPostcode[i];
+                            complaintRespondentDTO.Contacts = data.tousuContacts[i];
+                            complaintRespondentDTO.Phone = data.tousuPhone[i];
+                            complaintRespondentDTO.Sort = i;
+                            resultEntity = _cooperOrderService.saveComplaintRespondent(complaintRespondentDTO);
+                        }
+
+                    }
+                }
+
+                resultEntity = _cooperOrderService.deleteComplaintGongyingshang(complaintletterDTO.Id);
+                if (data.Gongytingshang != null && data.Gongytingshang.Length > 0)
+                {
+                    for (int i = 0; i < data.Gongytingshang.Length; i++)
+                    {
+                        if (!(string.IsNullOrEmpty(data.Gongytingshang[i])
+                      && string.IsNullOrEmpty(data.gongyingshangYoubian[i])
+                      && string.IsNullOrEmpty(data.gongyingshangLianxiren[i])
+                      && string.IsNullOrEmpty(data.gongyingshangLianxidianhua[i])
+                       && string.IsNullOrEmpty(data.gongyingshangDizhi[i])))
+                        {
+                            var complaintGongyingshangDTO = new TComplaintGongyingshangDTO();
+                            complaintGongyingshangDTO.ComplaintId = complaintletterDTO.Id;
+                            complaintGongyingshangDTO.Gongytingshang = data.Gongytingshang[i];
+                            complaintGongyingshangDTO.Youbian = data.gongyingshangYoubian[i];
+                            complaintGongyingshangDTO.Lianxiren = data.gongyingshangLianxiren[i];
+                            complaintGongyingshangDTO.Lianxidianhua = data.gongyingshangLianxidianhua[i];
+                            complaintGongyingshangDTO.Dizhi = data.gongyingshangDizhi[i];
+                            complaintGongyingshangDTO.Sort = i;
+                            resultEntity = _cooperOrderService.saveComplaintGongyingshang(complaintGongyingshangDTO);
+                        }
+
+                    }
+                }
+
+
+
+                resultEntity = _cooperOrderService.deleteComplaintItem(complaintletterDTO.Id);
+                if (data.Question != null && data.Question.Length > 0)
+                {
+                    for (int i = 0; i < data.Question.Length; i++)
+                    {
+                        if (!(string.IsNullOrEmpty(data.Question[i])
+                            && string.IsNullOrEmpty(data.Evidential[i])
+                            ))
+                        {
+                            string Law = "";
+                            var complaintItemId = data.complaintItemId[i];
+                            var Laws = data.Law;
+                            var complaintItemIdlaw = data.complaintItemIdlaw;
+                            if (Laws != null && Laws.Length > 0)
+                            {
+                                for (int j = 0; j < Laws.Length; j++)
+                                {
+                                    if (complaintItemId == complaintItemIdlaw[j])
+                                    {
+                                        Law += Laws[j] + ",";
+                                    }
+
+                                }
+                                if (!string.IsNullOrEmpty(Law))
+                                    Law = Law.TrimEnd(',');  //绉婚櫎鏈�鍚庣殑閫楀彿
+                            }
+
+                            var complaintItemDTO = new TComplaintItemDTO();
+                            complaintItemDTO.ComplaintId = complaintletterDTO.Id;
+                            complaintItemDTO.Question = data.Question[i];
+                            complaintItemDTO.Questionname = data.Questionname[i];
+                            complaintItemDTO.Evidential = data.Evidential[i];
+                            complaintItemDTO.Law = Law;
+                            //complaintItemDTO.Lawcoment = data.Lawcoment[i];
+                            complaintItemDTO.Sort = i;
+                            resultEntity = _cooperOrderService.saveComplaintItem(complaintItemDTO);
+                        }
+
+                    }
+                }
+
+                resultEntity = _cooperOrderService.deleteChallengeRequestInfo(complaintletterDTO.Id);
+                if (data.RequestInfos != null && data.RequestInfos.Length > 0)
+                {
+                    for (int i = 0; i < data.RequestInfos.Length; i++)
+                    {
+                        if (!string.IsNullOrEmpty(data.RequestInfos[i]))
+
+                        {
+                            var challengeRequestInfoDTO = new TChallengeRequestInfoDTO();
+                            challengeRequestInfoDTO.ChallengeId = complaintletterDTO.Id;
+                            challengeRequestInfoDTO.RequestInfo = data.RequestInfos[i];
+                            challengeRequestInfoDTO.RequestInfoname = data.RequestInfoname[i];
+
+                            resultEntity = _cooperOrderService.saveChallengeRequestInfo(challengeRequestInfoDTO);
+                        }
+
+                    }
+                }
+
+                scope.Complete();
+            }
+
+
+            return new JsonResult(resultEntity);
+        }
+
+
+
+        public IActionResult Printtousushu(string id = null)
+        {
+            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
+            ViewData["curentuser"] = curentuser;
+            var sysCodeDtls = _liaotianService.GetSYScode("expert_test_topicjiexi", "falv").OrderBy(x => x.CodeSn).ToList();//娉曞緥
+            var sysCodeDtls1 = _liaotianService.GetSYScode("t_complaint_items", "law").OrderBy(x => x.CodeSn).ToList();//娉曞緥渚濇嵁
+            foreach (var sysCodeDtl in sysCodeDtls1)
+            {
+                var sysCodeDtl1 = sysCodeDtls.Where(x => x.CodeSn == sysCodeDtl.Comments).FirstOrDefault();
+                if (sysCodeDtl1 != null)
+                    sysCodeDtl.Classify3 = sysCodeDtl1.Comments;
+            }
+            //鎶曡瘔涔�
+            List<TComplaintletterDTO> complaintletterDTOs = _cooperOrderService.GetListComplaintletter(id);
+            TComplaintletterDTO complaintletterDTO = new TComplaintletterDTO();
+            if (complaintletterDTOs != null && complaintletterDTOs.Count > 0)
+            {
+                complaintletterDTO = complaintletterDTOs[0];
+
+                if (complaintletterDTO.NoticeDate.HasValue)
+                {
+                    complaintletterDTO.NoticeDateName = complaintletterDTO.NoticeDate.Value.ToString("yyyy-MM-dd");
+                }
+
+                if (complaintletterDTO.ResultnoticeDate.HasValue)
+                {
+                    complaintletterDTO.ResultnoticeDateName = complaintletterDTO.ResultnoticeDate.Value.ToString("yyyy-MM-dd");
+                }
+
+                if (complaintletterDTO.ChallengeDate.HasValue)
+                {
+                    complaintletterDTO.ChallengeDateName = complaintletterDTO.ChallengeDate.Value.ToString("yyyy骞碝M鏈坉d鏃�");
+                }
+                if (complaintletterDTO.RespondDate.HasValue)
+                {
+                    complaintletterDTO.RespondDateName = complaintletterDTO.RespondDate.Value.ToString("yyyy骞碝M鏈坉d鏃�");
+                }
+
+
+                List<TComplaintItemDTO> complaintItemDTOs = _cooperOrderService.GetListComplaintItem(complaintletterDTO.Id);
+                if (complaintItemDTOs.Count > 0)
+                {
+                    complaintletterDTO.complaintItemDTOs = complaintItemDTOs;
+                    foreach (var complaintItemDTO in complaintletterDTO.complaintItemDTOs)
+                    {
+                        var sysCodeDtls2 = sysCodeDtls1.Where(x => x.Classify1 == complaintItemDTO.Question).ToList();
+                        if (!string.IsNullOrEmpty(complaintItemDTO.Law))
+                        {
+                            sysCodeDtls2 = sysCodeDtls2.Where(x => complaintItemDTO.Law.Split(',').Contains(x.CodeSn)).OrderBy(x => x.Classify3).ToList();
+                        }
+                        complaintItemDTO.sysCodeDtls = sysCodeDtls2;
+                    }
+                }
+                   
+                else
+                {
+                    complaintletterDTO.complaintItemDTOs = new List<TComplaintItemDTO>() { new TComplaintItemDTO() };
+                    complaintletterDTO.complaintItemDTOs[0].sysCodeDtls = new List<SysCodeDtl>() { new SysCodeDtl() };
+                }
+                    
+
+                List<TComplaintRespondentDTO> complaintRespondentDTOs = _cooperOrderService.GetListComplaintRespondent(complaintletterDTO.Id);
+                if (complaintRespondentDTOs.Count > 0)
+                    complaintletterDTO.complaintRespondentDTOs = complaintRespondentDTOs;
+                else
+                    complaintletterDTO.complaintRespondentDTOs = new List<TComplaintRespondentDTO>() { new TComplaintRespondentDTO() };
+
+                List<TComplaintShouquandaibiaoDTO> complaintShouquandaibiaoDTOs = _cooperOrderService.GetListComplaintShouquandaibiao(complaintletterDTO.Id);
+                if (complaintShouquandaibiaoDTOs.Count > 0)
+                    complaintletterDTO.complaintShouquandaibiaoDTOs = complaintShouquandaibiaoDTOs;
+                else
+                    complaintletterDTO.complaintShouquandaibiaoDTOs = new List<TComplaintShouquandaibiaoDTO>() /*{ new TComplaintShouquandaibiaoDTO() }*/;
+
+                List<TChallengeRequestInfoDTO> challengeRequestInfoDTOs = _cooperOrderService.GetListChallengeRequestInfo(complaintletterDTO.Id);
+                if (challengeRequestInfoDTOs.Count > 0)
+                    complaintletterDTO.challengeRequestInfoDTOs = challengeRequestInfoDTOs;
+                else
+                    complaintletterDTO.challengeRequestInfoDTOs = new List<TChallengeRequestInfoDTO>() /*{ new TChallengeRequestInfoDTO() }*/;
+
+                List<TComplaintGongyingshangDTO> complaintGongyingshangDTOs = _cooperOrderService.GetListComplaintGongyingshang(complaintletterDTO.Id);
+                if (complaintGongyingshangDTOs.Count > 0)
+                    complaintletterDTO.complaintGongyingshangDTOs = complaintGongyingshangDTOs;
+                else
+                    complaintletterDTO.complaintGongyingshangDTOs = new List<TComplaintGongyingshangDTO>()/* { new TComplaintGongyingshangDTO() }*/;
+
+            }
+            else
+            {
+                complaintletterDTO.complaintItemDTOs = new List<TComplaintItemDTO>() { new TComplaintItemDTO() };
+                complaintletterDTO.complaintItemDTOs[0].sysCodeDtls = new List<SysCodeDtl>() { new SysCodeDtl() };
+                complaintletterDTO.complaintRespondentDTOs = new List<TComplaintRespondentDTO>() { new TComplaintRespondentDTO() };
+                complaintletterDTO.complaintShouquandaibiaoDTOs = new List<TComplaintShouquandaibiaoDTO>()/* { new TComplaintShouquandaibiaoDTO() }*/;
+                complaintletterDTO.complaintGongyingshangDTOs = new List<TComplaintGongyingshangDTO>() /*{ new TComplaintGongyingshangDTO() }*/;
+                complaintletterDTO.challengeRequestInfoDTOs = new List<TChallengeRequestInfoDTO>() /*{ new TChallengeRequestInfoDTO() }*/;
+            }
+
+
+            if (string.IsNullOrEmpty(complaintletterDTO.ChallengeDateName))
+            {
+                complaintletterDTO.ChallengeDateName = "銆�銆�骞淬��鏈堛��鏃�";
+            }
+            if (string.IsNullOrEmpty(complaintletterDTO.Questioned))
+            {
+                complaintletterDTO.Questioned = "銆�銆�銆�銆�銆�銆�";
+            }
+            if (string.IsNullOrEmpty(complaintletterDTO.Respondent))
+            {
+                complaintletterDTO.Respondent = "銆�銆�銆�銆�銆�銆�";
+            }
+            if (string.IsNullOrEmpty(complaintletterDTO.RespondDateName))
+            {
+                complaintletterDTO.RespondDateName = "銆�銆�骞淬��鏈堛��鏃�";
+            }
+
+            //璐ㄧ枒鍑�
+            List<TChallengeletterDTO> challengeletterDTOs = _cooperOrderService.GetListChallengeletter(complaintletterDTO.TsrId);
+            TChallengeletterDTO challengeletterDTO = new TChallengeletterDTO();
+            if (challengeletterDTOs != null && challengeletterDTOs.Count > 0)
+            {
+                challengeletterDTO = challengeletterDTOs[0];
+
+                List<TChallengeItemDTO> challengeItemDTOs = _cooperOrderService.GetListChallengeItem(challengeletterDTO.Id);
+                complaintletterDTO.SqdbId = "";
+                if (challengeItemDTOs.Count > 0)
+                {
+                   
+                    foreach (var challengeItemDTO in challengeItemDTOs)
+                    {
+                        
+                        complaintletterDTO.SqdbId += challengeItemDTO.QuestionName+";";
+                    }
+                }
+
+
+
+            }
+            else
+            {
+                complaintletterDTO.SqdbId = "";
+                if (complaintletterDTO.complaintItemDTOs != null && complaintletterDTO.complaintItemDTOs.Count > 0)
+                {
+                    foreach (var complaintItemDTO in complaintletterDTO.complaintItemDTOs)
+                    {
+
+                        complaintletterDTO.SqdbId += complaintItemDTO.QuestionName + ";";
+                    }
+                }
+
+            }
+
+            var cooperOrderDTO = _cooperOrderService.Get(id);
+            var cooperatecustomCustomerDTO = _cooperatecustomCustomerService.Get(cooperOrderDTO.Khdw);
+            if (cooperatecustomCustomerDTO.Name.IndexOf("鑲′唤鏈夐檺鍏徃") >= 0)
+            {
+                cooperatecustomCustomerDTO.Zhiwu = "钁d簨闀�";
+            }
+            else if (cooperatecustomCustomerDTO.Name.IndexOf("鏈夐檺鍏徃") >= 0 || cooperatecustomCustomerDTO.Name.IndexOf("鏈夐檺璐d换鍏徃") >= 0)
+            {
+                cooperatecustomCustomerDTO.Zhiwu = "鎵ц钁d簨";
+            }
+            else if (cooperatecustomCustomerDTO.Name.IndexOf("鍗忎細") >= 0)
+            {
+                cooperatecustomCustomerDTO.Zhiwu = "浼氶暱";
+            }
+            else
+            {
+                cooperatecustomCustomerDTO.Zhiwu = "鎬荤粡鐞�";
+            }
+
+
+            ResultDataEntity<SysAttachmentDTO> resultsyinyezhizhao = new ResultDataEntity<SysAttachmentDTO>();
+
+            SysAttachmentDTOSearch searchEntity = new SysAttachmentDTOSearch();
+            searchEntity.page = 1;
+            searchEntity.rows = 1000;
+            searchEntity.AttObj = "Cooperyinyezhizhao";
+            searchEntity.AttObjid = cooperOrderDTO.Khdw;
+            resultsyinyezhizhao = _sysAttachmentService.SearchByPaging(searchEntity);
+
+            ViewBag.yinyezhizhao = resultsyinyezhizhao;
+
+
+            ResultDataEntity<SysAttachmentDTO> resultshenfenzheng = new ResultDataEntity<SysAttachmentDTO>();
+
+            SysAttachmentDTOSearch searchEntity1 = new SysAttachmentDTOSearch();
+            searchEntity1.page = 1;
+            searchEntity1.rows = 1000;
+            searchEntity1.AttObj = "Cooperashenfenzheng";
+            searchEntity1.AttObjid = cooperOrderDTO.Khdw;
+            resultshenfenzheng = _sysAttachmentService.SearchByPaging(searchEntity1);
+            ViewBag.shenfenzheng = resultshenfenzheng;
+
+            ViewBag.cooperatecustomCustomerDTO = cooperatecustomCustomerDTO;
+
+
+            ViewData.Model = complaintletterDTO;
+            return View();
+        }
+
+
+
+
+        public IActionResult Printbiaoshuhetong(string id = null)
+        {
+            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
+            ViewData["curentuser"] = curentuser;
+
+           var cooperOrderDTO =  _cooperOrderService.Get(id);
+           var cooperatecustomCustomerDTO =  _cooperatecustomCustomerService.Get(cooperOrderDTO.Khdw);
+            cooperOrderDTO.MoneyName = MoneyToUpperHelper.MoneyToUpper(cooperOrderDTO.Money.Value.ToString("0.##"));
+
+            ViewData["cooperOrderDTO"] = cooperOrderDTO;
+            ViewData["cooperatecustomCustomerDTO"] = cooperatecustomCustomerDTO;
+
+
+            return View();
+        }
+
+        public IActionResult Printzhiyitousuhetong(string id = null)
+        {
+            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
+            ViewData["curentuser"] = curentuser;
+
+            var cooperOrderDTO = _cooperOrderService.Get(id);
+            var cooperatecustomCustomerDTO = _cooperatecustomCustomerService.Get(cooperOrderDTO.Khdw);
+            cooperOrderDTO.MoneyName = MoneyToUpperHelper.MoneyToUpper(cooperOrderDTO.Money.Value.ToString("0.##"));
+
+            ViewData["cooperOrderDTO"] = cooperOrderDTO;
+            ViewData["cooperatecustomCustomerDTO"] = cooperatecustomCustomerDTO;
+
+
+            return View();
+        }
+
+        public IActionResult Printhuiyuanhetong(string id = null)
+        {
+            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
+            ViewData["curentuser"] = curentuser;
+
+            var cooperOrderDTO = _cooperOrderService.Get(id);
+            var cooperatecustomCustomerDTO = _cooperatecustomCustomerService.Get(cooperOrderDTO.Khdw);
+            cooperOrderDTO.MoneyName = MoneyToUpperHelper.MoneyToUpper(cooperOrderDTO.Money.Value.ToString("0.##"));
+
+            FiMemberDTO fiMemberDTO = _fiMemberService.GetList().Where(x => x.Id == cooperOrderDTO.OrderType1).FirstOrDefault();
+
+            if (fiMemberDTO != null)
+            {
+                cooperOrderDTO.OrderType1Name = fiMemberDTO.MemberType;
+                cooperOrderDTO.OrderType2 = fiMemberDTO.MemberAuthority;
+            }
+             
+
+
+
+            ViewData["cooperOrderDTO"] = cooperOrderDTO;
+            ViewData["cooperatecustomCustomerDTO"] = cooperatecustomCustomerDTO;
+
+
+            return View();
+        }
+
+        public IActionResult Printfengxianhetong(string id = null)
+        {
+            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
+            ViewData["curentuser"] = curentuser;
+
+            var cooperOrderDTO = _cooperOrderService.Get(id);
+            var cooperatecustomCustomerDTO = _cooperatecustomCustomerService.Get(cooperOrderDTO.Khdw);
+            cooperOrderDTO.MoneyName = MoneyToUpperHelper.MoneyToUpper(cooperOrderDTO.Money.Value.ToString("0.##"));
+            var jichumoney = cooperOrderDTO.Jichumoney.HasValue ? cooperOrderDTO.Jichumoney.Value : 0;
+            var tuihuimoney = cooperOrderDTO.Money.Value - jichumoney;
+
+            cooperOrderDTO.Jichumoney = tuihuimoney;
+            cooperOrderDTO.JichumoneyName = MoneyToUpperHelper.MoneyToUpper(tuihuimoney.ToString("0.##"));
+
+
+
+
+            ViewData["cooperOrderDTO"] = cooperOrderDTO;
+            ViewData["cooperatecustomCustomerDTO"] = cooperatecustomCustomerDTO;
+
+
+            return View();
+        }
+
+
     }
 }

--
Gitblit v1.9.1