Selaa lähdekoodia

Merge branch 'dev_v1.5.23_wh' of jianyu/datatools into feature/v1.5.23

王浩 7 kuukautta sitten
vanhempi
commit
f61d30aeac
1 muutettua tiedostoa jossa 101 lisäystä ja 10 poistoa
  1. 101 10
      clueSync/job.go

+ 101 - 10
clueSync/job.go

@@ -349,6 +349,9 @@ func FormatData(data map[string]interface{}, item string) (bool, bool, bool) {
 					old_cluename := common.ObjToString((*uCount)["cluename"])
 					old_top_cluetype := common.ObjToString((*uCount)["top_cluetype"])
 					old_sub_cluetype := common.ObjToString((*uCount)["sub_cluetype"])
+					labelChangeTime := gconv.String((*uCount)["labelChangeTime"])
+					label := gconv.Int64((*uCount)["label"])
+					trailstatusCode := gconv.String((*uCount)["trailstatus"])
 					clueUpdateData := map[string]interface{}{}
 					if old_name != name && name != "" {
 						clueUpdateData["name"] = name
@@ -356,6 +359,7 @@ func FormatData(data map[string]interface{}, item string) (bool, bool, bool) {
 							"clue_id":      clueId,
 							"change_field": "name",
 							"position_id":  0,
+							"seatNumber":   nil,
 							"change_type":  "基本信息变更",
 							"old_value":    common.If(old_name != "", old_name, "/"),
 							"new_value":    common.If(name != "", name, "/"),
@@ -459,7 +463,7 @@ func FormatData(data map[string]interface{}, item string) (bool, bool, bool) {
 						clueUpdateData["sub_cluetype"] = sub_cluetype //新的线索名不为空才替换
 						TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
 							"clue_id":      clueId,
-							"change_field": "sub_cluetype",
+							"change_field": "sub_cluetype", //111
 							"position_id":  0,
 							"change_type":  "基本信息变更",
 							"old_value":    common.If(old_subname != "", old_subname, "/"),
@@ -467,6 +471,8 @@ func FormatData(data map[string]interface{}, item string) (bool, bool, bool) {
 							"createtime":   nowTime,
 							"BCPCID":       BCPCID,
 							"operator_id":  -1})
+						//标签处理
+						LabelHandel(label, 2, uId, level, trailstatusCode, labelChangeTime)
 					}
 					clueUpdateData["company_nature"] = isGroup
 					clueUpdateData["company_verification"] = isCommerce
@@ -496,7 +502,6 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
 		if cluename == "" {
 			cluename = phone
 		}
-
 		clueId = TiDb.InsertByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{
 			"userid":               userId,
 			"uid":                  uId,
@@ -529,6 +534,8 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
 			"remark":               remark,
 			"customer_demand":      demand,
 			"FREEZE_TIME":          nowTime,
+			"label":                1,
+			"labelChangeTime":      time.Now().Format("2006-01-02"),
 		})
 		uodateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 			"clue_id":     clueId,
@@ -584,7 +591,7 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
 		uodateId6 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 			"clue_id":      clueId,
 			"position_id":  positionId,
-			"change_field": "sub_cluetype",
+			"change_field": "sub_cluetype", //222
 			"change_type":  "基本信息变更",
 			"old_value":    "/",
 			"new_value":    subname,
@@ -652,6 +659,8 @@ func SaveClue0(item, userId, uId, top_cluetype, sub_cluetype, topname, subname,
 			"company_verification": isCommerce,
 			"remark":               remark,
 			"FREEZE_TIME":          nowTime,
+			"label":                1,
+			"labelChangeTime":      time.Now().Format("2006-01-02"),
 		})
 		uodateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 			"clue_id":     clueId,
@@ -730,6 +739,8 @@ func WorkUpdateClue(data map[string]interface{}, saleData []map[string]interface
 	old_cluename := common.ObjToString(data["cluename"])
 	old_top_cluetype := common.ObjToString(data["top_cluetype"])
 	old_sub_cluetype := common.ObjToString(data["sub_cluetype"])
+	oldLabelChangeTime := gconv.String(data["labelChangeTime"])
+	label := gconv.Int64(data["label"])
 	old_topname, old_subname := "", ""
 	is_transfer := common.IntAll(data["is_transfer"])
 	if taskstatus == 1 || is_task == 0 {
@@ -931,7 +942,6 @@ func WorkUpdateClue(data map[string]interface{}, saleData []map[string]interface
 		//线索
 		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 {
@@ -1143,7 +1153,6 @@ func WorkUpdateClue(data map[string]interface{}, saleData []map[string]interface
 				}
 			}
 		}
-
 		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 {
@@ -1249,11 +1258,12 @@ func WorkUpdateClue(data map[string]interface{}, saleData []map[string]interface
 				"operator_id":  -1,
 			})
 		}
+		newPositionId := gconv.Int64(common.If(trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400, -1, common.If(trailstatus == "00" || is_assign == 0, positionId, common.If(is_assign == 1, positionId, common.If(is_assign == 1, positionId, common.Int64All(data["position_id"]))))))
 		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.If(is_assign == 1, positionId, common.If(is_assign == 1, positionId, common.Int64All(data["position_id"]))))),
-				"change_field": "sub_cluetype",
+				"change_field": "sub_cluetype", //333
 				"change_type":  "基本信息变更",
 				"old_value":    common.If(old_subname != "", old_subname, "/"),
 				"new_value":    common.If(subname != "", subname, "/"),
@@ -1261,6 +1271,16 @@ func WorkUpdateClue(data map[string]interface{}, saleData []map[string]interface
 				"BCPCID":       BCPCID,
 				"operator_id":  -1,
 			})
