From ff4660980ccfe3e123df8d5fa820266784625c74 Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期二, 14 十月 2025 20:39:27 +0800
Subject: [PATCH] 1111

---
 代码管理/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/InventoryServices.cs |   35 ++++++++++++++++++++---------------
 1 files changed, 20 insertions(+), 15 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 0e4cb00..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"
@@ -13,7 +13,6 @@
 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;
@@ -91,18 +90,19 @@
                 {
                     return new ApiResponse<Dt_Inventory> { code ="500",msg = "璇锋眰鍙傛暟鏃犳晥" };
                 }
-
+                BaseDal.Db.Ado.BeginTran();//寮�鍚簨鍔�
                 foreach (var detail in request.details)
                 {
-                    // 鍏堟煡搴撳瓨鏄惁瀛樺湪
-                    var entity = Db.Queryable<Dt_Inventory>()
-                                   .First(x => x.Goods_no == detail.productCode);
+                    // 鍏堟煡搴撳瓨鏄惁瀛樺湪锛堟寜鐓т骇鍝佺紪鍙峰拰鎵规鏉ュ鎵撅級
+                    var entity = BaseDal.Db.Queryable<Dt_Inventory>()
+                                   .First(x => x.Goods_no == detail.productCode && x.Batch_num == detail.batchNo);
                     //灏嗛泦鍚堜腑鐨勬暟閲忚繘琛岀疮鍔�
-                    decimal orderQty = detail.orderDetails?.Sum(x => Convert.ToDecimal(x.quantity)) ?? 0;
-                    decimal diffQty = detail.stocktakingDetails?.Sum(x => Convert.ToDecimal(x.differenceQuantity)) ?? 0;
-                    //decimal orderQty = detail.orderDetails?.Sum(x => Convert.ToDecimal(x.quantity)) ?? 0;
-                    //decimal diffQty = detail.stocktakingDetails?.Sum(x => Convert.ToDecimal(x.differenceQuantity)) ?? 0;
+                    // 瀹夊叏杞崲
 
+                    //姝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)
                     {
                         // 濡傛灉涓嶅瓨鍦紝鏂板缓涓�鏉�
@@ -111,7 +111,9 @@
                             Goods_no = detail.productCode ?? detail.productName,
                             Reservoirarea = "榛樿搴撳尯",
                             Batch_num = detail.batchNo,
+                            //涓氬姟搴撳瓨
                             Business_qty = 0,
+                            //瀹為檯搴撳瓨
                             Actual_qty = 0
                         };
                     }
@@ -135,15 +137,16 @@
                             {
                                 foreach (var stock in detail.stocktakingDetails)
                                 {
+                                    //姣忔閮藉彧鎷夸竴鏉℃槑缁嗕腑鐨勬暟閲�
                                     decimal diff = Convert.ToDecimal(stock.differenceQuantity);
                                     if (stock.IsProfit == "1") // 鐩樼泩
                                     {
-                                        entity.Actual_qty += diff;
+                                        entity.Business_qty += diff;//濡傛灉鐩樼泩浜嗗浜嗭紝灏卞皢涓氬姟鏁伴噺+锛岀洏浜忓垯鐩稿弽
                                     }
                                     else // 鐩樹簭
                                     {
-                                        entity.Actual_qty -= diff;
-                                        if (entity.Actual_qty < 0) entity.Actual_qty = 0;
+                                        entity.Business_qty -= diff;
+                                        //if (entity.Business_qty < 0) entity.Business_qty = 0;
                                     }
                                 }
                             }
@@ -152,19 +155,21 @@
 
                     // 淇濆瓨鏁版嵁
                     if (entity.Id == 0) // 鏂板缓
-                        Db.Insertable(entity).ExecuteCommand();
+                        BaseDal.Db.Insertable(entity).ExecuteCommand();
                     else // 鏇存柊
-                        Db.Updateable(entity).ExecuteCommand();
+                        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 };
             }
         }
 
+      
 
 
 

--
Gitblit v1.9.3