Browse Source

动态记录新增

WH01243 5 months ago
parent
commit
62e624e429
5 changed files with 242 additions and 1186 deletions
  1. 18 160
      clueSync/autoTask.go
  2. 4 18
      clueSync/everything.go
  3. 99 740
      clueSync/job.go
  4. 86 23
      clueSync/jobutil.go
  5. 35 245
      clueSync/kc.go

+ 18 - 160
clueSync/autoTask.go

@@ -103,15 +103,7 @@ func autoTask() {
 					"taskstatus": 0,
 					"tasksource": "超时未跟进自动加车",
 				}) {
-					TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-						"clue_id":     clueId,
-						"position_id": position_id,
-						"change_type": "加入任务车",
-						"new_value":   "超时未跟进自动加车",
-						"createtime":  nowTime,
-						"BCPCID":      common.GetRandom(32),
-						"operator_id": -1,
-					})
+					AddChangeRecord(nil, clueId, position_id, "", "加入任务车", "超时未跟进自动加车", "", nowTime, -1)
 				}
 			}
 			return true
@@ -138,15 +130,7 @@ func autoTasks() {
 						"taskstatus": 0,
 						"tasksource": "即将到达下次跟进时间",
 					}) {
-						TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-							"clue_id":     clueId,
-							"position_id": position_id,
-							"change_type": "加入任务车",
-							"new_value":   "即将到达下次跟进时间",
-							"createtime":  nowTime2,
-							"BCPCID":      common.GetRandom(32),
-							"operator_id": -1,
-						})
+						AddChangeRecord(nil, clueId, position_id, "", "加入任务车", "", "即将到达下次跟进时间", nowTime2, -1)
 					}
 				}
 			}
@@ -199,26 +183,8 @@ GROUP BY
 			if TiDb.ExecTx("退出线索", func(tx *sql.Tx) bool {
 				positionMap[positionId] = true
 				recordId := TiDb.UpdateOrDeleteBySqlByTx(tx, `UPDATE dwd_f_crm_clue_info SET is_assign=0,position_id=null,seatNumber=null,updatetime = ?,comeinsource_open=null,level_open=null,next_trail_time=null,is_task=null,tasktime=null,taskstatus=null,comeinsource_private=null,tasksource=null WHERE id = ?`, nowTime, clueId) //,start_trail_time=null,content=null
-				recordId2 := TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":     clueId,
-					"position_id": positionId,
-					"change_type": "退回公海",
-					"new_value":   "所有人员私海已达上限",
-					"createtime":  nowTime,
-					"BCPCID":      common.GetRandom(32),
-					"operator_id": -1,
-				})
-				recordId1 := 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":    GetPositionName(seatNumber),
-					"new_value":    "/",
-					"createtime":   nowTime,
-					"BCPCID":       common.GetRandom(32),
-					"operator_id":  -1,
-				})
+				recordId2 := AddChangeRecord(tx, clueId, positionId, "", "退回公海", "所有人员私海已达上限", "", nowTime, -1)
+				recordId1 := AddChangeRecord(tx, clueId, positionId, "position_id", "所属人变更", "/", GetPositionName(seatNumber), nowTime, -1)
 				return recordId > -1 && recordId1 > -1 && recordId2 > -1
 			}) {
 				//发送消息,找wjh
@@ -255,46 +221,10 @@ func autoExitSea() {
 				// } else if is_assign == 0 {
 				// 	ok1 = TiDb.DeleteByTx(tx, "dwd_f_crm_open_sea", map[string]interface{}{"clue_id": clueId})
 				// }
-				recordId1 := 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":    GetPositionName(seatNumber),
-					"new_value":    "/",
-					"createtime":   nowTime,
-					"BCPCID":       common.GetRandom(32),
-					"operator_id":  -1,
-				})
-				recordId2 := 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,
-				})
-				recordId3 := TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":     clueId,
-					"position_id": positionId,
-					"change_type": "退出任务车",
-					"new_value":   "空号停机自动从线索池删除",
-					"createtime":  nowTime,
-					"BCPCID":      common.GetRandom(32),
-					"operator_id": -1,
-				})
-				recordId4 := TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":     clueId,
-					"position_id": positionId,
-					"change_type": "退出公海",
-					"new_value":   "空号停机自动从线索池删除",
-					"createtime":  nowTime,
-					"BCPCID":      common.GetRandom(32),
-					"operator_id": -1,
-				})
+				recordId1 := AddChangeRecord(tx, clueId, positionId, "position_id", "所属人变更", GetPositionName(seatNumber), "/", nowTime, -1)
+				recordId2 := AddChangeRecord(tx, clueId, positionId, "trailstatus", "基本信息变更", "流失", "空号停机", nowTime, -1)
+				recordId3 := AddChangeRecord(tx, clueId, positionId, "", "退出任务车", "空号停机自动从线索池删除", "", nowTime, -1)
+				recordId4 := AddChangeRecord(tx, clueId, positionId, "trailstatus", "退出公海", "空号停机自动从线索池删除", "", nowTime, -1)
 				return recordId > -1 && recordId1 > -1 && recordId2 > -1 && recordId3 > -1 && recordId4 > -1
 			}) {
 				log.Println("自动退出线索成功")
@@ -314,46 +244,10 @@ func autoExitSea() {
 			// is_assign := common.IntAll(v["is_assign"])
 			if TiDb.ExecTx("自动退海", func(tx *sql.Tx) bool {
 				recordId := TiDb.UpdateOrDeleteBySqlByTx(tx, `UPDATE dwd_f_crm_clue_info SET is_assign=0,position_id=null,seatNumber=null,updatetime = ?,comeintime_open = ?,comeinsource_open=?,level_open=4,next_trail_time=null,is_task=null,tasktime=null,taskstatus=null,comeinsource_private=null,tasksource=null WHERE id = ?`, nowTime, nowTime, common.If(trailstatus == "00", 8, 11), clueId) //,content=null,start_trail_time=null
-				recordId1 := 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":    GetPositionName(seatNumber),
-					"new_value":    "/",
-					"createtime":   nowTime,
-					"BCPCID":       common.GetRandom(32),
-					"operator_id":  -1,
-				})
-				recordId2 := 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":    common.If(trailstatus == "00", "无意向客户", "拒绝客户"),
-					"new_value":    "流失",
-					"createtime":   nowTime,
-					"BCPCID":       common.GetRandom(32),
-					"operator_id":  -1,
-				})
-				recordId3 := TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":     clueId,
-					"position_id": positionId,
-					"change_type": "退出任务车",
-					"new_value":   common.If(trailstatus == "00", "无意向客户自动退回公海", "拒绝客户自动退回公海"),
-					"createtime":  nowTime,
-					"BCPCID":      common.GetRandom(32),
-					"operator_id": -1,
-				})
-				recordId4 := TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":     clueId,
-					"position_id": positionId,
-					"change_type": "退回公海",
-					"new_value":   common.If(trailstatus == "00", "无意向客户自动退回公海", "拒绝客户自动退回公海"),
-					"createtime":  nowTime,
-					"BCPCID":      common.GetRandom(32),
-					"operator_id": -1,
-				})
+				recordId1 := AddChangeRecord(tx, clueId, positionId, "position_id", "所属人变更", "/", GetPositionName(seatNumber), nowTime, -1)
+				recordId2 := AddChangeRecord(tx, clueId, positionId, "trailstatus", "基本信息变更", "流失", gconv.String(common.If(trailstatus == "00", "无意向客户", "拒绝客户")), nowTime, -1)
+				recordId3 := AddChangeRecord(tx, clueId, positionId, "", "退出任务车", gconv.String(common.If(trailstatus == "00", "无意向客户自动退回公海", "拒绝客户自动退回公海")), "", nowTime, -1)
+				recordId4 := AddChangeRecord(tx, clueId, positionId, "", "退回公海", gconv.String(common.If(trailstatus == "00", "无意向客户自动退回公海", "拒绝客户自动退回公海")), "", nowTime, -1)
 				return recordId > -1 && recordId1 > -1 && recordId2 > -1 && recordId3 > -1 && recordId4 > -1
 			}) {
 				log.Println("自动退出私海成功")
@@ -409,6 +303,7 @@ func Thaw() {
 				freezeInt64 = t.Unix()
 			}
 			if freezeInt64 < nowTime.Unix() {
+				nowTime := time.Now().Format(date.Date_Full_Layout)
 				//超三天处理
 				//分配状态改改
 				if TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{
@@ -416,55 +311,18 @@ func Thaw() {
 					"position_id": 0,
 					"seatNumber":  nil,
 				}) {
-					TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-						"clue_id":      clueId,
-						"position_id":  0,
-						"change_field": "position_id",
-						"change_type":  "所属人变更",
-						"old_value":    nameMap[positionId],
-						"new_value":    "/",
-						"createtime":   time.Now().Format(date.Date_Full_Layout),
-						"BCPCID":       common.GetRandom(32),
-						"operator_id":  -1,
-					})
+					AddChangeRecord(nil, clueId, positionId, "position_id", "所属人变更", "/", nameMap[positionId], nowTime, -1)
 				}
