| | |
| | | OrderManageSearch struct { |
| | | OrderManage |
| | | |
| | | Orm *gorm.DB |
| | | Orm *gorm.DB |
| | | Keyword string |
| | | OrderBy string |
| | | PageNum int |
| | | PageSize int |
| | | |
| | | } |
| | | ) |
| | | |
| | |
| | | return record, err |
| | | } |
| | | |
| | | func (slf *OrderManageSearch) FindAll() ([]*OrderManage, error) { |
| | | func (slf *OrderManageSearch) FindAll() ([]*OrderManage, int64, error) { |
| | | var db = slf.build() |
| | | var record = make([]*OrderManage, 0) |
| | | err := db.Preload("Client").Find(&record).Error |
| | | return record, err |
| | | var records = make([]*OrderManage, 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("Client").Order("id desc").Find(&records).Error |
| | | return records, total, err |
| | | } |
| | | |
| | | func (slf *OrderManageSearch) SetId(id int) *OrderManageSearch { |
| | |
| | | func (slf *OrderManageSearch) SetOrder(order string) *OrderManageSearch { |
| | | slf.OrderBy = order |
| | | return slf |
| | | } |
| | | } |
| | | func (slf *OrderManageSearch) SetIds(ids []int) *OrderManageSearch { |
| | | slf.Orm = slf.Orm.Where("id in (?)", ids) |
| | | return slf |
| | | } |