From be19d957b591ad27a47057929c4a8694f0776a1a Mon Sep 17 00:00:00 2001
From: jiangshuai <291802688@qq.com>
Date: 星期四, 26 十月 2023 10:15:26 +0800
Subject: [PATCH] bug修改

---
 controllers/product_controller.go |   32 ++++++++++++++++++++++++--------
 1 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/controllers/product_controller.go b/controllers/product_controller.go
index 9dee846..da77f6c 100644
--- a/controllers/product_controller.go
+++ b/controllers/product_controller.go
@@ -475,19 +475,35 @@
 				if err := tx.Save(listProdt[k]).Error; err != nil {
 					return err
 				}
-				var locAmount models.LocationProductAmount
-				if err := models.NewLocationProductAmountSearch().Orm.
-					Table("wms_location_product_amount").
-					Joins("inner join wms_location_product on wms_location_product.id=wms_location_product_amount.location_product_id").
-					Where("wms_location_product.product_id=? and wms_location_product.location_id=?", v.ID, operation.FromLocationID).
-					First(&locAmount).Error; err != nil {
+
+				//var locAmount models.LocationProductAmount
+				//if err := models.NewLocationProductAmountSearch().Orm.
+				//	Table("wms_location_product_amount").
+				//	Joins("inner join wms_location_product on wms_location_product.id=wms_location_product_amount.location_product_id").
+				//	Where("wms_location_product.product_id=? and wms_location_product.location_id=?", v.ID, operation.FromLocationID).
+				//	First(&locAmount).Error; err != nil {
+				//	return err
+				//}
+				//if locAmount.Amount.LessThan(value) {
+				//	return errors.New(fmt.Sprintf("浜у搧锛�%v,搴撳瓨锛�%v,鍑哄簱锛�%v,鏁伴噺涓嶅锛屾棤娉曞畬鎴愬嚭搴撴搷浣�", v.Name, v.Amount.String(), value.String()))
+				//}
+				//locAmount.Amount = locAmount.Amount.Sub(value)
+				//if err := models.NewLocationProductAmountSearch().SetID(locAmount.Id).Update(&locAmount); err != nil {
+				//	return err
+				//}
+
+				locAmount, res := models.NewLocationProductAmountSearch().
+					SetProductId(v.ID).
+					SetLocationId(operation.ToLocationID).
+					FirstRes()
+				if res.Error != nil {
 					return err
 				}
 				if locAmount.Amount.LessThan(value) {
-					return errors.New(fmt.Sprintf("浜у搧锛�%v,搴撳瓨锛�%v,鍑哄簱锛�%v,鏁伴噺涓嶅锛屾棤娉曞畬鎴愬嚭搴撴搷浣�", v.Name, v.Amount.String(), value.String()))
+					return errors.New(fmt.Sprintf("浜у搧锛�%v,搴撳瓨锛�%v,鎶ュ簾锛�%v,鏁伴噺涓嶅锛屾棤娉曞畬鎴愭姤搴熸搷浣�", v.Name, v.Amount.String(), value.String()))
 				}
 				locAmount.Amount = locAmount.Amount.Sub(value)
-				if err := models.NewLocationProductAmountSearch().SetID(locAmount.Id).Update(&locAmount); err != nil {
+				if err := models.NewLocationProductAmountSearch().SetID(locAmount.Id).Update(locAmount); err != nil {
 					return err
 				}
 			}

--
Gitblit v1.8.0