-				TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":      clueId,
-					"position_id":  0,
-					"change_field": "position_id",
-					"change_type":  "线索解冻",
-					"new_value":    "自动退回公海",
-					"createtime":   time.Now().Format(date.Date_Full_Layout),
-					"BCPCID":       common.GetRandom(32),
-					"operator_id":  -1,
-				})
+				AddChangeRecord(nil, clueId, positionId, "position_id", "线索解冻", "自动退回公海", "", nowTime, -1)
 			} else {
 				if !FindUpperLimit(gconv.String(positionId), "", false) {
+					nowTime := time.Now().Format(date.Date_Full_Layout)
 					if TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{
 						"is_assign": 1,
 					}) {
-						TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-							"clue_id":      clueId,
-							"position_id":  positionId,
-							"change_field": "position_id",
-							"change_type":  "所属人变更",
-							"old_value":    "/",
-							"new_value":    nameMap[positionId],
-							"createtime":   time.Now().Format(date.Date_Full_Layout),
-							"BCPCID":       common.GetRandom(32),
-							"operator_id":  -1,
-						})
+						AddChangeRecord(nil, clueId, positionId, "position_id", "所属人变更", nameMap[positionId], "/", nowTime, -1)
 					}
-					TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-						"clue_id":      clueId,
-						"position_id":  positionId,
-						"change_field": "position_id",
-						"change_type":  "线索解冻",
-						"new_value":    "销售人员私海线索已释放",
-						"createtime":   time.Now().Format(date.Date_Full_Layout),
-						"BCPCID":       common.GetRandom(32),
-						"operator_id":  -1,
-					})
+					AddChangeRecord(nil, clueId, positionId, "position_id", "线索解冻", "销售人员私海线索已释放", "", nowTime, -1)
 				}
 			}
 		}

+ 4 - 18
clueSync/everything.go

@@ -171,15 +171,7 @@ func everythingSync() {
 			if clueId > 0 && is_assign != 1 && is_transfer != 1 {
 				TiDb.Update("dwd_f_userbase_baseinfo", map[string]interface{}{"userid": user_id}, map[string]interface{}{"belong_to": "0301"})
 				TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone}, map[string]interface{}{"is_assign": -1})
-				TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":     clueId,
-					"position_id": common.If(position_id > 0, position_id, -1),
-					"change_type": "退出公海",
-					"new_value":   "通过合作渠道一切就好" + fmt.Sprint(common.If(user_mold == 1 || user_mold == 2, "登录", "注册")),
-					"createtime":  nowTime,
-					"BCPCID":      common.GetRandom(32),
-					"operator_id": -1,
-				})
+				AddChangeRecord(nil, clueId, gconv.Int64(common.If(position_id > 0, position_id, -1)), "", "退出公海", "通过合作渠道一切就好"+fmt.Sprint(common.If(user_mold == 1 || user_mold == 2, "登录", "注册")), "", nowTime, "", -1)
 			}
 		}
 		cfg.LastEverythingTime = common.ObjToString((*data)[len(*data)-1]["create_time"])
@@ -320,15 +312,9 @@ func saveEverything(user_id, phone, item, sourceName, sourceCode string) bool {
 	}
 	if clueId > 0 && is_assign != 1 && is_transfer != 1 {
 		TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone}, map[string]interface{}{"is_assign": -1})
-		TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-			"clue_id":     clueId,
-			"position_id": common.If(position_id > 0, position_id, -1),
-			"change_type": "退出公海",
-			"new_value":   "通过合作渠道一切就好登录",
-			"createtime":  nowTime,
-			"BCPCID":      common.GetRandom(32),
-			"operator_id": -1,
-		})
+		AddChangeRecord(nil, clueId, gconv.Int64(common.If(position_id > 0, position_id, -1)), "", "退出公海",
+			"通过合作渠道一切就好登录", "", nowTime, "", -1)
+
 	} else if is_assign == 1 || is_transfer == 1 {
 		isOk = true
 	}

+ 99 - 740
clueSync/job.go

@@ -369,82 +369,27 @@ func FormatData(data map[string]interface{}, item string) (bool, bool, bool) {
 					clueUpdateData := map[string]interface{}{}
 					if old_name != name && name != "" {
 						clueUpdateData["name"] = name
-						TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-							"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, "/"),
-							"createtime":   nowTime,
-							"BCPCID":       BCPCID,
-							"operator_id":  -1})
+						AddChangeRecord(nil, clueId, position_id, "name", "基本信息变更", gconv.String(common.If(name != "", name, "/")), gconv.String(common.If(old_name != "", old_name, "/")), nowTime, BCPCID, -1)
 					}
 					if old_position != position && position != "" {
 						clueUpdateData["position"] = position
-						TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-							"clue_id":      clueId,
-							"change_field": "position",
-							"position_id":  0,
-							"change_type":  "基本信息变更",
-							"old_value":    common.If(old_position != "", old_position, "/"),
-							"new_value":    common.If(position != "", position, "/"),
-							"createtime":   nowTime,
-							"BCPCID":       BCPCID,
-							"operator_id":  -1})
+						AddChangeRecord(nil, clueId, position_id, "position", "基本信息变更", gconv.String(common.If(position != "", position, "/")), gconv.String(common.If(old_position != "", old_position, "/")), nowTime, BCPCID, -1)
 					}
 					if old_department != department && department != "" {
 						clueUpdateData["department"] = department
-						TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-							"clue_id":      clueId,
-							"change_field": "department",
-							"position_id":  0,
-							"change_type":  "基本信息变更",
-							"old_value":    common.If(old_department != "", old_department, "/"),
-							"new_value":    common.If(department != "", department, "/"),
-							"createtime":   nowTime,
-							"BCPCID":       BCPCID,
-							"operator_id":  -1})
+						AddChangeRecord(nil, clueId, position_id, "department", "基本信息变更", gconv.String(common.If(department != "", department, "/")), gconv.String(common.If(old_department != "", old_department, "/")), nowTime, BCPCID, -1)
 					}
 					if old_follow_project_area != follow_project_area && follow_project_area != "" {
 						clueUpdateData["follow_project_area"] = follow_project_area
-						TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-							"clue_id":      clueId,
-							"change_field": "follow_project_area",
-							"position_id":  0,
-							"change_type":  "基本信息变更",
-							"old_value":    common.If(old_follow_project_area != "", old_follow_project_area, "/"),
-							"new_value":    common.If(follow_project_area != "", follow_project_area, "/"),
-							"createtime":   nowTime,
-							"BCPCID":       BCPCID,
-							"operator_id":  -1})
+						AddChangeRecord(nil, clueId, position_id, "follow_project_area", "基本信息变更", gconv.String(common.If(follow_project_area != "", follow_project_area, "/")), gconv.String(common.If(old_follow_project_area != "", old_follow_project_area, "/")), nowTime, BCPCID, -1)
 					}
 					if old_role != role && role != "" {
-						TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-							"clue_id":      clueId,
-							"change_field": "role",
-							"change_type":  "基本信息变更",
-							"old_value":    common.If(old_role != "", old_role, "/"),
-							"new_value":    common.If(role != "", role, "/"),
-							"createtime":   nowTime,
-							"position_id":  0,
-							"BCPCID":       BCPCID,
-							"operator_id":  -1})
+						AddChangeRecord(nil, clueId, position_id, "role", "基本信息变更", gconv.String(common.If(role != "", role, "/")), gconv.String(common.If(old_role != "", old_role, "/")), nowTime, BCPCID, -1)
 						clueUpdateData["role"] = role
 					}
 					if old_cluename != cluename && cluename != "" {
 						clueUpdateData["cluename"] = cluename //新的线索名不为空才替换
-						TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-							"clue_id":      clueId,
-							"change_field": "cluename",
-							"change_type":  "基本信息变更",
-							"old_value":    common.If(old_cluename != "", old_cluename, "/"),
-							"new_value":    common.If(cluename != "", cluename, "/"),
-							"createtime":   nowTime,
-							"BCPCID":       BCPCID,
-							"position_id":  0,
-							"operator_id":  -1})
+						AddChangeRecord(nil, clueId, position_id, "cluename", "基本信息变更", gconv.String(common.If(cluename != "", cluename, "/")), gconv.String(common.If(old_cluename != "", old_cluename, "/")), nowTime, BCPCID, -1)
 					}
 					old_topname := ""
 					old_subname := ""
