yuelujie 1 mēnesi atpakaļ
vecāks
revīzija
d5771fcf8f
6 mainītis faili ar 269 papildinājumiem un 114 dzēšanām
  1. 6 1
      clueSync/autoTask.go
  2. 24 0
      clueSync/config.go
  3. 181 109
      clueSync/everything.go
  4. 3 2
      clueSync/job.go
  5. 49 1
      clueSync/jobutil.go
  6. 6 1
      clueSync/main.go

+ 6 - 1
clueSync/autoTask.go

@@ -629,7 +629,12 @@ func ClueToDxTask() {
 			if data != nil && len(*data) > 0 {
 				log.Println("企业下员工数:", gconv.Int(val["ent_id"]), len(*data))
 				for _, vv := range *data {
-					childIds = append(childIds, gconv.String(vv["userid"]))
+					//判断员工是否有大会员权益
+					count := TiDb.CountBySql("SELECT COUNT(1) FROM dwd_f_data_equity_info WHERE (product_type = '大会员' or product_type='企业商机管理') AND equity_status = 1 AND user_type = 2 AND user_role = 1 AND uid = ?", gconv.String(vv["uid"]))
+					log.Println("用户是否有权益", gconv.String(vv["uid"]), count)
+					if count > 0 {
+						childIds = append(childIds, gconv.String(vv["userid"]))
+					}
 				}
 			}
 		}

+ 24 - 0
clueSync/config.go

@@ -5,6 +5,7 @@ import (
 	"context"
 	"fmt"
 	"github.com/ClickHouse/clickhouse-go/v2"
+	"github.com/gogf/gf/v2/util/gconv"
 	"gopkg.in/gomail.v2"
 	"log"
 	"time"
@@ -284,6 +285,29 @@ func InitProduct(product []string) {
 		ProductMap[v] = "dk"
 	}
 }
