fix
add multi-criteria query to salesLeads
| | |
| | | return
|
| | | }
|
| | |
|
| | | contacts, total, errCode := contactService.GetContactList(params.Page, params.PageSize, params.Keyword)
|
| | | contacts, total, errCode := contactService.GetContactList(params.Page, params.PageSize, params.SearchMap) |
| | | if errCode != ecode.OK {
|
| | | ctx.Fail(errCode)
|
| | | return
|
| | |
| | | "request.GetContactList": { |
| | | "type": "object", |
| | | "properties": { |
| | | "keyword": { |
| | | "type": "string" |
| | | }, |
| | | "page": { |
| | | "description": "页码", |
| | | "type": "integer" |
| | |
| | | "pageSize": { |
| | | "description": "每页大小", |
| | | "type": "integer" |
| | | }, |
| | | "search_map": { |
| | | "description": "搜索条件: map[string]interface{}{\"name\": \"xxx\"}; {\"name\": \"客户名称\", \"phone\": \"手机号码\", \"detail_address\":\"详细地址\", \"next_visit_time\":\"下回回访日期\", \"member_name\": \"销售负责人\", \"client_status\": \"客户状态\", \"client_level\": \"重要级别\"}", |
| | | "type": "object", |
| | | "additionalProperties": true |
| | | } |
| | | } |
| | | }, |
| | |
| | | "request.GetContactList": { |
| | | "type": "object", |
| | | "properties": { |
| | | "keyword": { |
| | | "type": "string" |
| | | }, |
| | | "page": { |
| | | "description": "页码", |
| | | "type": "integer" |
| | |
| | | "pageSize": { |
| | | "description": "每页大小", |
| | | "type": "integer" |
| | | }, |
| | | "search_map": { |
| | | "description": "搜索条件: map[string]interface{}{\"name\": \"xxx\"}; {\"name\": \"客户名称\", \"phone\": \"手机号码\", \"detail_address\":\"详细地址\", \"next_visit_time\":\"下回回访日期\", \"member_name\": \"销售负责人\", \"client_status\": \"客户状态\", \"client_level\": \"重要级别\"}", |
| | | "type": "object", |
| | | "additionalProperties": true |
| | | } |
| | | } |
| | | }, |
| | |
| | | type: object |
| | | request.GetContactList: |
| | | properties: |
| | | keyword: |
| | | type: string |
| | | page: |
| | | description: 页码 |
| | | type: integer |
| | | pageSize: |
| | | description: 每页大小 |
| | | type: integer |
| | | search_map: |
| | | additionalProperties: true |
| | | description: '搜索条件: map[string]interface{}{"name": "xxx"}; {"name": "客户名称", |
| | | "phone": "手机号码", "detail_address":"详细地址", "next_visit_time":"下回回访日期", "member_name": |
| | | "销售负责人", "client_status": "客户状态", "client_level": "重要级别"}' |
| | | type: object |
| | | type: object |
| | | request.GetContractList: |
| | | properties: |
| | |
| | | Contact
|
| | |
|
| | | Orm *gorm.DB
|
| | | Keyword string
|
| | | SearchMap map[string]interface{} |
| | | OrderBy string
|
| | | PageNum int
|
| | | PageSize int
|
| | |
| | |
|
| | | func (slf *ContactSearch) build() *gorm.DB {
|
| | | var db = slf.Orm.Model(&Contact{})
|
| | | if slf.Keyword != "" {
|
| | | db = db.Where("name LIKE ?", "%"+slf.Keyword+"%")
|
| | | }
|
| | | if slf.Id != 0 {
|
| | | db = db.Where("id = ?", slf.Id)
|
| | | }
|
| | |
| | |
|
| | | if slf.ClientId != 0 {
|
| | | db = db.Where("client_id = ?", slf.ClientId)
|
| | | } |
| | | |
| | | if len(slf.SearchMap) > 0 { |
| | | for key, value := range slf.SearchMap { |
| | | switch v := value.(type) { |
| | | case string: |
| | | if key == "name" || key == "position" || key == "phone" || key == "Number" { |
| | | db = db.Where(key+" LIKE ?", "%"+v+"%") |
| | | } |
| | | |
| | | if key == "member_name" { |
| | | db = db.Joins("Member").Where("Member.username LIKE ?", "%"+v+"%") |
| | | } |
| | | |
| | | if key == "client_name" { |
| | | db = db.Joins("inner join clients on clients.id = contacts.client_id").Where("clients.name LIKE ?", "%"+v+"%") |
| | | } |
| | | case int: |
| | | } |
| | | } |
| | | }
|
| | |
|
| | | return db
|
| | |
| | | db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize)
|
| | | }
|
| | |
|
| | |
|
| | | err := db.Preload("FollowRecord").Preload("Client").Preload("Country").Preload("Province").Preload("City").Preload("Region").Find(&records).Error
|
| | | return records, total, err
|
| | | }
|
| | |
| | | return db.Updates(data).Error
|
| | | }
|
| | |
|
| | | func (slf *ContactSearch) SetKeyword(keyword string) *ContactSearch {
|
| | | slf.Keyword = keyword
|
| | | return slf
|
| | | }
|
| | |
|
| | | func (slf *ContactSearch) SetPage(page, size int) *ContactSearch {
|
| | | slf.PageNum, slf.PageSize = page, size
|
| | | return slf
|
| | |
| | | slf.Orm = slf.Orm.Where("id in (?)", ids)
|
| | | return slf
|
| | | }
|
| | | |
| | | func (slf *ContactSearch) SetSearchMap(data map[string]interface{}) *ContactSearch { |
| | | slf.SearchMap = data |
| | | return slf |
| | | } |
| | |
| | |
|
| | | type GetContactList struct {
|
| | | PageInfo
|
| | | Keyword string `json:"keyword"`
|
| | | SearchMap map[string]interface{} `json:"search_map"` // 搜索条件: map[string]interface{}{"name": "xxx"}; {"name": "客户名称", "phone": "手机号码", "detail_address":"详细地址", "next_visit_time":"下回回访日期", "member_name": "销售负责人", "client_status": "客户状态", "client_level": "重要级别"} |
| | | }
|
| | |
|
| | | type DeleteContact struct {
|
| | |
| | | return ecode.OK
|
| | | }
|
| | |
|
| | | func (ContactService) GetContactList(page, pageSize int, keyword string) ([]*model.ContactDetail, int64, int) {
|
| | | func (ContactService) GetContactList(page, pageSize int, data map[string]interface{}) ([]*model.ContactDetail, int64, int) { |
| | | // get contact list
|
| | | contacts, total, err := model.NewContactSearch(nil).SetKeyword(keyword).SetPage(page, pageSize).FindAll()
|
| | | contacts, total, err := model.NewContactSearch(nil).SetPage(page, pageSize).SetSearchMap(data).FindAll() |
| | | if err != nil {
|
| | | return nil, 0, ecode.ContactListErr
|
| | | }
|