@@ -462,29 +407,11 @@ func FormatData(data map[string]interface{}, item string) (bool, bool, bool) {
 					}
 					if old_top_cluetype != top_cluetype && top_cluetype != "" {
 						clueUpdateData["top_cluetype"] = top_cluetype //新的线索名不为空才替换
-						TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-							"clue_id":      clueId,
-							"change_field": "top_cluetype",
-							"position_id":  0,
-							"change_type":  "基本信息变更",
-							"old_value":    common.If(old_topname != "", old_topname, "/"),
-							"new_value":    common.If(topname != "", topname, "/"),
-							"createtime":   nowTime,
-							"BCPCID":       BCPCID,
-							"operator_id":  -1})
+						AddChangeRecord(nil, clueId, position_id, "top_cluetype", "基本信息变更", gconv.String(common.If(old_topname != "", old_topname, "/")), gconv.String(common.If(old_topname != "", old_topname, "/")), nowTime, BCPCID, -1)
 					}
 					if old_sub_cluetype != sub_cluetype && sub_cluetype != "" {
 						clueUpdateData["sub_cluetype"] = sub_cluetype //新的线索名不为空才替换
-						TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-							"clue_id":      clueId,
-							"change_field": "sub_cluetype", //111
-							"position_id":  0,
-							"change_type":  "基本信息变更",
-							"old_value":    common.If(old_subname != "", old_subname, "/"),
-							"new_value":    common.If(subname != "", subname, "/"),
-							"createtime":   nowTime,
-							"BCPCID":       BCPCID,
-							"operator_id":  -1})
+						AddChangeRecord(nil, clueId, position_id, "sub_cluetype", "基本信息变更", gconv.String(common.If(old_subname != "", old_subname, "/")), gconv.String(common.If(old_subname != "", old_subname, "/")), nowTime, BCPCID, -1)
 						//标签处理
 						LabelHandel(nil, label, 2, uId, level, trailstatusCode, gconv.String(clueUpdateData["trailstatus"]), 1)
 					}
@@ -505,7 +432,7 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
 	log.Println("线索修改前", item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, departments, industry, follow_project_area, role, seatNumber, positionId, source, sourceCode, remark)
 	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")
-	clueId, uodateId1, uodateId2, uodateId3, uodateId4, uodateId5, uodateId6 := int64(0), int64(0), int64(0), int64(0), int64(0), int64(0), int64(0)
+	clueId, updateId1, updateId2, updateId3, updateId4, updateId5, updateId6 := int64(0), int64(0), int64(0), int64(0), int64(0), int64(0), int64(0)
 	if TiDb.ExecTx("保存线索", func(tx *sql.Tx) bool {
 		keywords := ""
 		if sourceCode == "app_xzcyh" {
@@ -551,70 +478,14 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
 			"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,
-			"position_id": positionId,
-			"change_type": "创建线索",
-			"new_value":   "系统自动创建",
-			"createtime":  nowTime,
-			"BCPCID":      common.GetRandom(32),
-			"operator_id": -1,
-		})
-		uodateId2 = 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":    "/",
-			"new_value":    saleName,
-			"createtime":   nowTime,
-			"BCPCID":       common.GetRandom(32),
-			"operator_id":  -1,
-		})
-		uodateId3 = 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,
-		})
-		uodateId4 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-			"clue_id":     clueId,
-			"position_id": positionId,
-			"change_type": "加入任务车",
-			"new_value":   "线索自动分配" + "-" + topname + "-" + subname,
-			"createtime":  nowTime,
-			"BCPCID":      common.GetRandom(32),
-			"operator_id": -1,
-		})
-		uodateId5 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-			"clue_id":      clueId,
-			"position_id":  positionId,
-			"change_field": "top_cluetype",
-			"change_type":  "基本信息变更",
-			"old_value":    "/",
-			"new_value":    topname,
-			"createtime":   nowTime,
-			"BCPCID":       common.GetRandom(32),
-			"operator_id":  -1,
-		})
-		uodateId6 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-			"clue_id":      clueId,
-			"position_id":  positionId,
-			"change_field": "sub_cluetype", //222
-			"change_type":  "基本信息变更",
-			"old_value":    "/",
-			"new_value":    subname,
-			"createtime":   nowTime,
-			"BCPCID":       common.GetRandom(32),
-			"operator_id":  -1,
-		})
+		updateId1 = AddChangeRecord(tx, clueId, clueId, "", "创建线索", "系统自动创建", "", nowTime, "", -1)
+		updateId2 = AddChangeRecord(tx, clueId, clueId, "position_id", "所属人变更", saleName, "/", nowTime, "", -1)
+		updateId3 = AddChangeRecord(tx, clueId, clueId, "trailstatus", "基本信息变更", "新增", "商机线索", nowTime, "", -1)
+		updateId4 = AddChangeRecord(tx, clueId, clueId, "", "加入任务车", "线索自动分配"+"-"+topname+"-"+subname, "", nowTime, "", -1)
+		updateId5 = AddChangeRecord(tx, clueId, clueId, "top_cluetype", "基本信息变更", "/", topname, nowTime, "", -1)
+		updateId6 = AddChangeRecord(tx, clueId, clueId, "sub_cluetype", "基本信息变更", "/", subname, nowTime, "", -1)
 		//冻结处理
-		return clueId > -1 && uodateId1 > -1 && uodateId2 > -1 && uodateId3 > -1 && uodateId4 > -1 && uodateId5 > -1 && uodateId6 > -1
+		return clueId > -1 && updateId1 > -1 && updateId2 > -1 && updateId3 > -1 && updateId4 > -1 && updateId5 > -1 && updateId6 > -1
 	}) {
 		log.Println("线索分配成功")
 		if TiDb.Count("dwd_f_userbase_contacts", map[string]interface{}{"phone": phone}) == 0 {
@@ -630,7 +501,7 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
 		}
 		return true
 	} else {
-		log.Println("线索分配失败!!!", clueId, uodateId1, uodateId2, uodateId3, uodateId4, uodateId5, uodateId6, " 用户信息 ", item, position, seatNumber, uId, userId, phone)
+		log.Println("线索分配失败!!!", clueId, updateId1, updateId2, updateId3, updateId4, updateId5, updateId6, " 用户信息 ", item, position, seatNumber, uId, userId, phone)
 		return false
 	}
 }
@@ -676,37 +547,9 @@ func SaveClue0(item, userId, uId, top_cluetype, sub_cluetype, topname, subname,
 			"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,
-			"position_id": positionId,
-			"change_type": "创建线索",
-			"new_value":   "系统自动创建",
-			"createtime":  nowTime,
-			"BCPCID":      common.GetRandom(32),
-			"operator_id": -1,
-		})
-		uodateId2 = 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":    "",
-			"new_value":    "/",
-			"createtime":   nowTime,
-			"BCPCID":       common.GetRandom(32),
-			"operator_id":  -1,
-		})
-		uodateId3 = 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,
-		})
+		uodateId1 = AddChangeRecord(nil, clueId, positionId, "", "创建线索", "系统自动创建", "", nowTime, "", -1)
+		uodateId2 = AddChangeRecord(nil, clueId, positionId, "position_id", "所属人变更", "/", "", nowTime, "", -1)
+		uodateId3 = AddChangeRecord(nil, clueId, positionId, "trailstatus", "基本信息变更", "新增", "商机线索", nowTime, "", -1)
 		return clueId > -1 && uodateId1 > -1 && uodateId2 > -1 && uodateId3 > -1
 	}) {
 		log.Println("线索分配成功")
@@ -958,162 +801,33 @@ func WorkUpdateClue(data map[string]interface{}, saleData []map[string]interface
 		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,
-				})
+				updateId1 = AddChangeRecord(nil, clueId, positionId, "position_id", "所属人变更", gconv.String(common.If(saleName != "", saleName, "/")), gconv.String(common.If(oldsaleName != "", oldsaleName, "/")), nowTime, "", -1)
+				updateId2 = AddChangeRecord(nil, clueId, positionId, "", "创建线索", "系统自动创建", "", nowTime, "", -1)
+				updateId3 = AddChangeRecord(nil, clueId, positionId, "trailstatus", "基本信息变更", "新增", CodeTrail[trailstatus], nowTime, "", -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,
-					})
+					updateId1 = AddChangeRecord(nil, clueId, positionId, "position_id", "所属人变更", gconv.String(common.If(saleName != "", saleName, "/")), gconv.String(common.If(oldsaleName != "", oldsaleName, "/")), nowTime, "", -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,
-					})
+					updateId1 = AddChangeRecord(nil, clueId, positionId, "position_id", "所属人变更", gconv.String(common.If(saleName != "", saleName, "/")), gconv.String(common.If(oldsaleName != "", oldsaleName, "/")), nowTime, "", -1)
+					updateId2 = AddChangeRecord(nil, clueId, positionId, "trailstatus", "基本信息变更", "流失", "无意向客户", nowTime, "", -1)
+					updateId3 = AddChangeRecord(nil, clueId, positionId, "trailstatus", "基本信息变更", "新增", "商机线索", nowTime, "", -1)
+					updateId4 = AddChangeRecord(nil, clueId, positionId, "trailstatus", "基本信息变更", "商机线索", "无意向客户", nowTime, "", -1)
 				}
 			}
 		} else if 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,