+func InitUserChannel() {
+	data := TiDb.SelectBySql(`SELECT
+	a.code,
+	a.clue_code,
+	b.name 
+FROM
+	jianyu.short_url a
+	INNER JOIN dwd_d_userbase_belongto_rulecode b ON a.clue_code = b.CODE  and   a.clue = 1 `)
+	if data != nil && len(*data) > 0 {
+		for _, v := range *data {
+			code := gconv.String(v["code"])
+			UserChannel[code] = map[string]interface{}{
+				"name":     gconv.String(v["name"]),
+				"clueCode": gconv.String(v["clue_code"]),
+			}
+		}
+	}
+	UserChannel["JyChCoopA"] = map[string]interface{}{
+		"name":     "一切都好",
+		"clueCode": "0301",
+	}
+	log.Println(UserChannel)
+}
 func ConnectClickhouse(cHouseConfig *CHouseConfig) error {
 	var (
 		ctx = context.Background()

+ 181 - 109
clueSync/everything.go

@@ -22,13 +22,23 @@ import (
 	"app.yhyue.com/moapp/jybase/common"
 )
 
+// 渠道定时任务
 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)
+	//sql := fmt.Sprintf(`select * from user_source where  id  =662847`)
+
 	log.Println("三方渠道数据定时任务开始", sql)
 	data := ThirdParty.SelectBySql(sql)
 	if data != nil && *data != nil && len(*data) > 0 {
+<<<<<<< HEAD
 		for _, v := range *data {
 			user_id := common.ObjToString(v["user_id"])
 			position_id := common.Int64All(v["position_id"])
@@ -77,123 +87,181 @@ func everythingSync() {
 				if len(pArr) > 0 {
 					order_type = strings.Join(pArr, ",")
 				}
+=======
+		everythingSyncHandle(data, true)
+	}
+	sql = fmt.Sprintf(`select * from user_source where channel_code in (%s) and ishandle=1  order by create_time asc`, strings.Join(codeArr, ","))
+	log.Println("三方渠道数据定时任务开始1", sql)
+	data = ThirdParty.SelectBySql(sql)
+	if data != nil && *data != nil && len(*data) > 0 {
+		everythingSyncHandle(data, false)
+	}
+	log.Println("三方渠道数据定时任务结束")
+}
+func everythingSyncHandle(data *[]map[string]interface{}, isUpdate bool) {
+	nowTime := time.Now().Format(dates.Date_Full_Layout)
+	for _, v := range *data {
+		id := gconv.Int64(v["id"])
+		channel_code := gconv.String(v["channel_code"])
+		changeMap := UserChannel[channel_code]
+		channeName := changeMap["name"]
+		channelCode := changeMap["clueCode"]
+		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, 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"])
+			if userSource == "0102" {
+				continue
+>>>>>>> master
 			}
-			uData, ok := Mgo.FindOne("user", map[string]interface{}{"_id": mongodb.StringTOBsonId(user_id)})
-			if ok && uData != nil {
-				l_registedate := common.Int64All((*uData)["l_registedate"])
-				registe_time = time.Unix(l_registedate, 0).Format(dates.Date_Full_Layout)
+		}
+		//
+		/*cuData := TiDbData.FindOne("customer", map[string]interface{}{"phone": phone}, "", "")
+		if cuData != nil {
+			owner = common.ObjToString((*cuData)["owner"])
+			unique_id = common.ObjToString((*cuData)["unique_id"])
+			belongTo = common.ObjToString((*cuData)["belongTo"])
+		}*/
+		vData := TiDb.FindOne("dwd_f_userbase_visit_info", map[string]interface{}{"userid": user_id}, "", "")
+		if vData != nil {
+			last_login_time = common.ObjToString((*vData)["date"])
+		}
+		dData := Mysql.Find("dataexport_order", map[string]interface{}{"user_id": user_id}, "", "", -1, -1)
+		if dData != nil && len(*dData) > 0 {
+			pMap := map[string]string{}
+			pArr := []string{}
+			for _, v := range *dData {
+				product_type := common.ObjToString(v["product_type"])
+				pMap[product_type] = "1"
 			}
-			sData, oks := Mgo.Find("saleLeads", map[string]interface{}{"userid": user_id}, `{"_id":-1}`, nil, false, 0, 1)
-			if oks && sData != nil {
-				if len(*sData) > 0 {
-					sDatas := (*sData)[0]
-					sales_lead_phone = common.ObjToString(sDatas["phone"])
-					sales_position = common.ObjToString(sDatas["position"])
-					sales_ent_name = common.ObjToString(sDatas["company"])
-					sales_dep = common.ObjToString(sDatas["branch"])
-					if sales_dep == "" {
-						sales_dep = common.ObjToString(sDatas["department"])
-					}
-					data_request = common.ObjToString(sDatas["data_requirement"])
-					mailbox = common.ObjToString(sDatas["mail"])
-					source = common.ObjToString(sDatas["interest"])
-				}
+			for k := range pMap {
+				pArr = append(pArr, k)
 			}
-			if state == 1 {
-				sales_leads_source = "一切都好登录"
-				if is_assign == 1 || is_transfer == 1 || owner != "" {
-					user_mold = 1
-				} else {
-					user_mold = 2
-				}
-			} else if state == 2 {
-				sales_leads_source = "一切都好注册"
-				if is_assign == 1 || is_transfer == 1 || owner != "" {
-					user_mold = 3
-				} else {
-					user_mold = 4
-				}
+			if len(pArr) > 0 {
+				order_type = strings.Join(pArr, ",")
 			}
-			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)
-					}
+		}
+		uData, ok := Mgo.FindOne("user", map[string]interface{}{"_id": mongodb.StringTOBsonId(user_id)})
+		if ok && uData != nil {
+			l_registedate := common.Int64All((*uData)["l_registedate"])
+			registe_time = time.Unix(l_registedate, 0).Format(dates.Date_Full_Layout)
+		}
+		if TiDb.Count("dwd_f_userbase_baseinfo", map[string]interface{}{
+			"userid": user_id,
+		}) <= 0 {
+			ThirdParty.Update("user_source", map[string]interface{}{
+				"id": id,
+			}, map[string]interface{}{
+				"ishandle": 1,
+			})
+			continue
+		}
+		sData, oks := Mgo.Find("saleLeads", map[string]interface{}{"userid": user_id}, `{"_id":-1}`, nil, false, 0, 1)
+		if oks && sData != nil {
+			if len(*sData) > 0 {
+				sDatas := (*sData)[0]
+				sales_lead_phone = common.ObjToString(sDatas["phone"])
+				sales_position = common.ObjToString(sDatas["position"])
+				sales_ent_name = common.ObjToString(sDatas["company"])
+				sales_dep = common.ObjToString(sDatas["branch"])
+				if sales_dep == "" {
+					sales_dep = common.ObjToString(sDatas["department"])
 				}
+				data_request = common.ObjToString(sDatas["data_requirement"])
+				mailbox = common.ObjToString(sDatas["mail"])
+				source = common.ObjToString(sDatas["interest"])
 			}
-			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,
-					"last_login_time":    common.If(last_login_time != "", last_login_time, nil),
-					"sales_lead_phone":   sales_lead_phone,
-					"sales_ent_name":     sales_ent_name,
-					"sales_position":     sales_position,
-					"sales_dep":          sales_dep,
-					"sales_leads_source": sales_leads_source,
-					"mailbox":            mailbox,
-					"order_type":         order_type,
-					"data_request":       data_request,
-					"source":             source,
-					"update_time":        nowTime,
-				})
+		}
+		if state == 1 {
+			sales_leads_source = fmt.Sprintf("%s登录", channeName)
+			if is_assign == 1 || is_transfer == 1 || owner != "" {
+				user_mold = 1
 			} else {
-				ThirdParty.Insert("user_channel_info", map[string]interface{}{
-					"user_id":            user_id,
-					"registe_time":       registe_time,
-					"phone":              phone,
-					"user_mold":          user_mold,
-					"last_login_time":    common.If(last_login_time != "", last_login_time, nil),
-					"sales_lead_phone":   sales_lead_phone,
-					"sales_ent_name":     sales_ent_name,
-					"sales_position":     sales_position,
-					"sales_dep":          sales_dep,
-					"sales_leads_source": sales_leads_source,
-					"order_type":         order_type,
-					"mailbox":            mailbox,
-					"data_request":       data_request,
-					"source":             source,
-					"update_time":        nowTime,
-				})
+				user_mold = 2
 			}
-			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,
-				})
+		} else if state == 2 {
+			sales_leads_source = fmt.Sprintf("%s注册", channeName)
+			if is_assign == 1 || is_transfer == 1 || owner != "" {
+				user_mold = 3
+			} else {
+				user_mold = 4
 			}
 		}
