| | |
| | | ContactPhone string `json:"contact_phone" gorm:"column:contact_phone;type:varchar(255);comment:联系人电话"` |
| | | ContactPosition string `json:"contact_position" gorm:"column:contact_position;type:varchar(255);comment:联系人职位"` |
| | | SalesSourcesId int `json:"sales_sources_id" gorm:"column:sales_sources_id;type:int(11);comment:商机来源ID"` |
| | | SalesSources SalesSources `json:"-" gorm:"foreignKey:SalesSourcesId"` |
| | | MemberId int `json:"member_id" gorm:"column:member_id;type:int(11);comment:销售负责人ID"` |
| | | Member User `json:"-" gorm:"foreignKey:MemberId"` |
| | | SalesStatus constvar.SalesStatus `json:"sales_status" gorm:"column:sales_status;type:int(11);comment:销售状态"` |
| | | Desc string `json:"desc" gorm:"column:desc;type:varchar(255);comment:备注"` |
| | | Reason string `json:"reason" gorm:"column:reason;type:text;comment:失败原因"` |
| | |
| | | SalesLeadsSearch struct { |
| | | SalesLeads |
| | | |
| | | 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 *SalesLeadsSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&SalesLeads{}) |
| | | if slf.Keyword != "" { |
| | | db = db.Where("name LIKE ?", "%"+slf.Keyword+"%") |
| | | } |
| | | if slf.Keyword != "" { |
| | | db = db.Where("name LIKE ?", "%"+slf.Keyword+"%") |
| | | } |
| | | if slf.Id != 0 { |
| | | db = db.Where("id = ?", slf.Id) |
| | | } |
| | |
| | | db = db.Where("name = ?", slf.Name) |
| | | } |
| | | |
| | | if slf.Number != "" { |
| | | db = db.Where("number = ?", slf.Number) |
| | | } |
| | | if len(slf.SearchMap) > 0 { |
| | | for key, value := range slf.SearchMap { |
| | | switch v := value.(type) { |
| | | case string: |
| | | if key == "number" || key == "contact_name" || key == "contact_phone" || key == "name" { |
| | | db = db.Where(key+" LIKE ?", "%"+v+"%") |
| | | } |
| | | |
| | | if slf.ContactName != "" { |
| | | db = db.Where("contact_name = ?", slf.ContactName) |
| | | } |
| | | if key == "city" { |
| | | db = db.Joins("City").Where("City.name LIKE ?", "%"+v+"%") |
| | | } |
| | | |
| | | if slf.ContactPhone != "" { |
| | | db = db.Where("contact_phone = ?", slf.ContactPhone) |
| | | } |
| | | if key == "province" { |
| | | db = db.Joins("Province").Where("Province.name LIKE ?", "%"+v+"%") |
| | | } |
| | | |
| | | if slf.ContactPosition != "" { |
| | | db = db.Where("contact_position = ?", slf.ContactPosition) |
| | | } |
| | | if key == "sales_sources" { |
| | | db = db.Joins("SalesSources").Where("SalesSources.name LIKE ?", "%"+v+"%") |
| | | } |
| | | |
| | | if slf.SalesSourcesId != 0 { |
| | | db = db.Where("sales_sources_id = ?", slf.SalesSourcesId) |
| | | } |
| | | if key == "member_name" { |
| | | db = db.Joins("Member").Where("Member.username LIKE ?", "%"+v+"%") |
| | | } |
| | | |
| | | if slf.MemberId != 0 { |
| | | db = db.Where("member_id = ?", slf.MemberId) |
| | | case int: |
| | | if key == "member_id" { |
| | | db = db.Where("member_id = ?", v) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | return db |
| | |
| | | return |
| | | } |
| | | |
| | | func (slf *SalesLeadsSearch) SetKeyword(keyword string) *SalesLeadsSearch { |
| | | slf.Keyword = keyword |
| | | return slf |
| | | } |
| | | |
| | | func (slf *SalesLeadsSearch) SetPage(page, size int) *SalesLeadsSearch { |
| | | slf.PageNum, slf.PageSize = page, size |
| | | return slf |
| | |
| | | slf.Orm = slf.Orm.Where("id in (?)", ids) |
| | | return slf |
| | | } |
| | | |
| | | func (slf *SalesLeadsSearch) SetSearchMap(data map[string]interface{}) *SalesLeadsSearch { |
| | | slf.SearchMap = data |
| | | return slf |
| | | } |