瀏覽代碼

放撞单修改

WH01243 1 年之前
父節點
當前提交
ae3ccbf9b3
共有 2 個文件被更改,包括 89 次插入48 次删除
  1. 3 2
      clueSync/job.go
  2. 86 46
      clueSync/jobutil.go

+ 3 - 2
clueSync/job.go

@@ -3,6 +3,7 @@ package main
 import (
 	"database/sql"
 	"fmt"
+	"github.com/gogf/gf/v2/util/gconv"
 	"log"
 	"strings"
 	"time"
@@ -723,7 +724,7 @@ func WorkUpdateClue(data map[string]interface{}, saleData []map[string]interface
 		"sub_cluetype":         sub_cluetype,
 		"userid":               userId,
 		"comeinsource_private": 2,
-		"tasksource":           "线索来源自动更新" + "-" + topname + "-" + subname,
+		"tasksource":           gconv.String(common.If(gconv.Int64(data["position_id"]) == 0, "线索自动分配", "线索来源自动更新")) + "-" + topname + "-" + subname,
 		"company_nature":       isGroup,
 		"company_verification": isCommerce,
 	}
@@ -1540,7 +1541,7 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 							"clue_id":     clueId,
 							"position_id": common.If(trailstatus == "00" || is_assign == 0, positionId, common.Int64All(data["position_id"])),
 							"change_type": "加入任务车",
-							"new_value":   "线索来源自动更新" + "-" + topname + "-" + subname,
+							"new_value":   gconv.String(common.If(gconv.Int64(data["position_id"]) == 0, "线索自动分配", "线索来源自动更新")) + "-" + topname + "-" + subname,
 							"createtime":  nowTime,
 							"BCPCID":      common.GetRandom(32),
 							"operator_id": -1,

+ 86 - 46
clueSync/jobutil.go

@@ -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"])
@@ -981,52 +972,101 @@ 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)
 			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
+				}
+				cdataNew := []map[string]interface{}{}
+				if len(*cdata) > 1 {
+					//可能有多个人跟进
+					clueIdArr := []int64{}
+					personMap := map[int64]bool{}
+					for _, m := range *cdata {
+						clueId := gconv.Int64(m["id"])
+						clueIdArr = append(clueIdArr, clueId)
+						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
-											}
-										}
-										isFreeze = true
-										positionId = 0
-										seatNumber = ""
-										saleName = ""
-										return
-									}
-								} else {
-									if FindUpperLimit(gconv.String(positionId), mode, true) {
-										isFreeze = true
-									}
-									saleName = common.ObjToString(v["name"])
+							if positionid == common.Int64All(v["position_id"]) {
+								if resign == 0 {
+									personMap[positionid] = true
+									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 {
+								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 {
+									data = m
 								}
 							}
+							if lastRingTime != 0 {
+								positionId = common.Int64All(data["position_id"])
+								noticePositionId = positionId
+								seatNumber = common.ObjToString(data["seatNumber"])
+								return
+							}
+						} else {
+							positionId = common.Int64All(data["position_id"])
+							noticePositionId = positionId
+							seatNumber = common.ObjToString(data["seatNumber"])
+							return
 						}
 					}
-					if isFreeze {
-						positionId = 0
-						seatNumber = ""
-						saleName = ""
+				} 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 = ""
+									return
+								}
+								saleName = common.ObjToString(v["name"])
+							}
+						}
 					}
-					return
 				}
 			}
 		}