+		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,
+				"last_login_time":    common.If(last_login_time != "", last_login_time, nil),
+				"sales_lead_phone":   sales_lead_phone,
+				"sales_ent_name":     sales_ent_name,
+				"sales_position":     sales_position,
+				"sales_dep":          sales_dep,
+				"sales_leads_source": sales_leads_source,
+				"mailbox":            mailbox,
+				"order_type":         order_type,
+				"data_request":       data_request,
+				"source":             source,
+				"update_time":        nowTime,
+			})
+		} else {
+			ThirdParty.Insert("user_channel_info", map[string]interface{}{
+				"user_id":            user_id,
+				"registe_time":       registe_time,
+				"phone":              phone,
+				"user_mold":          user_mold,
+				"last_login_time":    common.If(last_login_time != "", last_login_time, nil),
+				"sales_lead_phone":   sales_lead_phone,
+				"sales_ent_name":     sales_ent_name,
+				"sales_position":     sales_position,
+				"sales_dep":          sales_dep,
+				"sales_leads_source": sales_leads_source,
+				"order_type":         order_type,
+				"mailbox":            mailbox,
+				"data_request":       data_request,
+				"source":             source,
+				"update_time":        nowTime,
+			})
+		}
+		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": channelCode})
+			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.Sprintf("通过合作渠道%s", channeName) + fmt.Sprint(common.If(user_mold == 1 || user_mold == 2, "登录", "注册")),
+				"createtime":  nowTime,
+				"BCPCID":      common.GetRandom(32),
+				"operator_id": -1,
+			})
+		}
+		ThirdParty.Update("user_source", map[string]interface{}{
+			"id": id,
+		}, map[string]interface{}{
+			"ishandle": 0,
+		})
+	}
+	if isUpdate {
 		cfg.LastEverythingTime = common.ObjToString((*data)[len(*data)-1]["create_time"])
+		common.WriteSysConfig(&cfg)
 	}