-				})
+				updateId1 = AddChangeRecord(nil, clueId, positionId, "position_id", "所属人变更", gconv.String(common.If(saleName != "", saleName, "/")), gconv.String(common.If(oldsaleName != "", oldsaleName, "/")), nowTime, "", -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,
-					})
+					updateId4 = AddChangeRecord(nil, clueId, positionId, "trailstatus", "基本信息变更", "商机线索", CodeTrail[trailstatus], nowTime, "", -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,
-				})
+				updateId3 = AddChangeRecord(nil, clueId, positionId, "trailstatus", "基本信息变更", "新增", "商机线索", nowTime, "", -1)
 			}
 		} else if is_assign == -1 {
-			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,
-			})
-			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,
-			})
+			updateId1 = AddChangeRecord(nil, clueId, positionId, "position_id", "所属人变更", gconv.String(common.If(saleName != "", saleName, "/")), gconv.String(common.If(oldsaleName != "", oldsaleName, "/")), nowTime, "", -1)
+			updateId4 = AddChangeRecord(nil, clueId, positionId, "trailstatus", "基本信息变更", "商机线索", CodeTrail[trailstatus], nowTime, "", -1)
 		} else if (pIsOk && old_cluename == cluename && cluename != "") && is_assign == 1 && positionId != old_position_id {
-			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,
-			})
+			updateId1 = AddChangeRecord(nil, clueId, positionId, "position_id", "所属人变更", gconv.String(common.If(saleName != "", saleName, "/")), gconv.String(common.If(oldsaleName != "", oldsaleName, "/")), nowTime, "", -1)
 		}
 		if recordCount <= 0 || is_assign == 0 {
 			if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
@@ -1125,15 +839,8 @@ func WorkUpdateClue(data map[string]interface{}, saleData []map[string]interface
 							kcpositionId := common.Int64All((*cdata)["position_id"])
 							tasksource := gconv.String((*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,
-							})
+							updateId5 = AddChangeRecord(tx, clueId, kcpositionId, "", "加入任务车",
+								"线上主动留资", "", nowTime, "", -1)
 							if taskstatus == 1 {
 								tasksource = "10"
 							} else {
@@ -1154,15 +861,7 @@ func WorkUpdateClue(data map[string]interface{}, saleData []map[string]interface
 						}
 					}
 				} else if !is_ok {
-					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 || is_assign == -1, positionId, common.Int64All(data["position_id"])),
-						"change_type": "加入任务车",
-						"new_value":   gconv.String(common.If(gconv.Int64(data["position_id"]) == 0, "线索自动分配", "线索来源自动更新")) + "-" + topname + "-" + subname,
-						"createtime":  nowTime,
-						"BCPCID":      common.GetRandom(32),
-						"operator_id": -1,
-					})
+					updateId5 = AddChangeRecord(tx, clueId, gconv.Int64(common.If(trailstatus == "00" || is_assign == 0 || is_assign == -1, positionId, common.Int64All(data["position_id"]))), "", "加入任务车", gconv.String(common.If(gconv.Int64(data["position_id"]) == 0, "线索自动分配", "线索来源自动更新"))+"-"+topname+"-"+subname, "", nowTime, "", -1)
 				}
 			}
 		}
@@ -1180,46 +879,20 @@ func WorkUpdateClue(data map[string]interface{}, saleData []map[string]interface
 		}
 		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.If(is_assign == 1, 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,
-				})
+				updateId6 = AddChangeRecord(tx, clueId, 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.Int64All(data["position_id"]))))),
+					"trailstatus", "基本信息变更", gconv.String(common.If(name != "", name, "/")), gconv.String(common.If(old_name != "", old_name, "/")), nowTime, "", -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.If(is_assign == 1, 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,
-				})
+				updateId7 = AddChangeRecord(tx, clueId, 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.Int64All(data["position_id"]))))),
+					"position", "基本信息变更", gconv.String(common.If(position != "", position, "/")), gconv.String(common.If(old_position != "", old_position, "/")), nowTime, "", -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.If(is_assign == 1, 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,
-				})
+				updateId8 = AddChangeRecord(tx, clueId, 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.Int64All(data["position_id"]))))),
+					"department", "基本信息变更", gconv.String(common.If(department != "", department, "/")), gconv.String(common.If(old_department != "", old_department, "/")), nowTime, "", -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.If(is_assign == 1, 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})
+				updateId9 = AddChangeRecord(tx, clueId, 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.Int64All(data["position_id"]))))),
+					"role", "基本信息变更", gconv.String(common.If(role != "", role, "/")), gconv.String(common.If(old_role != "", old_role, "/")), nowTime, "", -1)
 			}
 			if old_follow_project_area != follow_project_area && follow_project_area != "" {
 				old_area, old_area_arr := "", []string{}
@@ -1232,58 +905,24 @@ func WorkUpdateClue(data map[string]interface{}, saleData []map[string]interface
 				}
 				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.If(is_assign == 1, 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,
-				})
+				updateId10 = AddChangeRecord(tx, clueId, 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.Int64All(data["position_id"]))))),
+					"follow_project_area", "基本信息变更", gconv.String(common.If(new_area != "", new_area, "/")), gconv.String(common.If(old_area != "", old_area, "/")), nowTime, "", -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.If(is_assign == 1, 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,
-				})
+				updateId11 = AddChangeRecord(tx, clueId, 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.Int64All(data["position_id"]))))),
+					"cluename", "基本信息变更", gconv.String(common.If(cluename != "", cluename, "/")), gconv.String(common.If(old_cluename != "", old_cluename, "/")), nowTime, "", -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.If(is_assign == 1, 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,
-			})
+			updateId12 = AddChangeRecord(tx, clueId, 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.Int64All(data["position_id"]))))),
+				"top_cluetype", "基本信息变更", gconv.String(common.If(topname != "", topname, "/")), gconv.String(common.If(old_topname != "", old_topname, "/")), nowTime, "", -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", //333
-				"change_type":  "基本信息变更",
-				"old_value":    common.If(old_subname != "", old_subname, "/"),
-				"new_value":    common.If(subname != "", subname, "/"),
-				"createtime":   nowTime,
-				"BCPCID":       BCPCID,
-				"operator_id":  -1,
-			})
+			updateId12 = AddChangeRecord(tx, clueId, 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.Int64All(data["position_id"]))))),
+				"sub_cluetype", "基本信息变更", gconv.String(common.If(subname != "", subname, "/")), gconv.String(common.If(old_subname != "", old_subname, "/")), nowTime, "", -1)
 			//标签处理
 			if old_position_id != positionId && newPositionId > 0 {
 				LabelHandel(tx, label, 1, uId, level, trailstatus, gconv.String(clueUpdateData["trailstatus"]), 0)
@@ -1589,86 +1228,17 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 				positionId = 0
 				seatNumber = ""
 			} 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,
-				})
+				updateId1 = AddChangeRecord(tx, clueId, positionId, "position_id", "所属人变更", gconv.String(common.If(saleName != "", saleName, "/")), gconv.String(common.If(oldsaleName != "", oldsaleName, "/")), nowTime, "", -1)
+				updateId3 = AddChangeRecord(tx, clueId, positionId, "trailstatus", "基本信息变更", "新增", CodeTrail[trailstatus], nowTime, "", -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,
-					})
+					updateId1 = AddChangeRecord(tx, clueId, positionId, "position_id", "所属人变更", gconv.String(
+						common.If(saleName != "", saleName, "/")), gconv.String(common.If(oldsaleName != "", oldsaleName, "/")), nowTime, "", -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,
-					})
+					updateId1 = AddChangeRecord(tx, clueId, positionId, "position_id", "所属人变更", gconv.String(common.If(saleName != "", saleName, "/")), gconv.String(common.If(oldsaleName != "", oldsaleName, "/")), nowTime, "", -1)
+					updateId2 = AddChangeRecord(tx, clueId, common.Int64All(data["position_id"]), "trailstatus", "基本信息变更", "流失", "无意向客户", nowTime, "", -1)
+					updateId3 = AddChangeRecord(tx, clueId, common.Int64All(data["position_id"]), "trailstatus", "基本信息变更", "新增", "商机线索", nowTime, "", -1)
+					updateId4 = AddChangeRecord(tx, clueId, positionId, "trailstatus", "基本信息变更", "商机线索", "无意向客户", nowTime, "", -1)
 				}
 			}
 		} else if is_assign == 0 {
@@ -1677,65 +1247,15 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 				positionId = 0
 				seatNumber = ""
 			} 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,
