From 528badf2f1efe5355975de7942fb7a26e71a8e18 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期六, 01 十一月 2025 18:34:37 +0800
Subject: [PATCH] 优化盘点流程、出入库退货流程

---
 新建文件夹/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/InventoryServices.cs |   91 ++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 84 insertions(+), 7 deletions(-)

diff --git "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/InventoryServices.cs" "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/InventoryServices.cs"
index 37bc1f4..d0f0bb3 100644
--- "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/InventoryServices.cs"
+++ "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/InventoryServices.cs"
@@ -28,12 +28,15 @@
 {
     public class InventoryServices : ServiceBase<Dt_Inventory, IRepository<Dt_Inventory>>, IInventoryServices
     {
+        private readonly ICabinOrderServices _cabinOrderServices;
         private readonly IDeliveryOrderServices _deliveryOrderServices;
-        public InventoryServices(IRepository<Dt_Inventory> BaseDal, IDeliveryOrderServices deliveryOrderServices) : base(BaseDal)
+        private readonly ISupplyTaskService _supplyTaskService;
+        public InventoryServices(IRepository<Dt_Inventory> BaseDal, ICabinOrderServices cabinOrderServices, IDeliveryOrderServices deliveryOrderServices, ISupplyTaskService supplyTaskService) : base(BaseDal)
         {
+            _cabinOrderServices = cabinOrderServices;
             _deliveryOrderServices = deliveryOrderServices;
+            _supplyTaskService = supplyTaskService;
         }
-
 
         /// <summary>
         /// 鑾峰彇涓婃父搴撳瓨淇℃伅
@@ -88,13 +91,85 @@
         }
 
 
+        public ApiResponse<Dt_InventoryInfo> OrderFeedback(EdiOrderCallbackRequest request)
+        {
+            try
+            {
+                if (request == null || request.details == null || request.details.Count < 1) throw new Exception("璇锋眰鍙傛暟鏃犳晥");
+                var Warecode = WarehouseEnum.绔嬪簱.ObjToInt().ToString("000");
+                switch (request.orderType)
+                {
+                    case "1": //鍏ュ簱
+                        {
+                            Dt_CabinOrder cabinOrder = _cabinOrderServices.Db.Queryable<Dt_CabinOrder>().Where(x => x.Order_no == request.externalOrderNo && x.Warehouse_no == Warecode).Includes(x => x.Details).First();
+                            if (cabinOrder == null) throw new Exception($"鏈壘鍒板叆搴撳崟鍙枫�恵request.externalOrderNo}銆戠殑鍏ュ簱鍗曚俊鎭�");
+                            if (cabinOrder.OdrderStatus == "宸插畬鎴�")
+                                return new ApiResponse<Dt_InventoryInfo> { code = "0", msg = $"鎴愬姛" };
+                            WebResponseContent content = _cabinOrderServices.CompleteLKInOrder(cabinOrder, request);
+                            if (!content.Status) throw new Exception(content.Message);
+                        }
+                        break;
+                    case "2":
+                        {
+                            Dt_DeliveryOrder deliveryOrder = _deliveryOrderServices.Db.Queryable<Dt_DeliveryOrder>().Where(x => x.Out_no == request.externalOrderNo && x.Warehouse_no == Warecode).Includes(x => x.Details).First();
+                            if (deliveryOrder == null) throw new Exception($"鏈壘鍒板嚭搴撳崟鍙枫�恵request.externalOrderNo}銆戠殑鍑哄簱鍗曚俊鎭�");
+                            if (deliveryOrder.OutStatus == "宸插畬鎴�")
+                                return new ApiResponse<Dt_InventoryInfo> { code = "0", msg = $"鎴愬姛" };
+                            WebResponseContent content = _deliveryOrderServices.CompleteLKOutOrder(deliveryOrder, request);
+                            if (!content.Status) throw new Exception(content.Message);
+                        }
+                        break;
+                    case "3":
+                        {
+                            #region 鎵剧洏鐐逛换鍔�
+                            List<Dt_SupplyTask> supplyTasks = _supplyTaskService.Repository.QueryData(x => x.OrderNo == request.externalOrderNo && x.WarehouseCode == Warecode && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt());
+                            foreach (var detail in request.details)
+                            {
+                                Dt_SupplyTask? supplyTask = supplyTasks.Where(x => x.MaterielCode == detail.productCode && x.BatchNo == detail.batchNo).FirstOrDefault();
+                                if (supplyTask == null) throw new Exception($"鏈壘鍒拌鍗曞彿銆恵request.externalOrderNo}銆戠墿鏂欑紪鍙枫�恵detail.productCode}銆戠殑鐩樼偣浠诲姟");
+                                if (detail.isLossOrProfit == 1) // 鐩樹簭
+                                {
+                                    supplyTask.SupplyQuantity = supplyTask.StockQuantity - detail.ea;
+                                }
+                                else if (detail.isLossOrProfit == 2) // 鐩樼泩
+                                {
+                                    supplyTask.SupplyQuantity = supplyTask.StockQuantity + detail.ea;
+                                }
+                                else // 鐩樹腑
+                                {
+                                    supplyTask.SupplyQuantity = supplyTask.StockQuantity;
+                                }
+                                var content = _deliveryOrderServices.CheckTaskFinish(supplyTask);
+                                if (!content.Status) throw new Exception(content.Message);
+                            }
+                            #endregion
+                        }
+                        break;
+                    default:
+                        throw new Exception($"鏈畾涔夌殑绫诲瀷銆恵request.orderType}銆�");
+                }
+                return new ApiResponse<Dt_InventoryInfo>
+                {
+                    code = "0",
+                    msg = $"鎴愬姛"
+                };
+            }
+            catch (Exception ex)
+            {
+                return new ApiResponse<Dt_InventoryInfo>
+                {
+                    code = "500",
+                    msg = $"澶勭悊澶辫触: {ex.Message}"
+                };
+            }
+        }
 
         /// <summary>
         /// wcs鍥炰紶缁欐垜璋冪敤鎴戠殑鏂规硶 涓嶇鏄叆搴� 鍑哄簱 鐩樼偣閮戒細璋冪敤杩欎釜鎺ュ彛
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
-        public ApiResponse<Dt_InventoryInfo> OrderFeedback(EdiOrderCallbackRequest request)
+        public ApiResponse<Dt_InventoryInfo> OrderFeedback1(EdiOrderCallbackRequest request)
         {
             try
             {
@@ -105,7 +180,7 @@
                 }
                 var reslut = WarehouseEnum.绔嬪簱.ObjToInt().ToString("000");
                 // 2锔忊儯 寮�鍚簨鍔�
-                BaseDal.Db.Ado.BeginTran();
+                //BaseDal.Db.Ado.BeginTran();
                 foreach (var detail in request.details)
                 {
                     #region 鏌ヨ鐗╂枡淇℃伅銆佽绠楁�诲拰
@@ -306,7 +381,7 @@
                         case "2":
                             {
                                 Dt_DeliveryOrder cabinOrder = Db.Queryable<Dt_DeliveryOrder>().Where(x => x.Out_no == request.externalOrderNo && x.Warehouse_no == reslut).Includes(x => x.Details).First();
-                                if (cabinOrder == null) throw new Exception($"鏈壘鍒板嚭搴撳崟鍙枫�恵request.externalOrderNo}銆戠殑鍏ュ簱鍗曚俊鎭�");
+                                if (cabinOrder == null) throw new Exception($"鏈壘鍒板嚭搴撳崟鍙枫�恵request.externalOrderNo}銆戠殑鍑哄簱鍗曚俊鎭�");
 
                                 if (cabinOrder.Out_type == "6")
                                 {
@@ -398,7 +473,7 @@
                 }
 
                 // 9锔忊儯 鎻愪氦浜嬪姟
-                BaseDal.Db.Ado.CommitTran();
+                //BaseDal.Db.Ado.CommitTran();
 
                 return new ApiResponse<Dt_InventoryInfo>
                 {
@@ -409,13 +484,15 @@
             catch (Exception ex)
             {
                 // 馃敓 鍥炴粴浜嬪姟
-                BaseDal.Db.Ado.RollbackTran();
+                //BaseDal.Db.Ado.RollbackTran();
 
                 return new ApiResponse<Dt_InventoryInfo>
                 {
                     code = "500",
                     msg = $"澶勭悊澶辫触: {ex.Message}"
                 };
+
+                //Console.WriteLine(ex.Message);
             }
         }
 

--
Gitblit v1.9.3