-	common.WriteSysConfig(&cfg)
-	log.Println("三方渠道数据定时任务结束")
 }
-
-func saveEverything(user_id, phone, item, sourceName, sourceCode string) bool {
+func saveEverything(user_id, phone, item, sourceName, sourceCode, belongTo string) bool {
+	changeMap := UserChannel[belongTo]
+	changeName := gconv.String(changeMap["name"])
 	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"])
@@ -201,14 +269,18 @@ 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"])
+<<<<<<< HEAD
 	}*/
 	dDataSql := fmt.Sprintf(`select b.product_type  from  dataexport_order  a   INNER JOIN  
     jy_order_detail   b    on   a.order_code=b.order_code and    a.user_id = ?`, user_id)
 	dData := Mysql.SelectBySql(dDataSql)
+=======
+	}
+	dData := Mysql.Find("dataexport_order", map[string]interface{}{"user_id": user_id}, "", "", -1, -1)
+>>>>>>> master
 	if dData != nil && len(*dData) > 0 {
 		pMap := map[string]string{}
 		pArr := []string{}
@@ -266,7 +338,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("合作渠道一切都好")
@@ -287,7 +359,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,
@@ -328,7 +400,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登录", changeName),
 			"createtime":  nowTime,
 			"BCPCID":      common.GetRandom(32),
 			"operator_id": -1,

+ 3 - 2
clueSync/job.go

@@ -283,7 +283,8 @@ func FormatData(data map[string]interface{}, item string) (bool, bool, bool) {
 	}
 	log.Println(333, cluename)
 	cluename = strings.ReplaceAll(cluename, " ", "")
-	isGroup, isCommerce := GetCompanyType(cluename, uId)                                                               //判断是否集团公司、工商库
+	isGroup, isCommerce := GetCompanyType(cluename, uId) //判断是否集团公司、工商库
+	//获取用户渠道
 	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)