-				})
+				updateId1 = AddChangeRecord(tx, clueId, positionId, "position_id", "所属人变更", gconv.String(common.If(saleName != "", saleName, "/")), gconv.String(common.If(oldsaleName != "", oldsaleName, "/")), nowTime, "", -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,
-					})
+					updateId4 = AddChangeRecord(tx, clueId, positionId, "trailstatus", "基本信息变更", "商机线索", CodeTrail[trailstatus], nowTime, "", -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,
-				})
+				updateId3 = AddChangeRecord(tx, clueId, positionId, "trailstatus", "基本信息变更", "新增", "商机线索", nowTime, "", -1)
 			}
 		} else if is_assign == -1 {
-			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,
-			})
-			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,
-			})
+			updateId1 = AddChangeRecord(tx, clueId, positionId, "position_id", "所属人变更", gconv.String(common.If(saleName != "", saleName, "/")), gconv.String(common.If(oldsaleName != "", oldsaleName, "/")), nowTime, "", -1)
+			updateId4 = AddChangeRecord(tx, clueId, positionId, "trailstatus", "基本信息变更", "商机线索", CodeTrail[trailstatus], nowTime, "", -1)
 		}
 		if recordCount <= 0 || is_assign == 0 {
 			if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
@@ -1750,15 +1270,7 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 							kcpositionId := common.Int64All((*cdata)["position_id"])
 							tasksource := gconv.String((*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,
-							})
+							updateId5 = AddChangeRecord(tx, clueId, kcpositionId, "", "加入任务车", "线上主动留资", "", nowTime, "", -1)
 							if taskstatus == 1 {
 								tasksource = "10"
 							} else {
@@ -1779,15 +1291,8 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 						}
 					}
 				} else if !is_ok {
-					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 || is_assign == -1, positionId, common.Int64All(data["position_id"])),
-						"change_type": "加入任务车",
-						"new_value":   gconv.String(common.If(gconv.Int64(data["position_id"]) == 0, "线索自动分配", "线索来源自动更新")) + "-" + topname + "-" + subname,
-						"createtime":  nowTime,
-						"BCPCID":      common.GetRandom(32),
-						"operator_id": -1,
-					})
+					updateId5 = AddChangeRecord(tx, clueId, gconv.String(common.If(trailstatus == "00" || is_assign == 0 || is_assign == -1, positionId, common.Int64All(data["position_id"]))), "", "加入任务车",
+						gconv.String(gconv.String(common.If(gconv.Int64(data["position_id"]) == 0, "线索自动分配", "线索来源自动更新"))+"-"+topname+"-"+subname), "", nowTime, "", -1)
 				}
 			}
 		}
@@ -1805,55 +1310,21 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 		}
 		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,
-				})
+				updateId6 = AddChangeRecord(tx, clueId, 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"])))), "name", "基本信息变更",
+					gconv.String(common.If(name != "", name, "/")), gconv.String(common.If(old_name != "", old_name, "/")), nowTime, "", -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,
-				})
+				updateId7 = AddChangeRecord(tx, clueId, 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"])))), "position", "基本信息变更",
+					gconv.String(common.If(position != "", position, "/")), gconv.String(common.If(old_position != "", old_position, "/")), nowTime, "", -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,
-				})
+				updateId8 = AddChangeRecord(tx, clueId, 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"])))), "department", "基本信息变更",
+					gconv.String(common.If(department != "", department, "/")), gconv.String(common.If(department != "", department, "/")), nowTime, "", -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})
+				updateId8 = AddChangeRecord(tx, clueId, 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"])))), "role", "基本信息变更",
+					gconv.String(common.If(role != "", role, "/")), gconv.String(common.If(old_role != "", old_role, "/")), nowTime, "", -1)
 			}
 			if old_follow_project_area != follow_project_area && follow_project_area != "" {
 				old_area, old_area_arr := "", []string{}
@@ -1866,58 +1337,22 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 				}
 				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,
-				})
+				updateId10 = AddChangeRecord(tx, clueId, 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"])))), "follow_project_area", "基本信息变更",
+					gconv.String(common.If(new_area != "", new_area, "/")), gconv.String(common.If(old_area != "", old_area, "/")), nowTime, "", -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,
-				})
+				updateId11 = AddChangeRecord(tx, clueId, 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"])))), "cluename", "基本信息变更",
+					gconv.String(common.If(cluename != "", cluename, "/")), gconv.String(common.If(old_cluename != "", old_cluename, "/")), nowTime, "", -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,
-			})
+			updateId12 = AddChangeRecord(tx, clueId, 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"])))), "top_cluetype", "基本信息变更",
+				gconv.String(common.If(topname != "", topname, "/")), gconv.String(common.If(old_topname != "", old_topname, "/")), nowTime, "", -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{}{
-				"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", //444
-				"change_type":  "基本信息变更",
-				"old_value":    common.If(old_subname != "", old_subname, "/"),
-				"new_value":    common.If(subname != "", subname, "/"),
-				"createtime":   nowTime,
-				"BCPCID":       BCPCID,
-				"operator_id":  -1,
-			})
+			updateId12 = AddChangeRecord(tx, clueId, 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"])))), "sub_cluetype", "基本信息变更",
+				gconv.String(common.If(subname != "", subname, "/")), gconv.String(common.If(old_subname != "", old_subname, "/")), nowTime, "", -1)
 			if old_position_id != newPositionId && newPositionId > 0 {
 				LabelHandel(tx, label, 1, uId, level, trailstatus, gconv.String(clueUpdateData["trailstatus"]), 0)
 			} else {
@@ -2012,55 +1447,19 @@ func clueInfoUpdate(data ClueMapEntity) bool {
 		}
 		if data.Item != "orders" {
 			if data.OldName != data.NewName && data.NewName != "" {
-				updateId6 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":      data.ClueId,
-					"position_id":  data.PositionId,
-					"change_field": "name",
-					"change_type":  "基本信息变更",
-					"old_value":    common.If(data.OldName != "", data.OldName, "/"),
-					"new_value":    common.If(data.NewName != "", data.NewName, "/"),
-					"createtime":   nowTime,
-					"BCPCID":       BCPCID,
-					"operator_id":  -1,
-				})
+				updateId6 = AddChangeRecord(tx, data.ClueId, data.PositionId, "name", "基本信息变更",
+					gconv.String(common.If(data.NewName != "", data.NewName, "/")), gconv.String(common.If(data.OldName != "", data.OldName, "/")), nowTime, "", -1)
 			}
 			if data.OldPosition != data.NewPosition && data.NewPosition != "" {
-				updateId7 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":      data.ClueId,
-					"position_id":  data.PositionId,
-					"change_field": "position",
-					"change_type":  "基本信息变更",
-					"old_value":    common.If(data.OldPosition != "", data.OldPosition, "/"),
-					"new_value":    common.If(data.NewPosition != "", data.NewPosition, "/"),
-					"createtime":   nowTime,
-					"BCPCID":       BCPCID,
-					"operator_id":  -1,
-				})
+				updateId7 = AddChangeRecord(tx, data.ClueId, data.PositionId, "position", "基本信息变更",
+					gconv.String(common.If(data.NewPosition != "", data.NewPosition, "/")), gconv.String(common.If(data.OldPosition != "", data.OldPosition, "/")), nowTime, "", -1)
 			}
 			if data.OldDepartment != data.NewDepartment && data.NewDepartment != "" {
-				updateId8 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":      data.ClueId,
-					"position_id":  data.PositionId,
-					"change_field": "department",
-					"change_type":  "基本信息变更",
-					"old_value":    common.If(data.OldDepartment != "", data.OldDepartment, "/"),
-					"new_value":    common.If(data.NewDepartment != "", data.NewDepartment, "/"),
-					"createtime":   nowTime,
-					"BCPCID":       BCPCID,
-					"operator_id":  -1,
-				})
+				updateId8 = AddChangeRecord(tx, data.ClueId, data.PositionId, "department", "基本信息变更",
+					gconv.String(common.If(data.NewDepartment != "", data.NewDepartment, "/")), gconv.String(common.If(data.OldDepartment != "", data.OldDepartment, "/")), nowTime, "", -1)
 			}
 			if data.OldRole != data.NewRole && data.NewRole != "" {
-				updateId9 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":      data.ClueId,
-					"position_id":  data.PositionId,
-					"change_field": "role",
-					"change_type":  "基本信息变更",
-					"old_value":    common.If(data.OldRole != "", data.OldRole, "/"),
-					"new_value":    common.If(data.NewRole != "", data.NewRole, "/"),
-					"createtime":   nowTime,
-					"BCPCID":       BCPCID,
-					"operator_id":  -1})
+				updateId9 = AddChangeRecord(nil, data.ClueId, data.PositionId, "role", "基本信息变更", gconv.String(common.If(data.NewRole != "", data.NewRole, "/")), gconv.String(common.If(data.OldRole != "", data.OldRole, "/")), nowTime, BCPCID, -1)
 			}
 			if data.OldFollowProjectArea != data.NewFollowProjectArea && data.NewFollowProjectArea != "" {
 				old_area, old_area_arr := "", []string{}
@@ -2073,57 +1472,17 @@ func clueInfoUpdate(data ClueMapEntity) bool {
 				}
 				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":      data.ClueId,
-					"position_id":  data.PositionId,
-					"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,
-				})
+				updateId10 = AddChangeRecord(nil, data.ClueId, data.PositionId, "follow_project_area", "基本信息变更", gconv.String(common.If(new_area != "", new_area, "/")), gconv.String(common.If(old_area != "", old_area, "/")), nowTime, BCPCID, -1)
 			}
 			if data.OldCluename != data.NewCluename && data.NewCluename != "" {
-				updateId11 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":      data.ClueId,
-					"position_id":  data.PositionId,
-					"change_field": "cluename",
-					"change_type":  "基本信息变更",
-					"old_value":    common.If(data.OldCluename != "", data.OldCluename, "/"),
-					"new_value":    common.If(data.NewCluename != "", data.NewCluename, "/"),
-					"createtime":   nowTime,
-					"BCPCID":       BCPCID,
-					"operator_id":  -1,
-				})
+				updateId11 = AddChangeRecord(nil, data.ClueId, data.PositionId, "cluename", "基本信息变更", gconv.String(common.If(data.NewCluename != "", data.NewCluename, "/")), gconv.String(common.If(data.OldCluename != "", data.OldCluename, "/")), nowTime, BCPCID, -1)
 			}
 		}
 		if data.OldTopCluetype != data.NewTopCluetype {
-			updateId12 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-				"clue_id":      data.ClueId,
-				"position_id":  data.PositionId,
-				"change_field": "top_cluetype",
-				"change_type":  "基本信息变更",
-				"old_value":    common.If(old_topname != "", old_topname, "/"),
-				"new_value":    common.If(data.Topname != "", data.Topname, "/"),
-				"createtime":   nowTime,
-				"BCPCID":       BCPCID,
-				"operator_id":  -1,
-			})
+			updateId12 = AddChangeRecord(nil, data.ClueId, data.PositionId, "top_cluetype", "基本信息变更", gconv.String(common.If(data.Topname != "", data.Topname, "/")), gconv.String(common.If(old_topname != "", old_topname, "/")), nowTime, BCPCID, -1)
 		}
 		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", //555
