From 91bad66d03c07b6cb2a3eb09bdd98faab4b8caa3 Mon Sep 17 00:00:00 2001
From: username@email.com <yzy2002yzy@163.com>
Date: 星期四, 02 十二月 2021 14:03:34 +0800
Subject: [PATCH] 提交

---
 zhengcaioa/zhengcaioa/Controllers/BusinessOrder/CooperOrderController.cs |  578 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 542 insertions(+), 36 deletions(-)

diff --git a/zhengcaioa/zhengcaioa/Controllers/BusinessOrder/CooperOrderController.cs b/zhengcaioa/zhengcaioa/Controllers/BusinessOrder/CooperOrderController.cs
index 3c67038..3c04b37 100644
--- a/zhengcaioa/zhengcaioa/Controllers/BusinessOrder/CooperOrderController.cs
+++ b/zhengcaioa/zhengcaioa/Controllers/BusinessOrder/CooperOrderController.cs
@@ -19,6 +19,9 @@
 using Services;
 using System.Transactions;
 using System.IdentityModel.Tokens.Jwt;
+using Microsoft.Extensions.Configuration;
+using Newtonsoft.Json.Linq;
+using System.Net.Http.Headers;
 
 namespace zhengcaioa.Controllers.BusinessOrder
 {
@@ -35,11 +38,23 @@
         private readonly IFiBookService _fiBookService;
         private readonly IFiServiceService _fiServiceService;
         private readonly IFiMemberService _fiMemberService;
+        private readonly IConfiguration _configuration;
+        private readonly IHttpClientFactory _clientFactory;
+        private readonly IAskService _askService;
+        private readonly IAdmGoodsRecordService _admGoodsRecordService;
+
+        private readonly IAdmGoodsManageService _admGoodsManageService;
 
 
         public CooperOrderController(ILogger<CooperOrderController> logger, ILiaotianService liaotianService, IUserService userService, ICooperOrderService cooperOrderService
             , ICooperatecustomCustomerService cooperatecustomCustomerService, IProjectService projectService, IPltPageService pltPageService, IFiBookService fiBookService
-            , IFiServiceService fiServiceService, IFiMemberService fiMemberService)
+            , IFiServiceService fiServiceService, IFiMemberService fiMemberService
+            , IConfiguration configuration
+            , IHttpClientFactory clientFactory
+            , IAskService askService
+            , IAdmGoodsRecordService admGoodsRecordService
+            , IAdmGoodsManageService admGoodsManageService
+            )
         {
             _logger = logger;
             _liaotianService = liaotianService;
@@ -51,6 +66,11 @@
             _fiBookService = fiBookService;
             _fiServiceService = fiServiceService;
             _fiMemberService = fiMemberService;
+            _configuration = configuration;
+            _clientFactory = clientFactory;
+            _askService = askService;
+            _admGoodsRecordService = admGoodsRecordService;
+            _admGoodsManageService = admGoodsManageService;
         }
 
         [CheckLogin]
@@ -396,19 +416,118 @@
             {
                 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;
 
+            }
+            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();
 
@@ -447,11 +566,10 @@
         /// 
         [CheckLogin]
         [HttpPost]
-        public IActionResult Save(CooperOrderDTO data)
+        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";
@@ -460,16 +578,293 @@
                     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 cooperatecustomCustomerDTO = _cooperatecustomCustomerService.Get(data.Khdw);
+                        if (cooperatecustomCustomerDTO != null && !string.IsNullOrEmpty(cooperatecustomCustomerDTO.HuiyuanId))
+                        {
+                            string huiyuanurl = _configuration.GetSection("huiyuanurl").Value;
+                            string SetCaseOrder = _configuration.GetSection("SetCaseOrder").Value;
+
+                            Uri postUrl2 = new Uri(huiyuanurl + SetCaseOrder);
+
+                            JObject questions2 = new JObject();
+                            questions2.Add("UserID", cooperatecustomCustomerDTO.HuiyuanId);
+                            if (data.OrderType == "03")
+                            {
+                                questions2.Add("CaseType", 0);
+                            }
+                            else if (data.OrderType == "07")
+                            {
+                                questions2.Add("CaseType", 1);
+                            }
+                            else if (data.OrderType == "07")
+                            {
+                                questions2.Add("CaseType", 1);
+                            }
+                            else if (data.OrderType == "02" && (data.OrderType1 == "浠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);
+                            }
+                        }
+                    }
+
+
+                
+
+                    
                 }
