fix
wangpengfei
2023-08-10 f26d6d27c5f756c88a2a44f2cf0125f277ff177e
fix

add multi-criteria query to followRecord
11个文件已修改
169 ■■■■■ 已修改文件
api/v1/followRecord.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
constvar/const.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/contact.go 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/followRecord.go 75 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/request/contact.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/request/followRecord.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/followRecord.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/salesLeads.go 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/followRecord.go
@@ -210,7 +210,7 @@
        return
    }
    followRecords, total, errCode := followRecordService.GetFollowRecordList(params.Page, params.PageSize, params.Keyword)
    followRecords, total, errCode := followRecordService.GetFollowRecordList(params.Page, params.PageSize, params.SearchMap)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
constvar/const.go
@@ -37,7 +37,6 @@
const (
    SalesStatusNew                           SalesStatus = iota // 新建
    SalesStatusIng                                              // 进行中
    SalesStatusSuccess                                          // 成功
    SalesStatusLevelUptoClient                                  // 升级为客户
    SalesStatusLevelUptoClientAndSalesChance                    // 升级为客户并且有销售机会
    SalesStatusFail                          SalesStatus = -1   // 失败
docs/docs.go
@@ -9663,7 +9663,6 @@
                1,
                2,
                3,
                4,
                -1
            ],
            "x-enum-comments": {
@@ -9671,13 +9670,11 @@
                "SalesStatusIng": "进行中",
                "SalesStatusLevelUptoClient": "升级为客户",
                "SalesStatusLevelUptoClientAndSalesChance": "升级为客户并且有销售机会",
                "SalesStatusNew": "新建",
                "SalesStatusSuccess": "成功"
                "SalesStatusNew": "新建"
            },
            "x-enum-varnames": [
                "SalesStatusNew",
                "SalesStatusIng",
                "SalesStatusSuccess",
                "SalesStatusLevelUptoClient",
                "SalesStatusLevelUptoClientAndSalesChance",
                "SalesStatusFail"
@@ -10369,6 +10366,9 @@
                },
                "id": {
                    "type": "integer"
                },
                "member": {
                    "$ref": "#/definitions/model.User"
                },
                "member_id": {
                    "type": "integer"
@@ -13682,7 +13682,7 @@
                    "type": "integer"
                },
                "search_map": {
                    "description": "搜索条件: map[string]interface{}{\"name\": \"xxx\"}; {\"name\": \"客户名称\", \"phone\": \"手机号码\", \"detail_address\":\"详细地址\", \"next_visit_time\":\"下回回访日期\", \"member_name\": \"销售负责人\", \"client_status\": \"客户状态\", \"client_level\": \"重要级别\"}",
                    "description": "搜索条件: map[string]interface{}{\"name\": \"xxx\"}; {\"name\": \"客户名称\", \"phone\": \"手机号码\", \"detail_address\":\"详细地址\", \"next_visit_time\":\"下回回访日期\", \"member_name\": \"销售负责人\", \"client_status\": \"客户状态\", \"client_level\": \"重要级别\", \"is_first\": \"是否是首要联系人\"}",
                    "type": "object",
                    "additionalProperties": true
                }
