fix
add multi-criteria query to followRecord
| | |
| | | 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
|
| | |
| | | const ( |
| | | SalesStatusNew SalesStatus = iota // 新建 |
| | | SalesStatusIng // 进行中 |
| | | SalesStatusSuccess // 成功 |
| | | SalesStatusLevelUptoClient // 升级为客户 |
| | | SalesStatusLevelUptoClientAndSalesChance // 升级为客户并且有销售机会 |
| | | SalesStatusFail SalesStatus = -1 // 失败 |
| | |
| | | 1, |
| | | 2, |
| | | 3, |
| | | 4, |
| | | -1 |
| | | ], |
| | | "x-enum-comments": { |
| | |
| | | "SalesStatusIng": "进行中", |
| | | "SalesStatusLevelUptoClient": "升级为客户", |
| | | "SalesStatusLevelUptoClientAndSalesChance": "升级为客户并且有销售机会", |
| | | "SalesStatusNew": "新建", |
| | | "SalesStatusSuccess": "成功" |
| | | "SalesStatusNew": "新建" |
| | | }, |
| | | "x-enum-varnames": [ |
| | | "SalesStatusNew", |
| | | "SalesStatusIng", |
| | | "SalesStatusSuccess", |
| | | "SalesStatusLevelUptoClient", |
| | | "SalesStatusLevelUptoClientAndSalesChance", |
| | | "SalesStatusFail" |
| | |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "member": { |
| | | "$ref": "#/definitions/model.User" |
| | | }, |
| | | "member_id": { |
| | | "type": "integer" |
| | |
| | | "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 |
| | | } |
| | |
| | | "request.GetFollowRecordList": { |
| | | "type": "object", |
| | | "properties": { |
| | | "keyword": { |
| | | "type": "string" |
| | | }, |
| | | "page": { |
| | | "description": "页码", |
| | | "type": "integer" |
| | |
| | | "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 |
| | | } |
| | | } |
| | | }, |
| | |
| | | 1, |
| | | 2, |
| | | 3, |
| | | 4, |
| | | -1 |
| | | ], |
| | | "x-enum-comments": { |
| | |
| | | "SalesStatusIng": "进行中", |
| | | "SalesStatusLevelUptoClient": "升级为客户", |
| | | "SalesStatusLevelUptoClientAndSalesChance": "升级为客户并且有销售机会", |
| | | "SalesStatusNew": "新建", |
| | | "SalesStatusSuccess": "成功" |
| | | "SalesStatusNew": "新建" |
| | | }, |
| | | "x-enum-varnames": [ |
| | | "SalesStatusNew", |
| | | "SalesStatusIng", |
| | | "SalesStatusSuccess", |
| | | "SalesStatusLevelUptoClient", |
| | | "SalesStatusLevelUptoClientAndSalesChance", |
| | | "SalesStatusFail" |
| | |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "member": { |
| | | "$ref": "#/definitions/model.User" |
| | | }, |
| | | "member_id": { |
| | | "type": "integer" |
| | |
| | | "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 |
| | | } |
| | |
| | | "request.GetFollowRecordList": { |
| | | "type": "object", |
| | | "properties": { |
| | | "keyword": { |
| | | "type": "string" |
| | | }, |
| | | "page": { |
| | | "description": "页码", |
| | | "type": "integer" |
| | |
| | | "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 |
| | | } |
| | | } |
| | | }, |
| | |
| | | - 1 |
| | | - 2 |
| | | - 3 |
| | | - 4 |
| | | - -1 |
| | | type: integer |
| | | x-enum-comments: |
| | |
| | | SalesStatusLevelUptoClient: 升级为客户 |
| | | SalesStatusLevelUptoClientAndSalesChance: 升级为客户并且有销售机会 |
| | | SalesStatusNew: 新建 |
| | | SalesStatusSuccess: 成功 |
| | | x-enum-varnames: |
| | | - SalesStatusNew |
| | | - SalesStatusIng |
| | | - SalesStatusSuccess |
| | | - SalesStatusLevelUptoClient |
| | | - SalesStatusLevelUptoClientAndSalesChance |
| | | - SalesStatusFail |
| | |
| | | type: string |
| | | id: |
| | | type: integer |
| | | member: |
| | | $ref: '#/definitions/model.User' |
| | | member_id: |
| | | type: integer |
| | | next_follow_time: |
| | |
| | | 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: |
| | |
| | | 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: |
| | |
| | | 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"` |
| | |
| | | } |
| | | |
| | | 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: |
| | | } |
| | |
| | | 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:跟进主题"`
|
| | |
| | | FollowRecord
|
| | |
|
| | | Orm *gorm.DB
|
| | | Keyword string
|
| | | SearchMap map[string]interface{} |
| | | OrderBy string
|
| | | PageNum int
|
| | | PageSize int
|
| | |
| | |
|
| | | 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
|
| | |
| | | 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
|
| | |
| | | var db = slf.build()
|
| | | return db.Updates(data).Error
|
| | | }
|
| | | |
| | | func (slf *FollowRecordSearch) SetSearchMap(data map[string]interface{}) *FollowRecordSearch { |
| | | slf.SearchMap = data |
| | | return slf |
| | | } |
| | |
| | | |
| | | 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 { |
| | |
| | |
|
| | | 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 {
|
| | |
| | | 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
|
| | | }
|
| | |
| | | } |
| | | |
| | | // 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) { |
| | |
| | | |
| | | 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{}{ |