From 7a3a9a739392d048655efac6a28592410a8809c2 Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期五, 17 十一月 2023 09:57:29 +0800 Subject: [PATCH] 在库产品类型修改 --- controllers/product_controller.go | 16 ++++++++++++++++ models/location_product_amount.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 0 deletions(-) diff --git a/controllers/product_controller.go b/controllers/product_controller.go index 96f9306..3a40e59 100644 --- a/controllers/product_controller.go +++ b/controllers/product_controller.go @@ -214,6 +214,22 @@ return } + //鏇存柊鍦ㄥ簱鐨勪骇鍝佺被鍨� + if params.CategoryId > 0 { + find, _ := models.NewLocationProductAmountSearch().SetProductId(params.ID).Find() + if len(find) > 0 { + var ids []int + for _, f := range find { + if f.ProductCategoryID != params.CategoryId { + ids = append(ids, f.Id) + } + } + m := make(map[string]interface{}) + m["productCategoryId"] = params.CategoryId + _ = models.NewLocationProductAmountSearch().SetIds(ids).UpdateByMap(m) + } + } + materialAttachmentList := []*models.MaterialAttachment{} for _, v := range params.AttachmentIDs { ma := &models.MaterialAttachment{MaterialID: params.ID, AttachmentID: v} diff --git a/models/location_product_amount.go b/models/location_product_amount.go index 6f3f767..4f1af2b 100644 --- a/models/location_product_amount.go +++ b/models/location_product_amount.go @@ -35,6 +35,7 @@ //LocationProductIds []int LocationIds []int ProductIds []string + Ids []int } LocationProductAmountWithOperation struct { @@ -80,6 +81,11 @@ func (slf *LocationProductAmountSearch) SetID(id int) *LocationProductAmountSearch { slf.Id = id + return slf +} + +func (slf *LocationProductAmountSearch) SetIds(ids []int) *LocationProductAmountSearch { + slf.Ids = ids return slf } @@ -151,6 +157,10 @@ if slf.ProductId != "" { db = db.Where("product_id=?", slf.ProductId) + } + + if len(slf.Ids) > 0 { + db = db.Where("id in (?)", slf.Ids) } return db @@ -247,3 +257,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