Browse Source

渠道做活处理

WH01243 1 tháng trước cách đây
mục cha
commit
a09674c89e
4 tập tin đã thay đổi với 27 bổ sung14 xóa
  1. 15 2
      clueSync/config.go
  2. 9 8
      clueSync/everything.go
  3. 1 3
      clueSync/job.go
  4. 2 1
      clueSync/main.go

+ 15 - 2
clueSync/config.go

@@ -286,13 +286,26 @@ func InitProduct(product []string) {
 	}
 }
 func InitUserChannel() {
-	data := Mysql.SelectBySql(`SELECT code,clue_name FROM short_url WHERE clue = 1 `)
+	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] = gconv.String(v["clue_name"])
+			UserChannel[code] = map[string]interface{}{
+				"name":     gconv.String(v["name"]),
+				"clueCode": gconv.String(v["clue_code"]),
+			}
 		}
 	}
+	UserChannel["JyChCoopA"] = map[string]interface{}{
+		"name":     "一切都好",
+		"clueCode": "0301",
+	}
 }
 func ConnectClickhouse(cHouseConfig *CHouseConfig) error {
 	var (

+ 9 - 8
clueSync/everything.go

@@ -36,8 +36,10 @@ func everythingSync() {
 	data := ThirdParty.SelectBySql(sql)
 	if data != nil && *data != nil && len(*data) > 0 {
 		for _, v := range *data {
-			channel_code := gconv.String("channel_code")
-			channeName := UserChannel[channel_code]
+			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"])
@@ -154,7 +156,7 @@ func everythingSync() {
 				})
 			}
 			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_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,
@@ -173,10 +175,9 @@ func everythingSync() {
 	log.Println("三方渠道数据定时任务结束")
 }
 
-func saveEverything(user_id, phone, item, sourceName, sourceCode, channeName string) bool {
-	if channeName == "" {
-		channeName = "一切都好"
-	}
+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, clueId, position_id := "", "", "", "", "", "", int64(0), int64(0)
@@ -311,7 +312,7 @@ func saveEverything(user_id, phone, item, sourceName, sourceCode, channeName str
 			"clue_id":     clueId,
 			"position_id": common.If(position_id > 0, position_id, -1),
 			"change_type": "退出公海",
-			"new_value":   fmt.Sprintf("通过合作渠道%s登录", channeName),
+			"new_value":   fmt.Sprintf("通过合作渠道%s登录", changeName),
 			"createtime":  nowTime,
 			"BCPCID":      common.GetRandom(32),
 			"operator_id": -1,

+ 1 - 3
clueSync/job.go

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

+ 2 - 1
clueSync/main.go

@@ -38,7 +38,7 @@ var (
 	mode                = flag.Int("m", 1, "")
 	startTime, endTime  = "00:00", "23:59"
 	Gmail               mail.GmailAuth
-	UserChannel         = make(map[string]string)
+	UserChannel         = make(map[string]map[string]interface{})
 )
 
 func main() {
@@ -207,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()           //移交客成