-				"change_type":  "基本信息变更",
-				"old_value":    common.If(old_subname != "", old_subname, "/"),
-				"new_value":    common.If(data.Subname != "", data.Subname, "/"),
-				"createtime":   nowTime,
-				"BCPCID":       BCPCID,
-				"operator_id":  -1,
-			})
+			updateId13 = AddChangeRecord(nil, data.ClueId, data.PositionId, "sub_cluetype", "基本信息变更", gconv.String(common.If(data.Subname != "", data.Subname, "/")), gconv.String(common.If(old_subname != "", old_subname, "/")), nowTime, BCPCID, -1)
 			LabelHandel(tx, data.Label, 1, data.UId, data.Level, data.Trailstatus, data.Trailstatus, 0)
 		}
 		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

+ 86 - 23
clueSync/jobutil.go

@@ -3,6 +3,7 @@ package main
 import (
 	"app.yhyue.com/moapp/jybase/mail"
 	"app.yhyue.com/moapp/jybase/redis"
+	"database/sql"
 	"fmt"
 	"github.com/tealeg/xlsx"
 	"log"
@@ -51,6 +52,7 @@ func rderAcceptance() {
 						product = gconv.String(v1["field_value"])
 					}
 				}
+				//工单开始创建
 				if !WorkDataHandle(company, phone, demand, name, product, v) {
 					log.Println("工单创建失败")
 				}
@@ -58,6 +60,8 @@ func rderAcceptance() {
 		}
 	}
 }
+
+// 工单创建处理
 func WorkDataHandle(company, phone, demand, name, product string, acceptanceData map[string]interface{}) bool {
 	uId := ""
 	query := map[string]interface{}{}
@@ -80,14 +84,17 @@ func WorkDataHandle(company, phone, demand, name, product string, acceptanceData
 	isGroup, isCommerce := GetCompanyType(cluename, uId)
 	uCount, _ := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", ""), true //查当前线索是否已存在
 	if uCount != nil && len(*uCount) > 0 {
+		//线索信息修改
 		isUpdate := gconv.Int64((*uCount)["is_artificially_modified"])
 		if isUpdate == 1 {
 			cluename = ""
 		}
 		clueId := gconv.Int64((*uCount)["id"])
 		positionId := gconv.Int64((*uCount)["position_id"])
+		lockPositionId := gconv.Int64((*uCount)["lock_position_id"])
 		trailstatus := gconv.String((*uCount)["trailstatus"])
 		IS_TRANSFER := gconv.Int64((*uCount)["IS_TRANSFER"])
+		//1客成0销售
 		if IS_TRANSFER == 1 {
 			//客成处理
 			//客成
@@ -96,7 +103,6 @@ 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)
 				WorkUpdateClue(*uCount, saleData, "", "", uId, "5", "169", "新增线索", "主动咨询客服留资客户", cluename, name, gconv.String((*uCount)["name"]), phone, "", "", "", "", "", "", gconv.String((*uCount)["seat_number"]), "", gconv.Int64((*uCount)["position_id"]), "", "", "", []string{}, "", isGroup, isCommerce, false, demand)
 				data = map[string]interface{}{
 					"type":        "kc",
@@ -107,17 +113,10 @@ func WorkDataHandle(company, phone, demand, name, product string, acceptanceData
 				log.Println("查询不到客成数据", clueId, uId)
 				return false
 			}
-			TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-				"clue_id":     clueId,
-				"position_id": (*customerMap)["position_id"],
-				"change_type": "加入任务车",
-				"new_value":   "咨询客服转客成",
-				"createtime":  time.Now().Format(date.Date_Full_Layout),
-				"BCPCID":      common.GetRandom(32),
-				"operator_id": -1,
-			})
+			AddChangeRecord(nil, clueId, gconv.Int64((*customerMap)["position_id"]), "", "加入任务车", "咨询客服转客成", "/", time.Now().Format(date.Date_Full_Layout), -1)
 		} else {
-			if positionId == 0 {
+			//普通销售
+			if positionId == 0 && lockPositionId == 0 {
 				//线索变更
 				ok, data, saleData = FindPosition(0, "", gconv.String(acceptanceData["creator_time"]))
 				if !ok {
@@ -126,7 +125,12 @@ func WorkDataHandle(company, phone, demand, name, product string, acceptanceData
 				}
 				WorkUpdateClue(*uCount, saleData, "", "", uId, "5", "169", "新增线索", "主动咨询客服留资客户", cluename, name, gconv.String(data["name"]), phone, "", "", "", "", "", "", gconv.String(data["seat_number"]), "", gconv.Int64(data["position_id"]), "", "", "", []string{}, "", isGroup, isCommerce, true, demand)
 			} else {
-				ok, data, saleData = FindPosition(positionId, trailstatus, gconv.String(acceptanceData["creator_time"]))
+				ok, data, saleData := true, map[string]interface{}{}, []map[string]interface{}{}
+				if positionId == 0 {
+					ok, data, saleData = FindPosition(lockPositionId, trailstatus, gconv.String(acceptanceData["creator_time"]))
+				} else {
+					ok, data, saleData = FindPosition(positionId, trailstatus, gconv.String(acceptanceData["creator_time"]))
+				}
 				if !ok {
 					log.Println(positionId, "用户查询失败")
 					return false
@@ -136,12 +140,12 @@ func WorkDataHandle(company, phone, demand, name, product string, acceptanceData
 				} else {
 					WorkUpdateClue(*uCount, saleData, "", "", uId, "5", "169", "新增线索", "主动咨询客服留资客户", cluename, name, gconv.String(data["name"]), phone, "", "", "", "", "", "", gconv.String(data["seat_number"]), "", gconv.Int64(data["position_id"]), "", "", "", []string{}, "", isGroup, isCommerce, true, demand)
 				}
-
 			}
 		}
 	} else {
 		//新增线索
-		ok, data, _ = FindPosition(0, "", gconv.String(acceptanceData["creator_time"]))
+		relatedId, _ := FindRelatedData(cluename)
+		ok, data, _ = FindPosition(relatedId, "", gconv.String(acceptanceData["creator_time"]))
 		if !ok {
 			return false
 		}
@@ -856,15 +860,7 @@ func userbase() {
 					})
 				}
 				if clueId > 0 {
-					TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-						"clue_id":     clueId,
-						"position_id": -1,
-						"change_type": "创建线索",
-						"new_value":   "系统自动创建",
-						"createtime":  nowTime,
-						"BCPCID":      common.GetRandom(32),
-						"operator_id": -1,
-					})
+					AddChangeRecord(nil, clueId, -1, "", "创建线索", "系统自动创建", "/", nowTime, -1)
 				}
 			}
 		}
@@ -1943,3 +1939,70 @@ func nextYearActivity() {
 	}
 	log.Println("开年活动处理结束")
 }
