| | |
| | | QuotationSearch struct { |
| | | Quotation |
| | | |
| | | Orm *gorm.DB |
| | | Keyword string |
| | | OrderBy string |
| | | PageNum int |
| | | PageSize int |
| | | Orm *gorm.DB |
| | | SearchMap map[string]interface{} |
| | | OrderBy string |
| | | PageNum int |
| | | PageSize int |
| | | } |
| | | ) |
| | | |
| | |
| | | |
| | | func (slf *QuotationSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&Quotation{}) |
| | | if slf.Keyword != "" { |
| | | db = db.Where("name LIKE ?", "%"+slf.Keyword+"%") |
| | | } |
| | | if slf.Id != 0 { |
| | | db = db.Where("id = ?", slf.Id) |
| | | } |
| | | |
| | | if len(slf.SearchMap) > 0 { |
| | | for key, value := range slf.SearchMap { |
| | | switch v := value.(type) { |
| | | case string: |
| | | if key == "validity_date" { |
| | | db = db.Where(key+" = ?", v) |
| | | } |
| | | case int: |
| | | if key == "client_id" || key == "sale_chance_id" { |
| | | db = db.Where(key+" = ?", v) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | return db |
| | |
| | | return db.Updates(data).Error |
| | | } |
| | | |
| | | func (slf *QuotationSearch) SetKeyword(keyword string) *QuotationSearch { |
| | | slf.Keyword = keyword |
| | | return slf |
| | | } |
| | | |
| | | func (slf *QuotationSearch) SetPage(page, size int) *QuotationSearch { |
| | | slf.PageNum, slf.PageSize = page, size |
| | | return slf |
| | |
| | | slf.OrderBy = order |
| | | return slf |
| | | } |
| | | |
| | | func (slf *QuotationSearch) SetSearchMap(searchMap map[string]interface{}) *QuotationSearch { |
| | | slf.SearchMap = searchMap |
| | | return slf |
| | | } |