瀏覽代碼

Merge branch 'dev_v1.5.3_wh1' of jianyu/datatools into feature/v1.5.3

王浩 1 年之前
父節點
當前提交
8daf62c95d
共有 2 個文件被更改,包括 532 次插入6 次删除
  1. 527 2
      clueSync/job.go
  2. 5 4
      clueSync/jobutil.go

+ 527 - 2
clueSync/job.go

@@ -249,7 +249,8 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
 			if batch_import != "" && item == "users" { //有导入批次号还是新用户,不执行
 				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, "")
+			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 { //不存在走新增
 			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, isFreeze, "")
 			if oks { //新增成功,销售分配次数+1
@@ -634,7 +635,7 @@ func SaveClue0(item, userId, uId, top_cluetype, sub_cluetype, topname, subname,
 		return false
 	}
 }
-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, demand string) bool {
+func UpdateClue1(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, demand string) bool {
 	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")
 	trailstatus := common.ObjToString(data["trailstatus"]) //data都为原线索数据
@@ -1188,3 +1189,527 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 		return false
 	}
 }
+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")
+	nowTimes := time.Unix(time.Now().Unix()+3600*12, 0).Format("2006-01-02 15:04:05")
+	trailstatus := common.ObjToString(data["trailstatus"]) //data都为原线索数据
+	trailstatusTime := common.ObjToString(data["trailstatus_time"])
+	var trailstatusTimes time.Time
+	if trailstatusTime != "" {
+		trailstatusTimes, _ = time.ParseInLocation(date.Date_Full_Layout, trailstatusTime, time.Local)
+	}
+	clueId := common.Int64All(data["id"])
+	is_assign := common.IntAll(data["is_assign"])
+	oldsaleName, oldTaskTime, taskTime, is_task, taskstatus := "", "", "", 0, 0
+	old_position_id, old_seatNumber := common.Int64All(data["position_id"]), common.ObjToString(data["seatNumber"])
+	oldTaskTime = common.ObjToString(data["tasktime"])
+	is_task = common.IntAll(data["is_task"])
+	taskstatus = common.IntAll(data["taskstatus"])
+	BCPCID := common.GetRandom(32)
+	old_name := common.ObjToString(data["name"])
+	old_position := common.ObjToString(data["position"])
+	old_department := common.ObjToString(data["department"])
+	old_follow_project_area := common.ObjToString(data["follow_project_area"])
+	old_role := common.ObjToString(data["role"])
+	old_cluename := common.ObjToString(data["cluename"])
+	old_top_cluetype := common.ObjToString(data["top_cluetype"])
+	old_sub_cluetype := common.ObjToString(data["sub_cluetype"])
+	old_topname, old_subname := "", ""
+	is_transfer := common.IntAll(data["is_transfer"])
+	if taskstatus == 1 || is_task == 0 {
+		taskTime = common.ObjToString(common.If(item != "users", nowTime, nowTimes)) //任务时间,正常的是当前时间,新用户是当前时间+12个小时
+	} else {
+		if is_task == 1 {
+			if oldTaskTime != "" { //以最新的任务时间为主
+				t1, err := time.Parse("2006-01-02 15:04:05", oldTaskTime)
+				if err == nil && time.Now().Before(t1) {
+					taskTime = nowTime
+				} else {
+					taskTime = oldTaskTime
+				}
+			}
+		}
+	}
+	count, counts, t := 0, 0, time.Now() //加入任务车判断节假日
+	for {
+		count++
+		currentTime := t.AddDate(0, 0, -count)
+		if currentTime.Weekday() == time.Sunday || currentTime.Weekday() == time.Saturday {
+			isok := false
+			for k, v := range DateMap {
+				if currentTime.Format(date.Date_Short_Layout) == k && v == 2 {
+					isok = true
+				}
+			}
+			if isok {
+				counts++
+			}
+		} else {
+			isok := true
+			for k, v := range DateMap {
+				if currentTime.Format(date.Date_Short_Layout) == k && v == 1 {
+					isok = false
+				}
+			}
+			if isok {
+				counts++
+			}
+		}
+		if counts >= 2 {
+			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))
+	//
+	clueUpdateData := map[string]interface{}{
+		"updatetime":           nowTime,
+		"top_cluetype":         top_cluetype,
+		"sub_cluetype":         sub_cluetype,
+		"userid":               userId,
+		"comeinsource_private": 2,
+		"tasksource":           "线索来源自动更新" + "-" + topname + "-" + subname,
+		"company_nature":       isGroup,
+		"company_verification": isCommerce,
+	}
+	old_remark := common.ObjToString(data["remark"])
+	if old_remark != "" {
+		remark = old_remark + ";" + remark //备注不能替换,只能往上拼接
+	}
+	clueUpdateData["remark"] = remark
+	if cluename != "" {
+		clueUpdateData["cluename"] = cluename //新的线索名不为空才替换
+	}
+
+	if item != "orders" && item != "users" { //新用户和订单之外的替换一下新的留资信息
+		if name != "" {
+			clueUpdateData["name"] = name
+		}
+		if position != "" {
+			clueUpdateData["position"] = position
+		}
+		if department != "" {
+			clueUpdateData["department"] = department
+		}
+		if follow_project_area != "" {
+			clueUpdateData["follow_project_area"] = follow_project_area
+		}
+		if role != "" {
+			clueUpdateData["role"] = role
+		}
+		// clueUpdateData["industry"] = industry
+	}
+	if sourceCode == "app_xzcyh" { //这个留资单独处理一下
+		if departments != "" {
+			clueUpdateData["department"] = departments
+			department = departments
+		}
+		business_scope := common.ObjToString(data["business_scope"])
+		keywords := ""
+		if len(keyword) > 0 && keyword[0] != "" {
+			keywords = strings.Join(keyword, ",")
+			if business_scope != "" {
+				clueUpdateData["business_scope"] = business_scope + "," + keywords
+			} else {
+				clueUpdateData["business_scope"] = keywords
+			}
+		}
+	}
+	if trailstatus == "00" || old_position_id == 0 || is_assign != 1 || (pIsOk && old_cluename != cluename && cluename != "") {
+		if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
+		} else {
+			clueUpdateData["seatNumber"] = seatNumber
+			clueUpdateData["position_id"] = positionId
+			clueUpdateData["comeintime"] = nowTime
+			clueUpdateData["is_assign"] = 1
+			clueUpdateData["comeinsource_open"] = nil
+			clueUpdateData["level_open"] = nil
+			clueUpdateData["clue_level"] = nil
+			for _, v := range saleData {
+				if common.Int64All(data["position_id"]) == common.Int64All(v["position_id"]) {
+					oldsaleName = common.ObjToString(v["name"])
+				}
+			}
+		}
+	} else { //不属于上边情况就还是属于原来的销售,不更换销售
+		clueUpdateData["seatNumber"] = old_seatNumber
+		clueUpdateData["position_id"] = old_position_id
+		clueUpdateData["is_assign"] = 1
+		clueUpdateData["comeinsource_open"] = nil
+		clueUpdateData["level_open"] = nil
+		clueUpdateData["clue_level"] = nil
+	}
+	if trailstatus != "08" && is_assign == 0 { //在公海的成交客户
+		if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
+		} else {
+			clueUpdateData["trailstatus"] = "01"
+			clueUpdateData["trailstatus_time"] = nowTime
+		}
+	}
+	is_ok := false
+	if (trailstatus != "08" && recordCount <= 0) || is_assign == 0 {
+		if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
+		} else {
+			if item == "eventReg" {
+				eData := TiDb.Find("dwd_f_crm_clue_change_record", map[string]interface{}{"clue_id": clueId, "change_type": "加入任务车"}, "", "", -1, -1)
+				if eData != nil && len(*eData) > 0 {
+					for _, e := range *eData {
+						new_value := common.ObjToString(e["new_value"])
+						if strings.Contains(new_value, subname) {
+							is_ok = true
+						}
+					}
+				}
+				if !is_ok {
+					if old_sub_cluetype != sub_cluetype || is_assign == 0 {
+						if taskTime == "" {
+							taskTime = nowTime
+						}
+						clueUpdateData["task_time"] = nowTime
+						clueUpdateData["tasktime"] = taskTime
+						clueUpdateData["taskstatus"] = 0
+					}
+					if is_transfer != 1 {
+						clueUpdateData["is_task"] = 1
+					}
+				}
+			} else {
+				if old_sub_cluetype != sub_cluetype || is_assign == 0 {
+					if taskTime == "" {
+						taskTime = nowTime
+					}
+					clueUpdateData["task_time"] = nowTime
+					clueUpdateData["tasktime"] = taskTime
+					clueUpdateData["taskstatus"] = 0
+				}
+				if is_transfer != 1 {
+					clueUpdateData["is_task"] = 1
+				}
+			}
+		}
+	}
+	ok, updateId14 := true, true
+	updateId1, updateId2, updateId3, updateId4, updateId5 := int64(0), int64(0), int64(0), int64(0), int64(0)
+	updateId6, updateId7, updateId8, updateId9, updateId10 := int64(0), int64(0), int64(0), int64(0), int64(0)
+	updateId11, updateId12, updateId13 := int64(0), int64(0), int64(0)
+	if TiDb.ExecTx("更新线索", func(tx *sql.Tx) bool {
+		//线索
+		ok = TiDb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, clueUpdateData)
+		//变更记录
+		if (trailstatus == "00" || old_position_id == 0 || (pIsOk && old_cluename != cluename && cluename != "")) && is_assign == 1 {
+			if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
+			} else if old_position_id == 0 {
+				updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+					"clue_id":      clueId,
+					"position_id":  positionId,
+					"change_field": "position_id",
+					"change_type":  "所属人变更",
+					"old_value":    common.If(oldsaleName != "", oldsaleName, "/"),
+					"new_value":    common.If(saleName != "", saleName, "/"),
+					"createtime":   nowTime,
+					"BCPCID":       common.GetRandom(32),
+					"operator_id":  -1,
+				})
+				updateId3 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+					"clue_id":      clueId,
+					"position_id":  positionId,
+					"change_field": "trailstatus",
+					"change_type":  "基本信息变更",
+					"old_value":    CodeTrail[trailstatus],
+					"new_value":    "新增",
+					"createtime":   nowTime,
+					"BCPCID":       common.GetRandom(32),
+					"operator_id":  -1,
+				})
+			} else {
+				if pIsOk && old_cluename != cluename && cluename != "" {
+					updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+						"clue_id":      clueId,
+						"position_id":  positionId,
+						"change_field": "position_id",
+						"change_type":  "所属人变更",
+						"old_value":    common.If(oldsaleName != "", oldsaleName, "/"),
+						"new_value":    common.If(saleName != "", saleName, "/"),
+						"createtime":   nowTime,
+						"BCPCID":       common.GetRandom(32),
+						"operator_id":  -1,
+					})
+				} else {
+					updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+						"clue_id":      clueId,
+						"position_id":  positionId,
+						"change_field": "position_id",
+						"change_type":  "所属人变更",
+						"old_value":    common.If(oldsaleName != "", oldsaleName, "/"),
+						"new_value":    common.If(saleName != "", saleName, "/"),
+						"createtime":   nowTime,
+						"BCPCID":       common.GetRandom(32),
+						"operator_id":  -1,
+					})
+					updateId2 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+						"clue_id":      clueId,
+						"position_id":  common.Int64All(data["position_id"]),
+						"change_field": "trailstatus",
+						"change_type":  "基本信息变更",
+						"old_value":    "无意向客户",
+						"new_value":    "流失",
+						"createtime":   nowTime,
+						"BCPCID":       common.GetRandom(32),
+						"operator_id":  -1,
+					})
+					updateId3 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+						"clue_id":      clueId,
+						"position_id":  positionId,
+						"change_field": "trailstatus",
+						"change_type":  "基本信息变更",
+						"old_value":    "商机线索",
+						"new_value":    "新增",
+						"createtime":   nowTime,
+						"BCPCID":       common.GetRandom(32),
+						"operator_id":  -1,
+					})
+					updateId4 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+						"clue_id":      clueId,
+						"position_id":  positionId,
+						"change_field": "trailstatus",
+						"change_type":  "基本信息变更",
+						"old_value":    "无意向客户",
+						"new_value":    "商机线索",
+						"createtime":   nowTime,
+						"BCPCID":       common.GetRandom(32),
+						"operator_id":  -1,
+					})
+				}
+			}
+		} else if trailstatus != "08" && is_assign == 0 {
+			if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
+			} else {
+				updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+					"clue_id":      clueId,
+					"position_id":  positionId,
+					"change_field": "position_id",
+					"change_type":  "所属人变更",
+					"old_value":    common.If(oldsaleName != "", oldsaleName, "/"),
+					"new_value":    common.If(saleName != "", saleName, "/"),
+					"createtime":   nowTime,
+					"BCPCID":       common.GetRandom(32),
+					"operator_id":  -1,
+				})
+				if trailstatus != "01" {
+					updateId4 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+						"clue_id":      clueId,
+						"position_id":  positionId,
+						"change_field": "trailstatus",
+						"change_type":  "基本信息变更",
+						"old_value":    CodeTrail[trailstatus],
+						"new_value":    "商机线索",
+						"createtime":   nowTime,
+						"BCPCID":       common.GetRandom(32),
+						"operator_id":  -1,
+					})
+				}
+				updateId3 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+					"clue_id":      clueId,
+					"position_id":  positionId,
+					"change_field": "trailstatus",
+					"change_type":  "基本信息变更",
+					"old_value":    "商机线索",
+					"new_value":    "新增",
+					"createtime":   nowTime,
+					"BCPCID":       common.GetRandom(32),
+					"operator_id":  -1,
+				})
+			}
+		}
+		if (trailstatus != "08" && recordCount <= 0) || is_assign == 0 {
+			if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
+			} else {
+				if old_sub_cluetype != sub_cluetype && !is_ok {
+					if is_transfer != 1 {
+						updateId5 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", 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,
+							"createtime":  nowTime,
+							"BCPCID":      common.GetRandom(32),
+							"operator_id": -1,
+						})
+					} else {
+						cdata := TiDb.FindOne("dwd_f_csm_customer_info", map[string]interface{}{"clue_id": clueId}, "", "")
+						if cdata != nil && len(*cdata) > 0 {
+							kcpositionId := common.Int64All((*cdata)["position_id"])
+							tasksource := common.ObjToString((*cdata)["tasksource"])
+							taskstatus := common.IntAll((*cdata)["taskstatus"])
+							updateId5 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+								"clue_id":     clueId,
+								"position_id": kcpositionId,
+								"change_type": "加入任务车",
+								"new_value":   "线上主动留资",
+								"createtime":  nowTime,
+								"BCPCID":      common.GetRandom(32),
+								"operator_id": -1,
+							})
+							if taskstatus == 1 {
+								tasksource = "10"
+							} else {
+								if tasksource != "" && !strings.Contains(tasksource, "10") {
+									if !strings.Contains(tasksource, "10") {
+										tasksource += ",10"
+									}
+								} else {
+									tasksource = "10"
+								}
+							}
+							updateId14 = TiDb.UpdateByTx(tx, "dwd_f_csm_customer_info", map[string]interface{}{"clue_id": clueId}, map[string]interface{}{
+								"tasksource": tasksource,
+								"tasktime":   nowTime,
+								"is_task":    1,
+								"taskstatus": 0,
+							})
+						}
+					}
+				}
+			}
+		}
+		if old_top_cluetype != "" {
+			pcodeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": old_top_cluetype}, "", "")
+			if pcodeData != nil && len(*pcodeData) > 0 {
+				old_topname = common.ObjToString((*pcodeData)["name"])
+			}
+		}
+		if old_sub_cluetype != "" {
+			pcodeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": old_sub_cluetype}, "", "")
+			if pcodeData != nil && len(*pcodeData) > 0 {
+				old_subname = common.ObjToString((*pcodeData)["name"])
+			}
+		}
+		if item != "orders" {
+			if old_name != name && name != "" {
+				updateId6 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+					"clue_id":      clueId,
+					"position_id":  common.If(trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400, -1, common.If(trailstatus == "00" || is_assign == 0, positionId, common.Int64All(data["position_id"]))),
+					"change_field": "name",
+					"change_type":  "基本信息变更",
+					"old_value":    common.If(old_name != "", old_name, "/"),
+					"new_value":    common.If(name != "", name, "/"),
+					"createtime":   nowTime,
+					"BCPCID":       BCPCID,
+					"operator_id":  -1,
+				})
+			}
+			if old_position != position && position != "" {
+				updateId7 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+					"clue_id":      clueId,
+					"position_id":  common.If(trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400, -1, common.If(trailstatus == "00" || is_assign == 0, positionId, common.Int64All(data["position_id"]))),
+					"change_field": "position",
+					"change_type":  "基本信息变更",
+					"old_value":    common.If(old_position != "", old_position, "/"),
+					"new_value":    common.If(position != "", position, "/"),
+					"createtime":   nowTime,
+					"BCPCID":       BCPCID,
+					"operator_id":  -1,
+				})
+			}
+			if old_department != department && department != "" {
+				updateId8 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+					"clue_id":      clueId,
+					"position_id":  common.If(trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400, -1, common.If(trailstatus == "00" || is_assign == 0, positionId, common.Int64All(data["position_id"]))),
+					"change_field": "department",
+					"change_type":  "基本信息变更",
+					"old_value":    common.If(old_department != "", old_department, "/"),
+					"new_value":    common.If(department != "", department, "/"),
+					"createtime":   nowTime,
+					"BCPCID":       BCPCID,
+					"operator_id":  -1,
+				})
+			}
+			if old_role != role && role != "" {
+				updateId9 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{"clue_id": clueId, "position_id": common.If(trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400, -1, common.If(trailstatus == "00" || is_assign == 0, positionId, common.Int64All(data["position_id"]))), "change_field": "role", "change_type": "基本信息变更", "old_value": common.If(old_role != "", old_role, "/"), "new_value": common.If(role != "", role, "/"), "createtime": nowTime, "BCPCID": BCPCID, "operator_id": -1})
+			}
+			if old_follow_project_area != follow_project_area && follow_project_area != "" {
+				old_area, old_area_arr := "", []string{}
+				new_area, new_area_arr := "", []string{}
+				for _, v := range strings.Split(old_follow_project_area, ",") {
+					old_area_arr = append(old_area_arr, CodeArea[v])
+				}
+				for _, v := range strings.Split(follow_project_area, ",") {
+					new_area_arr = append(new_area_arr, CodeArea[v])
+				}
+				old_area = strings.Join(old_area_arr, ",")
+				new_area = strings.Join(new_area_arr, ",")
+				updateId10 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+					"clue_id":      clueId,
+					"position_id":  common.If(trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400, -1, common.If(trailstatus == "00" || is_assign == 0, positionId, common.Int64All(data["position_id"]))),
+					"change_field": "follow_project_area",
+					"change_type":  "基本信息变更",
+					"old_value":    common.If(old_area != "", old_area, "/"),
+					"new_value":    common.If(new_area != "", new_area, "/"),
+					"createtime":   nowTime,
+					"BCPCID":       BCPCID,
+					"operator_id":  -1,
+				})
+			}
+			if old_cluename != cluename && cluename != "" {
+				updateId11 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+					"clue_id":      clueId,
+					"position_id":  common.If(trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400, -1, common.If(trailstatus == "00" || is_assign == 0, positionId, common.Int64All(data["position_id"]))),
+					"change_field": "cluename",
+					"change_type":  "基本信息变更",
+					"old_value":    common.If(old_cluename != "", old_cluename, "/"),
+					"new_value":    common.If(cluename != "", cluename, "/"),
+					"createtime":   nowTime,
+					"BCPCID":       BCPCID,
+					"operator_id":  -1,
+				})
+			}
+		}
+		if old_top_cluetype != top_cluetype {
+			updateId12 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+				"clue_id":      clueId,
+				"position_id":  common.If(trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400, -1, common.If(trailstatus == "00" || is_assign == 0, positionId, common.Int64All(data["position_id"]))),
+				"change_field": "top_cluetype",
+				"change_type":  "基本信息变更",
+				"old_value":    common.If(old_topname != "", old_topname, "/"),
+				"new_value":    common.If(topname != "", topname, "/"),
+				"createtime":   nowTime,
+				"BCPCID":       BCPCID,
+				"operator_id":  -1,
+			})
+		}
+		if old_sub_cluetype != sub_cluetype {
+			updateId13 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+				"clue_id":      clueId,
+				"position_id":  common.If(trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400, -1, common.If(trailstatus == "00" || is_assign == 0, positionId, common.Int64All(data["position_id"]))),
+				"change_field": "sub_cluetype",
+				"change_type":  "基本信息变更",
+				"old_value":    common.If(old_subname != "", old_subname, "/"),
+				"new_value":    common.If(subname != "", subname, "/"),
+				"createtime":   nowTime,
+				"BCPCID":       BCPCID,
+				"operator_id":  -1,
+			})
+		}
+		return ok && updateId1 > -1 && updateId2 > -1 && updateId3 > -1 && updateId4 > -1 && updateId5 > -1 && updateId6 > -1 && updateId7 > -1 && updateId8 > -1 && updateId9 > -1 && updateId10 > -1 && updateId11 > -1 && updateId12 > -1 && updateId13 > -1 && updateId14
+	}) {
+		log.Println("线索更新成功")
+		if TiDb.Count("dwd_f_userbase_contacts", map[string]interface{}{"phone": phone}) == 0 {
+			TiDb.Insert("dwd_f_userbase_contacts", map[string]interface{}{
+				"status":      1,
+				"is_delete":   1,
+				"createtime":  nowTime,
+				"updatetime":  nowTime,
+				"phone":       phone,
+				"baseinfo_id": uId,
+				"SOURCE":      source,
+			})
+		}
+		if old_position_id == 0 {
+			TiDb.UpdateOrDeleteBySql(`update dwd_f_crm_clue_autodraw_record set count = count + 1 where position_id = ? and clue_level = ?`, positionId, level)
+		}
+		return true
+	} else {
+		log.Println("线索更新失败!!!", ok, updateId1, updateId2, updateId3, updateId4, updateId5, updateId6, updateId7, updateId8, updateId9, updateId10, updateId11, updateId12, updateId13, updateId14, " 用户信息 ", item, position, seatNumber, uId, userId, phone)
+		return false
+	}
+}

