From b4400a06b5f801bc7a85320680d0b6c45c547ff0 Mon Sep 17 00:00:00 2001 From: wangpengfei <274878379@qq.com> Date: 星期五, 28 七月 2023 10:21:33 +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..8c694d8 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) + var total int64 + if err := db.Count(&total).Error; err != nil { + return records, total, err + } if slf.PageNum > 0 && slf.PageSize > 0 { db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize) } 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