|
@@ -32,8 +32,8 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
|
|
userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
|
|
userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
|
|
if userInfo != nil && len(*userInfo) > 0 {
|
|
if userInfo != nil && len(*userInfo) > 0 {
|
|
uId = common.ObjToString((*userInfo)["uid"])
|
|
uId = common.ObjToString((*userInfo)["uid"])
|
|
- source = common.ObjToString((*userInfo)["source"])
|
|
|
|
- belong_to = common.ObjToString((*userInfo)["belong_to"])
|
|
|
|
|
|
+ source = common.ObjToString((*userInfo)["source"]) //用户来源
|
|
|
|
+ belong_to = common.ObjToString((*userInfo)["belong_to"]) //用户归属
|
|
}
|
|
}
|
|
cluename = common.ObjToString(data["company_name"])
|
|
cluename = common.ObjToString(data["company_name"])
|
|
phone = common.ObjToString(data["user_phone"])
|
|
phone = common.ObjToString(data["user_phone"])
|
|
@@ -98,7 +98,7 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
|
|
log.Println("留资没有source", phone)
|
|
log.Println("留资没有source", phone)
|
|
return true, true
|
|
return true, true
|
|
}
|
|
}
|
|
- remark = common.ObjToString(data["jyRemark"])
|
|
|
|
|
|
+ remark = common.ObjToString(data["jyRemark"]) //荟聚线索备注
|
|
keywordArr := data["keyword"]
|
|
keywordArr := data["keyword"]
|
|
if keywordArr != nil {
|
|
if keywordArr != nil {
|
|
keyword = common.ObjArrToStringArr(data["keyword"].([]interface{}))
|
|
keyword = common.ObjArrToStringArr(data["keyword"].([]interface{}))
|
|
@@ -123,7 +123,7 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
|
|
userId = common.ObjToString((*userInfo)["userid"])
|
|
userId = common.ObjToString((*userInfo)["userid"])
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- if sourceCode == "report_retention" || sourceCode == "marketing_retention" {
|
|
|
|
|
|
+ if sourceCode == "report_retention" || sourceCode == "marketing_retention" { //荟聚线索来源,不是剑鱼用户,需要等待用户归集
|
|
log.Println("不是剑鱼用户留资,等待用户", phone)
|
|
log.Println("不是剑鱼用户留资,等待用户", phone)
|
|
return false, false
|
|
return false, false
|
|
} else if remark != "" {
|
|
} else if remark != "" {
|
|
@@ -176,15 +176,15 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
|
|
sourceId = common.Int64All(data["sourceId"])
|
|
sourceId = common.Int64All(data["sourceId"])
|
|
}
|
|
}
|
|
if cluename == "" && item != "message" && item != "orders" && item != "readClue" {
|
|
if cluename == "" && item != "message" && item != "orders" && item != "readClue" {
|
|
- cluename = phone
|
|
|
|
|
|
+ cluename = phone //没有线索名,手机号代替
|
|
}
|
|
}
|
|
- isGroup, isCommerce := GetCompanyType(cluename) //判断是否集团公司、工商库
|
|
|
|
- if source == "0104" || strings.HasPrefix(belong_to, "02") || source == "0102" || source == "0103" || phone == "" {
|
|
|
|
|
|
+ isGroup, isCommerce := GetCompanyType(cluename) //判断是否集团公司、工商库
|
|
|
|
+ if source == "0104" || strings.HasPrefix(belong_to, "02") || source == "0102" || source == "0103" || phone == "" { //参照用户来源代码表
|
|
log.Println("线索分配失败,线索过滤!!", item, source, phone, userId)
|
|
log.Println("线索分配失败,线索过滤!!", item, source, phone, userId)
|
|
saveHlyj(belong_to, item, phone, name, sourceName, cluename, position, nowTime, isGroup, isCommerce)
|
|
saveHlyj(belong_to, item, phone, name, sourceName, cluename, position, nowTime, isGroup, isCommerce)
|
|
return true, false
|
|
return true, false
|
|
}
|
|
}
|
|
- if uId == "" {
|
|
|
|
|
|
+ if uId == "" { //没有进用户归集,等待进入,结束任务,放在下次继续执行
|
|
if isExists, _ := redis.Exists("bidx", "bidx_userId_"+userId); isExists {
|
|
if isExists, _ := redis.Exists("bidx", "bidx_userId_"+userId); isExists {
|
|
redisInt := redis.GetInt("bidx", "bidx_userId_"+userId)
|
|
redisInt := redis.GetInt("bidx", "bidx_userId_"+userId)
|
|
if redisInt > 4 {
|
|
if redisInt > 4 {
|
|
@@ -216,11 +216,11 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
top_cluetype, sub_cluetype, level, topname, subname = getClueType(item, data, sourceCode, sourceId) //查留资来源名字
|
|
top_cluetype, sub_cluetype, level, topname, subname = getClueType(item, data, sourceCode, sourceId) //查留资来源名字
|
|
- if topname == "市场活动" && item == "saleLeads" {
|
|
|
|
|
|
+ if topname == "市场活动" && item == "saleLeads" { //市场活动的不要
|
|
log.Println("市场活动留资过滤 ", userId, phone)
|
|
log.Println("市场活动留资过滤 ", userId, phone)
|
|
return true, false
|
|
return true, false
|
|
}
|
|
}
|
|
- if strings.HasPrefix(belong_to, "03") {
|
|
|
|
|
|
+ if strings.HasPrefix(belong_to, "03") { //一切都好的不进
|
|
isOk := saveEverything(userId, phone, item, subname, sourceCode)
|
|
isOk := saveEverything(userId, phone, item, subname, sourceCode)
|
|
log.Println("渠道线索电销", userId, phone, item, subname, sourceCode)
|
|
log.Println("渠道线索电销", userId, phone, item, subname, sourceCode)
|
|
if !isOk {
|
|
if !isOk {
|
|
@@ -233,19 +233,19 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
|
|
log.Println("线索分配失败,线索过滤top_cluetype!!", item, uId, phone, userId)
|
|
log.Println("线索分配失败,线索过滤top_cluetype!!", item, uId, phone, userId)
|
|
return true, true
|
|
return true, true
|
|
}
|
|
}
|
|
- position_id, seatNumber, saleName, saleData, pIsOk := autoDraw(level, cluename, phone, isGroup, isCommerce)
|
|
|
|
|
|
+ position_id, seatNumber, saleName, saleData, pIsOk := autoDraw(level, cluename, phone, isGroup, isCommerce) //查询当前分配次数最少的,如果当前线索有销售,此次找出的不会+1
|
|
log.Println("data -------", position_id, seatNumber, saleName)
|
|
log.Println("data -------", position_id, seatNumber, saleName)
|
|
if position_id > 0 && seatNumber != "" {
|
|
if position_id > 0 && seatNumber != "" {
|
|
- uCount, oks := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", ""), true
|
|
|
|
- if uCount != nil && len(*uCount) > 0 {
|
|
|
|
|
|
+ uCount, oks := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", ""), true //查当前线索是否已存在
|
|
|
|
+ if uCount != nil && len(*uCount) > 0 { //已存在,走更新
|
|
batch_import := common.ObjToString((*uCount)["batch_import"])
|
|
batch_import := common.ObjToString((*uCount)["batch_import"])
|
|
- if batch_import != "" && item == "users" {
|
|
|
|
|
|
+ if batch_import != "" && item == "users" { //有导入批次号还是新用户,不执行
|
|
return true, true
|
|
return true, true
|
|
}
|
|
}
|
|
oks = UpdateClue(*uCount, saleData, item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, departments, industry, follow_project_area, role, seatNumber, level, position_id, source, sourceCode, remark, keyword, belong_to, isGroup, isCommerce, pIsOk)
|
|
oks = UpdateClue(*uCount, saleData, item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, departments, industry, follow_project_area, role, seatNumber, level, position_id, source, sourceCode, remark, keyword, belong_to, isGroup, isCommerce, pIsOk)
|
|
- } else {
|
|
|
|
|
|
+ } else { //不存在走新增
|
|
oks = SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, departments, industry, follow_project_area, role, seatNumber, position_id, source, sourceCode, remark, keyword, belong_to, isGroup, isCommerce)
|
|
oks = SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, departments, industry, follow_project_area, role, seatNumber, position_id, source, sourceCode, remark, keyword, belong_to, isGroup, isCommerce)
|
|
- if oks {
|
|
|
|
|
|
+ if oks { //新增成功,销售分配次数+1
|
|
TiDb.UpdateOrDeleteBySql(`update dwd_f_crm_clue_autodraw_record set count = count + 1 where seatNumber = ? and clue_level = ?`, seatNumber, level)
|
|
TiDb.UpdateOrDeleteBySql(`update dwd_f_crm_clue_autodraw_record set count = count + 1 where seatNumber = ? and clue_level = ?`, seatNumber, level)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -388,9 +388,7 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
|
|
func UpdateClue(data map[string]interface{}, saleData []map[string]interface{}, item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, departments, industry, follow_project_area, role, seatNumber, level string, positionId int64, source, sourceCode, remark string, keyword []string, belong_to string, isGroup, isCommerce int, pIsOk bool) bool {
|
|
func UpdateClue(data map[string]interface{}, saleData []map[string]interface{}, item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, departments, industry, follow_project_area, role, seatNumber, level string, positionId int64, source, sourceCode, remark string, keyword []string, belong_to string, isGroup, isCommerce int, pIsOk bool) bool {
|
|
nowTime := time.Now().Format("2006-01-02 15:04:05")
|
|
nowTime := time.Now().Format("2006-01-02 15:04:05")
|
|
nowTimes := time.Unix(time.Now().Unix()+3600*12, 0).Format("2006-01-02 15:04:05")
|
|
nowTimes := time.Unix(time.Now().Unix()+3600*12, 0).Format("2006-01-02 15:04:05")
|
|
- //trailstatus = 无意向 为变更线索状态
|
|
|
|
- //没有变更所属人查任务车,有车不变
|
|
|
|
- trailstatus := common.ObjToString(data["trailstatus"])
|
|
|
|
|
|
+ trailstatus := common.ObjToString(data["trailstatus"]) //data都为原线索数据
|
|
trailstatusTime := common.ObjToString(data["trailstatus_time"])
|
|
trailstatusTime := common.ObjToString(data["trailstatus_time"])
|
|
var trailstatusTimes time.Time
|
|
var trailstatusTimes time.Time
|
|
if trailstatusTime != "" {
|
|
if trailstatusTime != "" {
|
|
@@ -415,10 +413,10 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
|
|
old_topname, old_subname := "", ""
|
|
old_topname, old_subname := "", ""
|
|
is_transfer := common.IntAll(data["is_transfer"])
|
|
is_transfer := common.IntAll(data["is_transfer"])
|
|
if taskstatus == 1 || is_task == 0 {
|
|
if taskstatus == 1 || is_task == 0 {
|
|
- taskTime = common.ObjToString(common.If(item != "users", nowTime, nowTimes))
|
|
|
|
|
|
+ taskTime = common.ObjToString(common.If(item != "users", nowTime, nowTimes)) //任务时间,正常的是当前时间,新用户是当前时间+12个小时
|
|
} else {
|
|
} else {
|
|
if is_task == 1 {
|
|
if is_task == 1 {
|
|
- if oldTaskTime != "" {
|
|
|
|
|
|
+ if oldTaskTime != "" { //以最新的任务时间为主
|
|
t1, err := time.Parse("2006-01-02 15:04:05", oldTaskTime)
|
|
t1, err := time.Parse("2006-01-02 15:04:05", oldTaskTime)
|
|
if err == nil && time.Now().Before(t1) {
|
|
if err == nil && time.Now().Before(t1) {
|
|
taskTime = nowTime
|
|
taskTime = nowTime
|
|
@@ -428,8 +426,7 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- //加入任务车判断节假日
|
|
|
|
- count, counts, t := 0, 0, time.Now()
|
|
|
|
|
|
+ count, counts, t := 0, 0, time.Now() //加入任务车判断节假日
|
|
for {
|
|
for {
|
|
count++
|
|
count++
|
|
currentTime := t.AddDate(0, 0, -count)
|
|
currentTime := t.AddDate(0, 0, -count)
|
|
@@ -458,6 +455,7 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
|
|
break
|
|
break
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ //两天之前不包含节假日,有没有跟进记录
|
|
recordCount := TiDb.CountBySql(`select count(1) from dwd_f_crm_trail_content where clue_id = ? and createtime > ?`, clueId, t.AddDate(0, 0, -count).Format(date.Date_Full_Layout))
|
|
recordCount := TiDb.CountBySql(`select count(1) from dwd_f_crm_trail_content where clue_id = ? and createtime > ?`, clueId, t.AddDate(0, 0, -count).Format(date.Date_Full_Layout))
|
|
//
|
|
//
|
|
clueUpdateData := map[string]interface{}{
|
|
clueUpdateData := map[string]interface{}{
|
|
@@ -472,14 +470,14 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
|
|
}
|
|
}
|
|
old_remark := common.ObjToString(data["remark"])
|
|
old_remark := common.ObjToString(data["remark"])
|
|
if old_remark != "" {
|
|
if old_remark != "" {
|
|
- remark = old_remark + ";" + remark
|
|
|
|
|
|
+ remark = old_remark + ";" + remark //备注不能替换,只能往上拼接
|
|
}
|
|
}
|
|
clueUpdateData["remark"] = remark
|
|
clueUpdateData["remark"] = remark
|
|
if cluename != "" {
|
|
if cluename != "" {
|
|
- clueUpdateData["cluename"] = cluename
|
|
|
|
|
|
+ clueUpdateData["cluename"] = cluename //新的线索名不为空才替换
|
|
}
|
|
}
|
|
|
|
|
|
- if item != "orders" && item != "users" {
|
|
|
|
|
|
+ if item != "orders" && item != "users" { //新用户和订单之外的替换一下新的留资信息
|
|
if name != "" {
|
|
if name != "" {
|
|
clueUpdateData["name"] = name
|
|
clueUpdateData["name"] = name
|
|
}
|
|
}
|
|
@@ -497,7 +495,7 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
|
|
}
|
|
}
|
|
// clueUpdateData["industry"] = industry
|
|
// clueUpdateData["industry"] = industry
|
|
}
|
|
}
|
|
- if sourceCode == "app_xzcyh" {
|
|
|
|
|
|
+ if sourceCode == "app_xzcyh" { //这个留资单独处理一下
|
|
if departments != "" {
|
|
if departments != "" {
|
|
clueUpdateData["department"] = departments
|
|
clueUpdateData["department"] = departments
|
|
department = departments
|
|
department = departments
|
|
@@ -529,7 +527,7 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
|
|
+ } else { //不属于上边情况就还是属于原来的销售,不更换销售
|
|
clueUpdateData["seatNumber"] = old_seatNumber
|
|
clueUpdateData["seatNumber"] = old_seatNumber
|
|
clueUpdateData["position_id"] = old_position_id
|
|
clueUpdateData["position_id"] = old_position_id
|
|
clueUpdateData["is_assign"] = 1
|
|
clueUpdateData["is_assign"] = 1
|
|
@@ -537,7 +535,7 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
|
|
clueUpdateData["level_open"] = nil
|
|
clueUpdateData["level_open"] = nil
|
|
clueUpdateData["clue_level"] = nil
|
|
clueUpdateData["clue_level"] = nil
|
|
}
|
|
}
|
|
- if trailstatus != "08" && is_assign == 0 {
|
|
|
|
|
|
+ if trailstatus != "08" && is_assign == 0 { //在公海的成交客户
|
|
if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
|
|
if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
|
|
} else {
|
|
} else {
|
|
clueUpdateData["trailstatus"] = "01"
|
|
clueUpdateData["trailstatus"] = "01"
|