Browse Source

客成移交修改

WH01243 7 tháng trước cách đây
mục cha
commit
4ea3907975
2 tập tin đã thay đổi với 158 bổ sung225 xóa
  1. 155 220
      clueSync/kc.go
  2. 3 5
      clueSync/main.go

+ 155 - 220
clueSync/kc.go

@@ -13,7 +13,6 @@ import (
 	"app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/date"
 	"app.yhyue.com/moapp/jybase/mongodb"
-	"app.yhyue.com/moapp/jybase/redis"
 )
 
 func kcSync() {
@@ -44,233 +43,167 @@ func kcJob(data map[string]interface{}) int {
 	nowTime := time.Now().Format(date.Date_Full_Layout)
 	uId, entId, clueId, saveMap, name, positionId, status := common.ObjToString(data["uid"]), fmt.Sprint(data["ent_id"]), int64(0), map[string]interface{}{}, "", int64(0), 1
 	clueData := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", "")
-	if clueData != nil && len(*clueData) > 0 {
-		clueId = common.Int64All((*clueData)["id"])
-		starttime := common.ObjToString(data["vip_starttime"])
-		endtime := common.ObjToString(data["vip_endtime"])
-		// user_role := common.IntAll(data["user_role"])
-		buy_subject := common.IntAll(data["buy_subject"])
-		product_type := common.ObjToString(data["product_type"])
-		data_spec := common.ObjToString(data["data_spec"])
-		userName := common.ObjToString((*clueData)["name"])
-		//phone := common.ObjToString((*clueData)["phone"])
-		product, company_name := 0, common.ObjToString(data["company_name"])
-		productMap := map[string]int{
-			"dhy6":   1,
-			"dhy7":   2,
-			"dhy3":   4,
-			"dhy1":   5,
-			"dhy2":   6,
-			"dhy5":   7,
-			"企业商机管理": 8,
-		}
-		if buy_subject == 1 || buy_subject == 0 {
-			entId = common.ObjToString(data["userid"])
+
+	if clueData == nil || len(*clueData) == 0 {
+		//创建线索
+		saleDep, _, salesperson := FindSaleRecord(orderCode)
+		if saleDep == "客户成功组" {
+
 		}
-		if product_type == "企业商机管理" {
-			product = productMap[product_type]
-			powerData := TiDb.FindOne("dwd_f_data_equity_info", map[string]interface{}{"uid": uId, "product_type": "商机管理"}, "", "comeintime desc")
-			if powerData != nil {
-				starttime = common.ObjToString((*powerData)["starttime"])
-				endtime = common.ObjToString((*powerData)["endtime"])
-			} else {
-				log.Println("客成移交权限未查到--", uId)
-				return 0
-			}
+	}
+
+	clueId = common.Int64All((*clueData)["id"])
+	starttime := common.ObjToString(data["vip_starttime"])
+	endtime := common.ObjToString(data["vip_endtime"])
+	buy_subject := common.IntAll(data["buy_subject"])
+	product_type := common.ObjToString(data["product_type"])
+	data_spec := common.ObjToString(data["data_spec"])
+	userName := common.ObjToString((*clueData)["name"])
+	product, company_name := 0, common.ObjToString(data["company_name"])
+	productMap := map[string]int{
+		"dhy6":   1,
+		"dhy7":   2,
+		"dhy3":   4,
+		"dhy1":   5,
+		"dhy2":   6,
+		"dhy5":   7,
+		"企业商机管理": 8,
+	}
+	if buy_subject == 1 || buy_subject == 0 {
+		entId = common.ObjToString(data["userid"])
+	}
+	if product_type == "企业商机管理" {
+		product = productMap[product_type]
+		powerData := TiDb.FindOne("dwd_f_data_equity_info", map[string]interface{}{"uid": uId, "product_type": "商机管理"}, "", "comeintime desc")
+		if powerData != nil {
+			starttime = common.ObjToString((*powerData)["starttime"])
+			endtime = common.ObjToString((*powerData)["endtime"])
 		} else {
-			if data_spec == "dhy6" {
-				product = 1
-				filter := common.ObjToString(data["filter"])
-				filterMap := map[string]interface{}{}
-				json.Unmarshal([]byte(filter), &filterMap)
-				if len(filterMap) > 0 {
-					areaCount := common.IntAll(filterMap["areaCount"])
-					if areaCount == 1 {
-						product = 3
-					}
+			log.Println("客成移交权限未查到--", uId)
+			return 0
+		}
+	} else {
+		if data_spec == "dhy6" {
+			product = 1
+			filter := common.ObjToString(data["filter"])
+			filterMap := map[string]interface{}{}
+			json.Unmarshal([]byte(filter), &filterMap)
+			if len(filterMap) > 0 {
+				areaCount := common.IntAll(filterMap["areaCount"])
+				if areaCount == 1 {
+					product = 3
 				}
-			} else {
-				product = productMap[data_spec]
 			}
+		} else {
+			product = productMap[data_spec]
 		}
-		//同一公司名称(以客户详情-组织机构-公司名称)下的线索需分配给同1人
-		//合力亿捷线索同步
-		/*customerData := TiDbData.FindOne("customer", map[string]interface{}{"phone": phone}, "", "")
-		if customerData != nil {
-			log.Println("移交客成查询到合力亿捷")
-			status999 := common.ObjToString((*customerData)["status999"])               //线索状态
-			source := common.ObjToString((*customerData)["source"])                     //销售来源
-			customerNeeds := common.ObjToString((*customerData)["customerNeeds"])       //客户需求
-			wantGoods := common.ObjToString((*customerData)["wantGoods"])               //意向产品
-			job := common.ObjToString((*customerData)["job"])                           //职位
-			createTime := common.ObjToString((*customerData)["createTime"])             //创建时间
-			lastUpdateTime := common.ObjToString((*customerData)["lastUpdateTime"])     //更新时间
-			area := common.ObjToString((*customerData)["area"])                         //关注区域
-			customerBudget := common.ObjToString((*customerData)["customerBudget"])     //客户预算
-			isPolicymaker := common.ObjToString((*customerData)["customerBudget"])      //是否为决策人
-			belongToIndustry := common.ObjToString((*customerData)["belongToIndustry"]) //所属行业
-			seatNumber := common.ObjToString((*customerData)["empNo"])                  //坐席号
-			statusMap := map[string]string{
-				"status0":     "08",
-				"status1":     "07",
-				"status2":     "06",
-				"status3":     "05",
-				"status4":     "04",
-				"status6":     "00",
-				"status5":     "01",
-				"spaceNumber": "02",
-				"phoneDown":   "02",
-			}
-			if status999 != "" {
-				status999 = statusMap[status999]
-			} else {
-				status999 = "01"
-			}
-			top_cluetype := "172"
-			sub_cluetype := ""
-			cluetypeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"name": "其他-" + source}, "", "")
-			if cluetypeData != nil {
-				sub_cluetype = common.ObjToString((*cluetypeData)["code"])
-			}
-			wantGoods = strings.ReplaceAll(wantGoods, "剑鱼大会员", "大会员")
-			wantGoods = strings.ReplaceAll(wantGoods, "数据导出", "数据流量包")
-			if isPolicymaker == "是" {
-				isPolicymaker = "决策人"
-			} else {
-				isPolicymaker = "使用人"
-			}
-			areaCodeArr := []string{}
-			areaCode := ""
-			for _, v := range strings.Split(area, ",") {
-				areaCodeArr = append(areaCodeArr, AreaCode[v])
-			}
-			if len(areaCodeArr) > 0 {
-				areaCode = strings.Join(areaCodeArr, ",")
-			}
-			SalePositionId := getSeatNumberPositionId(seatNumber)
-			TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, map[string]interface{}{
-				"position_id":         SalePositionId,
-				"seatNumber":          seatNumber,
-				"is_assign":           -2,
-				"createtime":          createTime,
-				"updatetime":          lastUpdateTime,
-				"top_cluetype":        top_cluetype,
-				"sub_cluetype":        sub_cluetype,
-				"customer_demand":     customerNeeds,
-				"intended_products":   wantGoods,
-				"customer_budget":     customerBudget,
-				"contact_type":        isPolicymaker,
-				"position":            job,
-				"industry":            belongToIndustry,
-				"follow_project_area": areaCode,
+	}
+	//同一公司名称(以客户详情-组织机构-公司名称)下的线索需分配给同1人
+	entIds := common.IntAll(data["ent_id"])
+	positionId, name = cAutoDraw(entIds)
+	log.Println("移交客成positionId", positionId, name)
+	saveMap = map[string]interface{}{
+		"clue_id":                   clueId,
+		"transfertime":              nowTime,
+		"position_id":               positionId,
+		"name":                      name,
+		"service_starttime":         starttime,
+		"service_endtime":           endtime,
+		"ent_id":                    entId,
+		"is_task":                   1,
+		"tasktime":                  nowTime,
+		"taskstatus":                0,
+		"tasksource":                "1",
+		"is_admin":                  1,
+		"product_access":            product,
+		"buy_subject":               buy_subject,
+		"relationship_building_way": 1,
+		"inventory_way":             1,
+		"training_way":              1,
+		"is_pre_sales_training":     0,
+		"service_stage":             1,
+		"company_name":              company_name,
+	}
+	if TiDb.Count("dwd_f_csm_customer_info", map[string]interface{}{"clue_id": clueId}) > 0 {
+		csmdata := TiDb.FindOne("dwd_f_csm_customer_info", map[string]interface{}{"clue_id": clueId}, "", "")
+		if csmdata != nil && len(*csmdata) > 0 {
+			TiDb.Update("dwd_f_csm_customer_info", map[string]interface{}{"clue_id": clueId}, map[string]interface{}{
+				"is_transfer":           0,
+				"is_renewal_protection": 0,
+				"product_access":        product,
+				"buy_subject":           buy_subject,
+				"transfertime":          nowTime,
+				"service_starttime":     starttime,
+				"service_endtime":       endtime,
+				"ent_id":                entId,
+				"company_name":          company_name,
+			})
+			TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
+				"clue_id":     clueId,
+				"position_id": (*csmdata)["position_id"],
+				"change_type": "成交客户移交",
+				"new_value":   "移交至客户成功组",
+				"createtime":  nowTime,
+				"BCPCID":      common.GetRandom(32),
+				"operator_id": -1,
 			})
-		}*/
-		//
-		entIds := common.IntAll(data["ent_id"])
-		positionId, name = cAutoDraw(entIds)
-		log.Println("移交客成positionId", positionId, name)
-		saveMap = map[string]interface{}{
-			"clue_id":                   clueId,
-			"transfertime":              nowTime,
-			"position_id":               positionId,
-			"name":                      name,
-			"service_starttime":         starttime,
-			"service_endtime":           endtime,
-			"ent_id":                    entId,
-			"is_task":                   1,
-			"tasktime":                  nowTime,
-			"taskstatus":                0,
-			"tasksource":                "1",
-			"is_admin":                  1,
-			"product_access":            product,
-			"buy_subject":               buy_subject,
-			"relationship_building_way": 1,
-			"inventory_way":             1,
-			"training_way":              1,
-			"is_pre_sales_training":     0,
-			"service_stage":             1,
-			"company_name":              company_name,
+			TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
+				"clue_id":      clueId,
+				"position_id":  (*csmdata)["position_id"],
+				"change_field": "position_id",
+				"change_type":  "客户成功经理",
+				"old_value":    "/",
+				"new_value":    (*csmdata)["name"],
+				"createtime":   nowTime,
+				"BCPCID":       common.GetRandom(32),
+				"operator_id":  -1,
+			})
+			TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{"is_transfer": 1, "updatetime": nowTime, "name": userName})
 		}
-		if TiDb.Count("dwd_f_csm_customer_info", map[string]interface{}{"clue_id": clueId}) > 0 {
-			csmdata := TiDb.FindOne("dwd_f_csm_customer_info", map[string]interface{}{"clue_id": clueId}, "", "")
-			if csmdata != nil && len(*csmdata) > 0 {
-				TiDb.Update("dwd_f_csm_customer_info", map[string]interface{}{"clue_id": clueId}, map[string]interface{}{
-					"is_transfer":           0,
-					"is_renewal_protection": 0,
-					"product_access":        product,
-					"buy_subject":           buy_subject,
-					"transfertime":          nowTime,
-					"service_starttime":     starttime,
-					"service_endtime":       endtime,
-					"ent_id":                entId,
-					"company_name":          company_name,
-				})
-				TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":     clueId,
-					"position_id": (*csmdata)["position_id"],
-					"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":  (*csmdata)["position_id"],
-					"change_field": "position_id",
-					"change_type":  "客户成功经理",
-					"old_value":    "/",
-					"new_value":    (*csmdata)["name"],
-					"createtime":   nowTime,
-					"BCPCID":       common.GetRandom(32),
-					"operator_id":  -1,
-				})
-				TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{"is_transfer": 1, "updatetime": nowTime, "name": userName})
-			}
+	} else {
+		cId, ok, updateId1, updateId2, updateId3 := int64(-1), false, int64(-1), int64(-1), int64(-1)
+		if TiDb.ExecTx("保存客户", func(tx *sql.Tx) bool {
+			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})
+			updateId1 = 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,
+			})
+			updateId2 = 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,
+			})
+			updateId3 = 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":    name,
+				"createtime":   nowTime,
+				"BCPCID":       common.GetRandom(32),
+				"operator_id":  -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)
+			log.Println("保存客户成功")
 		} else {
-			cId, ok, updateId1, updateId2, updateId3 := int64(-1), false, int64(-1), int64(-1), int64(-1)
-			if TiDb.ExecTx("保存客户", func(tx *sql.Tx) bool {
-				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})
-				updateId1 = 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,
-				})
-				updateId2 = 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,
-				})
-				updateId3 = 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":    name,
-					"createtime":   nowTime,
-					"BCPCID":       common.GetRandom(32),
-					"operator_id":  -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)
-				log.Println("保存客户成功")
-			} else {
-				log.Println("保存客户失败!!!", clueId, cId, ok, updateId1, updateId2, updateId3, " 用户信息 ", name, positionId, uId)
-			}
+			log.Println("保存客户失败!!!", clueId, cId, ok, updateId1, updateId2, updateId3, " 用户信息 ", name, positionId, uId)
 		}
