From 402f9568e48e6e1a9d29d37dcda46737047425d5 Mon Sep 17 00:00:00 2001
From: username@email.com <yzy2002yzy@163.com>
Date: 星期四, 25 十一月 2021 10:49:10 +0800
Subject: [PATCH] 专家通讯录优化

---
 zhengcaioa/zhengcaioa/Controllers/BusinessOrder/CooperOrderController.cs |  230 ++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 195 insertions(+), 35 deletions(-)

diff --git a/zhengcaioa/zhengcaioa/Controllers/BusinessOrder/CooperOrderController.cs b/zhengcaioa/zhengcaioa/Controllers/BusinessOrder/CooperOrderController.cs
index 8fd61ed..c4cdcf7 100644
--- a/zhengcaioa/zhengcaioa/Controllers/BusinessOrder/CooperOrderController.cs
+++ b/zhengcaioa/zhengcaioa/Controllers/BusinessOrder/CooperOrderController.cs
@@ -40,13 +40,21 @@
         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
             , IConfiguration configuration
-            , IHttpClientFactory clientFactory)
+            , IHttpClientFactory clientFactory
+            , IAskService askService
+            , IAdmGoodsRecordService admGoodsRecordService
+            , IAdmGoodsManageService admGoodsManageService
+            )
         {
             _logger = logger;
             _liaotianService = liaotianService;
@@ -60,6 +68,9 @@
             _fiMemberService = fiMemberService;
             _configuration = configuration;
             _clientFactory = clientFactory;
+            _askService = askService;
+            _admGoodsRecordService = admGoodsRecordService;
+            _admGoodsManageService = admGoodsManageService;
         }
 
         [CheckLogin]
@@ -405,12 +416,15 @@
             {
                 dto = _cooperOrderService.Get(id);
                 ViewBag.ShouliStatus = ShouliStatus;
+                //ViewBag.YouHuiList = _askService.GetAskYouHuiList(dto.Khdw, dto.OrderType);
             }
             else
             {
                 dto.XdTime = DateTime.Now;
                 dto.OrderNum = 1;
                 ViewBag.ShouliStatus = "1";
+                dto.OrderNo = _cooperOrderService.GetOrderNo();
+                //ViewBag.YouHuiList = new List<AdmAskYouHuiDTO>();
             }
 
 
@@ -534,14 +548,49 @@
 
                     
                 }
-                data.ShouliStatus = "1";
-                data.Modifier = curentuser.Id;
-                data.Modifytime = DateTime.Now;
 
-                resultEntity = _cooperOrderService.save(data);
+            var youHuiDTOs = _askService.GetAskYouHuiList(data.Khdw, data.OrderType).FirstOrDefault();
+            if (youHuiDTOs != null)
+            {
+                data.Youhuier = youHuiDTOs.Id;
+                if(youHuiDTOs.Youhuistandard == "01")
+                {
+                    data.Youhui = youHuiDTOs.YouHui.Value;
+                    if(data.Money.Value < data.Youhui.Value)
+                    {
+                        data.Money = 0;
+                    }
+                    else
+                    {
+                        data.Money = data.Money.Value - data.Youhui.Value;
+                    }
+                   
+                }
+                else if (youHuiDTOs.Youhuistandard == "02")
+                {
+                    if (youHuiDTOs.YouHui.Value >= 100)
+                    {
+                        data.Youhui = data.Money.Value;
+                        data.Money = 0;
+                    }
+                    else
+                    {
+                        data.Youhui =Math.Round(data.Money.Value * youHuiDTOs.YouHui.Value * new decimal(0.01),2);
+                        data.Money = data.Money.Value - data.Youhui.Value;
+                    }
+                }
+                  
+                  
+            }
+            
+            data.ShouliStatus = "1";
+            data.Modifier = curentuser.Id;
+            data.Modifytime = DateTime.Now;
+
+            resultEntity = _cooperOrderService.save(data);
             //    scope.Complete();
             //}
-           
+
 
             return new JsonResult(resultEntity);
         }
@@ -576,19 +625,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);
         }
@@ -636,24 +748,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]
@@ -847,7 +1004,7 @@
                 result = JsonConvert.SerializeObject(shi);
             }
 
-            if (OrderType == "08" || OrderType == "10")
+            if (OrderType == "08" || OrderType == "10" || OrderType == "11")
             {
                
                 result = "[]";
@@ -906,7 +1063,10 @@
 
                
             }
-           
+            if (result == "")
+            {
+                result = "[]";
+            }
             return result;
 
         }

--
Gitblit v1.9.1