| | |
| | | import ( |
| | | "aps_crm/pkg/mysqlx" |
| | | "gorm.io/gorm" |
| | | "time" |
| | | ) |
| | | |
| | | type ( |
| | |
| | | Budget float64 `json:"budget" gorm:"column:budget;type:decimal(10,2);comment:预算"` |
| | | ProjectedAmount float64 `json:"projected_amount" gorm:"column:projected_amount;type:decimal(10,2);comment:预计金额"` |
| | | Currency int `json:"currency" gorm:"column:currency;type:int(11);comment:币种"` |
| | | ExpectedTime time.Time `json:"expected_time" gorm:"column:expected_time;type:datetime;comment:预计成交时间"` |
| | | ExpectedTime *CustomTime `json:"expected_time" gorm:"column:expected_time;type:datetime;comment:预计成交时间"` |
| | | StatusId int `json:"status_id" gorm:"column:status_id;type:int(11);comment:状态ID"` |
| | | PainPoints string `json:"pain_points" gorm:"column:pain_points;type:text;comment:痛点"` |
| | | WhetherEstablished string `json:"whether_established" gorm:"column:whether_established;type:text;comment:是否成立"` |
| | |
| | | SaleChanceSearch struct { |
| | | SaleChance |
| | | |
| | | 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 *SaleChanceSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&SaleChance{}) |
| | | if slf.Keyword != "" { |
| | | db = db.Where("name LIKE ?", "%"+slf.Keyword+"%") |
| | | } |
| | | if slf.Id > 0 { |
| | | db = db.Where("id = ?", slf.Id) |
| | | } |
| | | if slf.Name != "" { |
| | | db = db.Where("name = ?", slf.Name) |
| | | } |
| | | |
| | | if len(slf.SearchMap) > 0 { |
| | | for key, value := range slf.SearchMap { |
| | | switch v := value.(type) { |
| | | case string: |
| | | if key == "name" || key == "number" { |
| | | db = db.Where(key+" LIKE ?", "%"+v+"%") |
| | | } |
| | | |
| | | if key == "client_name" { |
| | | db = db.Joins("Client").Where("Client.name LIKE ?", "%"+v+"%") |
| | | } |
| | | |
| | | if key == "contact_name" { |
| | | db = db.Joins("Contact").Where("Contact.name LIKE ?", "%"+v+"%") |
| | | } |
| | | |
| | | if key == "member_name" { |
| | | db = db.Joins("User").Where("User.name LIKE ?", "%"+v+"%") |
| | | } |
| | | |
| | | if key == "sale_stage" { |
| | | db = db.Joins("SaleStage").Where("SaleStage.name LIKE ?", "%"+v+"%") |
| | | } |
| | | |
| | | if key == "possibilities" { |
| | | db = db.Joins("Possibilities").Where("Possibilities.name LIKE ?", "%"+v+"%") |
| | | } |
| | | |
| | | if key == "expected_time" { |
| | | db = db.Where("expected_time LIKE ?", "%"+v+"%") |
| | | } |
| | | |
| | | case int: |
| | | case float64: |
| | | if key == "member_id" || key == "budget" || key == "projected_amount" { |
| | | db = db.Where(key+" = ?", v) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | return db |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *SaleChanceSearch) SetKeyword(keyword string) *SaleChanceSearch { |
| | | slf.Keyword = keyword |
| | | return slf |
| | | } |
| | | |
| | | func (slf *SaleChanceSearch) SetPage(page, size int) *SaleChanceSearch { |
| | | slf.PageNum, slf.PageSize = page, size |
| | | return slf |
| | |
| | | slf.OrderBy = order |
| | | return slf |
| | | } |
| | | |
| | | func (slf *SaleChanceSearch) SetSearchMap(searchMap map[string]interface{}) *SaleChanceSearch { |
| | | slf.SearchMap = searchMap |
| | | return slf |
| | | } |