Jelajahi Sumber

Merge branch 'dev_v1.5.36.2_wh' of jianyu/datatools into hotfix/v1.5.36.2

王浩 2 bulan lalu
induk
melakukan
acb87a0715
3 mengubah file dengan 27 tambahan dan 40 penghapusan
  1. 23 36
      clueSync/everything.go
  2. 3 3
      clueSync/job.go
  3. 1 1
      clueSync/main.go

+ 23 - 36
clueSync/everything.go

@@ -25,24 +25,31 @@ import (
 func everythingSync() {
 	lastEverythingTime := cfg.LastEverythingTime
 	nowTime := time.Now().Format(dates.Date_Full_Layout)
-	sql := fmt.Sprintf(`select * from user_source where channel_code = "JyChCoopA" and create_time > "%s" order by create_time asc`, lastEverythingTime)
+	codeArr := []string{}
+	if len(UserChannel) > 0 {
+		for i, _ := range UserChannel {
+			codeArr = append(codeArr, fmt.Sprintf(`"%s"`, i))
+		}
+	}
+	sql := fmt.Sprintf(`select * from user_source where channel_code in (%s) and create_time > "%s" order by create_time asc`, strings.Join(codeArr, ","), lastEverythingTime)
 	log.Println("三方渠道数据定时任务开始", sql)
 	data := ThirdParty.SelectBySql(sql)
 	if data != nil && *data != nil && len(*data) > 0 {
 		for _, v := range *data {
+			channel_code := gconv.String("channel_code")
+			channelName := UserChannel[channel_code]
 			user_id := common.ObjToString(v["user_id"])
 			position_id := common.Int64All(v["position_id"])
 			phone := common.ObjToString(v["phone"])
 			state := common.IntAll(v["state"])
 			user_mold, is_assign, is_transfer, last_login_time, registe_time, mailbox, source, clueId, order_type := 4, 0, 0, "", "", "", "", int64(0), ""
-			owner, sales_lead_phone, sales_ent_name, sales_position, sales_dep, data_request, unique_id, belongTo, sales_leads_source := "", "", "", "", "", "", "", "", ""
+			owner, sales_lead_phone, sales_ent_name, sales_position, sales_dep, data_request, sales_leads_source := "", "", "", "", "", "", ""
 			cData := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone}, "", "")
 			if cData != nil {
 				is_assign = common.IntAll((*cData)["is_assign"])
 				is_transfer = common.IntAll((*cData)["is_transfer"])
 				clueId = common.Int64All((*cData)["id"])
 			}
-			//
 			udata := TiDb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{"userid": user_id}, "", "")
 			if udata != nil {
 				userSource := common.ObjToString((*udata)["source"])
@@ -98,42 +105,20 @@ func everythingSync() {
 				}
 			}
 			if state == 1 {
-				sales_leads_source = "一切都好登录"
+				sales_leads_source = fmt.Sprintf("%s登录", channelName)
 				if is_assign == 1 || is_transfer == 1 || owner != "" {
 					user_mold = 1
 				} else {
 					user_mold = 2
 				}
 			} else if state == 2 {
-				sales_leads_source = "一切都好注册"
+				sales_leads_source = fmt.Sprintf("%s注册", channelName)
 				if is_assign == 1 || is_transfer == 1 || owner != "" {
 					user_mold = 3
 				} else {
 					user_mold = 4
 				}
 			}
-			if owner == "" && unique_id != "" && belongTo == "市场部" {
-				token := getToken()
-				if token != "" {
-					sss := url.QueryEscape("合作渠道一切都好")
-					urls := `https://a1.7x24cc.com/commonInte?flag=1008&account=N000000029739&accessToken=` + token + `&cusObj={"unique_id":"` + unique_id + `","empNo":"8049","owner":"8049","source":"` + sss + `"}&dbType=0001`
-					bs, err := doGet(urls)
-					if err != nil {
-						log.Println("调用接口失败", unique_id, err)
-					}
-					resMap := common.StringToMap(string(bs))
-					if resMap["success"] != nil && resMap["success"].(bool) {
-						/*ok := TiDbData.Update("customer", map[string]interface{}{"unique_id": unique_id}, map[string]interface{}{"empNo": "8049", "owner": "8049", "source": "合作渠道一切都好"})
-						if ok {
-							log.Println("更新成功", unique_id)
-						} else {
-							log.Println("更新失败", unique_id)
-						}*/
-					} else {
-						log.Println("调用接口失败!!", unique_id)
-					}
-				}
-			}
 			if ThirdParty.Count("user_channel_info", map[string]interface{}{"user_id": user_id}) > 0 {
 				ThirdParty.Update("user_channel_info", map[string]interface{}{"user_id": user_id}, map[string]interface{}{
 					"user_mold":          user_mold,
@@ -175,7 +160,7 @@ func everythingSync() {
 					"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, "登录", "注册")),
+					"new_value":   fmt.Sprintf("通过合作渠道%s", channelName) + fmt.Sprint(common.If(user_mold == 1 || user_mold == 2, "登录", "注册")),
 					"createtime":  nowTime,
 					"BCPCID":      common.GetRandom(32),
 					"operator_id": -1,
@@ -188,10 +173,13 @@ func everythingSync() {
 	log.Println("三方渠道数据定时任务结束")
 }
 
-func saveEverything(user_id, phone, item, sourceName, sourceCode string) bool {
+func saveEverything(user_id, phone, item, sourceName, sourceCode, channelName string) bool {
+	if channelName == "" {
+		channelName = "一切都好"
+	}
 	nowTime, isOk := time.Now().Format(dates.Date_Full_Layout), false
 	user_mold, is_assign, is_transfer, last_login_time, registe_time, mailbox, source, order_type, sales_leads_source := 4, 0, 0, "", "", "", "", "", ""
-	owner, sales_lead_phone, sales_ent_name, sales_position, sales_dep, data_request, unique_id, belongTo, clueId, position_id := "", "", "", "", "", "", "", "", int64(0), int64(0)
+	owner, sales_lead_phone, sales_ent_name, sales_position, sales_dep, data_request, clueId, position_id := "", "", "", "", "", "", int64(0), int64(0)
 	cData := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone}, "", "")
 	if cData != nil {
 		is_assign = common.IntAll((*cData)["is_assign"])
@@ -199,11 +187,10 @@ func saveEverything(user_id, phone, item, sourceName, sourceCode string) bool {
 		clueId = common.Int64All((*cData)["is_transfer"])
 		position_id = common.Int64All((*cData)["position_id"])
 	}
-	/*cuData := TiDbData.FindOne("customer", map[string]interface{}{"phone": phone}, "", "")
+	cuData := TiDbData.FindOne("customer", map[string]interface{}{"phone": phone}, "", "")
 	if cuData != nil {
-		unique_id = common.ObjToString((*cuData)["unique_id"])
 		owner = common.ObjToString((*cuData)["owner"])
-	}*/
+	}
 	dData := Mysql.Find("dataexport_order", map[string]interface{}{"user_id": user_id}, "", "", -1, -1)
 	if dData != nil && len(*dData) > 0 {
 		pMap := map[string]string{}
@@ -262,7 +249,7 @@ func saveEverything(user_id, phone, item, sourceName, sourceCode string) bool {
 	} else {
 		user_mold = 2
 	}
-	if owner == "" && unique_id != "" && belongTo == "市场部" {
+	/*if owner == "" && unique_id != "" && belongTo == "市场部" {
 		token := getToken()
 		if token != "" {
 			sss := url.QueryEscape("合作渠道一切都好")
@@ -283,7 +270,7 @@ func saveEverything(user_id, phone, item, sourceName, sourceCode string) bool {
 				log.Println("调用接口失败!!", unique_id)
 			}
 		}
-	}
+	}*/
 	if ThirdParty.Count("user_channel_info", map[string]interface{}{"user_id": user_id}) > 0 {
 		ThirdParty.Update("user_channel_info", map[string]interface{}{"user_id": user_id}, map[string]interface{}{
 			"user_mold":          user_mold,
@@ -324,7 +311,7 @@ func saveEverything(user_id, phone, item, sourceName, sourceCode string) bool {
 			"clue_id":     clueId,
 			"position_id": common.If(position_id > 0, position_id, -1),
 			"change_type": "退出公海",
-			"new_value":   "通过合作渠道一切就好登录",
+			"new_value":   fmt.Sprintf("通过合作渠道%s登录", channelName),
 			"createtime":  nowTime,
 			"BCPCID":      common.GetRandom(32),
 			"operator_id": -1,

+ 3 - 3
clueSync/job.go

@@ -286,8 +286,7 @@ func FormatData(data map[string]interface{}, item string) (bool, bool, bool) {
 	isGroup, isCommerce := GetCompanyType(cluename, uId) //判断是否集团公司、工商库
 	//获取用户渠道
 	channel := GetUserChannel(uId)
-	_, exit := UserChannel[channel]
-	if source == "0104" || strings.HasPrefix(belong_to, "02") || source == "0102" || source == "0103" || phone == "" || (channel != "" && exit) { //参照用户来源代码表
+	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, true, true
@@ -333,7 +332,8 @@ func FormatData(data map[string]interface{}, item string) (bool, bool, bool) {
 		return true, true, true
 	}
 	if strings.HasPrefix(belong_to, "03") { //一切都好的不进
-		isOk := saveEverything(userId, phone, item, subname, sourceCode)
+		changeName, _ := UserChannel[channel]
+		isOk := saveEverything(userId, phone, item, subname, sourceCode, changeName)
 		log.Println("渠道线索电销", userId, phone, item, subname, sourceCode)
 		if !isOk {
 			return true, true, true

+ 1 - 1
clueSync/main.go

@@ -38,7 +38,7 @@ var (
 	mode                = flag.Int("m", 1, "")
 	startTime, endTime  = "00:00", "23:59"
 	Gmail               mail.GmailAuth
-	UserChannel         map[string]bool
+	UserChannel         = make(map[string]string)
 )
 
 func main() {