+
+            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required,
+                new TransactionOptions
+                {
+                    IsolationLevel = IsolationLevel.ReadCommitted,
+                    Timeout = TransactionManager.MaximumTimeout
+                }
+                ))
+            {
+
+                var youHuiDTOs = _askService.GetAskYouHuiList(data.Khdw, data.OrderType).FirstOrDefault();
+                if (youHuiDTOs != null)
+                {
+                    data.Youhuier = youHuiDTOs.Id;
+                    if (youHuiDTOs.Youhuistandard == "01")
+                    {
+                        data.Youhui = youHuiDTOs.YouHui.Value;
+                        if (data.Money.Value < data.Youhui.Value)
+                        {
+                            data.Money = 0;
+                        }
+                        else
+                        {
+                            data.Money = data.Money.Value - data.Youhui.Value;
+                        }
+
+                    }
+                    else if (youHuiDTOs.Youhuistandard == "02")
+                    {
+                        if (youHuiDTOs.YouHui.Value >= 100)
+                        {
+                            data.Youhui = data.Money.Value;
+                            data.Money = 0;
+                        }
+                        else
+                        {
+                            data.Youhui = Math.Round(data.Money.Value * youHuiDTOs.YouHui.Value * new decimal(0.01), 2);
+                            data.Money = data.Money.Value - data.Youhui.Value;
+                        }
+                    }
+
+
+                }
+
                 data.ShouliStatus = "1";
                 data.Modifier = curentuser.Id;
                 data.Modifytime = DateTime.Now;
 
                 resultEntity = _cooperOrderService.save(data);
+
+                if (data.OrderType1 == "浠f嫙鎶曡瘔涔�")
+                {
+                    //鏌ヨ涓昏〃
+                    var complaintletterDTO = _cooperOrderService.GetListComplaintletter(data.Id).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.Modifier = curentuser.Id;
+                        complaintletterDTO.Modifytime = DateTime.Now;
+                        complaintletterDTO.Status = 1;
+                        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.Modifier = curentuser.Id;
+                        complaintletterDTO.Modifytime = DateTime.Now;
+                        complaintletterDTO.Creater = curentuser.Id;
+                        complaintletterDTO.Createtime = complaintletterDTO.Modifytime;
+                        complaintletterDTO.Status = 1;
+                        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++)
+                        {
+                            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++)
+                        {
+                            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++)
+                        {
+                            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);
+                        }
+                    }
+
+                }
+                else if (data.OrderType1 == "浠f嫙璐ㄧ枒鍑�")
+                {
+                    //鏌ヨ涓昏〃
+                    var challengeletterDTO = _cooperOrderService.GetListChallengeletter(data.Id).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 = 1;
+                        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 = 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++)
+                        {
+                            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);
         }
@@ -504,19 +899,82 @@
             ResultEntity resultEntity = new ResultEntity();
             resultEntity.Result = false;
 
-            CooperOrderDTO dto = _cooperOrderService.Get(id);
-            if(dto.ShouliStatus != "1")
+            using (TransactionScope scope = new TransactionScope())
             {
-                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);
+
+                }
+
+
+
+                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);
         }
@@ -564,24 +1022,69 @@
 
             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";
+
+                resultEntity = _cooperOrderService.chedan(dto);
+                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]
@@ -775,7 +1278,7 @@
                 result = JsonConvert.SerializeObject(shi);
             }
 
-            if (OrderType == "08" || OrderType == "10")
+            if (OrderType == "08" || OrderType == "10" || OrderType == "11")
             {
                
                 result = "[]";
@@ -834,7 +1337,10 @@
 
                
             }
-           
+            if (result == "")
+            {
+                result = "[]";
+            }
             return result;
 
         }

--
Gitblit v1.9.1