+ 5 - 4
clueSync/jobutil.go

@@ -90,7 +90,8 @@ func WorkDataHandle(company, phone, demand, name, product string, acceptanceData
 				"clue_id": clueId,
 			}, "position_id,name", "")
 			if customerMap != nil && len(*customerMap) > 0 {
-				UpdateClue(*uCount, saleData, "", "", uId, "5", "169", "新增线索", "主动咨询客服留资客户", company, name, gconv.String((*uCount)["name"]), phone, "", "", "", "", "", "", gconv.String((*uCount)["seat_number"]), "", gconv.Int64((*uCount)["position_id"]), "", "", "", []string{}, "", isGroup, isCommerce, false, demand)
+				//UpdateClue(*uCount, saleData, "", "", uId, "5", "169", "新增线索", "主动咨询客服留资客户", company, name, gconv.String((*uCount)["name"]), phone, "", "", "", "", "", "", gconv.String((*uCount)["seat_number"]), "", gconv.Int64((*uCount)["position_id"]), "", "", "", []string{}, "", isGroup, isCommerce, false, demand)
+				UpdateClue(*uCount, saleData, "", "", uId, "5", "169", "新增线索", "主动咨询客服留资客户", company, name, gconv.String((*uCount)["name"]), phone, "", "", "", "", "", "", gconv.String((*uCount)["seat_number"]), "", gconv.Int64((*uCount)["position_id"]), "", "", "", []string{}, "", isGroup, isCommerce, false)
 				data = map[string]interface{}{
 					"type":        "kc",
 					"position_id": (*customerMap)["position_id"],
@@ -117,7 +118,7 @@ func WorkDataHandle(company, phone, demand, name, product string, acceptanceData
 					log.Println(positionId, "用户查询失败")
 					return false
 				}
-				UpdateClue(*uCount, saleData, "", "", uId, "5", "169", "新增线索", "主动咨询客服留资客户", company, name, gconv.String(data["name"]), phone, "", "", "", "", "", "", gconv.String(data["seat_number"]), "", gconv.Int64(data["position_id"]), "", "", "", []string{}, "", isGroup, isCommerce, true, demand)
+				UpdateClue(*uCount, saleData, "", "", uId, "5", "169", "新增线索", "主动咨询客服留资客户", company, name, gconv.String(data["name"]), phone, "", "", "", "", "", "", gconv.String(data["seat_number"]), "", gconv.Int64(data["position_id"]), "", "", "", []string{}, "", isGroup, isCommerce, true)
 			} else {
 				ok, data, saleData = FindPosition(positionId, trailstatus, gconv.String(acceptanceData["creator_time"]))
 				if !ok {
@@ -125,9 +126,9 @@ func WorkDataHandle(company, phone, demand, name, product string, acceptanceData
 					return false
 				}
 				if gconv.Int64(data["position_id"]) == positionId {
-					UpdateClue(*uCount, saleData, "", "", uId, "5", "169", "新增线索", "主动咨询客服留资客户", company, name, gconv.String(data["name"]), phone, "", "", "", "", "", "", gconv.String(data["seat_number"]), "", gconv.Int64(data["position_id"]), "", "", "", []string{}, "", isGroup, isCommerce, false, demand)
+					UpdateClue(*uCount, saleData, "", "", uId, "5", "169", "新增线索", "主动咨询客服留资客户", company, name, gconv.String(data["name"]), phone, "", "", "", "", "", "", gconv.String(data["seat_number"]), "", gconv.Int64(data["position_id"]), "", "", "", []string{}, "", isGroup, isCommerce, false)
 				} else {
-					UpdateClue(*uCount, saleData, "", "", uId, "5", "169", "新增线索", "主动咨询客服留资客户", company, name, gconv.String(data["name"]), phone, "", "", "", "", "", "", gconv.String(data["seat_number"]), "", gconv.Int64(data["position_id"]), "", "", "", []string{}, "", isGroup, isCommerce, true, demand)
+					UpdateClue(*uCount, saleData, "", "", uId, "5", "169", "新增线索", "主动咨询客服留资客户", company, name, gconv.String(data["name"]), phone, "", "", "", "", "", "", gconv.String(data["seat_number"]), "", gconv.Int64(data["position_id"]), "", "", "", []string{}, "", isGroup, isCommerce, true)
 				}
 
 			}