+
+// 查询关联公司
+func relatedCompany(companyName string) int64 {
+	sqlStr := fmt.Sprintf(`SELECT
+			position_id 
+		FROM
+			dwd_f_crm_clue_info 
+		WHERE
+			cluename IN ( SELECT companyName FROM ( SELECT b_name AS companyName FROM ent_relation WHERE a_name ="%s" UNION SELECT a_name AS companyName FROM ent_relation WHERE b_name = "%s") ) 
+			AND position_id > 0 
+			LIMIT 1`, companyName, companyName)
+	companyList := TiDb.SelectBySql(sqlStr)
+	if companyList == nil || len(*companyList) == 0 {
+		return 0
+	}
+	return gconv.Int64((*companyList)[0]["position_id"])
+}
+
+// 锁定状态变更
+func AddLockeStatusChange(tx *sql.Tx, clueId, positionId, oldLockStatus, lock_status int64, nowTime, clueName string) int64 {
+	//需要批量查处理   后期处理
+	if clueName != "" {
+		_, clueList := FindRelatedData(clueName)
+		for _, v := range clueList {
+			AddChangeRecord(nil, clueId, positionId, "lock_status", "基本信息变更", gconv.String(CodeLock[lock_status]), gconv.String(common.If(lock_status == 0, CodeLock[lock_status], CodeLock[lock_status])), nowTime, -1)
+		}
+	}
+	return 1
+}
+
+// 锁定认变更
+func AddLockePersonChange(tx *sql.Tx, clueId, positionId int64, oldpersonName, personName, nowTime, clueName string) int64 {
+	//需要批量查处理   后期处理
+	if clueName != "" {
+		lockPositionId, clueList := FindRelatedData(clueName)
+		if lockPositionId != positionId {
+			log.Println(clueName, positionId, lockPositionId, "锁定人变更失败")
+		}
+		for _, v := range clueList {
+			AddChangeRecord(nil, v, positionId, "lock_position_id", "锁定人变更", personName, oldpersonName, nowTime, positionId)
+		}
+	}
+	return 1
+}
+func FindRelatedData(companyName string) (int64, []int64) {
+	sqlStr := fmt.Sprintf(`SELECT
+			position_id,id
+		FROM
+			dwd_f_crm_clue_info 
+		WHERE
+			cluename IN ( SELECT companyName FROM ( SELECT b_name AS companyName FROM ent_relation WHERE a_name ="%s" UNION SELECT a_name AS companyName FROM ent_relation WHERE b_name = "%s") ) 
+			AND position_id > 0 
+			LIMIT 1`, companyName, companyName)
+	companyList := TiDb.SelectBySql(sqlStr)
+	if companyList == nil || len(*companyList) == 0 {
+		return 0, []int64{}
+	}
+	positionId := int64(0)
+	clueList := []int64{}
+	for _, v := range *companyList {
+		if gconv.Int64(v["position_id"]) > 0 {
+			positionId = gconv.Int64(v["position_id"])
+		}
+		clueList = append(clueList, gconv.Int64(v["id"]))
+	}
+	return positionId, clueList
+}

+ 35 - 245
clueSync/kc.go

@@ -16,6 +16,13 @@ import (
 	"app.yhyue.com/moapp/jybase/mongodb"
 )
 
+var (
+	CodeLock = map[int64]interface{}{
+		1: "无需锁定",
+		0: "/",
+	}
+)
+
 func kcSync() {
 	log.Println("客户成功系统移交定时任务开始")
 	sql := `select * from dwd_f_userbase_order_info where (payable_money > 0 or  (payable_money=0 and  ( filter  like "%分期付款补充权益%"  or   filter  like "%原订单不支持开通多项权益%"  or    filter  like "%权益码兑换%")))
@@ -108,15 +115,7 @@ func kcJob(data map[string]interface{}) int {
 			"label":                common.If(position_id > 0, 1, nil),
 		})
 		if clueId > 0 {
-			TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-				"clue_id":     clueId,
-				"position_id": common.If(position_id > 0, position_id, -1),
-				"change_type": "创建线索",
-				"new_value":   "系统自动创建",
-				"createtime":  nowTime,
-				"BCPCID":      common.GetRandom(32),
-				"operator_id": -1,
-			})
+			AddChangeRecord(nil, clueId, gconv.Int64(common.If(position_id > 0, position_id, -1)), "", "创建线索", "系统自动创建", "", nowTime, -1)
 			clueData = TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", "")
 			if clueData == nil || len(*clueData) == 0 {
 				return 0
@@ -227,36 +226,10 @@ func kcJob(data map[string]interface{}) int {
 				updateMap["is_task"] = 1
 			}
 			TiDb.Update("dwd_f_csm_customer_info", map[string]interface{}{"clue_id": clueId}, updateMap)
-			TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-				"clue_id":     clueId,
-				"position_id": customerPositionId,
-				"change_type": "成交客户移交",
-				"new_value":   "移交至客户成功组",
-				"createtime":  nowTime,
-				"BCPCID":      common.GetRandom(32),
-				"operator_id": -1,
-			})
+			AddChangeRecord(nil, clueId, customerPositionId, "", "成交客户移交", "移交至客户成功组", "", nowTime, -1)
 			if customerPositionId > 0 && (is_transfer == 1 || customerPositionId != gconv.Int64((*csmdata)["position_id"])) {
-				TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":      clueId,
-					"position_id":  customerPositionId,
-					"change_field": "position_id",
-					"change_type":  "客户成功经理",
-					"old_value":    common.If(oldName != customerName, oldName, common.If(oldName == "", "/", oldName)),
-					"new_value":    customerName,
-					"createtime":   nowTime,
-					"BCPCID":       common.GetRandom(32),
-					"operator_id":  -1,
-				})
-				TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":     clueId,
-					"position_id": customerPositionId,
-					"change_type": "加入任务车",
-					"new_value":   "未建联",
-					"createtime":  nowTime,
-					"BCPCID":      common.GetRandom(32),
-					"operator_id": -1,
-				})
+				AddChangeRecord(nil, clueId, customerPositionId, "position_id", "客户成功经理", customerName, gconv.String(common.If(oldName != customerName, oldName, common.If(oldName == "", "/", oldName))), nowTime, -1)
+				AddChangeRecord(nil, clueId, customerPositionId, "", "加入任务车", "未建联", "", nowTime, -1)
 			}
 			if is_transfer == 1 || customerPositionId != gconv.Int64((*csmdata)["position_id"]) {
 				if customerName == db.KeCheng.Admin {
@@ -279,37 +252,11 @@ func kcJob(data map[string]interface{}) int {
 			cId = TiDb.InsertByTx(tx, "dwd_f_csm_customer_info", saveMap)
 			ok = TiDb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{"is_transfer": 1, "updatetime": nowTime, "name": userName})
 			if customerPositionId > 0 {
-				updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":     clueId,
-					"position_id": customerPositionId,
-					"change_type": "加入任务车",
-					"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":  customerPositionId,
-					"change_field": "position_id",
-					"change_type":  "客户成功经理",
-					"old_value":    "/",
-					"new_value":    customerName,
-					"createtime":   nowTime,
-					"BCPCID":       common.GetRandom(32),
-					"operator_id":  -1,
-				})
+				updateId1 = AddChangeRecord(tx, clueId, customerPositionId, "", "加入任务车", "未建联", "", nowTime, -1)
+				updateId3 = AddChangeRecord(tx, clueId, customerPositionId, "position_id", "客户成功经理", "/", customerName, nowTime, -1)
 			}
 			KcSend(orderCode, customerName)
-			updateId2 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-				"clue_id":     clueId,
-				"position_id": customerPositionId,
-				"change_type": "成交客户移交",
-				"new_value":   "移交至客户成功组",
-				"createtime":  nowTime,
-				"BCPCID":      common.GetRandom(32),
-				"operator_id": -1,
-			})
+			updateId2 := AddChangeRecord(tx, clueId, customerPositionId, "", "成交客户移交", "移交至客户成功组", "", nowTime, -1)
 			return cId > -1 && ok && updateId1 > -1 && updateId2 > -1 && updateId3 > -1
 		}) {
 			//TiDb.UpdateOrDeleteBySql(`update dwd_f_csm_customer_autodraw_record set count = count + 1 where name = ?`, name)
@@ -465,26 +412,11 @@ func kcAuto() {
 			taskstatus := common.IntAll(v["taskstatus"])
 			if relationship_building_way != 1 && inventory_way == 1 {
 				tasksources = "2"
-				TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":     clueId,
-					"position_id": positionId,
-					"change_type": "加入任务车",
-					"new_value":   "未盘点",
-					"createtime":  nowTime,
-					"BCPCID":      common.GetRandom(32),
-					"operator_id": -1,
-				})
+				AddChangeRecord(nil, clueId, positionId, "", "加入任务车", "未盘点", "", "", -1)
+
 			} else if inventory_way != 1 && training_way == 1 {
 				tasksources = "3"
-				TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":     clueId,
-					"position_id": positionId,
-					"change_type": "加入任务车",
-					"new_value":   "未培训",
-					"createtime":  nowTime,
-					"BCPCID":      common.GetRandom(32),
-					"operator_id": -1,
-				})
+				AddChangeRecord(nil, clueId, positionId, "position_id", "加入任务车", "未培训", "", nowTime, -1)
 			}
 			if taskstatus == 1 {
 				tasksource = tasksources
@@ -641,26 +573,11 @@ func ordersClue() {
 						})
 					}
 					if clueId > 0 {
-						TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-							"clue_id":     clueId,
-							"position_id": common.If(positionId > 0, positionId, -1),
-							"change_type": "创建线索",
-							"new_value":   "系统自动创建",
-							"createtime":  nowTime,
-							"BCPCID":      common.GetRandom(32),
-							"operator_id": -1,
-						})
+						AddChangeRecord(tx, clueId, gconv.Int64(common.If(positionId > 0, positionId, -1)), "", "创建线索", "系统自动创建", "", nowTime, -1)
 						if is_assign == -3 {
 							//新增冻结记录
-							TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-								"clue_id":     clueId,
-								"position_id": positionId,
-								"change_type": "线索冻结",
-								"new_value":   "销售人员私海已达上限",
-								"createtime":  nowTime,
-								"BCPCID":      common.GetRandom(32),
-								"operator_id": -1,
-							})
+							AddChangeRecord(tx, clueId, positionId, "", "线索冻结", "销售人员私海已达上限", "", nowTime, -1)
+
 							//移交失败发送消息
 							if IsFreeze(source, pay_money, gconv.String(positionId), trailstatus) {
 								//发送邮件信息
@@ -749,46 +666,10 @@ func refundAuto() {
 			if isAllRefund {
 				//全退款了
 				TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET is_unfollow=0,is_assign=0,trailstatus="01",position_id=null,seatNumber=null,updatetime=?,comeintime_open=?,comeinsource_open=1,level_open=3,next_trail_time=null,is_task=null,tasktime=null,taskstatus=null,comeinsource_private=null,tasksource=null,is_transfer=0 WHERE id = ?`, nowTime, nowTime, clueId)