+			//标签处理
+			if old_position_id != positionId && newPositionId > 0 {
+				LabelHandel(label, 1, uId, level, gconv.String(clueUpdateData["trailstatus"]), oldLabelChangeTime)
+			} else {
+				LabelHandel(label, 2, uId, level, gconv.String(clueUpdateData["trailstatus"]), oldLabelChangeTime)
+			}
+		} else {
+			if old_position_id != positionId && newPositionId > 0 {
+				LabelHandel(label, 1, uId, level, gconv.String(clueUpdateData["trailstatus"]), oldLabelChangeTime)
+			}
 		}
 		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
 	}) {
@@ -1314,6 +1334,8 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 	old_sub_cluetype := common.ObjToString(data["sub_cluetype"])
 	old_topname, old_subname := "", ""
 	is_transfer := common.IntAll(data["is_transfer"])
+	oldLabelChangeTime := gconv.String(data["labelChangeTime"])
+	label := gconv.Int64(data["label"])
 	if taskstatus == 1 || is_task == 0 {
 		taskTime = common.ObjToString(common.If(item != "users", nowTime, nowTimes)) //任务时间,正常的是当前时间,新用户是当前时间+12个小时
 	} else {
@@ -1442,6 +1464,9 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 			Phone:                phone,
 			Source:               source,
 			PositionId:           old_position_id,
+			Level:                level,
+			LabelChangeTime:      oldLabelChangeTime,
+			Label:                label,
 		}
 		return clueInfoUpdate(clueMapEntity)
 
@@ -1867,11 +1892,12 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 				"operator_id":  -1,
 			})
 		}
+		newPositionId := gconv.Int64(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"]))))
 		if old_sub_cluetype != sub_cluetype {
-			updateId13 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+			updateId13 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_re cord", 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_field": "sub_cluetype", //444
 				"change_type":  "基本信息变更",
 				"old_value":    common.If(old_subname != "", old_subname, "/"),
 				"new_value":    common.If(subname != "", subname, "/"),
@@ -1879,6 +1905,15 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 				"BCPCID":       BCPCID,
 				"operator_id":  -1,
 			})
+			if old_position_id != newPositionId && newPositionId > 0 {
+				LabelHandel(label, 1, uId, level, gconv.String(clueUpdateData["trailstatus"]), oldLabelChangeTime)
+			} else {
+				LabelHandel(label, 2, uId, level, gconv.String(clueUpdateData["trailstatus"]), oldLabelChangeTime)
+			}
+		} else {
+			if old_position_id != newPositionId && newPositionId > 0 {
+				LabelHandel(label, 1, uId, level, gconv.String(clueUpdateData["trailstatus"]), oldLabelChangeTime)
+			}
 		}
 		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
 	}) {
@@ -1931,6 +1966,9 @@ type ClueMapEntity struct {
 	Phone                string
 	Source               string
 	PositionId           int64
+	Label                int64
+	LabelChangeTime      string
+	Level                string
 }
 
 // 基本信息变更
@@ -2061,11 +2099,11 @@ func clueInfoUpdate(data ClueMapEntity) bool {
 				"operator_id":  -1,
 			})
 		}
-		if data.OldTopCluetype != data.NewTopCluetype {
+		if data.OldSubCluetype != data.OldSubCluetype {
 			updateId13 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 				"clue_id":      data.ClueId,
 				"position_id":  data.PositionId,
-				"change_field": "sub_cluetype",
+				"change_field": "sub_cluetype", //555
 				"change_type":  "基本信息变更",
 				"old_value":    common.If(old_subname != "", old_subname, "/"),
 				"new_value":    common.If(data.Subname != "", data.Subname, "/"),
@@ -2073,6 +2111,7 @@ func clueInfoUpdate(data ClueMapEntity) bool {
 				"BCPCID":       BCPCID,
 				"operator_id":  -1,
 			})
+			LabelHandel(data.Label, 1, data.UId, data.Level, data.Trailstatus, data.LabelChangeTime)
 		}
 		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
 	}) {
@@ -2094,3 +2133,55 @@ func clueInfoUpdate(data ClueMapEntity) bool {
 		return false
 	}
 }
+
+// 线索标签修改 label  labelChangeTime
+func LabelHandel(oldlabelType, labelType int64, uId, level, trailstatusCode, labelChangeTime string) {
+	log.Println("线索标签修改:", oldlabelType, labelType, uId, level, trailstatusCode, labelChangeTime)
+	//先查询以前什么类型
+	if trailstatusCode != "01" {
+		return
+	}
+	updateLabelType := int64(0)
+	nowStr := time.Now().Format("2006-01-02")
+	if labelType == 1 {
+		//直接更新
+		if labelChangeTime == nowStr {
+			if oldlabelType != 1 {
+				updateLabelType = labelType
+			}
+		} else {
+			updateLabelType = labelType
+		}
+	} else if labelType == 2 {
+		if level != "A" && level != "level" && level != "C" {
+			return
+		}
+		//查询以前是什么数据
+		if labelChangeTime == nowStr {
+			//同一天修改过
+			if oldlabelType != 0 {
+				updateLabelType = labelType
+			}
+		} else {
+			updateLabelType = labelType
+		}
+	} else {
+		//查询以前是什么数据
+		if labelChangeTime == nowStr {
+			//同一天修改过
+			if oldlabelType != 3 {
+				updateLabelType = oldlabelType
+			}
+		} else {
+			updateLabelType = labelType
+		}
+	}
+	if updateLabelType > 0 {
+		TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{
+			"uid": uId,
+		}, map[string]interface{}{
+			"label":           updateLabelType,
+			"labelChangeTime": nowStr,
+		})
+	}
+}