From 216c9e49dafdb7a5bd025f6d6fa899a33befc38c Mon Sep 17 00:00:00 2001
From: liujiandao <274878379@qq.com>
Date: 星期三, 17 四月 2024 10:33:01 +0800
Subject: [PATCH] 产品添加字段

---
 models/location_product_amount.go |   44 +++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 43 insertions(+), 1 deletions(-)

diff --git a/models/location_product_amount.go b/models/location_product_amount.go
index f076f91..c102c5b 100644
--- a/models/location_product_amount.go
+++ b/models/location_product_amount.go
@@ -17,7 +17,7 @@
 		LocationId        int             `json:"locationId" gorm:"type:int;not null;comment:浣嶇疆id"` //浣嶇疆id
 		Location          Location        `json:"location" gorm:"foreignKey:LocationId;references:id"`
 		ProductCategoryID int             `json:"productCategoryId" gorm:"type:int;not null;comment:浜у搧绉嶇被id"` //浜у搧绉嶇被id
-		ProductCategory   ProductCategory `json:"productCategory"`
+		ProductCategory   ProductCategory `json:"productCategory" gorm:"foreignKey:ProductCategoryID;references:Id"`
 		ProductId         string          `json:"productId" gorm:"type:varchar(191);not null;comment:浜у搧id"` //浜у搧id
 		Product           Material        `json:"product" gorm:"foreignKey:ProductId;references:ID"`
 		Amount            decimal.Decimal `json:"amount" gorm:"type:decimal(20,2);not null;comment:搴撳瓨鏁伴噺"` //搴撳瓨鏁伴噺
@@ -35,6 +35,8 @@
 		//LocationProductIds []int
 		LocationIds []int
 		ProductIds  []string
+		Ids         []int
+		Query       string
 	}
 
 	LocationProductAmountWithOperation struct {
@@ -52,6 +54,7 @@
 		OperationId             int                        `json:"operationId" gorm:"column:operation_id"`
 		Status                  constvar.OperationStatus   `json:"status" gorm:"status"`
 		BaseOperationType       constvar.BaseOperationType `json:"baseOperationType" gorm:"base_operation_type"`
+		Weight                  decimal.Decimal            `gorm:"type:decimal(20,3);comment:閲嶉噺" json:"weight"` //閲嶉噺
 	}
 )
 
@@ -83,6 +86,11 @@
 	return slf
 }
 
+func (slf *LocationProductAmountSearch) SetIds(ids []int) *LocationProductAmountSearch {
+	slf.Ids = ids
+	return slf
+}
+
 func (slf *LocationProductAmountSearch) SetKeyword(keyword string) *LocationProductAmountSearch {
 	slf.Keyword = keyword
 	return slf
@@ -110,6 +118,11 @@
 
 func (slf *LocationProductAmountSearch) SetLocationIds(ids []int) *LocationProductAmountSearch {
 	slf.LocationIds = ids
+	return slf
+}
+
+func (slf *LocationProductAmountSearch) SetQuery(query string) *LocationProductAmountSearch {
+	slf.Query = query
 	return slf
 }
 
@@ -151,6 +164,14 @@
 
 	if slf.ProductId != "" {
 		db = db.Where("product_id=?", slf.ProductId)
+	}
+
+	if len(slf.Ids) > 0 {
+		db = db.Where("id in (?)", slf.Ids)
+	}
+
+	if slf.Query != "" {
+		db = db.Where(slf.Query)
 	}
 
 	return db
@@ -247,3 +268,24 @@
 
 	return record, db.First(&record)
 }
+
+func (slf *LocationProductAmountSearch) Count() (int64, error) {
+	var (
+		total int64
+		db    = slf.build()
+	)
+	err := db.Count(&total).Error
+	return total, err
+}
+
+func (slf *LocationProductAmountSearch) UpdateByMap(upMap map[string]interface{}) error {
+	var (
+		db = slf.build()
+	)
+
+	if err := db.Updates(upMap).Error; err != nil {
+		return fmt.Errorf("update by map err: %v, upMap: %+v", err, upMap)
+	}
+
+	return nil
+}

--
Gitblit v1.8.0