From 8e216cfa89d3bcd6f010376ecb4f2f0e90724ea0 Mon Sep 17 00:00:00 2001
From: jiangshuai <291802688@qq.com>
Date: 星期一, 13 十一月 2023 14:38:12 +0800
Subject: [PATCH] 取消接口bug

---
 controllers/product_controller.go |   68 +++++++++++++++++++++++++++++++++-
 1 files changed, 66 insertions(+), 2 deletions(-)

diff --git a/controllers/product_controller.go b/controllers/product_controller.go
index da77f6c..a7dab0d 100644
--- a/controllers/product_controller.go
+++ b/controllers/product_controller.go
@@ -52,6 +52,19 @@
 		util.ResponseFormat(c, code.RequestParamError, "浜у搧淇℃伅淇濆瓨澶辫触")
 		return
 	}
+
+	materialAttachmentList := []*models.MaterialAttachment{}
+	for _, v := range params.AttachmentIDs {
+		ma := &models.MaterialAttachment{MaterialID: params.ID, AttachmentID: v}
+		materialAttachmentList = append(materialAttachmentList, ma)
+	}
+	if len(materialAttachmentList) > 0 {
+		if err := models.NewMaterialAttachmentSearch().CreateBatch(materialAttachmentList); err != nil {
+			util.ResponseFormat(c, code.SaveFail, "闄勪欢淇濆瓨澶辫触")
+			return
+		}
+	}
+
 	util.ResponseFormat(c, code.Success, "淇濆瓨鎴愬姛")
 }
 
@@ -72,7 +85,7 @@
 	if params.PageInfo.Check() {
 		search.SetPage(params.Page, params.PageSize)
 	}
-	products, total, err := search.SetKeyword(params.KeyWord).SetCategoryId(params.CategoryId).SetOrder("created_at desc").Find()
+	products, total, err := search.SetPreload(true).SetKeyword(params.KeyWord).SetCategoryId(params.CategoryId).SetOrder("created_at desc").Find()
 	if err != nil {
 		util.ResponseFormat(c, code.RequestParamError, "鏌ユ壘澶辫触")
 		return
@@ -110,7 +123,7 @@
 		util.ResponseFormat(c, code.RequestParamError, "鏃犳晥id")
 		return
 	}
-	material, err := models.NewMaterialSearch().SetID(id).First()
+	material, err := models.NewMaterialSearch().SetID(id).SetPreload(true).First()
 	if err != nil {
 		util.ResponseFormat(c, code.RequestParamError, "鏌ユ壘澶辫触")
 		return
@@ -147,6 +160,22 @@
 	if err != nil {
 		util.ResponseFormat(c, code.RequestParamError, "浜у搧淇℃伅鏇存柊澶辫触")
 		return
+	}
+
+	materialAttachmentList := []*models.MaterialAttachment{}
+	for _, v := range params.AttachmentIDs {
+		ma := &models.MaterialAttachment{MaterialID: params.ID, AttachmentID: v}
+		materialAttachmentList = append(materialAttachmentList, ma)
+	}
+	if err := models.NewMaterialAttachmentSearch().SetMaterialID(params.ID).Delete(); err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "浜у搧闄勪欢娓呴櫎澶辫触")
+		return
+	}
+	if len(materialAttachmentList) > 0 {
+		if err := models.NewMaterialAttachmentSearch().CreateBatch(materialAttachmentList); err != nil {
+			util.ResponseFormat(c, code.RequestParamError, "浜у搧淇℃伅鏇存柊澶辫触")
+			return
+		}
 	}
 	util.ResponseFormat(c, code.Success, "鏇存柊鎴愬姛")
 }
@@ -619,3 +648,38 @@
 
 	util.ResponseFormatListWithPage(c, code.Success, list, int(total), params.Page, params.PageSize)
 }
+
+// CancelDisuse
+//
+//	@Tags		浜у搧
+//	@Summary	鍙栨秷鎶ュ簾
+//	@Produce	application/json
+//	@Param		id	path		int			true	"id"
+//	@Success	200	{object}	util.Response	"鎴愬姛"
+//	@Router		/api-wms/v1/product/cancelDisuse/{id} [put]
+func (slf ProductController) CancelDisuse(c *gin.Context) {
+	id, err := strconv.Atoi(c.Param("id"))
+	if err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "閿欒鐨刬d鍊�")
+		return
+	}
+	if id == 0 {
+		util.ResponseFormat(c, code.RequestParamError, "id涓�0")
+		return
+	}
+	operation, err := models.NewOperationSearch().SetID(id).First()
+	if err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "鏈壘鍒扮浉鍏充俊鎭�:"+err.Error())
+		return
+	}
+	if operation.Status != constvar.OperationStatus_Ready {
+		util.ResponseFormat(c, code.RequestError, "璇ヤ俊鎭棤娉曞彇娑�")
+		return
+	}
+	operation.Status = constvar.OperationStatus_Cancel
+	if err := models.NewOperationSearch().SetID(operation.Id).Save(operation); err != nil {
+		util.ResponseFormat(c, code.SaveFail, err.Error())
+		return
+	}
+	util.ResponseFormat(c, code.Success, "鎿嶄綔鎴愬姛")
+}

--
Gitblit v1.8.0