Ver Fonte

客成查找人修改

WH01243 há 18 horas atrás
pai
commit
142fb45f18
1 ficheiros alterados com 68 adições e 103 exclusões
  1. 68 103
      clueSync/kc.go

+ 68 - 103
clueSync/kc.go

@@ -117,6 +117,7 @@ ORDER BY
 	log.Println("客户成功系统移交定时任务结束")
 	log.Println("客户成功系统移交定时任务结束")
 }
 }
 
 
+// 进客成处理
 func kcJob(data map[string]interface{}) int {
 func kcJob(data map[string]interface{}) int {
 	nowTime := time.Now().Format(date.Date_Full_Layout)
 	nowTime := time.Now().Format(date.Date_Full_Layout)
 	uId, entId, clueId, saveMap, status := "", gconv.String(data["ent_id"]), int64(0), map[string]interface{}{}, 1
 	uId, entId, clueId, saveMap, status := "", gconv.String(data["ent_id"]), int64(0), map[string]interface{}{}, 1
@@ -231,7 +232,7 @@ func kcJob(data map[string]interface{}) int {
 			log.Println(1111111, id, orderCode)
 			log.Println(1111111, id, orderCode)
 			//'已移交销售,0移交客成 1移交销售',
 			//'已移交销售,0移交客成 1移交销售',
 			is_transfer := gconv.Int64((*csmdata)["is_transfer"])
 			is_transfer := gconv.Int64((*csmdata)["is_transfer"])
-			customerPositionId, customerName := cAutoDraw(0, orderPositionId, salesperson, saleDep, true, csmdata)
+			customerPositionId, customerName := cAutoDraw(0, orderPositionId, salesperson, saleDep, csmdata, company_name)
 			log.Println("移交客成positionId", customerPositionId, customerName, saleDep, orderPositionId, salesperson, true)
 			log.Println("移交客成positionId", customerPositionId, customerName, saleDep, orderPositionId, salesperson, true)
 			oldName := gconv.String((*csmdata)["name"])
 			oldName := gconv.String((*csmdata)["name"])
 			updateMap := map[string]interface{}{
 			updateMap := map[string]interface{}{
@@ -300,7 +301,7 @@ func kcJob(data map[string]interface{}) int {
 			TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{"is_transfer": 1, "updatetime": nowTime, "name": userName})
 			TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{"is_transfer": 1, "updatetime": nowTime, "name": userName})
 		}
 		}
 	} else {
 	} else {
-		customerPositionId, customerName := cAutoDraw(gconv.Int(entId), orderPositionId, salesperson, saleDep, false, nil)
+		customerPositionId, customerName := cAutoDraw(gconv.Int(entId), orderPositionId, salesperson, saleDep, nil, company_name)
 		log.Println("移交客成positionId", customerPositionId, customerName, saleDep, orderPositionId, salesperson, false)
 		log.Println("移交客成positionId", customerPositionId, customerName, saleDep, orderPositionId, salesperson, false)
 		cId, ok, updateId1, updateId2, updateId3 := int64(0), false, int64(0), int64(0), int64(0)
 		cId, ok, updateId1, updateId2, updateId3 := int64(0), false, int64(0), int64(0), int64(0)
 		if TiDb.ExecTx("保存客户", func(tx *sql.Tx) bool {
 		if TiDb.ExecTx("保存客户", func(tx *sql.Tx) bool {
@@ -355,129 +356,93 @@ func kcJob(data map[string]interface{}) int {
 	return status
 	return status
 }
 }
 
 
-func cAutoDraw(entId int, orderPositionId int64, salesperson, saleDep string, isExist bool, csmdata *map[string]interface{}) (positionId int64, name string) {
+// 客成人员查询
+func cAutoDraw(entId int, orderPositionId int64, salesperson, saleDep string, customData *map[string]interface{}, company_name string) (positionId int64, name string) {
+	if customData != nil {
+		//查看一下之前有没有人
+		positionId = common.Int64All((*customData)["position_id"])
+		if positionId != 0 {
+			name = gconv.String((*customData)["name"])
+			return
+		}
+	}
 	query := `SELECT name,position_id FROM dwd_d_crm_department_level_succbi WHERE bi_pcode = (SELECT bi_code FROM dwd_d_crm_department_level_succbi WHERE name = "客户成功部" and resign=0 and  ent_id=?) and resign = 0 and   position_id   is  not  null `
 	query := `SELECT name,position_id FROM dwd_d_crm_department_level_succbi WHERE bi_pcode = (SELECT bi_code FROM dwd_d_crm_department_level_succbi WHERE name = "客户成功部" and resign=0 and  ent_id=?) and resign = 0 and   position_id   is  not  null `
 	data := TiDb.SelectBySql(query, db.EntId)
 	data := TiDb.SelectBySql(query, db.EntId)
 	if data == nil || len(*data) == 0 {
 	if data == nil || len(*data) == 0 {
 		return
 		return
 	}
 	}
-	positionId, name = findKcOldPerson(entId, orderPositionId, salesperson, saleDep, isExist, csmdata, data)
-	if positionId == 0 {
-		positionId, name = findKcNewPerson(entId, data)
-	}
-	return
-}
-func findKcOldPerson(entId int, orderPositionId int64, salesperson, saleDep string, isExist bool, csmdata *map[string]interface{}, data *[]map[string]interface{}) (positionId int64, name string) {
-	//判断是否需要新增客成数据
-	if isExist {
-		//用户存在客成数据
-		positionid := common.Int64All((*csmdata)["position_id"])
-		if positionid != 0 {
-			//以前没有,需要找一个新的
-			for _, v := range *data {
-				deptPositionId := gconv.Int64(v["position_id"])
-				if deptPositionId == positionid {
-					positionId = positionid
-					name = gconv.String((*csmdata)["name"])
-					return
-				}
-			}
-		}
-		//原始用户已离职 查看订单是否有合适的订单
-		if saleDep == "客户成功部" {
-			positionId = orderPositionId
-			name = salesperson
-			return
-		}
+	//个人的话随机分
+	if entId == 0 {
+		positionId, name = getKCperson(data)
+		return
 	}
 	}
-	//客成数据不存在的时候
-	//查找企业有没有其他信息
-	if entId > 0 {
-		entdata := TiDb.Find("dwd_f_csm_customer_info", map[string]interface{}{"ent_id": entId}, "", "", -1, -1)
-		if entdata != nil && len(*entdata) > 0 {
-			for _, v := range *entdata {
-				positionid := common.Int64All(v["position_id"])
+	//看其他公司上边有没有客成人员  有的话新分给这个人
+	customerData := TiDb.Find("dwd_f_csm_customer_info", map[string]interface{}{"company_name": company_name}, "", "", -1, -1)
+	if customerData != nil && len(*customerData) > 0 {
+		for _, v := range *customerData {
+			positionid := common.Int64All(v["position_id"])
+			if positionid != 0 {
 				name = gconv.String(v["name"])
 				name = gconv.String(v["name"])
-				for _, v := range *data {
-					deptPositionId := gconv.Int64(v["position_id"])
-					if deptPositionId == positionId {
-						positionId = positionid
-						name = gconv.String((*csmdata)["name"])
-						return
-					}
-				}
+				return
 			}
 			}
 		}
 		}
-		//原始用户已离职 或者没有查找相关企业客成信息    以订单信息为主
-		if saleDep == "客户成功部" {
-			positionId = orderPositionId
-			name = salesperson
-		}
-		return
-		//没有相同企业的客成信息
-	} else {
-		//没有人  分配给自己
-		if saleDep == "客户成功部" {
-			positionId = orderPositionId
-			name = salesperson
-			return
-		}
+	}
+	//没有的话看下业绩归属
+	if saleDep == "客户成功部" {
+		positionId = orderPositionId
+		name = salesperson
 		return
 		return
 	}
 	}
+	//随机分配
+	positionId, name = getKCperson(data)
+	return
 }
 }
-func findKcNewPerson(entId int, data *[]map[string]interface{}) (positionId int64, name string) {
-	if entId > 0 {
-		entdata := TiDb.FindOne("dwd_f_csm_customer_info", map[string]interface{}{"ent_id": entId}, "", "")
-		if entdata != nil && len(*entdata) > 0 {
-			positionId = common.Int64All((*entdata)["position_id"])
-			name = gconv.String((*entdata)["name"])
-			return
-		}
-	}
-	sql := `select a.name,a.count from dwd_f_csm_customer_autodraw_record a INNER JOIN dwd_d_crm_department_level_succbi b on b.ent_id=? and  (a.name = b.name)  and  b.resign = 0`
-	countData := TiDb.SelectBySql(sql, db.EntId)
-	if countData != nil && len(*countData) > 0 {
-		for _, v := range *data {
-			//判断是否有新员工
-			isOk := false
-			for _, vv := range *countData {
-				if gconv.String(v["name"]) == gconv.String(vv["name"]) {
-					isOk = true
+
+// 获取客成里边最少的一个人
+func getKCperson(data *[]map[string]interface{}) (positionId int64, name string) {
+	if data != nil && len(*data) > 0 {
+		sql := `select a.name,a.count from dwd_f_csm_customer_autodraw_record a INNER JOIN dwd_d_crm_department_level_succbi b on b.ent_id=? and  (a.name = b.name)  and  b.resign = 0`
+		countData := TiDb.SelectBySql(sql, db.EntId)
+		if countData != nil && len(*countData) > 0 {
+			for _, v := range *countData {
+				//判断是否有新员工
+				isOk := false
+				for _, vv := range *data {
+					if gconv.String(v["name"]) == gconv.String(vv["name"]) {
+						isOk = true
+					}
+				}
+				//有新员工直接分给新员工
+				if !isOk {
+					name = gconv.String(v["name"])
+					rData := TiDb.FindOne("dwd_f_csm_customer_autodraw_record", map[string]interface{}{}, "", "count desc")
+					TiDb.Insert("dwd_f_csm_customer_autodraw_record", map[string]interface{}{
+						"name":  name,
+						"count": common.Int64All((*rData)["count"]),
+					})
+					break
 				}
 				}
 			}
 			}
-			//有新员工直接分给新员工
-			if !isOk {
-				name = gconv.String(v["name"])
-				rData := TiDb.FindOne("dwd_f_csm_customer_autodraw_record", map[string]interface{}{}, "", "count desc")
-				TiDb.Insert("dwd_f_csm_customer_autodraw_record", map[string]interface{}{
-					"name":  name,
-					"count": common.Int64All((*rData)["count"]),
-				})
-				break
-			}
-		}
-		res := int64(0)
-		countres := 0
-		for _, v := range *countData {
-			if countres == 0 {
-				res = common.Int64All(v["count"])
-				name = gconv.String(v["name"])
-			} else {
-				if common.Int64All(v["count"]) <= res {
+			res := int64(0)
+			countres := 0
+			for _, v := range *countData {
+				if countres == 0 {
 					res = common.Int64All(v["count"])
 					res = common.Int64All(v["count"])
 					name = gconv.String(v["name"])
 					name = gconv.String(v["name"])
+				} else {
+					if common.Int64All(v["count"]) <= res {
+						res = common.Int64All(v["count"])
+						name = gconv.String(v["name"])
+					}
 				}
 				}
+				countres++
 			}
 			}
-			countres++
-		}
-	}
-	for _, v := range *data {
-		if name == gconv.String(v["name"]) {
-			positionId = common.Int64All(v["position_id"])
 		}
 		}
 	}
 	}
 	return
 	return
 }
 }
+
+// 客成自动加入任务车
 func kcAuto() {
 func kcAuto() {
 	log.Println("客户成功系统自动进入任务车定时任务开始")
 	log.Println("客户成功系统自动进入任务车定时任务开始")
 	nowTime := time.Now().Format(date.Date_Full_Layout)
 	nowTime := time.Now().Format(date.Date_Full_Layout)