fix
add multi-criteria query to salesLeads
| | |
| | | return |
| | | } |
| | | |
| | | salesLeadss, total, errCode := salesLeadsService.GetSalesLeadsList(params.Page, params.PageSize, params.Keyword) |
| | | salesLeadss, total, errCode := salesLeadsService.GetSalesLeadsList(params.Page, params.PageSize, params.SearchMap) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | |
| | | "type": "integer" |
| | | }, |
| | | "search_map": { |
| | | "description": "搜索条件: map[string]interface{}{\"name\": \"xxx\"}; \"not_contact\": 超过15天未联系; \"public_sea\": 公海客户", |
| | | "description": "搜索条件: map[string]interface{}{\"name\": \"xxx\"}; \"name\": 客户名称; \"number\": 公海客户", |
| | | "type": "object", |
| | | "additionalProperties": true |
| | | } |
| | |
| | | "request.GetSalesLeadsList": { |
| | | "type": "object", |
| | | "properties": { |
| | | "keyword": { |
| | | "type": "string" |
| | | }, |
| | | "page": { |
| | | "description": "页码", |
| | | "type": "integer" |
| | |
| | | "pageSize": { |
| | | "description": "每页大小", |
| | | "type": "integer" |
| | | }, |
| | | "search_map": { |
| | | "description": "搜索条件: map[string]interface{}{\"name\": \"xxx\"} {\"client_name\": \"客户名称\", \"number\": \"销售线索编号\", \"contact_name\": \"联系人姓名\", \"phone\": \"手机号码\", \"sales_resources\": \"商机来源\", \"city\": \"城市\", \"province\": \"省份\", \"member_name\": \"负责人\"}", |
| | | "type": "object", |
| | | "additionalProperties": true |
| | | } |
| | | } |
| | | }, |
| | |
| | | "type": "integer" |
| | | }, |
| | | "search_map": { |
| | | "description": "搜索条件: map[string]interface{}{\"name\": \"xxx\"}; \"not_contact\": 超过15天未联系; \"public_sea\": 公海客户", |
| | | "description": "搜索条件: map[string]interface{}{\"name\": \"xxx\"}; \"name\": 客户名称; \"number\": 公海客户", |
| | | "type": "object", |
| | | "additionalProperties": true |
| | | } |
| | |
| | | "request.GetSalesLeadsList": { |
| | | "type": "object", |
| | | "properties": { |
| | | "keyword": { |
| | | "type": "string" |
| | | }, |
| | | "page": { |
| | | "description": "页码", |
| | | "type": "integer" |
| | |
| | | "pageSize": { |
| | | "description": "每页大小", |
| | | "type": "integer" |
| | | }, |
| | | "search_map": { |
| | | "description": "搜索条件: map[string]interface{}{\"name\": \"xxx\"} {\"client_name\": \"客户名称\", \"number\": \"销售线索编号\", \"contact_name\": \"联系人姓名\", \"phone\": \"手机号码\", \"sales_resources\": \"商机来源\", \"city\": \"城市\", \"province\": \"省份\", \"member_name\": \"负责人\"}", |
| | | "type": "object", |
| | | "additionalProperties": true |
| | | } |
| | | } |
| | | }, |
| | |
| | | type: integer |
| | | search_map: |
| | | additionalProperties: true |
| | | description: '搜索条件: map[string]interface{}{"name": "xxx"}; "not_contact": |
| | | 超过15天未联系; "public_sea": 公海客户' |
| | | description: '搜索条件: map[string]interface{}{"name": "xxx"}; "name": 客户名称; "number": |
| | | 公海客户' |
| | | type: object |
| | | type: object |
| | | request.GetContactList: |
| | |
| | | type: object |
| | | request.GetSalesLeadsList: |
| | | properties: |
| | | keyword: |
| | | type: string |
| | | page: |
| | | description: 页码 |
| | | type: integer |
| | | pageSize: |
| | | description: 每页大小 |
| | | type: integer |
| | | search_map: |
| | | additionalProperties: true |
| | | description: '搜索条件: map[string]interface{}{"name": "xxx"} {"client_name": |
| | | "客户名称", "number": "销售线索编号", "contact_name": "联系人姓名", "phone": "手机号码", "sales_resources": |
| | | "商机来源", "city": "城市", "province": "省份", "member_name": "负责人"}' |
| | | type: object |
| | | type: object |
| | | request.GetSalesRefundList: |
| | | properties: |
| | |
| | | |
| | | type GetClientList struct { |
| | | PageInfo |
| | | SearchMap map[string]interface{} `json:"search_map"` // 搜索条件: map[string]interface{}{"name": "xxx"}; "not_contact": 超过15天未联系; "public_sea": 公海客户 |
| | | SearchMap map[string]interface{} `json:"search_map"` // 搜索条件: map[string]interface{}{"name": "xxx"}; "name": 客户名称; "number": 公海客户 |
| | | } |
| | | |
| | | type DeleteClient struct { |
| | |
| | | |
| | | type GetSalesLeadsList struct { |
| | | PageInfo |
| | | Keyword string `json:"keyword"` |
| | | SearchMap map[string]interface{} `json:"search_map"` // 搜索条件: map[string]interface{}{"name": "xxx"} {"name": "客户名称", "number": "销售线索编号", "contact_name": "联系人姓名", "phone": "手机号码", "sales_resources": "商机来源", "city": "城市", "province": "省份", "member_name": "负责人"} |
| | | } |
| | | |
| | | type DeleteSalesLeads struct { |
| | |
| | | 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 |
| | | } |
| | |
| | | return ecode.OK |
| | | } |
| | | |
| | | func (SalesLeadsService) GetSalesLeadsList(page, pageSize int, keyword string) ([]*model.SalesLeads, int64, int) { |
| | | func (SalesLeadsService) GetSalesLeadsList(page, pageSize int, data map[string]interface{}) ([]*model.SalesLeads, int64, int) { |
| | | // get contact list |
| | | contacts, total, err := model.NewSalesLeadsSearch(nil).SetKeyword(keyword).SetPage(page, pageSize).FindAll() |
| | | contacts, total, err := model.NewSalesLeadsSearch(nil).SetPage(page, pageSize).SetSearchMap(data).FindAll() |
| | | if err != nil { |
| | | return nil, 0, ecode.SalesLeadsListErr |
| | | } |