-		return status
-	} else {
+	}
+	return status
+	/*} else {
 		log.Println("客户未查到线索!!!", uId)
 		if isExists, _ := redis.Exists("bidx", "bidx_uId_"+uId); isExists {
 			redisInt := redis.GetInt("bidx", "bidx_uId_"+uId)
@@ -284,7 +217,7 @@ func kcJob(data map[string]interface{}) int {
 			redis.Put("bidx", "bidx_uId_"+uId, 1, 3600)
 			return 0
 		}
-	}
+	}*/
 }
 
 func cAutoDraw(entId int) (positionId int64, name string) {
@@ -864,6 +797,8 @@ func FindSaleRecord(orderCode string) (dept string, positionId int64, position s
 			saler_dept = "销售部"
 		} else if strings.Contains(saler_dept, "市场") {
 			saler_dept = "市场部"
+		} else if strings.Contains(saler_dept, "客户成功组") {
+			saler_dept = "客户成功组"
 		} else {
 			saler_dept = ""
 		}

+ 3 - 5
clueSync/main.go

@@ -6,10 +6,8 @@ import (
 	"app.yhyue.com/moapp/jybase/mongodb"
 	"app.yhyue.com/moapp/jybase/mysql"
 	"app.yhyue.com/moapp/jybase/redis"
-	"bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
 	"flag"
 	"fmt"
-	"github.com/robfig/cron"
 	"log"
 )
 
@@ -145,7 +143,8 @@ func main() {
 	MgoQyxy = mongodb.NewMgoWithUser(db.MgoQyxy.Address, db.MgoQyxy.DbName, db.MgoQyxy.User, db.MgoQyxy.Password, db.MgoQyxy.DbSize)
 	InitArea()
 	InitProduct(db.ProductArr)
-	if *mode == 1 {
+
+	/*if *mode == 1 {
 		go ordersClue() //后台订单进线索
 		//一秒钟一次
 		go p.VarTimeTask.RunInSecondTimeLoop("1秒钟定时任务", "", "", db.CornExp8, true, true, nil, func() {
@@ -159,7 +158,6 @@ func main() {
 		})
 		//5分钟一次
 		go p.VarTimeTask.RunInTimeSection("5分钟定时任务1", db.CornExp2Start, db.CornExp2End, db.CornExp2, func(dayFirst bool) {
-
 			users()               //新注册用户进线索
 			saleLeads()           //留资进线索
 			eventReg()            //渠道
@@ -234,5 +232,5 @@ func main() {
 	} else {
 		users()
 		saleLeads()
-	}
+	}*/
 }