123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- package service
- import (
- "app.yhyue.com/moapp/jybase/common"
- "bp.jydev.jianyu360.cn/BaseService/biService/entity"
- "bp.jydev.jianyu360.cn/BaseService/biService/rpc/pb"
- "fmt"
- "github.com/gogf/gf/v2/util/gconv"
- "math"
- )
- type ClueInfo struct {
- Id int64 `json:"id"`
- Uid string `json:"uid"`
- ClueName string `json:"cluename"`
- PositionId int64 `json:"position_id"`
- SeatNumber string `json:"seatNumber"`
- CompanyNature int `json:"company_natural"` // 公司性质 集团/非集团
- CompanyNatureStr string `json:"company_natural_str"` // 公司性质 集团/非集团
- LockStatus int `json:"lock_status"` // 锁定状态
- LockStatusStr string `json:"lock_status_str"`
- LockPerson string `json:"lock_person"` // 锁定人
- LockTime string `json:"lock_time"` // 锁定时间
- LockPositionId int64 `json:"lock_position_id"`
- Name string `json:"name"` // 联系人
- SalesPeople string `json:"sales_people"` // 销售人员
- IsAssign int `json:"is_assign"` // 线索池
- IsAssignStr string `json:"is_assign_str"` // 线索池
- CustomerDemand string `json:"customer_demand"` // 客户需求
- IntendedProducts string `json:"intended_products"` // 意向产品
- CustomerBudget int64 `json:"customer_budget"` // 客户预算
- Content string `json:"content"` // 最近跟进内容
- TrailTime string `json:"trail_time"` // 最近跟进时间
- StartTrailTime string `json:"start_trail_time"` // 开始跟进时间
- ClueStatus string `json:"clue_status"` // 线索状态
- IsTransfer int `json:"is_transfer"`
- CompanyVerification int `json:"company_verification"`
- //客成
- SucManager string `json:"suc_manager"` // 客成经理
- // 企业
- LegalPerson string `json:"legal_person"` // 法人
- ClueOwn string `json:"clue_own"` // 线索归属
- }
- func CheckingList(in *pb.ClueInfoReq) *pb.BiReply {
- sql0 := `SELECT a1.*, a3.name as customer, a4.name as trailstatus_name, a5.name as sales_people FROM dwd_f_crm_clue_info a1 LEFT JOIN dwd_f_csm_customer_info a3 ON a1.id = a3.clue_id
- LEFT JOIN dwd_d_crm_trailstatus_code a4 ON a1.trailstatus = a4.code
- LEFT JOIN dwd_d_crm_department_level_succbi a5 ON a1.position_id = a5.position_id
- WHERE a1.cluename LIKE '%%%s%%' ORDER BY a1.lock_status ASC, a1.trail_time DESC, a1.id ASC limit ? offset ?`
- cq0 := `SELECT COUNT(1) FROM dwd_f_crm_clue_info a1 WHERE a1.cluename LIKE '%%%s%%'`
- sql1 := `SELECT a1.*, a3.name as customer, a4.name as trailstatus_name, a5.name as sales_people FROM dwd_f_crm_clue_info a1 LEFT JOIN dwd_f_csm_customer_info a3 ON a1.id = a3.clue_id
- LEFT JOIN dwd_d_crm_trailstatus_code a4 ON a1.trailstatus = a4.code
- LEFT JOIN dwd_d_crm_department_level_succbi a5 ON a1.position_id = a5.position_id
- WHERE a1.name = '%s' ORDER BY a1.lock_status ASC, a1.trail_time DESC, a1.id ASC limit ? offset ?`
- cq1 := `SELECT COUNT(1) FROM dwd_f_crm_clue_info a1 WHERE a1.name = '%s'`
- sql2 := `SELECT a1.*, a3.name as customer, a4.name as trailstatus_name, a5.name as sales_people FROM dwd_f_crm_clue_info a1 LEFT JOIN dwd_f_csm_customer_info a3 ON a1.id = a3.clue_id
- LEFT JOIN dwd_d_crm_trailstatus_code a4 ON a1.trailstatus = a4.code
- LEFT JOIN dwd_d_crm_department_level_succbi a5 ON a1.position_id = a5.position_id
- WHERE a1.phone = '%s' ORDER BY a1.lock_status ASC, a1.trail_time DESC, a1.id ASC limit ? offset ?`
- cq2 := `SELECT COUNT(1) FROM dwd_f_crm_clue_info a1 WHERE a1.phone = '%s'`
- sql, cq := "", ""
- if in.SearchType == "0" {
- sql = sql0
- cq = cq0
- } else if in.SearchType == "1" {
- sql = sql1
- cq = cq1
- } else if in.SearchType == "2" {
- sql = sql2
- cq = cq2
- }
- if in.PageSize == 0 {
- in.PageSize = 10
- }
- rows := entity.JyBiTidb.Query(fmt.Sprintf(sql, in.SearchTxt), in.PageSize, (in.PageNum-1)*in.PageSize)
- var resultList []*ClueInfo
- for _, m := range *rows {
- resultList = append(resultList, getClueInfo(m))
- }
- count := entity.JyBiTidb.CountBySql(fmt.Sprintf(cq, in.SearchTxt))
- totalPage := int64(math.Ceil(float64(count) / float64(in.PageSize)))
- result := map[string]interface{}{
- "list": resultList,
- "count": count,
- }
- if totalPage > in.PageNum {
- result["hasNextPage"] = true
- } else {
- result["hasNextPage"] = false
- }
- return &pb.BiReply{
- Data: gconv.Bytes(result),
- }
- }
- func getClueInfo(tmp map[string]interface{}) *ClueInfo {
- clueInfo := &ClueInfo{
- Id: common.Int64All(tmp["id"]),
- Uid: common.ObjToString(tmp["uid"]),
- ClueName: common.ObjToString(tmp["cluename"]),
- SeatNumber: common.ObjToString(tmp["seatNumber"]),
- PositionId: common.Int64All(tmp["position_id"]),
- CompanyNature: common.IntAll(tmp["company_nature"]),
- CompanyNatureStr: common.ObjToString(common.If(common.IntAll(tmp["company_nature"]) == 0, "非集团公司", "集团公司")),
- LockStatus: common.IntAll(tmp["lock_status"]),
- LockTime: common.ObjToString(tmp["lock_time"]),
- LockPositionId: common.Int64All(tmp["lock_position_id"]),
- Name: common.ObjToString(tmp["name"]),
- IsAssign: common.IntAll(tmp["is_assign"]),
- CustomerDemand: common.ObjToString(tmp["customer_demand"]),
- IntendedProducts: common.ObjToString(tmp["intended_products"]),
- CustomerBudget: common.Int64All(tmp["customer_budget"]),
- Content: common.ObjToString(tmp["content"]),
- TrailTime: common.ObjToString(tmp["trail_time"]),
- SalesPeople: common.ObjToString(tmp["sales_people"]),
- SucManager: common.ObjToString(common.If(common.IntAll(tmp["is_transfer"]) == 1, common.ObjToString(tmp["customer"]), "/")),
- ClueStatus: common.ObjToString(tmp["trailstatus_name"]),
- IsTransfer: common.IntAll(tmp["is_transfer"]),
- CompanyVerification: common.IntAll(tmp["company_verification"]),
- }
- switch clueInfo.IsAssign {
- case 0:
- clueInfo.IsAssignStr = "公海"
- case 1:
- clueInfo.IsAssignStr = "私海"
- case -1:
- clueInfo.IsAssignStr = "退出公海"
- case -2:
- clueInfo.IsAssignStr = "域外"
- case -3:
- clueInfo.IsAssignStr = "冻结池"
- case -4:
- clueInfo.IsAssignStr = "内部员工"
- case -5:
- clueInfo.IsAssignStr = "存在大会员子账号权益,临时处理"
- case -6:
- clueInfo.IsAssignStr = "特殊原因,不允许销售进行跟进"
- }
- switch clueInfo.LockStatus {
- case 1:
- clueInfo.LockStatusStr = "已锁定"
- case 2:
- clueInfo.LockStatusStr = "未锁定"
- case 3:
- clueInfo.LockStatusStr = "无需锁定"
- }
- clueInfo.LockPerson, _ = getSeatNumber(common.Int64All(tmp["lock_position_id"]))
- if common.IntAll(tmp["company_verification"]) == 1 {
- ent, b := entity.MgoQyxy.FindOneByField("qyxy_std", map[string]interface{}{"company_name": clueInfo.ClueName},
- map[string]interface{}{"legal_person": 1})
- if b && len(*ent) > 0 {
- clueInfo.LegalPerson = common.ObjToString((*ent)["legal_person"])
- }
- }
- if common.IntAll(tmp["is_transfer"]) == 1 {
- clueInfo.ClueOwn = "客户成功组"
- } else if clueInfo.IsAssign == 0 && clueInfo.PositionId == 0 {
- clueInfo.ClueOwn = "销售一部、三部"
- } else if clueInfo.IsAssign == -4 && clueInfo.PositionId == 0 {
- clueInfo.ClueOwn = "/"
- } else if clueInfo.PositionId != 0 {
- info := entity.JyBiTidb.FindOne("dwd_d_crm_department_level_succbi", map[string]interface{}{"position_id": clueInfo.PositionId}, "dept_name", "")
- if info != nil && len(*info) > 0 {
- clueInfo.ClueOwn = common.ObjToString((*info)["dept_name"])
- }
- }
- return clueInfo
- }
|