From 1444c7c800fc042cd99213e901d6ad3722d0f03f Mon Sep 17 00:00:00 2001
From: jiangshuai <291802688@qq.com>
Date: 星期三, 27 九月 2023 16:13:53 +0800
Subject: [PATCH] 1.二期一部分代码

---
 controllers/product_controller.go |   39 +++++++++++++++++++++++++++------------
 1 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/controllers/product_controller.go b/controllers/product_controller.go
index ab762ae..c1f3d00 100644
--- a/controllers/product_controller.go
+++ b/controllers/product_controller.go
@@ -76,12 +76,28 @@
 	if params.PageInfo.Check() {
 		search.SetPage(params.Page, params.PageSize)
 	}
-	products, total, err := search.SetKeyword(params.KeyWord).SetOrder("created_at desc").Find()
+	products, total, err := search.SetKeyword(params.KeyWord).SetCategoryId(params.CategoryId).SetOrder("created_at desc").Find()
 	if err != nil {
 		util.ResponseFormat(c, code.RequestParamError, "鏌ユ壘澶辫触")
 		return
 	}
 
+	ids := make([]int, 0)
+	for _, product := range products {
+		ids = append(ids, product.CategoryId)
+	}
+	categories, err := models.NewProductCategorySearch().SetIds(ids).FindNotTotal()
+	if err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "浜у搧绫诲瀷鏌ユ壘澶辫触")
+		return
+	}
+	for _, product := range products {
+		for _, category := range categories {
+			if product.CategoryId == int(category.ID) {
+				product.CategoryName = category.Name
+			}
+		}
+	}
 	util.ResponseFormatList(c, code.Success, products, int(total))
 }
 
@@ -344,19 +360,18 @@
 	}
 	detail := &models.OperationDetails{
 		ProductId: params.ProductId,
-		//ProductName: params.ProductName,
-		Amount: params.Amount,
-		//Unit:        params.Unit,
+		Amount:    params.Amount,
 	}
 	operation := models.Operation{
-		Number:          strconv.FormatInt(time.Now().Unix(), 10),
-		SourceNumber:    params.SourceNumber,
-		OperationTypeId: 0,
-		Status:          constvar.OperationStatus_Ready,
-		FromLocationID:  params.FromLocationId,
-		ToLocationID:    params.ToLocationId,
-		OperationDate:   time.Now().Format("2006-01-02 15:04:05"),
-		Details:         []*models.OperationDetails{detail},
+		Number:            strconv.FormatInt(time.Now().Unix(), 10),
+		SourceNumber:      params.SourceNumber,
+		OperationTypeId:   0,
+		Status:            constvar.OperationStatus_Ready,
+		FromLocationID:    params.FromLocationId,
+		ToLocationID:      params.ToLocationId,
+		OperationDate:     time.Now().Format("2006-01-02 15:04:05"),
+		Details:           []*models.OperationDetails{detail},
+		BaseOperationType: constvar.BaseOperationTypeDisuse,
 	}
 	if err := models.NewOperationSearch().Create(&operation); err != nil {
 		logx.Errorf("Operation create err: %v", err)

--
Gitblit v1.8.0