| | |
| | | ClientSearch struct { |
| | | Client |
| | | |
| | | Orm *gorm.DB |
| | | Orm *gorm.DB |
| | | Keyword string |
| | | OrderBy string |
| | | PageNum int |
| | | PageSize int |
| | | |
| | | } |
| | | ) |
| | | |
| | |
| | | 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 { |
| | |
| | | func (slf *ClientSearch) SetOrder(order string) *ClientSearch { |
| | | slf.OrderBy = order |
| | | return slf |
| | | } |
| | | } |