@@ -13729,9 +13729,6 @@
        "request.GetFollowRecordList": {
            "type": "object",
            "properties": {
                "keyword": {
                    "type": "string"
                },
                "page": {
                    "description": "页码",
                    "type": "integer"
@@ -13739,6 +13736,11 @@
                "pageSize": {
                    "description": "每页大小",
                    "type": "integer"
                },
                "search_map": {
                    "description": "搜索条件: map[string]interface{}{\"name\": \"xxx\"}; {\"topic\": \"跟进主题\", \"member_name\": \"跟进人\", \"client_name\": \"客户名称\", \"client_status\": \"客户状态\", \"follow_time\": \"跟进时间\", \"next_follow_time\": \"下次跟进时间\", \"record\": \"跟进记录\", \"phone\": \"联系人电话\", \"contact_name\": \"联系人姓名\"}",
                    "type": "object",
                    "additionalProperties": true
                }
            }
        },
docs/swagger.json
@@ -9651,7 +9651,6 @@
                1,
                2,
                3,
                4,
                -1
            ],
            "x-enum-comments": {
@@ -9659,13 +9658,11 @@
                "SalesStatusIng": "进行中",
                "SalesStatusLevelUptoClient": "升级为客户",
                "SalesStatusLevelUptoClientAndSalesChance": "升级为客户并且有销售机会",
                "SalesStatusNew": "新建",
                "SalesStatusSuccess": "成功"
                "SalesStatusNew": "新建"
            },
            "x-enum-varnames": [
                "SalesStatusNew",
                "SalesStatusIng",
                "SalesStatusSuccess",
                "SalesStatusLevelUptoClient",
                "SalesStatusLevelUptoClientAndSalesChance",
                "SalesStatusFail"
@@ -10357,6 +10354,9 @@
                },
                "id": {
                    "type": "integer"
                },
                "member": {
                    "$ref": "#/definitions/model.User"
                },
                "member_id": {
                    "type": "integer"
@@ -13670,7 +13670,7 @@
                    "type": "integer"
                },
                "search_map": {
                    "description": "搜索条件: map[string]interface{}{\"name\": \"xxx\"}; {\"name\": \"客户名称\", \"phone\": \"手机号码\", \"detail_address\":\"详细地址\", \"next_visit_time\":\"下回回访日期\", \"member_name\": \"销售负责人\", \"client_status\": \"客户状态\", \"client_level\": \"重要级别\"}",
                    "description": "搜索条件: map[string]interface{}{\"name\": \"xxx\"}; {\"name\": \"客户名称\", \"phone\": \"手机号码\", \"detail_address\":\"详细地址\", \"next_visit_time\":\"下回回访日期\", \"member_name\": \"销售负责人\", \"client_status\": \"客户状态\", \"client_level\": \"重要级别\", \"is_first\": \"是否是首要联系人\"}",
                    "type": "object",
                    "additionalProperties": true
                }
@@ -13717,9 +13717,6 @@
        "request.GetFollowRecordList": {
            "type": "object",
            "properties": {
                "keyword": {
                    "type": "string"
                },
                "page": {
                    "description": "页码",
                    "type": "integer"
@@ -13727,6 +13724,11 @@
                "pageSize": {
                    "description": "每页大小",
                    "type": "integer"
                },
                "search_map": {
                    "description": "搜索条件: map[string]interface{}{\"name\": \"xxx\"}; {\"topic\": \"跟进主题\", \"member_name\": \"跟进人\", \"client_name\": \"客户名称\", \"client_status\": \"客户状态\", \"follow_time\": \"跟进时间\", \"next_follow_time\": \"下次跟进时间\", \"record\": \"跟进记录\", \"phone\": \"联系人电话\", \"contact_name\": \"联系人姓名\"}",
                    "type": "object",
                    "additionalProperties": true
                }
            }
        },
docs/swagger.yaml
@@ -120,7 +120,6 @@
    - 1
    - 2
    - 3
    - 4
    - -1
    type: integer
    x-enum-comments:
@@ -129,11 +128,9 @@
      SalesStatusLevelUptoClient: 升级为客户
      SalesStatusLevelUptoClientAndSalesChance: 升级为客户并且有销售机会
      SalesStatusNew: 新建
      SalesStatusSuccess: 成功
    x-enum-varnames:
    - SalesStatusNew
    - SalesStatusIng
    - SalesStatusSuccess
    - SalesStatusLevelUptoClient
    - SalesStatusLevelUptoClientAndSalesChance
    - SalesStatusFail
@@ -611,6 +608,8 @@
        type: string
      id:
        type: integer
      member:
        $ref: '#/definitions/model.User'
      member_id:
        type: integer
      next_follow_time:
@@ -2852,7 +2851,7 @@
        additionalProperties: true
        description: '搜索条件: map[string]interface{}{"name": "xxx"}; {"name": "客户名称",
          "phone": "手机号码", "detail_address":"详细地址", "next_visit_time":"下回回访日期", "member_name":
          "销售负责人", "client_status": "客户状态", "client_level": "重要级别"}'
          "销售负责人", "client_status": "客户状态", "client_level": "重要级别", "is_first": "是否是首要联系人"}'
        type: object
    type: object
  request.GetContractList:
@@ -2883,14 +2882,19 @@
    type: object
  request.GetFollowRecordList:
    properties:
      keyword:
        type: string
      page:
        description: 页码
        type: integer
      pageSize:
        description: 每页大小
        type: integer
      search_map:
        additionalProperties: true
        description: '搜索条件: map[string]interface{}{"name": "xxx"}; {"topic": "跟进主题",
          "member_name": "跟进人", "client_name": "客户名称", "client_status": "客户状态", "follow_time":
          "跟进时间", "next_follow_time": "下次跟进时间", "record": "跟进记录", "phone": "联系人电话",
          "contact_name": "联系人姓名"}'
        type: object
    type: object
  request.GetMasterOrderList:
    properties:
model/contact.go
@@ -12,6 +12,7 @@
        Name     string    `json:"name" gorm:"column:name;type:varchar(255);comment:联系人姓名"`
        Number   string    `json:"number" gorm:"column:number;type:varchar(255);comment:联系人编号"`
        ClientId int       `json:"client_id" gorm:"column:client_id;type:int(11);comment:客户ID"`
        Client   Client    `json:"-" gorm:"foreignKey:ClientId"`
        Position string    `json:"position" gorm:"column:position;type:varchar(255);comment:职位"`
        Phone    string    `json:"phone" gorm:"column:phone;type:varchar(255);comment:电话"`
        MemberId int       `json:"member_id" gorm:"column:member_id;type:int(11);comment:负责人ID"`
@@ -80,7 +81,16 @@
                }
                if key == "client_name" {
                    db = db.Joins("inner join clients on clients.id = contacts.client_id").Where("clients.name LIKE ?", "%"+v+"%")
                    //db = db.Joins("inner join clients on clients.id = contacts.client_id").Where("clients.name LIKE ?", "%"+v+"%")
                    db = db.Joins("Client").Where("Client.name LIKE ?", "%"+v+"%")
                }
                if key == "is_first" {
                    if v == "是" {
                        db = db.Where("is_first = ?", true)
                    } else if v == "否" {
                        db = db.Where("is_first = ?", false)
                    }
                }
            case int:
            }
model/followRecord.go
@@ -12,6 +12,7 @@
        ClientId             int       `json:"client_id" gorm:"column:client_id;type:int(11);comment:客户id"`
        ClientStatusId       int       `json:"client_status_id" gorm:"column:client_status_id;type:int(11);comment:客户状态id"`
        MemberId             int       `json:"member_id" gorm:"column:member_id;type:int(11);comment:跟进人id"`
        Member               User      `json:"member" gorm:"foreignKey:MemberId"`
        Number               string    `json:"number" gorm:"column:number;type:varchar(255);comment:跟进编号"`
        ContactId            int       `json:"contact_id" gorm:"column:contact_id;type:int(11);comment:联系人id"`
        Topic                string    `json:"topic" gorm:"column:topic;type:varchar(255);comment:跟进主题"`
@@ -32,7 +33,7 @@
        FollowRecord
        Orm      *gorm.DB
        Keyword  string
        SearchMap map[string]interface{}
        OrderBy  string
        PageNum  int
        PageSize int
