From 530fed8ec225453572d57b15c200ab062c335457 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期三, 01 十一月 2023 19:20:21 +0800 Subject: [PATCH] 公海member_id使用0 --- model/masterOrder.go | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 43 insertions(+), 2 deletions(-) diff --git a/model/masterOrder.go b/model/masterOrder.go index dd7e52b..3b77851 100644 --- a/model/masterOrder.go +++ b/model/masterOrder.go @@ -2,6 +2,7 @@ import ( "aps_crm/pkg/mysqlx" + "fmt" "gorm.io/gorm" ) @@ -48,6 +49,9 @@ if slf.Id != 0 { db = db.Where("id = ?", slf.Id) } + if slf.Number != "" { + db = db.Where("number = ?", slf.Number) + } if len(slf.SearchMap) > 0 { for key, value := range slf.SearchMap { @@ -64,10 +68,13 @@ if key == "member_name" { db = db.Joins("Member").Where("Member.username = ?", v) } - case int: - case float64: + case int, float64: if key == "client_id" || key == "member_id" || key == "money" { db = db.Where(key+" = ?", v) + } + case []int: + if key == "member_ids" { + db = db.Where("master_order.member_id in ?", v) } } } @@ -113,6 +120,30 @@ return records, total, err } +func (slf *MasterOrderSearch) Count() (int64, error) { + var db = slf.build() + var total int64 + err := db.Count(&total).Error + return total, err +} + +func (slf *MasterOrderSearch) MaxAutoIncr() (int, error) { + type Result struct { + Max int + } + + var ( + result Result + db = slf.build() + ) + + err := db.Select("MAX(id) as max").Scan(&result).Error + if err != nil { + return result.Max, fmt.Errorf("max err: %v", err) + } + return result.Max, nil +} + func (slf *MasterOrderSearch) SetId(id int) *MasterOrderSearch { slf.Id = id return slf @@ -136,3 +167,13 @@ slf.Orm = slf.Orm.Where("id in (?)", ids) return slf } + +func (slf *MasterOrderSearch) SetNumber(number string) *MasterOrderSearch { + slf.Number = number + return slf +} + +func (slf *MasterOrderSearch) UpdateByMap(data map[string]interface{}) error { + var db = slf.build() + return db.Updates(data).Error +} -- Gitblit v1.8.0