| | |
| | | Quotation Quotation `json:"quotation" gorm:"foreignKey:QuotationId;references:Id"` |
| | | StatusId int `json:"statusId" gorm:"column:status_id;type:int;comment:合同状态"` |
| | | File string `json:"file" gorm:"column:file;type:varchar(255);comment:合同文件"` |
| | | gorm.Model `json:"-"` |
| | | gormModel |
| | | } |
| | | |
| | | ContractSearch struct { |
| | | Contract |
| | | |
| | | 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 *ContractSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&Contract{}) |
| | | 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 == "client_name" { |
| | | db = db.Joins("Client").Where("Client.name LIKE ?", "%"+v+"%") |
| | | } |
| | | |
| | | if key == "member_name" { |
| | | db = db.Joins("User").Where("User.username LIKE ?", "%"+v+"%") |
| | | } |
| | | |
| | | if key == "number" { |
| | | db = db.Where("number LIKE ?", "%"+v+"%") |
| | | } |
| | | |
| | | if key == "created_at" { |
| | | db = db.Where(key+"= ?", v) |
| | | } |
| | | case int: |
| | | } |
| | | } |
| | | } |
| | | |
| | | return db |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ContractSearch) SetKeyword(keyword string) *ContractSearch { |
| | | slf.Keyword = keyword |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ContractSearch) SetPage(page, size int) *ContractSearch { |
| | | slf.PageNum, slf.PageSize = page, size |
| | | return slf |
| | |
| | | func (slf *ContractSearch) SetOrder(order string) *ContractSearch { |
| | | slf.OrderBy = order |
| | | return slf |
| | | } |
| | | } |
| | | |
| | | func (slf *ContractSearch) SetSearchMap(data map[string]interface{}) *ContractSearch { |
| | | slf.SearchMap = data |
| | | return slf |
| | | } |