From d09db513efa9e90b216d0348586540dc76a1e2e3 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期六, 01 十一月 2025 01:45:39 +0800
Subject: [PATCH] 1

---
 代码管理/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/InventoryServices.cs |  100 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 99 insertions(+), 1 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/InventoryServices.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/InventoryServices.cs"
index fdec116..abf0fb4 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/InventoryServices.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/InventoryServices.cs"
@@ -9,12 +9,13 @@
 using WIDESEA_Core;
 using WIDESEA_Core.BaseServices;
 using WIDESEA_Core.Helper;
+using WIDESEA_DTO.SquareCabin;
 using WIDESEA_ISquareCabinRepository;
 using WIDESEA_ISquareCabinServices;
 using WIDESEA_Model.Models;
-using WIDESEA_Model.Models.SquareCabin;
 using WIDESEA_SquareCabinRepository;
 using static WIDESEA_DTO.SquareCabin.OrderDto;
+using static WIDESEA_DTO.SquareCabin.TowcsDto;
 
 namespace WIDESEA_SquareCabinServices
 {
@@ -75,6 +76,103 @@
             }
         }
 
+
+        /// <summary>
+        /// wcs鍥炰紶缁欐垜 
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        public ApiResponse<Dt_Inventory> OrderFeedback(EdiOrderCallbackRequest request)
+        {
+            try
+            {
+                if (request == null || request.details == null || !request.details.Any())
+                {
+                    return new ApiResponse<Dt_Inventory> { code ="500",msg = "璇锋眰鍙傛暟鏃犳晥" };
+                }
+                BaseDal.Db.Ado.BeginTran();//寮�鍚簨鍔�
+                foreach (var detail in request.details)
+                {
+                    // 鍏堟煡搴撳瓨鏄惁瀛樺湪锛堟寜鐓т骇鍝佺紪鍙峰拰鎵规鏉ュ鎵撅級
+                    var entity = BaseDal.Db.Queryable<Dt_Inventory>()
+                                   .First(x => x.Goods_no == detail.productCode && x.Batch_num == detail.batchNo);
+                    //灏嗛泦鍚堜腑鐨勬暟閲忚繘琛岀疮鍔�
+                    // 瀹夊叏杞崲
+
+                    //姝e父鍑哄叆搴�
+                    decimal orderQty = detail.orderDetails?.Sum(x => decimal.TryParse(x.quantity, out var q) ? q : 0) ?? 0;
+                    //鐩樼偣鐩樹簭
+                    decimal diffQty = detail.stocktakingDetails?.Sum(x => Convert.ToDecimal(x.differenceQuantity)) ?? 0;
+                    if (entity == null)
+                    {
+                        // 濡傛灉涓嶅瓨鍦紝鏂板缓涓�鏉�
+                        entity = new Dt_Inventory
+                        {
+                            Goods_no = detail.productCode ?? detail.productName,
+                            Reservoirarea = "榛樿搴撳尯",
+                            Batch_num = detail.batchNo,
+                            //涓氬姟搴撳瓨
+                            Business_qty = 0,
+                            //瀹為檯搴撳瓨
+                            Actual_qty = 0
+                        };
+                    }
+
+                    switch (request.orderType)
+                    {
+                        case "1": // 鍏ュ簱
+                            entity.Business_qty += orderQty;
+                            entity.Actual_qty += orderQty;
+                            break;
+
+                        case "2": // 鍑哄簱
+                            entity.Business_qty -= orderQty;
+                            entity.Actual_qty -= orderQty;
+                            if (entity.Business_qty < 0) entity.Business_qty = 0; // 鍙�夛細闃叉璐熸暟
+                            if (entity.Actual_qty < 0) entity.Actual_qty = 0;
+                            break;
+
+                        case "3": // 鐩樼偣
+                            if (detail.stocktakingDetails != null && detail.stocktakingDetails.Any())
+                            {
+                                foreach (var stock in detail.stocktakingDetails)
+                                {
+                                    //姣忔閮藉彧鎷夸竴鏉℃槑缁嗕腑鐨勬暟閲�
+                                    decimal diff = Convert.ToDecimal(stock.differenceQuantity);
+                                    if (stock.IsProfit == "1") // 鐩樼泩
+                                    {
+                                        entity.Business_qty += diff;//濡傛灉鐩樼泩浜嗗浜嗭紝灏卞皢涓氬姟鏁伴噺+锛岀洏浜忓垯鐩稿弽
+                                    }
+                                    else // 鐩樹簭
+                                    {
+                                        entity.Business_qty -= diff;
+                                        //if (entity.Business_qty < 0) entity.Business_qty = 0;
+                                    }
+                                }
+                            }
+                            break;
+                    }
+
+                    // 淇濆瓨鏁版嵁
+                    if (entity.Id == 0) // 鏂板缓
+                        BaseDal.Db.Insertable(entity).ExecuteCommand();
+                    else // 鏇存柊
+                        BaseDal.Db.Updateable(entity).ExecuteCommand();
+                }
+                BaseDal.Db.Ado.CommitTran(); // 鎻愪氦浜嬪姟
+                return new ApiResponse<Dt_Inventory> {code = "0", msg = "鎴愬姛" };
+            }
+            catch (Exception ex)
+            {
+                BaseDal.Db.Ado.RollbackTran();//鍥炴粴浜嬪姟
+                return new ApiResponse<Dt_Inventory> { code = "500", msg = ex.Message };
+            }
+        }
+
+      
+
+
+
         /// <summary>
         /// 鎺ㄩ�佸紓甯镐俊鎭粰涓婃父绯荤粺1.鍏ュ簱鍗曟帴鍙o紱2.鍏ュ簱鍗曟姤瀹屾垚鎺ュ彛锛�3.鍑哄簱鍗曟帴鍙o紱4.鍑哄簱鎶ュ畬鎴愭帴鍙o紱5.鑽搧鍩虹淇℃伅鍚屾鎺ュ彛锛�6.渚涘簲鍟嗕俊鎭帴鍙o紱7.瀹㈡埛淇℃伅鎺ュ彛锛�8.搴撳瓨
         /// </summary>

--
Gitblit v1.9.3