From 2716487d13f3521adeb25a48aa07a89f885d32c7 Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期一, 09 十月 2023 09:36:08 +0800 Subject: [PATCH] 仓库功能修改 --- models/material.go | 29 ++++++++++++++++++++++++----- 1 files changed, 24 insertions(+), 5 deletions(-) diff --git a/models/material.go b/models/material.go index df61270..77f3181 100644 --- a/models/material.go +++ b/models/material.go @@ -77,11 +77,12 @@ //MaterialTypes []constvar.MaterialType Keyword string //SetTemplateType constvar.SetTemplateType - Order string - PageNum int - PageSize int - Ids []string - Orm *gorm.DB + Order string + PageNum int + PageSize int + Ids []string + Orm *gorm.DB + CategoryIds []int } IdAndName struct { @@ -157,6 +158,11 @@ return slf } +func (slf *MaterialSearch) SetCategoryIds(ids []int) *MaterialSearch { + slf.CategoryIds = ids + return slf +} + // //func (slf *MaterialSearch) SetSetTemplateType(setType constvar.SetTemplateType) *MaterialSearch { // slf.SetTemplateType = setType @@ -229,6 +235,9 @@ } if slf.CategoryId > 0 { db = db.Where("category_id = ?", slf.CategoryId) + } + if len(slf.CategoryIds) > 0 { + db = db.Where("category_id in ?", slf.CategoryIds) } return db @@ -503,3 +512,13 @@ Amount decimal.Decimal `json:"amount" gorm:"type:decimal(20,2);not null;comment:鏁伴噺"` //鏁伴噺 Unit string `json:"unit" gorm:"type:varchar(31);comment:鍗曚綅"` } + +func (slf *MaterialSearch) Update(record *Material) error { + var db = slf.build() + + if err := db.Omit("CreatedAt").Updates(record).Error; err != nil { + return fmt.Errorf("save err: %v, record: %+v", err, record) + } + + return nil +} -- Gitblit v1.8.0