@@ -51,56 +52,50 @@
func (slf *FollowRecordSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&FollowRecord{})
    if slf.Keyword != "" {
        db = db.Where("name LIKE ?", "%"+slf.Keyword+"%")
    }
    if slf.Keyword != "" {
        db = db.Where("topic 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 slf.ClientStatusId != 0 {
        db = db.Where("client_status_id = ?", slf.ClientStatusId)
    if len(slf.SearchMap) > 0 {
        for key, value := range slf.SearchMap {
            switch v := value.(type) {
            case string:
                if key == "topic" || key == "record" {
                    db = db.Where(key+" LIKE ?", "%"+v+"%")
    }
    if slf.MemberId != 0 {
        db = db.Where("member_id = ?", slf.MemberId)
                if key == "client_name" {
                    db = db.Joins("Client").Where("Client.name LIKE ?", "%"+v+"%")
    }
    if slf.Number != "" {
        db = db.Where("number = ?", slf.Number)
                if key == "contact_name" {
                    db = db.Joins("Contact").Where("Contact.name LIKE ?", "%"+v+"%")
    }
    if slf.ContactId != 0 {
        db = db.Where("contact_id = ?", slf.ContactId)
                if key == "member_name" {
                    db = db.Joins("Member").Where("Member.username LIKE ?", "%"+v+"%")
    }
    if slf.Topic != "" {
        db = db.Where("topic = ?", slf.Topic)
                if key == "phone" {
                    db = db.Joins("Contact").Where("Contacts.phone LIKE ?", "%"+v+"%")
    }
    if slf.Record != "" {
        db = db.Where("record = ?", slf.Record)
                if key == "follow_time" {
                    db = db.Where("follow_time = ?", v)
    }
    if slf.SaleChanceId != 0 {
        db = db.Where("sale_chance_id = ?", slf.SaleChanceId)
                if key == "next_follow_time" {
                    db = db.Where("next_follow_time = ?", v)
    }
    if slf.SalesLeadsId != 0 {
        db = db.Where("sales_leads_id = ?", slf.SalesLeadsId)
                if key == "client_status" {
                    db = db.Joins("Client").Joins("Client.ClientStatus").Where("Client__ClientStatus.name LIKE ?", "%"+v+"%")
    }
    if slf.ContactInformationId != 0 {
        db = db.Where("contact_information_id = ?", slf.ContactInformationId)
    }
    if !slf.FollowTime.IsZero() {
        db = db.Where("follow_time = ?", slf.FollowTime)
    }
    if !slf.NextFollowTime.IsZero() {
        db = db.Where("next_follow_time = ?", slf.NextFollowTime)
    }
    if slf.Purpose != "" {
        db = db.Where("purpose = ?", slf.Purpose)
    }
    if slf.Content != "" {
        db = db.Where("content = ?", slf.Content)
    }
    return db
@@ -169,11 +164,6 @@
    return slf
}
func (slf *FollowRecordSearch) SetKeyword(keyword string) *FollowRecordSearch {
    slf.Keyword = keyword
    return slf
}
func (slf *FollowRecordSearch) SetPage(page, size int) *FollowRecordSearch {
    slf.PageNum, slf.PageSize = page, size
    return slf
@@ -192,3 +182,8 @@
    var db = slf.build()
    return db.Updates(data).Error
}
func (slf *FollowRecordSearch) SetSearchMap(data map[string]interface{}) *FollowRecordSearch {
    slf.SearchMap = data
    return slf
}
model/request/contact.go
@@ -29,7 +29,7 @@
type GetContactList struct {
    PageInfo
    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": "重要级别"}
    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": "重要级别", "is_first": "是否是首要联系人"}
}
type DeleteContact struct {
model/request/followRecord.go
@@ -28,7 +28,7 @@
type GetFollowRecordList struct {
    PageInfo
    Keyword string `json:"keyword"`
    SearchMap map[string]interface{} `json:"search_map"` // 搜索条件: map[string]interface{}{"name": "xxx"}; {"topic": "跟进主题", "member_name": "跟进人", "client_name": "客户名称", "client_status": "客户状态", "follow_time": "跟进时间", "next_follow_time": "下次跟进时间", "record": "跟进记录", "phone": "联系人电话", "contact_name": "联系人姓名"}
}
type DeleteFollowRecord struct {
service/followRecord.go
@@ -40,9 +40,9 @@
    return ecode.OK
}
func (FollowRecordService) GetFollowRecordList(page, pageSize int, keyword string) ([]*model.FollowRecord, int64, int) {
func (FollowRecordService) GetFollowRecordList(page, pageSize int, data map[string]interface{}) ([]*model.FollowRecord, int64, int) {
    // get contact list
    contacts, total, err := model.NewFollowRecordSearch().SetKeyword(keyword).SetPage(page, pageSize).FindAll()
    contacts, total, err := model.NewFollowRecordSearch().SetPage(page, pageSize).SetSearchMap(data).FindAll()
    if err != nil {
        return nil, 0, ecode.FollowRecordListErr
    }
service/salesLeads.go
@@ -27,17 +27,17 @@
}
// CheckSalesLeadsExist check salesLeads exist
func CheckSalesLeadsExist(id int) int {
    tmp, err := model.NewSalesLeadsSearch(nil).SetId(id).Find()
func CheckSalesLeadsExist(id int) (int, *model.SalesLeads) {
    tmp, err := model.NewSalesLeadsSearch(nil).SetId(id).First()
    if err != nil {
        return ecode.SalesLeadsNotExist
        return ecode.SalesLeadsNotExist, nil
    }
    if len(tmp) == 0 {
        return ecode.SalesLeadsNotExist
    if tmp.Id == 0 {
        return ecode.SalesLeadsNotExist, nil
    }
    return ecode.OK
    return ecode.OK, &tmp
}
func (SalesLeadsService) GetSalesLeadsList(page, pageSize int, data map[string]interface{}) ([]*model.SalesLeads, int64, int) {
@@ -78,11 +78,16 @@
func (SalesLeadsService) PushSalesLeads(id int, step constvar.SalesStatus, txt string) int {
    // check salesLeads exist
    errCode := CheckSalesLeadsExist(id)
    errCode, tmp := CheckSalesLeadsExist(id)
    if errCode != ecode.OK {
        return errCode
    }
    // check step
    if tmp.SalesStatus > step && step != constvar.SalesStatusFail {
        return ecode.SalesLeadsStatusErr
    }
    switch step {
    case constvar.SalesStatusFail:
        err := model.NewSalesLeadsSearch(nil).SetId(id).UpdateMap(map[string]interface{}{