| | |
| | | slf.Ids = ids |
| | | return slf |
| | | } |
| | | |
| | | func (slf *OperationSearch) SetStatus(status constvar.OperationStatus) *OperationSearch { |
| | | slf.Status = status |
| | | return slf |
| | | } |
| | | |
| | | func (slf *OperationSearch) SetBaseOperationType(baseOperationType constvar.BaseOperationType) *OperationSearch { |
| | | slf.BaseOperationType = baseOperationType |
| | | return slf |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | if slf.Keyword != "" { |
| | | db = db.Where("product_name like ?", fmt.Sprintf("%%%v%%", slf.Keyword)) |
| | | db = db.Where("number like ? or source_number like ?", fmt.Sprintf("%%%v%%", slf.Keyword), fmt.Sprintf("%%%v%%", slf.Keyword)) |
| | | } |
| | | |
| | | if slf.SourceNumber != "" { |
| | |
| | | |
| | | if slf.Status > 0 { |
| | | db = db.Where("status = ?", slf.Status) |
| | | } |
| | | |
| | | if slf.BaseOperationType != 0 { |
| | | db = db.Where("base_operation_type = ?", slf.BaseOperationType) |
| | | } |
| | | |
| | | return db |
| | |
| | | if slf.PageNum*slf.PageSize > 0 { |
| | | db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) |
| | | } |
| | | if err := db.Preload("FromLocation").Preload("ToLocation").Find(&records).Error; err != nil { |
| | | if err := db.Preload("FromLocation").Preload("ToLocation").Order("created_at desc").Find(&records).Error; err != nil { |
| | | return records, total, fmt.Errorf("find records err: %v", err) |
| | | } |
| | | |