From 84d2953e7b641600779e7aecc80bdd35e96d31d6 Mon Sep 17 00:00:00 2001 From: jiangshuai <291802688@qq.com> Date: 星期二, 06 二月 2024 10:13:12 +0800 Subject: [PATCH] 拦截器 --- service/purchase/purchase.go | 25 +++++++++++++++++++------ 1 files changed, 19 insertions(+), 6 deletions(-) diff --git a/service/purchase/purchase.go b/service/purchase/purchase.go index 4809c9b..fb3db12 100644 --- a/service/purchase/purchase.go +++ b/service/purchase/purchase.go @@ -7,8 +7,8 @@ "github.com/spf13/cast" "gorm.io/gorm" "srm/global" - "srm/model/common/request" "srm/model/purchase" + purchaserequest "srm/model/purchase/request" "srm/proto/qualityinspect" "srm/service/test" ) @@ -123,7 +123,7 @@ //@param: info request.PageInfo //@return: list interface{}, total int64, err error -func (slf *PurchaseService) GetPurchaseList(info request.PageInfo) (list interface{}, total int64, err error) { +func (slf *PurchaseService) GetPurchaseList(info purchaserequest.PurchaseSearch) (list interface{}, total int64, err error) { limit := info.PageSize offset := info.PageSize * (info.Page - 1) db := global.GVA_DB.Model(&purchase.Purchase{}) @@ -140,16 +140,18 @@ if err != nil { return purchaseList, total, err } + } else if info.SupplierId != 0 { + db = db.Where("supplier_id = ?", info.SupplierId) } - err = db.Count(&total).Error - if err != nil { + if err != nil || total == 0 { return purchaseList, total, err } if len(ids) != 0 { db = global.GVA_DB.Model(&purchase.Purchase{}) err = db.Where("id in (?)", ids).Preload("Supplier").Order("updated_at desc").Find(&purchaseList).Error } else { + //db = global.GVA_DB.Model(&purchase.Purchase{}) err = db.Limit(limit).Offset(offset).Preload("Supplier").Order("updated_at desc").Find(&purchaseList).Error } @@ -173,7 +175,7 @@ //@param: id uint //@return: err error -func (slf *PurchaseService) Submit(id int, status purchase.OrderStatus) (err error) { +func (slf *PurchaseService) Submit(id int, status purchase.OrderStatus, warehouse string) (err error) { //purchaseData, err := slf.GetPurchase(id) //if err != nil { @@ -189,7 +191,12 @@ // targetStatus = purchase.OrderStatusCompleted //} err = global.GVA_DB.Transaction(func(tx *gorm.DB) error { - err = tx.Where("id = ?", id).Model(&purchase.Purchase{}).Updates(map[string]interface{}{"status": status}).Error + m := make(map[string]interface{}) + m["status"] = status + if warehouse != "" { + m["warehouse"] = warehouse + } + err = tx.Where("id = ?", id).Model(&purchase.Purchase{}).Updates(m).Error if err != nil { return err } @@ -290,3 +297,9 @@ err = db.Order("pin desc, sort desc, id asc").Find(&list).Error return list, err } + +func (slf *PurchaseService) MaxAutoIncr() (int, error) { + var total int64 + err := global.GVA_DB.Model(&purchase.Purchase{}).Count(&total).Error + return int(total), err +} -- Gitblit v1.8.0