From 45a526194b33ddb4c7e668d7582e7481d0ca1fca Mon Sep 17 00:00:00 2001 From: wangpengfei <274878379@qq.com> Date: 星期四, 27 七月 2023 10:09:25 +0800 Subject: [PATCH] fix --- model/client.go | 13 ++++++++----- 1 files changed, 8 insertions(+), 5 deletions(-) diff --git a/model/client.go b/model/client.go index 3df4638..2dc0889 100644 --- a/model/client.go +++ b/model/client.go @@ -35,12 +35,11 @@ ClientSearch struct { Client - Orm *gorm.DB + Orm *gorm.DB Keyword string OrderBy string PageNum int PageSize int - } ) @@ -110,15 +109,19 @@ return record, err } -func (slf *ClientSearch) Find() ([]*Client, error) { +func (slf *ClientSearch) Find() ([]*Client, int64, error) { var db = slf.build() var records = make([]*Client, 0) if slf.PageNum > 0 && slf.PageSize > 0 { db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize) } + var total int64 + if err := db.Count(&total).Error; err != nil { + return records, total, err + } err := db.Preload("ClientStatus").Preload("ClientType").Preload("ClientOrigin").Preload("ClientLevel").Preload("FollowRecord").Preload("EnterpriseNature").Preload("RegisteredCapital").Preload("Industry").Preload("EnterpriseScale").Preload("Contacts").Preload("Country").Preload("Province").Preload("City").Preload("Region").Find(&records).Error - return records, err + return records, total, err } func (slf *ClientSearch) UpdateByMap(data map[string]interface{}) error { @@ -139,4 +142,4 @@ func (slf *ClientSearch) SetOrder(order string) *ClientSearch { slf.OrderBy = order return slf -} \ No newline at end of file +} -- Gitblit v1.8.0