@@ -326,7 +327,7 @@ 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)
+		isOk := saveEverything(userId, phone, item, subname, sourceCode, belong_to)
 		log.Println("渠道线索电销", userId, phone, item, subname, sourceCode)
 		if !isOk {
 			return true, true, true

+ 49 - 1
clueSync/jobutil.go

@@ -564,12 +564,20 @@ func users() {
 	log.Println("新注册用户定时任务开始", cfg.LastUserId)
 	selectTimeEnd := cfg.LastUserId
 	sql := fmt.Sprintf(`select * from dwd_f_userbase_baseinfo   where createtime > "%s" and (s_platform != 'xcx' or    s_sourceid='jyzbw'    or  s_platform is  NULL)  and source = "0101" and status != 2  order by  createtime asc`, selectTimeEnd)
-	//sql := fmt.Sprintf(`select * from dwd_f_userbase_baseinfo   where id= 2259277`)
+	//sql := fmt.Sprintf(`select * from dwd_f_userbase_baseinfo   where id= 12617743`)
 	data := TiDb.SelectBySql(sql)
 	if data != nil && *data != nil && len(*data) > 0 {
 		for k, v := range *data {
 			//判断用户是否有小程序切使用过剑鱼其他产品
 			createtime := common.ObjToString(v["createtime"])
+			changeCode := GetUserChannel(gconv.String(v["userid"]))
+			if changeCode != "" {
+				TiDb.Update("dwd_f_userbase_baseinfo", map[string]interface{}{
+					"userid": gconv.String(v["userid"]),
+				}, map[string]interface{}{
+					"belong_to": changeCode,
+				})
+			}
 			ok1, ok2, _ := FormatData(v, "users")
 			if !ok1 {
 				log.Println("线索卡点", "users", v, selectTimeEnd)
@@ -629,6 +637,14 @@ WHERE
 			//判断用户是否有小程序切使用过剑鱼其他产品
 			//判断uid
 			uId := ""
+			changeCode := GetUserChannel(gconv.String(v["userId"]))
+			if changeCode != "" {
+				TiDb.Update("dwd_f_userbase_baseinfo", map[string]interface{}{
+					"userid": gconv.String(v["userId"]),
+				}, map[string]interface{}{
+					"belong_to": changeCode,
+				})
+			}
 			for i := 0; i < 10; i++ {
 				phone := common.ObjToString(v["phone"])
 				contactsData := TiDb.SelectBySql("select * from dwd_f_userbase_contacts where phone = ? and is_delete = 1", phone)
@@ -764,6 +780,14 @@ func userbase() {
 			phone := common.ObjToString(v["phone"])
 			uId := common.ObjToString(v["uid"])
 			userId := common.ObjToString(v["userid"])
+			changeCode := GetUserChannel(userId)
+			if changeCode != "" {
+				TiDb.Update("", map[string]interface{}{
+					"userid": userId,
+				}, map[string]interface{}{
+					"belong_to": changeCode,
+				})
+			}
 			registedate := common.ObjToString(v["l_registedate"])
 			name := common.ObjToString(v["name"])
 			nowTime := time.Now().Format(date.Date_Full_Layout)
@@ -1791,3 +1815,27 @@ func nextYearActivity() {
 	}
 	log.Println("开年活动处理结束")
 }
+
+// 获取用户渠道信息
+func GetUserChannel(userId string) string {
+	if userId == "" {
+		return ""
+	}
+	codeArr := []string{}
+	if len(UserChannel) > 0 {
+		for i := range UserChannel {
+			codeArr = append(codeArr, fmt.Sprintf(`"%s"`, i))
+		}
+	}
+	//查找注册日志表
+	sql := fmt.Sprintf(`select  channel_code   from   user_source     where  user_id  ="%s"  and   channel_code  in   (%s)   ORDER BY   create_time  desc   limit   1  `, userId, strings.Join(codeArr, ","))
+	courceData := ThirdParty.SelectBySql(sql)
+	if courceData != nil && len(*courceData) > 0 {
+		channelCode := gconv.String((*courceData)[0]["channel_code"])
+		data, exit := UserChannel[channelCode]
+		if exit {
+			return gconv.String(data["clueCode"])
+		}
+	}
+	return ""
+}

+ 6 - 1
clueSync/main.go

@@ -38,6 +38,7 @@ var (
 	mode                = flag.Int("m", 1, "")
 	startTime, endTime  = "00:00", "23:59"
 	Gmail               mail.GmailAuth
+	UserChannel         = make(map[string]map[string]interface{})
 )
 
 func main() {
@@ -159,6 +160,7 @@ func main() {
 	MgoQyxy = mongodb.NewMgoWithUser(db.MgoQyxy.Address, db.MgoQyxy.DbName, db.MgoQyxy.User, db.MgoQyxy.Password, db.MgoQyxy.DbSize)
 	InitArea()
 	InitProduct(db.ProductArr)
+	InitUserChannel()
 	if *mode == 1 {
 		go ordersClue() //后台订单进线索
 		//一秒钟一次
@@ -174,7 +176,7 @@ func main() {
 		})
 		//5分钟一次
 		go p.VarTimeTask.RunInTimeSection("5分钟定时任务1", db.CornExp2Start, db.CornExp2End, db.CornExp2, func(dayFirst bool) {
-
+			InitUserChannel()
 			users()               //新注册用户进线索
 			saleLeads()           //留资进线索
 			eventReg()            //渠道
@@ -205,6 +207,7 @@ func main() {
 		// 5分钟一次
 		go p.VarTimeTask.RunInTimeLoop("5分钟定时任务2", "", "", db.CornExp5, true, true, nil, func() {
 			//go p.VarTimeTask.RunInTimeSection("5分钟定时任务2", startTime, endTime, db.CornExp5, func(dayFirst bool) {
+			InitUserChannel()
 			everythingSync()   //渠道
 			ordersClue()       //后台已支付订单进线索
 			kcSync()           //移交客成
@@ -255,6 +258,8 @@ func main() {
 		select {}
 	} else if *mode == 2 {
 		LabelToClue()
+	} else if *mode == 3 {
+		ClueToDxTask()
 	} else {
 		users()
 		saleLeads()