-				TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":     clueId,
-					"position_id": common.If(kcposition_id > 0, kcposition_id, -1),
-					"change_type": "退回公海",
-					"new_value":   "成交客户申请退款",
-					"createtime":  nowTime,
-					"BCPCID":      common.GetRandom(32),
-					"operator_id": -1,
-				})
-				TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":      clueId,
-					"position_id":  common.If(kcposition_id > 0, kcposition_id, -1),
-					"change_field": "trailstatus",
-					"change_type":  "基本信息变更",
-					"old_value":    "成交客户",
-					"new_value":    "商机线索",
-					"createtime":   nowTime,
-					"BCPCID":       common.GetRandom(32),
-					"operator_id":  -1,
-				})
-				TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":      clueId,
-					"position_id":  common.If(kcposition_id > 0, kcposition_id, -1),
-					"change_type":  "客户成功经理",
-					"change_field": "position_id",
-					"old_value":    name,
-					"new_value":    "/",
-					"createtime":   nowTime,
-					"BCPCID":       common.GetRandom(32),
-					"operator_id":  -1,
-				})
-				TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":     clueId,
-					"position_id": common.If(kcposition_id > 0, kcposition_id, -1),
-					"change_type": "移交销售",
-					"new_value":   "成交客户申请退款",
-					"createtime":  nowTime,
-					"BCPCID":      common.GetRandom(32),
-					"operator_id": -1,
-				})
+				AddChangeRecord(nil, clueId, gconv.Int64(common.If(kcposition_id > 0, kcposition_id, -1)), "", "退回公海", "成交客户申请退款", "", nowTime, -1)
+				AddChangeRecord(nil, clueId, gconv.Int64(common.If(kcposition_id > 0, kcposition_id, -1)), "trailstatus", "基本信息变更", "商机线索", "成交客户", nowTime, -1)
+				AddChangeRecord(nil, clueId, gconv.Int64(common.If(kcposition_id > 0, kcposition_id, -1)), "position_id", "客户成功经理", "/", name, nowTime, -1)
+				AddChangeRecord(nil, clueId, gconv.Int64(common.If(kcposition_id > 0, kcposition_id, -1)), "", "移交销售", "成交客户申请退款", "", nowTime, -1)
 				mailData[name] = append(mailData[name], map[string]interface{}{
 					"company_name": company_name,
 					"phone":        phone,
@@ -922,58 +803,14 @@ func refundAuto() {
 								"cluename":     cluename,
 							})
 						}
-						TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-							"clue_id":      clueId,
-							"position_id":  common.If(kcposition_id > 0, kcposition_id, -1),
-							"change_type":  "基本信息变更",
-							"old_value":    "成交客户",
-							"change_field": "trailstatus",
-							"new_value":    "商机线索",
-							"createtime":   nowTime,
-							"BCPCID":       common.GetRandom(32),
-							"operator_id":  -1,
-						})
-						TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-							"clue_id":     clueId,
-							"position_id": saleId,
-							"change_type": "加入任务车",
-							"new_value":   "线索自动分配-其他-成交客户续约失败",
-							"createtime":  nowTime,
-							"BCPCID":      common.GetRandom(32),
-							"operator_id": -1,
-						})
-						TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-							"clue_id":      clueId,
-							"position_id":  common.If(kcposition_id > 0, kcposition_id, -1),
-							"change_type":  "客户成功经理",
-							"change_field": "position_id",
-							"old_value":    name,
-							"new_value":    "/",
-							"createtime":   nowTime,
-							"BCPCID":       common.GetRandom(32),
-							"operator_id":  -1,
-						})
-						TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-							"clue_id":     clueId,
-							"position_id": saleId,
-							"change_type": "移交销售",
-							"new_value":   "成交客户续费失败,到期自动移交",
-							"createtime":  nowTime,
-							"BCPCID":      common.GetRandom(32),
-							"operator_id": -1,
-						})
+						AddChangeRecord(nil, clueId, gconv.Int64(common.If(kcposition_id > 0, kcposition_id, -1)), "trailstatus", "基本信息变更", "商机线索", "", nowTime, -1)
+						AddChangeRecord(nil, clueId, saleId, "trailstatus", "加入任务车", "线索自动分配-其他-成交客户续约失败", "", nowTime, -1)
+						AddChangeRecord(nil, clueId, gconv.Int64(common.If(kcposition_id > 0, kcposition_id, -1)), "position_id", "客户成功经理", "/", name, nowTime, -1)
+						AddChangeRecord(nil, clueId, saleId, "", "移交销售", "成交客户续费失败,到期自动移交", "", nowTime, -1)
 						TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_csm_customer_info SET is_transfer=1 WHERE clue_id = ?`, clueId)
 						if isFull {
 							//新增冻结记录
-							TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-								"clue_id":     clueId,
-								"position_id": saleId,
-								"change_type": "线索冻结",
-								"new_value":   "销售人员私海已达上限",
-								"createtime":  nowTime,
-								"BCPCID":      common.GetRandom(32),
-								"operator_id": -1,
-							})
+							AddChangeRecord(nil, clueId, 线索冻结, "trailstatus", "线索冻结", "销售人员私海已达上限", "", nowTime, -1)
 							//发送邮件
 							mailContent := ""
 							if cluename != "" {
@@ -1472,59 +1309,12 @@ func kcClue(userId, uId, seatNumber, cluename, top_cluetype, sub_cluetype,
 			"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,
-			"position_id": positionId,
-			"change_type": "创建线索",
-			"new_value":   "系统自动创建",
-			"createtime":  nowTime,
-			"BCPCID":      common.GetRandom(32),
-			"operator_id": -1,
-		})
-		uodateId2 = 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":    "/",
-			"new_value":    saleName,
-			"createtime":   nowTime,
-			"BCPCID":       common.GetRandom(32),
-			"operator_id":  -1,
-		})
-		uodateId3 = 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,
-		})
-		uodateId5 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-			"clue_id":      clueId,
-			"position_id":  positionId,
-			"change_field": "top_cluetype",
-			"change_type":  "基本信息变更",
-			"old_value":    "/",
-			"new_value":    topname,
-			"createtime":   nowTime,
-			"BCPCID":       common.GetRandom(32),
-			"operator_id":  -1,
-		})
-		uodateId5 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-			"clue_id":      clueId,
-			"position_id":  positionId,
-			"change_field": "sub_cluetype", //222
-			"change_type":  "基本信息变更",
-			"old_value":    "/",
-			"new_value":    subname,
-			"createtime":   nowTime,
-			"BCPCID":       common.GetRandom(32),
-			"operator_id":  -1,
-		})
+
+		uodateId1 = AddChangeRecord(tx, clueId, positionId, "", "创建线索", "系统自动创建", "", nowTime, -1)
+		uodateId2 = AddChangeRecord(tx, clueId, positionId, "position_id", "所属人变更", saleName, "/", nowTime, -1)
+		uodateId3 = AddChangeRecord(tx, clueId, positionId, "trailstatus", "基本信息变更", "新增", "商机线索", nowTime, -1)
+		uodateId4 = AddChangeRecord(tx, clueId, positionId, "top_cluetype", "基本信息变更", topname, "/", nowTime, -1)
+		uodateId5 = AddChangeRecord(tx, clueId, positionId, "sub_cluetype", "基本信息变更", subname, "/", nowTime, -1)
 		return clueId > -1 && uodateId1 > -1 && uodateId2 > -1 && uodateId3 > -1 && uodateId4 > -1 && uodateId5 > -1
 	}) {
 		log.Println("线索分配成功")