diff --git a/model/common.go b/model/common.go index 00e32d3..703f692 100644 --- a/model/common.go +++ b/model/common.go @@ -31,7 +31,7 @@ type Page struct { IsDescending bool `json:"is_descending"` // false:ascending;true:descending } -func FormatPage(db *gorm.DB, page *Page) { +func FormatPage(db *gorm.DB, page *Page) *gorm.DB { if page.PageNum <= 0 { page.PageNum = 1 } @@ -47,4 +47,5 @@ func FormatPage(db *gorm.DB, page *Page) { db = db.Order(page.OrderBy) } } + return db } diff --git a/model/roles.go b/model/roles.go index 4172662..9a12ec0 100644 --- a/model/roles.go +++ b/model/roles.go @@ -65,7 +65,7 @@ func (dao *Role) List(db *gorm.DB, where map[string]interface{}, page *Page, key db = db.Where("name like ? or description like ?", "%"+keywords+"%", "%"+keywords+"%") } if page != nil { - FormatPage(db, page) + db = FormatPage(db, page) } err = db.Find(&roles).Count(&total).Error return @@ -76,8 +76,8 @@ func (dao *Role) Update(db *gorm.DB, where map[string]interface{}, updates map[s return result.RowsAffected, result.Error } -func (dao *Role) Delete(db *gorm.DB) (affected int64, err error) { - result := db.Delete(dao) +func (dao *Role) Delete(db *gorm.DB, where map[string]interface{}) (affected int64, err error) { + result := db.Delete(dao, where) return result.RowsAffected, result.Error } diff --git a/model/tenant.go b/model/tenant.go index 8bcc1fc..001ec7a 100644 --- a/model/tenant.go +++ b/model/tenant.go @@ -50,7 +50,7 @@ func (o *Tenant) List(db *gorm.DB, where map[string]interface{}, page *Page, key db = db.Where("concat (id, title, remark) like ?", "%"+keywords+"%") } if page != nil { - FormatPage(db, page) + db = FormatPage(db, page) } err = db.Find(&tenants).Count(&total).Error return diff --git a/model/user.go b/model/user.go index 545d452..9efcf70 100644 --- a/model/user.go +++ b/model/user.go @@ -121,7 +121,7 @@ func (u *User) QueryByCondition(db *gorm.DB, condition map[string]interface{}, p } db = db.Where(condition).Count(&total) if page != nil { - FormatPage(db, page) + db = FormatPage(db, page) } err = db.Find(&users).Error if errors.Is(err, gorm.ErrRecordNotFound) {