Browse Source

完善注释

xuzhiheng 1 year ago
parent
commit
3a79e51c24
4 changed files with 241 additions and 34 deletions
  1. 27 29
      clueSync/job.go
  2. 4 4
      clueSync/jobutil.go
  3. 209 0
      clueSync/kc.go
  4. 1 1
      clueSync/main.go

+ 27 - 29
clueSync/job.go

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

+ 4 - 4
clueSync/jobutil.go

@@ -367,10 +367,10 @@ func getClueType(item string, data map[string]interface{}, sourceCode string, so
 // 获取自动分配的人
 func autoDraw(mode, cluename, phone string, isGroup, isCommerce int) (positionId int64, seatNumber, saleName string, saleData []map[string]interface{}, isOk bool) {
 	isOk = false
-	if TiDb.Count("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone, "is_assign": 1}) == 0 {
-		if isGroup == 0 && isCommerce == 1 && cluename != "" {
+	if TiDb.Count("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone, "is_assign": 1}) == 0 { //线索没销售进入,有销售走分配次数最少的逻辑
+		if isGroup == 0 && isCommerce == 1 && cluename != "" { //非集团在工商库线索名不为空
 			cdata := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"cluename": cluename, "is_assign": 1}, "", "")
-			if cdata != nil && len(*cdata) > 0 {
+			if cdata != nil && len(*cdata) > 0 { //找到了公司有人在跟进
 				isOk = true
 				positionId = common.Int64All((*cdata)["position_id"])
 				seatNumber = common.ObjToString((*cdata)["seatNumber"])
@@ -382,7 +382,7 @@ func autoDraw(mode, cluename, phone string, isGroup, isCommerce int) (positionId
 						for _, v := range *pdata {
 							resign := common.IntAll(v["resign"])
 							if seatNumber == common.ObjToString(v["seat_number"]) {
-								if resign == 1 { //离职分配
+								if resign == 1 { //离职分配,找到的销售离职了,分给组员,没离职就给他
 									sdata := TiDb.SelectBySql(`SELECT b.name,b.position_id,b.seat_number from dwd_d_crm_department_level_succbi a INNER JOIN dwd_f_crm_personnel_management b on a.position_id = b.position_id where a.bi_pcode = (SELECT bi_pcode from dwd_d_crm_department_level_succbi where position_id = ?) and b.role_id = 3`, positionId)
 									if sdata != nil && len(*sdata) > 0 {
 										positionId = common.Int64All((*sdata)[0]["position_id"])

+ 209 - 0
clueSync/kc.go

@@ -772,3 +772,212 @@ func refundAuto() {
 	}, `select ent_id,clue_id,position_id,name,is_renewal_protection from dwd_f_csm_customer_info where is_transfer = 0`)
 	log.Println("自动移交销售定时任务结束")
 }
+
+func refundAutoHistory() {
+	log.Println("历史数据移交销售任务开始")
+	nowTime := time.Now().Format(date.Date_Full_Layout)
+	TiDb.SelectByBath(100, func(l *[]map[string]interface{}) bool {
+		for _, v := range *l {
+			saleId, cluename, company_nature, company_verification, uid := int64(0), "", 0, 0, ""
+			clueId := common.Int64All(v["clue_id"])
+			name := common.ObjToString(v["name"])
+			kcposition_id := common.Int64All(v["position_id"])
+			isRenewalProtection := common.IntAll(v["is_renewal_protection"])
+			clueData := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, "company_nature,company_verification,cluename,userid,position_id,uid", "")
+			if clueData != nil && len(*clueData) > 0 {
+				saleId = common.Int64All((*clueData)["position_id"])
+				cluename = common.ObjToString((*clueData)["cluename"])
+				company_nature = common.IntAll((*clueData)["company_nature"])
+				company_verification = common.IntAll((*clueData)["company_verification"])
+				uid = common.ObjToString((*clueData)["uid"])
+			}
+			query1 := fmt.Sprintf(`select id from dwd_f_userbase_order_info where (product_type = "企业商机管理" or product_type = "大会员") and vip_endtime > "%s" and order_status = 1 and uid = "%s"`, nowTime, uid)
+			query2 := fmt.Sprintf(`select id from dwd_f_userbase_order_info where (product_type = "企业商机管理" or product_type = "大会员") and refund_status in (0,2) and order_status = 1 and uid = "%s"`, uid)
+			log.Println("query1 ", query1)
+			log.Println("query2 ", query2)
+			order2 := TiDb.SelectBySql(query2)
+			if order2 == nil || len(*order2) == 0 {
+				//全退款了
+				if saleId > 0 {
+					saleData := TiDb.FindOne("dwd_f_crm_personnel_management", map[string]interface{}{"position_id": saleId, "resign": 0}, "", "")
+					if saleData != nil && len(*saleData) > 0 {
+						TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",top_cluetype="532",sub_cluetype="537",taskstatus=0,tasksource="其他-成交客户续约失败",is_transfer=0 WHERE id = ?`, nowTime, clueId)
+					} else {
+						if company_nature == 0 && company_verification == 1 && cluename != "" {
+							adata := TiDb.Find("dwd_f_crm_clue_info", map[string]interface{}{"cluename": cluename, "is_assign": 1}, "seatNumber,position_id", "", -1, -1)
+							if adata != nil && len(*adata) > 0 {
+								isOks := false
+								for _, vv := range *adata {
+									position_ids := common.Int64All(vv["position_id"])
+									seatNumber := common.ObjToString(vv["seatNumber"])
+									saleDatas := TiDb.FindOne("dwd_f_crm_personnel_management", map[string]interface{}{"position_id": position_ids, "resign": 0}, "", "")
+									if saleDatas != nil && len(*saleDatas) > 0 {
+										saleId = position_ids
+										TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",position_id=?,seatNumber=?,top_cluetype="532",sub_cluetype="537",taskstatus=0,tasksource="其他-成交客户续约失败",is_transfer=0 WHERE id = ?`, nowTime, saleId, seatNumber, clueId)
+										isOks = true
+										break
+									}
+								}
+								if !isOks {
+									sdata := TiDb.SelectBySql(`SELECT b.name,b.position_id,b.seat_number from dwd_d_crm_department_level_succbi a INNER JOIN dwd_f_crm_personnel_management b on a.position_id = b.position_id where a.bi_pcode = (SELECT bi_pcode from dwd_d_crm_department_level_succbi where position_id = ?) and b.role_id = 3`, saleId)
+									if sdata != nil && len(*sdata) > 0 {
+										saleId = common.Int64All((*sdata)[0]["position_id"])
+										seatNumber := common.ObjToString((*sdata)[0]["seat_number"])
+										TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",position_id=?,seatNumber=?,top_cluetype="532",sub_cluetype="537",taskstatus=0,tasksource="其他-成交客户续约失败",is_transfer=0 WHERE id = ?`, nowTime, saleId, seatNumber, clueId)
+									}
+								}
+							}
+						} else {
+							sdata := TiDb.SelectBySql(`SELECT b.name,b.position_id,b.seat_number from dwd_d_crm_department_level_succbi a INNER JOIN dwd_f_crm_personnel_management b on a.position_id = b.position_id where a.bi_pcode = (SELECT bi_pcode from dwd_d_crm_department_level_succbi where position_id = ?) and b.role_id = 3`, saleId)
+							if sdata != nil && len(*sdata) > 0 {
+								saleId = common.Int64All((*sdata)[0]["position_id"])
+								seatNumber := common.ObjToString((*sdata)[0]["seat_number"])
+								TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",position_id=?,seatNumber=?,top_cluetype="532",sub_cluetype="537",taskstatus=0,tasksource="其他-成交客户续约失败",is_transfer=0 WHERE id = ?`, nowTime, saleId, seatNumber, clueId)
+							}
+						}
+					}
+				} else {
+					TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",top_cluetype="532",sub_cluetype="537",is_transfer=0 WHERE id = ?`, 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_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,
+				})
+				TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_csm_customer_info SET is_transfer=1 WHERE clue_id = ?`, clueId)
+			} else {
+				order1 := TiDb.SelectBySql(query1)
+				if order1 == nil || len(*order1) == 0 {
+					isOk := false
+					query3 := fmt.Sprintf(`select vip_endtime from dwd_f_userbase_order_info where (product_type = "企业商机管理" or product_type = "大会员") and vip_endtime < "%s" and order_status = 1 and uid = "%s"`, nowTime, uid)
+					log.Println("query3 ", query3)
+					order3 := TiDb.SelectBySql(query3)
+					if order3 != nil && len(*order3) > 0 {
+						for _, vv := range *order3 {
+							if isRenewalProtection == 1 {
+								vip_endtime := common.ObjToString(vv["vip_endtime"])
+								vip_endtimes, _ := time.ParseInLocation(date.Date_Full_Layout, vip_endtime, time.Local)
+								if time.Now().Unix()-vip_endtimes.Unix() < 30*86400 {
+									isOk = true
+								}
+							}
+						}
+					}
+					if !isOk {
+						//全到期了
+						if saleId > 0 {
+							saleData := TiDb.FindOne("dwd_f_crm_personnel_management", map[string]interface{}{"position_id": saleId, "resign": 0}, "", "")
+							if saleData != nil && len(*saleData) > 0 {
+								TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",is_task=1,tasktime=?,top_cluetype="532",sub_cluetype="537",taskstatus=0,tasksource="其他-成交客户续约失败",is_transfer=0 WHERE id = ?`, nowTime, nowTime, clueId)
+							} else {
+								if company_nature == 0 && company_verification == 1 && cluename != "" {
+									adata := TiDb.Find("dwd_f_crm_clue_info", map[string]interface{}{"cluename": cluename, "is_assign": 1}, "seatNumber,position_id", "", -1, -1)
+									if adata != nil && len(*adata) > 0 {
+										isOks := false
+										for _, vv := range *adata {
+											position_ids := common.Int64All(vv["position_id"])
+											seatNumber := common.ObjToString(vv["seatNumber"])
+											saleDatas := TiDb.FindOne("dwd_f_crm_personnel_management", map[string]interface{}{"position_id": position_ids, "resign": 0}, "", "")
+											if saleDatas != nil && len(*saleDatas) > 0 {
+												saleId = position_ids
+												TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",position_id=?,seatNumber=?,is_task=1,tasktime=?,top_cluetype="532",sub_cluetype="537",taskstatus=0,tasksource="其他-成交客户续约失败",is_transfer=0 WHERE id = ?`, nowTime, saleId, seatNumber, nowTime, clueId)
+												isOks = true
+												break
+											}
+										}
+										if !isOks {
+											sdata := TiDb.SelectBySql(`SELECT b.name,b.position_id,b.seat_number from dwd_d_crm_department_level_succbi a INNER JOIN dwd_f_crm_personnel_management b on a.position_id = b.position_id where a.bi_pcode = (SELECT bi_pcode from dwd_d_crm_department_level_succbi where position_id = ?) and b.role_id = 3`, saleId)
+											if sdata != nil && len(*sdata) > 0 {
+												saleId = common.Int64All((*sdata)[0]["position_id"])
+												seatNumber := common.ObjToString((*sdata)[0]["seat_number"])
+												TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",position_id=?,seatNumber=?,is_task=1,tasktime=?,top_cluetype="532",sub_cluetype="537",taskstatus=0,tasksource="其他-成交客户续约失败",is_transfer=0 WHERE id = ?`, nowTime, saleId, seatNumber, nowTime, clueId)
+											}
+										}
+									}
+								} else {
+									sdata := TiDb.SelectBySql(`SELECT b.name,b.position_id,b.seat_number from dwd_d_crm_department_level_succbi a INNER JOIN dwd_f_crm_personnel_management b on a.position_id = b.position_id where a.bi_pcode = (SELECT bi_pcode from dwd_d_crm_department_level_succbi where position_id = ?) and b.role_id = 3`, saleId)
+									if sdata != nil && len(*sdata) > 0 {
+										saleId = common.Int64All((*sdata)[0]["position_id"])
+										seatNumber := common.ObjToString((*sdata)[0]["seat_number"])
+										TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",position_id=?,seatNumber=?,is_task=1,tasktime=?,top_cluetype="532",sub_cluetype="537",taskstatus=0,tasksource="其他-成交客户续约失败",is_transfer=0 WHERE id = ?`, nowTime, saleId, seatNumber, nowTime, clueId)
+									}
+								}
+							}
+						} else {
+							TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",top_cluetype="532",sub_cluetype="537",is_transfer=0 WHERE id = ?`, 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":  "基本信息变更",
+							"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,
+						})
+						TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_csm_customer_info SET is_transfer=1 WHERE clue_id = ?`, clueId)
+					}
+				}
+			}
+		}
+		return true
+	}, `select ent_id,clue_id,position_id,name,is_renewal_protection from dwd_f_csm_customer_info where is_transfer = 0`)
+	log.Println("历史数据移交销售任务结束")
+}

+ 1 - 1
clueSync/main.go

@@ -154,7 +154,6 @@ func main() {
 		})
 		f.Start()
 		//自动进入任务车 1天一次
-		go refundAuto() //客成移交销售
 		g := cron.New()
 		g.AddFunc(cfg.CornExp7, func() {
 			readClue()   //读取中间表进线索
@@ -165,5 +164,6 @@ func main() {
 		g.Start()
 		select {}
 	} else {
+		refundAutoHistory()
 	}
 }