|
@@ -573,16 +573,11 @@ func users() {
|
|
|
log.Println(v, "用户是否有小程序且未使用过剑鱼其他产品")
|
|
|
} else {
|
|
|
ok1, ok2 := FormatData(v, "users")
|
|
|
- //ok1, ok2 := true, true
|
|
|
if !ok1 {
|
|
|
- common.WriteSysConfig(&cfg)
|
|
|
log.Println("线索卡点", "users", v, selectTimeEnd)
|
|
|
- break
|
|
|
} else {
|
|
|
if !ok2 {
|
|
|
log.Println("用户分配已达上限", "users", v, selectTimeEnd)
|
|
|
- common.WriteSysConfig(&cfg)
|
|
|
- break
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -684,14 +679,10 @@ func saleLeads() {
|
|
|
}
|
|
|
ok1, ok2 := FormatData(thisData, "saleLeads")
|
|
|
if !ok1 {
|
|
|
- common.WriteSysConfig(&cfg)
|
|
|
log.Println("线索卡点", "saleLeads", thisData, lastId)
|
|
|
- break
|
|
|
} else {
|
|
|
if !ok2 {
|
|
|
log.Println("用户分配已达上限", "saleLeads", thisData, lastId)
|
|
|
- common.WriteSysConfig(&cfg)
|
|
|
- break
|
|
|
}
|
|
|
}
|
|
|
cfg.LastId = mongodb.BsonIdToSId(thisData["_id"])
|
|
@@ -743,28 +734,46 @@ func userbase() {
|
|
|
log.Println("userbase uid 注册时间 ", registedates)
|
|
|
if time.Now().Unix()-registedates.Unix() > int64(db.RegTimes)*86400 {
|
|
|
if count == 0 {
|
|
|
- // TiDb.Insert("dwd_f_crm_open_sea", map[string]interface{}{
|
|
|
- // "clue_id": clueId,
|
|
|
- // "comeintime": nowTime,
|
|
|
- // "comeinsource": 2,
|
|
|
- // })
|
|
|
- clueId := TiDb.Insert("dwd_f_crm_clue_info", map[string]interface{}{
|
|
|
- "userid": userId,
|
|
|
- "uid": uId,
|
|
|
- "is_assign": 0,
|
|
|
- "comeintime": nowTime,
|
|
|
- "createtime": nowTime,
|
|
|
- "updatetime": nowTime,
|
|
|
- "cluename": phone,
|
|
|
- "top_cluetype": "532",
|
|
|
- "sub_cluetype": "475",
|
|
|
- "trailstatus": "01",
|
|
|
- "name": name,
|
|
|
- "phone": phone,
|
|
|
- "comeintime_open": nowTime,
|
|
|
- "comeinsource_open": 1,
|
|
|
- "FREEZE_TIME": nowTime,
|
|
|
- })
|
|
|
+ clueId := int64(0)
|
|
|
+ sql := fmt.Sprintf(`select * from freeClubSign where mogUserId="%s" and sub_again_date > "%s" `, userId, selectTimeEnd)
|
|
|
+ data := BiService.SelectBySql(sql)
|
|
|
+ if len(*data) > 0 && userId != "" {
|
|
|
+ clueId = TiDb.Insert("dwd_f_crm_clue_info", map[string]interface{}{
|
|
|
+ "userid": userId,
|
|
|
+ "uid": uId,
|
|
|
+ "is_assign": 0,
|
|
|
+ "comeintime": nowTime,
|
|
|
+ "createtime": nowTime,
|
|
|
+ "updatetime": nowTime,
|
|
|
+ "cluename": phone,
|
|
|
+ "top_cluetype": "532",
|
|
|
+ "sub_cluetype": "670",
|
|
|
+ "trailstatus": "01",
|
|
|
+ "name": name,
|
|
|
+ "phone": phone,
|
|
|
+ "comeintime_open": nowTime,
|
|
|
+ "comeinsource_open": 1,
|
|
|
+ "FREEZE_TIME": nowTime,
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ clueId = TiDb.Insert("dwd_f_crm_clue_info", map[string]interface{}{
|
|
|
+ "userid": userId,
|
|
|
+ "uid": uId,
|
|
|
+ "is_assign": 0,
|
|
|
+ "comeintime": nowTime,
|
|
|
+ "createtime": nowTime,
|
|
|
+ "updatetime": nowTime,
|
|
|
+ "cluename": phone,
|
|
|
+ "top_cluetype": "532",
|
|
|
+ "sub_cluetype": "475",
|
|
|
+ "trailstatus": "01",
|
|
|
+ "name": name,
|
|
|
+ "phone": phone,
|
|
|
+ "comeintime_open": nowTime,
|
|
|
+ "comeinsource_open": 1,
|
|
|
+ "FREEZE_TIME": nowTime,
|
|
|
+ })
|
|
|
+ }
|
|
|
if clueId > 0 {
|
|
|
TiDb.Insert("dwd_f_userbase_contacts", map[string]interface{}{
|
|
|
"status": 1,
|
|
@@ -957,6 +966,32 @@ func getClueType(item string, data map[string]interface{}, sourceCode string, so
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ } else if item == "allocation" {
|
|
|
+ pcode = "532"
|
|
|
+ code = "671"
|
|
|
+ level = "C"
|
|
|
+ pcodeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": pcode}, "", "")
|
|
|
+ if pcodeData != nil && len(*pcodeData) > 0 {
|
|
|
+ topname = common.ObjToString((*pcodeData)["name"])
|
|
|
+ }
|
|
|
+ pcodeData = TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": code}, "", "")
|
|
|
+ if pcodeData != nil && len(*pcodeData) > 0 {
|
|
|
+ subname = common.ObjToString((*pcodeData)["name"])
|
|
|
+ }
|
|
|
+ } else if item == "rebind" {
|
|
|
+ pcode = "532"
|
|
|
+ code = "670"
|
|
|
+ level = "C"
|
|
|
+ pcodeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": pcode}, "", "")
|
|
|
+ if pcodeData != nil && len(*pcodeData) > 0 {
|
|
|
+
|
|
|
+ topname = common.ObjToString((*pcodeData)["name"])
|
|
|
+
|
|
|
+ }
|
|
|
+ pcodeData = TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": code}, "", "")
|
|
|
+ if pcodeData != nil && len(*pcodeData) > 0 {
|
|
|
+ subname = common.ObjToString((*pcodeData)["name"])
|
|
|
+ }
|
|
|
} else {
|
|
|
if sourceCode != "" {
|
|
|
codeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"source": sourceCode}, "", "")
|
|
@@ -981,52 +1016,130 @@ func autoDraw(mode, cluename, phone string, isGroup, isCommerce int) (positionId
|
|
|
isFreeze = false
|
|
|
if TiDb.Count("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone, "is_assign": 1}) == 0 { //线索没销售进入,有销售走分配次数最少的逻辑
|
|
|
if isGroup == 0 && isCommerce == 1 && cluename != "" { //非集团在工商库线索名不为空
|
|
|
- cdata := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"cluename": cluename, "is_assign": 1}, "", "")
|
|
|
+ //cdata := TiDb.Find("dwd_f_crm_clue_info", map[string]interface{}{"cluename": cluename, "is_assign": 1}, "", "", -1, -1)
|
|
|
+ cdata := TiDb.SelectBySql(`select position_id,MAX(trail_time) as trail_time,max(last_ring_time) as last_ring_time,seatNumber,count(id) as count from dwd_f_crm_clue_info where cluename=? and is_assign =1 GROUP BY position_id `, cluename)
|
|
|
if cdata != nil && len(*cdata) > 0 { //找到了公司有人在跟进
|
|
|
isOk = true
|
|
|
- positionId = common.Int64All((*cdata)["position_id"])
|
|
|
- noticePositionId = positionId
|
|
|
- seatNumber = common.ObjToString((*cdata)["seatNumber"])
|
|
|
- if positionId > 0 {
|
|
|
- pdata := TiDb.SelectBySql(`select * from dwd_f_crm_personnel_management where seat_number is not null and seat_number != ""`)
|
|
|
- if pdata != nil {
|
|
|
- saleData = *pdata
|
|
|
+ pdata := TiDb.SelectBySql(`select * from dwd_f_crm_personnel_management where seat_number is not null and seat_number != ""`)
|
|
|
+ if pdata == nil {
|
|
|
+ positionId = 0
|
|
|
+ seatNumber = ""
|
|
|
+ saleName = ""
|
|
|
+ return
|
|
|
+ }
|
|
|
+ saleData = *pdata
|
|
|
+ cdataNew := []map[string]interface{}{}
|
|
|
+ if len(*cdata) > 1 {
|
|
|
+ //可能有多个人跟进
|
|
|
+ personMap := map[int64]bool{}
|
|
|
+ for _, m := range *cdata {
|
|
|
+ positionid := gconv.Int64(m["position_id"])
|
|
|
for _, v := range *pdata {
|
|
|
resign := common.IntAll(v["resign"])
|
|
|
- if positionId == common.Int64All(v["position_id"]) {
|
|
|
- if resign == 1 { //离职分配,找到的销售离职了,分给组员,没离职就给他
|
|
|
- sdata := TiDb.SelectBySql(`SELECT b.name,b.position_id,b.seat_number from dwd_d_crm_department_level_succbi a INNER JOIN dwd_f_crm_personnel_management b on a.position_id = b.position_id where a.bi_pcode = (SELECT bi_pcode from dwd_d_crm_department_level_succbi where position_id = ?) and b.role_id = 3`, positionId)
|
|
|
- if sdata != nil && len(*sdata) > 0 {
|
|
|
- for _, m := range *sdata {
|
|
|
- if !FindUpperLimit(gconv.String(positionId), mode, true) {
|
|
|
- positionId = common.Int64All(m["position_id"])
|
|
|
- noticePositionId = positionId
|
|
|
- seatNumber = common.ObjToString(m["seat_number"])
|
|
|
- saleName = common.ObjToString(m["name"])
|
|
|
- return
|
|
|
- }
|
|
|
+ if positionid == common.Int64All(v["position_id"]) {
|
|
|
+ if resign == 0 {
|
|
|
+ if !FindUpperLimit(gconv.String(positionId), mode, true) {
|
|
|
+ personMap[positionid] = true
|
|
|
+ m["saleName"] = common.ObjToString(v["name"])
|
|
|
+ cdataNew = append(cdataNew, m)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //查询是否都有没有离职
|
|
|
+ if len(personMap) != 0 && len(cdataNew) > 0 {
|
|
|
+ layout := "2006-01-02 15:04:05"
|
|
|
+ //有人没有离职
|
|
|
+ data := map[string]interface{}{}
|
|
|
+ trailTime := int64(0)
|
|
|
+ for _, m := range cdataNew {
|
|
|
+ currentTime := int64(0)
|
|
|
+ if gconv.String(m["trail_time"]) == "" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ t, _ := time.Parse(layout, gconv.String(m["trail_time"]))
|
|
|
+ currentTime = t.Unix()
|
|
|
+ if currentTime > trailTime {
|
|
|
+ trailTime = currentTime
|
|
|
+ data = m
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if trailTime == 0 {
|
|
|
+ //需要查看通话记录
|
|
|
+ lastRingTime := int64(0)
|
|
|
+ for _, m := range cdataNew {
|
|
|
+ currentTime := int64(0)
|
|
|
+ if gconv.String(m["last_ring_time"]) == "" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ t, _ := time.Parse(layout, gconv.String(m["last_ring_time"]))
|
|
|
+ currentTime = t.Unix()
|
|
|
+ if currentTime > lastRingTime {
|
|
|
+ lastRingTime = currentTime
|
|
|
+ data = m
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if lastRingTime != 0 {
|
|
|
+ positionId = common.Int64All(data["position_id"])
|
|
|
+ noticePositionId = positionId
|
|
|
+ seatNumber = common.ObjToString(data["seatNumber"])
|
|
|
+ saleName = common.ObjToString(data["saleName"])
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ count := 0
|
|
|
+ for i, v := range cdataNew {
|
|
|
+ if i == 0 {
|
|
|
+ count = gconv.Int(v["count"])
|
|
|
+ data = v
|
|
|
+ } else {
|
|
|
+ if count < gconv.Int(v["count"]) {
|
|
|
+ count = gconv.Int(v["count"])
|
|
|
+ data = v
|
|
|
}
|
|
|
- isFreeze = true
|
|
|
- positionId = 0
|
|
|
- seatNumber = ""
|
|
|
- saleName = ""
|
|
|
- return
|
|
|
}
|
|
|
+
|
|
|
+ }
|
|
|
+ //
|
|
|
+ positionId = common.Int64All(data["position_id"])
|
|
|
+ noticePositionId = positionId
|
|
|
+ saleName = common.ObjToString(data["saleName"])
|
|
|
+ seatNumber = common.ObjToString(data["seatNumber"])
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ positionId = common.Int64All(data["position_id"])
|
|
|
+ noticePositionId = positionId
|
|
|
+ seatNumber = common.ObjToString(data["seatNumber"])
|
|
|
+ saleName = common.ObjToString(data["saleName"])
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //只有一人跟进
|
|
|
+ //(1)该销售人员未离职,则继续分配给该销售人员(保持现状);
|
|
|
+ //该销售人员已离职,则随机分配
|
|
|
+ positionId = common.Int64All((*cdata)[0]["position_id"])
|
|
|
+ noticePositionId = positionId
|
|
|
+ seatNumber = common.ObjToString((*cdata)[0]["seatNumber"])
|
|
|
+ for _, v := range *pdata {
|
|
|
+ resign := common.IntAll(v["resign"])
|
|
|
+ if positionId == common.Int64All(v["position_id"]) {
|
|
|
+ if resign == 0 {
|
|
|
+ if FindUpperLimit(gconv.String(positionId), mode, true) {
|
|
|
+ isFreeze = true
|
|
|
+ positionId = 0
|
|
|
+ seatNumber = ""
|
|
|
+ saleName = ""
|
|
|
+ break
|
|
|
} else {
|
|
|
- if FindUpperLimit(gconv.String(positionId), mode, true) {
|
|
|
- isFreeze = true
|
|
|
- }
|
|
|
saleName = common.ObjToString(v["name"])
|
|
|
+ return
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if isFreeze {
|
|
|
- positionId = 0
|
|
|
- seatNumber = ""
|
|
|
- saleName = ""
|
|
|
- }
|
|
|
- return
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1170,3 +1283,68 @@ func getSeatNumberPositionId(seatNumber string) (positionId int64) {
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// 重新关注用户处理
|
|
|
+func rebind() {
|
|
|
+ log.Println("重新关注用户处理开始")
|
|
|
+ //判断节假日
|
|
|
+ runOk := getRunOk()
|
|
|
+ if !runOk {
|
|
|
+ log.Println("不是工作日,任务暂停")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ rebindTimeEnd := cfg.RebindTime
|
|
|
+ sql := fmt.Sprintf(`select * from freeClubSign where sub_again_date > "%s" order by sub_again_date asc`, rebindTimeEnd)
|
|
|
+ data := BiService.SelectBySql(sql)
|
|
|
+ if data != nil && *data != nil && len(*data) > 0 {
|
|
|
+ for _, v := range *data {
|
|
|
+ rebindTimeEnd = common.ObjToString(v["sub_again_date"])
|
|
|
+ registedates, _ := time.Parse(date.Date_Full_Layout, gconv.String(v["register_time"]))
|
|
|
+ if time.Now().Unix()-registedates.Unix() > int64(db.RegTimes)*86400 {
|
|
|
+ ok1, ok2 := FormatData(v, "rebind")
|
|
|
+ if !ok1 {
|
|
|
+ log.Println("线索卡点", "allocation", v, rebindTimeEnd)
|
|
|
+ } else {
|
|
|
+ if !ok2 {
|
|
|
+ log.Println("用户分配已达上限", "allocation", v, rebindTimeEnd)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ cfg.RebindTime = rebindTimeEnd
|
|
|
+ common.WriteSysConfig(&cfg)
|
|
|
+ }
|
|
|
+ log.Println("重新关注用户处理结束")
|
|
|
+}
|
|
|
+
|
|
|
+// 活跃用户处理
|
|
|
+func activeUsers() {
|
|
|
+ log.Println("活跃用户处理开始")
|
|
|
+ //判断节假日
|
|
|
+ runOk := getRunOk()
|
|
|
+ if !runOk {
|
|
|
+ log.Println("不是工作日,任务暂停")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //活跃用户查询
|
|
|
+ activeTimeEnd := cfg.ActiveTime
|
|
|
+ sql := fmt.Sprintf(`select * from freeClubSign where act_again_date > "%s" order by act_again_date asc`, activeTimeEnd)
|
|
|
+ data := BiService.SelectBySql(sql)
|
|
|
+ if data != nil && *data != nil && len(*data) > 0 {
|
|
|
+ for _, v := range *data {
|
|
|
+ activeTimeEnd = common.ObjToString(v["act_again_date"])
|
|
|
+ ok1, ok2 := FormatData(v, "allocation")
|
|
|
+ log.Println(v, "allocation", ok1, ok2)
|
|
|
+ if !ok1 {
|
|
|
+ log.Println("线索卡点", "allocation", v, activeTimeEnd)
|
|
|
+ } else {
|
|
|
+ if !ok2 {
|
|
|
+ log.Println("用户分配已达上限", "allocation", v, activeTimeEnd)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ cfg.ActiveTime = activeTimeEnd
|
|
|
+ common.WriteSysConfig(&cfg)
|
|
|
+ }
|
|
|
+ log.Println("活跃用户处理结束")
|
|
|
+}
|