fix
wangpengfei
2023-08-09 c229f8922a4142a8ae2ac161bb6c121b9c9de672
fix

add multi-criteria query to salesLeads
7个文件已修改
68 ■■■■■ 已修改文件
api/v1/contact.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/contact.go 36 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/request/contact.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/contact.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/contact.go
@@ -159,7 +159,7 @@
        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
docs/docs.go
@@ -13673,9 +13673,6 @@
        "request.GetContactList": {
            "type": "object",
            "properties": {
                "keyword": {
                    "type": "string"
                },
                "page": {
                    "description": "页码",
                    "type": "integer"
@@ -13683,6 +13680,11 @@
                "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
                }
            }
        },
docs/swagger.json
@@ -13661,9 +13661,6 @@
        "request.GetContactList": {
            "type": "object",
            "properties": {
                "keyword": {
                    "type": "string"
                },
                "page": {
                    "description": "页码",
                    "type": "integer"
@@ -13671,6 +13668,11 @@
                "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
                }
            }
        },
docs/swagger.yaml
@@ -2842,14 +2842,18 @@
    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:
model/contact.go
@@ -28,7 +28,7 @@
        Contact
        Orm      *gorm.DB
        Keyword  string
        SearchMap map[string]interface{}
        OrderBy  string
        PageNum  int
        PageSize int
@@ -56,9 +56,6 @@
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)
    }
@@ -68,6 +65,26 @@
    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
@@ -123,7 +140,6 @@
        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
}
@@ -155,11 +171,6 @@
    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
@@ -173,3 +184,8 @@
    slf.Orm = slf.Orm.Where("id in (?)", ids)
    return slf
}
func (slf *ContactSearch) SetSearchMap(data map[string]interface{}) *ContactSearch {
    slf.SearchMap = data
    return slf
}
model/request/contact.go
@@ -29,7 +29,7 @@
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 {
service/contact.go
@@ -102,9 +102,9 @@
    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
    }