xuzhiheng 1 жил өмнө
parent
commit
7d471f7b27

+ 1 - 0
clueSync/config.go

@@ -26,6 +26,7 @@ type (
 		LastkcTime         string `json:"lastkcTime"`
 		LastEverythingTime string `json:"lastEverythingTime"`
 		LastEventRegTime   string `json:"lastEventRegTime"`
+		LastReadClueTime   string `json:"lastReadClueTime"`
 		XlsxNum            string `json:"xlsxNum"`
 		CountLimit         int64  `json:"countLimit"`
 		RegTimes           int    `json:"regTimes"`

+ 2 - 1
clueSync/config.json

@@ -15,7 +15,8 @@
 	"lastSubscribeId": "64473e36c572141d78ec7a03",
 	"lastMessageTime": "",
 	"lastkcTime": "",
-	"LastEverythingTime":"",
+	"lastEverythingTime":"",
+	"lastReadClueTime":"",
 	"countLimit": 1000,
 	"xlsxNum": "1",
 	"regTimes": 7,

+ 1 - 1
clueSync/everything.go

@@ -510,7 +510,7 @@ func bigCustomer() {
 	} else {
 		detailName = time.Now().Format(date.Date_Short_Layout) + "无线索"
 	}
-	email := "xuzhiheng@topnet.net.cn,zoushanshan@topnet.net.cn,fanzongdong@topnet.net.cn,sunzhenjie@topnet.net.cn"
+	email := "xuzhiheng@topnet.net.cn,wenyue@topnet.net.cn,zoushanshan@topnet.net.cn,fanzongdong@topnet.net.cn,sunzhenjie@topnet.net.cn"
 	// email = "xuzhiheng@jianyu360.com"
 	dir := "./xlsx/" + fileName + ".xlsx"
 	err := xf.Save(dir)

+ 22 - 98
clueSync/job.go

@@ -15,103 +15,10 @@ import (
 	"app.yhyue.com/moapp/jybase/mongodb"
 )
 
-// 未支付订单 30分钟一次
-func orders() {
-	//一个小时未支付进入线索 A
-	log.Println("未支付订单定时任务开始")
-	lastOrderId := cfg.LastOrderId
-	selectTimeStart := time.Unix(time.Now().Unix()-7200, 0).Format(date.Date_Full_Layout)
-	selectTimeEnd := time.Unix(time.Now().Unix()-3600, 0).Format(date.Date_Full_Layout)
-	sql := fmt.Sprintf(`select * from dataexport_order where create_time <= "%s" and create_time >= "%s" and id > %s`, selectTimeEnd, selectTimeStart, fmt.Sprint(lastOrderId))
-	data := Mysql.SelectBySql(sql)
-	if data != nil && *data != nil && len(*data) > 0 {
-		for _, v := range *data {
-			order_status := common.IntAll(v["order_status"])
-			is_backstage_order := common.IntAll(v["is_backstage_order"])
-			product_type_str1 := `"大会员","VIP订阅","数据流量包","历史数据"`
-			product_type := common.ObjToString(v["product_type"])
-			if order_status == 0 && is_backstage_order == 0 && strings.Contains(product_type_str1, product_type) {
-				ok1, _ := FormatData(v, "orders")
-				if !ok1 {
-					common.WriteSysConfig(&cfg)
-					break
-				}
-			}
-			cfg.LastOrderId = common.IntAll(v["id"])
-		}
-	}
-	common.WriteSysConfig(&cfg)
-	log.Println("未支付订单定时任务结束")
-}
-
-// 新注册用户 5分钟一次
-func users() {
-	//判断节假日
-	runOk := getRunOk()
-	if !runOk {
-		log.Println("不是工作日,任务暂停")
-		return
-	}
-	//新用户注册后5分钟内进入线索 C
-	log.Println("新注册用户定时任务开始")
-	selectTimeEnd := cfg.LastUserId
-	sql := fmt.Sprintf(`select * from dwd_f_userbase_baseinfo where createtime > "%s" and source = "0101" and status != 2`, selectTimeEnd)
-	data := TiDb.SelectBySql(sql)
-	if data != nil && *data != nil && len(*data) > 0 {
-		for k, v := range *data {
-			createtime := common.ObjToString(v["createtime"])
-			FormatData(v, "users")
-			if k == len(*data)-1 {
-				cfg.LastUserId = createtime
-			}
-		}
-	}
-	common.WriteSysConfig(&cfg)
-	log.Println("新注册用户定时任务结束")
-}
-
-// 留资 5分钟一次
-func saleLeads() {
-	//判断节假日
-	runOk := getRunOk()
-	if !runOk {
-		log.Println("不是工作日,任务暂停")
-		return
-	}
-	//留资后5分钟内进入线索
-	//分为免费留资和付费留资 付费B 免费C
-	log.Println("用户留资定时任务开始")
-	session := Mgo.GetMgoConn()
-	lastId := cfg.LastId
-	defer func() {
-		Mgo.DestoryMongoConn(session)
-	}()
-	query := map[string]interface{}{}
-	if lastId != "" {
-		query["_id"] = map[string]interface{}{"$gt": mongodb.StringTOBsonId(lastId)}
-	}
-	log.Println("query :", query)
-	iter := session.DB(cfg.Mgo.DbName).C("saleLeads").Find(&query).Sort("_id").Iter()
-	thisData := map[string]interface{}{}
-	for {
-		if !iter.Next(&thisData) {
-			break
-		}
-		ok1, _ := FormatData(thisData, "saleLeads")
-		if !ok1 {
-			common.WriteSysConfig(&cfg)
-			break
-		}
-		cfg.LastId = mongodb.BsonIdToSId(thisData["_id"])
-	}
-	common.WriteSysConfig(&cfg)
-	log.Println("用户留资定时任务结束")
-}
-
 func FormatData(data map[string]interface{}, item string) (bool, bool) {
 	userId, uId, positionId, source, cluename, phone, sourceCode, keyword := common.ObjToString(data["user_id"]), "", "", "", "", "", "", []string{}
 	role, industry, department, departments, position, name, top_cluetype, sub_cluetype, follow_project_area, level := "", "", "", "", "", "", "", "", "", ""
-	query, topname, subname, belong_to, sourceName, remark := map[string]interface{}{}, "", "", "01", "", ""
+	query, topname, subname, belong_to, sourceName, remark, sourceId := map[string]interface{}{}, "", "", "01", "", "", int64(0)
 	nowTime := time.Now().Format("2006-01-02 15:04:05")
 	if item == "orders" { //订单
 		if !mongodb.IsObjectIdHex(userId) {
@@ -216,8 +123,13 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
 				userId = common.ObjToString((*userInfo)["userid"])
 			}
 		} else {
-			log.Println("不是剑鱼用户留资,等待用户")
-			return false, false
+			if sourceCode == "report_retention" || sourceCode == "marketing_retention" {
+				log.Println("不是剑鱼用户留资,等待用户", phone)
+				return false, false
+			} else if remark != "" {
+				log.Println("留资source过滤", phone, sourceCode)
+				return true, true
+			}
 		}
 	} else if item == "eventReg" { //渠道
 		userId = common.ObjToString(data["userid"])
@@ -250,8 +162,20 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
 		if role == "集成商" || role == "设计院" {
 			role = "其他-" + role
 		}
+	} else if item == "readClue" {
+		userId = common.ObjToString(data["userId"])
+		query["userid"] = userId
+		userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
+		if userInfo != nil && len(*userInfo) > 0 {
+			uId = common.ObjToString((*userInfo)["uid"])
+			source = common.ObjToString((*userInfo)["source"])
+			belong_to = common.ObjToString((*userInfo)["belong_to"])
+		}
+		// cluename = common.ObjToString(data["companyName"])
+		phone = common.ObjToString(data["phone"])
+		sourceId = common.Int64All(data["sourceId"])
 	}
-	if cluename == "" && item != "message" && item != "orders" {
+	if cluename == "" && item != "message" && item != "orders" && item != "readClue" {
 		cluename = phone
 	}
 	isGroup, isCommerce := GetCompanyType(cluename) //判断是否集团公司、工商库
@@ -291,7 +215,7 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
 			name = common.ObjToString(sdata["name"])
 		}
 	}
-	top_cluetype, sub_cluetype, level, topname, subname = getClueType(item, data, sourceCode) //查留资来源名字
+	top_cluetype, sub_cluetype, level, topname, subname = getClueType(item, data, sourceCode, sourceId) //查留资来源名字
 	if topname == "市场活动" && item == "saleLeads" {
 		log.Println("市场活动留资过滤 ", userId, phone)
 		return true, false

+ 133 - 3
clueSync/jobutil.go

@@ -8,12 +8,125 @@ import (
 
 	"app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/date"
+	"app.yhyue.com/moapp/jybase/mongodb"
 )
 
+// 未支付订单 30分钟一次
+func orders() {
+	//一个小时未支付进入线索 A
+	log.Println("未支付订单定时任务开始")
+	lastOrderId := cfg.LastOrderId
+	selectTimeStart := time.Unix(time.Now().Unix()-7200, 0).Format(date.Date_Full_Layout)
+	selectTimeEnd := time.Unix(time.Now().Unix()-3600, 0).Format(date.Date_Full_Layout)
+	sql := fmt.Sprintf(`select * from dataexport_order where create_time <= "%s" and create_time >= "%s" and id > %s`, selectTimeEnd, selectTimeStart, fmt.Sprint(lastOrderId))
+	data := Mysql.SelectBySql(sql)
+	if data != nil && *data != nil && len(*data) > 0 {
+		for _, v := range *data {
+			order_status := common.IntAll(v["order_status"])
+			is_backstage_order := common.IntAll(v["is_backstage_order"])
+			product_type_str1 := `"大会员","VIP订阅","数据流量包","历史数据"`
+			product_type := common.ObjToString(v["product_type"])
+			if order_status == 0 && is_backstage_order == 0 && strings.Contains(product_type_str1, product_type) {
+				ok1, _ := FormatData(v, "orders")
+				if !ok1 {
+					common.WriteSysConfig(&cfg)
+					break
+				}
+			}
+			cfg.LastOrderId = common.IntAll(v["id"])
+		}
+	}
+	common.WriteSysConfig(&cfg)
+	log.Println("未支付订单定时任务结束")
+}
+
+func readClue() {
+	log.Println("读表进线索定时任务开始")
+	lastReadClueTime := cfg.LastReadClueTime
+	sql := fmt.Sprintf(`select * from clue_info where updatetime > "%s" order by updatetime asc`, fmt.Sprint(lastReadClueTime))
+	data := TiDb.SelectBySql(sql)
+	if data != nil && *data != nil && len(*data) > 0 {
+		for _, v := range *data {
+			ok1, _ := FormatData(v, "readClue")
+			if !ok1 {
+				common.WriteSysConfig(&cfg)
+				break
+			}
+			cfg.LastReadClueTime = common.ObjToString(v["updatetime"])
+		}
+	}
+	common.WriteSysConfig(&cfg)
+	log.Println("读表进线索定时任务结束")
+}
+
+// 新注册用户 5分钟一次
+func users() {
+	//判断节假日
+	runOk := getRunOk()
+	if !runOk {
+		log.Println("不是工作日,任务暂停")
+		return
+	}
+	//新用户注册后5分钟内进入线索 C
+	log.Println("新注册用户定时任务开始")
+	selectTimeEnd := cfg.LastUserId
+	sql := fmt.Sprintf(`select * from dwd_f_userbase_baseinfo where createtime > "%s" and source = "0101" and status != 2`, selectTimeEnd)
+	data := TiDb.SelectBySql(sql)
+	if data != nil && *data != nil && len(*data) > 0 {
+		for k, v := range *data {
+			createtime := common.ObjToString(v["createtime"])
+			FormatData(v, "users")
+			if k == len(*data)-1 {
+				cfg.LastUserId = createtime
+			}
+		}
+	}
+	common.WriteSysConfig(&cfg)
+	log.Println("新注册用户定时任务结束")
+}
+
+// 留资 5分钟一次
+func saleLeads() {
+	//判断节假日
+	runOk := getRunOk()
+	if !runOk {
+		log.Println("不是工作日,任务暂停")
+		return
+	}
+	//留资后5分钟内进入线索
+	//分为免费留资和付费留资 付费B 免费C
+	log.Println("用户留资定时任务开始")
+	session := Mgo.GetMgoConn()
+	lastId := cfg.LastId
+	defer func() {
+		Mgo.DestoryMongoConn(session)
+	}()
+	query := map[string]interface{}{}
+	if lastId != "" {
+		query["_id"] = map[string]interface{}{"$gt": mongodb.StringTOBsonId(lastId)}
+	}
+	log.Println("query :", query)
+	iter := session.DB(cfg.Mgo.DbName).C("saleLeads").Find(&query).Sort("_id").Iter()
+	thisData := map[string]interface{}{}
+	for {
+		if !iter.Next(&thisData) {
+			break
+		}
+		ok1, _ := FormatData(thisData, "saleLeads")
+		if !ok1 {
+			common.WriteSysConfig(&cfg)
+			break
+		}
+		cfg.LastId = mongodb.BsonIdToSId(thisData["_id"])
+	}
+	common.WriteSysConfig(&cfg)
+	log.Println("用户留资定时任务结束")
+}
+
 func userbase() {
 	log.Println("userbase定时任务开始")
 	selectTimeEnd := time.Unix(time.Now().Unix()-1800, 0).Format("2006-01-02 15:04:05")
-	sql := fmt.Sprintf(`select * from dwd_f_userbase_baseinfo where updatetime > "%s" and source != "0105" and source != "0104"`, selectTimeEnd)
+	sql := fmt.Sprintf(`select * from dwd_f_userbase_baseinfo where updatetime > "%s" and source != "0105" and source != "0104" and source != "0103" and source != "0102"`, selectTimeEnd)
 	data := TiDb.SelectBySql(sql)
 	if data != nil && *data != nil && len(*data) > 0 {
 		for _, v := range *data {
@@ -59,7 +172,7 @@ func userbase() {
 									"createtime":        nowTime,
 									"updatetime":        nowTime,
 									"cluename":          phone,
-									"top_cluetype":      "474",
+									"top_cluetype":      "532",
 									"sub_cluetype":      "475",
 									"trailstatus":       "01",
 									"name":              name,
@@ -185,7 +298,7 @@ func getAreaCode(userId string) (code string) {
 	return
 }
 
-func getClueType(item string, data map[string]interface{}, sourceCode string) (pcode, code, level, topname, subname string) {
+func getClueType(item string, data map[string]interface{}, sourceCode string, sourceId int64) (pcode, code, level, topname, subname string) {
 	if item == "orders" {
 		productType := common.ObjToString(data["product_type"])
 		pcode = "1"
@@ -216,6 +329,23 @@ func getClueType(item string, data map[string]interface{}, sourceCode string) (p
 		level = "B"
 		topname = "其他"
 		subname = "机器人客服主动咨询"
+	} else if item == "readClue" {
+		level = "A"
+		topname = "超级订阅临期用户"
+		pcode = "614"
+		if sourceId == 1 {
+			code = "615"
+			subname = "60天后到期"
+		} else if sourceId == 2 {
+			code = "616"
+			subname = "45天后到期"
+		} else if sourceId == 3 {
+			code = "617"
+			subname = "15天后到期"
+		} else {
+			code = "618"
+			subname = "7天后到期"
+		}
 	} else {
 		if sourceCode != "" {
 			codeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"source": sourceCode}, "", "")

+ 1 - 1
clueSync/kc.go

@@ -66,7 +66,7 @@ func kcJob(data map[string]interface{}) int {
 			"dhy5":   7,
 			"企业商机管理": 8,
 		}
-		if buy_subject == 1 {
+		if buy_subject == 1 || buy_subject == 0 {
 			entId = common.ObjToString(data["userid"])
 		}
 		if product_type == "企业商机管理" {

+ 7 - 1
clueSync/main.go

@@ -107,7 +107,7 @@ func main() {
 	InitArea()
 	if *mode == 1 {
 		// 未支付订单 30分钟一次
-		orders()
+		// orders()
 		a := cron.New()
 		a.AddFunc(cfg.CornExp1, func() {
 			orders()
@@ -169,8 +169,10 @@ func main() {
 		//自动进入任务车 1天一次
 		// autoTask()
 		// autoTasks()
+		go readClue()
 		g := cron.New()
 		g.AddFunc(cfg.CornExp7, func() {
+			go readClue()
 			autoTask()
 			autoTasks()
 		})
@@ -199,5 +201,9 @@ func main() {
 		lzhSync()
 	} else if *mode == 31 {
 		piliangfenpeicuowu()
+	} else if *mode == 32 {
+		pilianggonghaicuowu()
+	} else if *mode == 33 {
+		userbase_error()
 	}
 }

+ 97 - 0
clueSync/trailContent.go

@@ -1,6 +1,7 @@
 package main
 
 import (
+	"fmt"
 	"log"
 	"regexp"
 
@@ -516,3 +517,99 @@ func piliangfenpeicuowu() {
 		}
 	}
 }
+
+func pilianggonghaicuowu() {
+	count := 0
+	data := TiDb.SelectBySql(`SELECT id FROM dwd_f_crm_clue_info WHERE comeintime_open >= "2024-03-04 16:46:16" and comeintime_open <= "2024-03-04 16:46:18"`)
+	if data != nil && len(*data) > 0 {
+		log.Println("LEN", len(*data))
+		for _, v := range *data {
+			count++
+			clue_id := common.Int64All(v["id"])
+			log.Println("COUNT ", count, clue_id)
+			sdata := TiDb.SelectBySql(`SELECT a.clue_id,a.old_value,a.new_value,b.position_id,b.seat_number,a.createtime FROM dwd_f_crm_clue_change_record a INNER JOIN dwd_f_crm_personnel_management b on b.name = a.new_value where a.clue_id = ` + fmt.Sprint(clue_id) + ` and a.change_type = "所属人变更" and a.new_value != "/" and a.new_value != "沈炳毅" ORDER BY a.createtime desc`)
+			if sdata != nil && len(*sdata) > 0 {
+				name := common.ObjToString((*sdata)[0]["new_value"])
+				position_id := common.Int64All((*sdata)[0]["position_id"])
+				seat_number := common.ObjToString((*sdata)[0]["seat_number"])
+				ok := TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clue_id}, map[string]interface{}{"position_id": position_id, "seatNumber": seat_number, "is_assign": 1})
+				if ok {
+					log.Println("修改成功 ", clue_id, name)
+				} else {
+					log.Println("修改失败!!! ", clue_id, name, position_id, seat_number)
+				}
+			}
+		}
+	}
+}
+
+func userbase_error() {
+	log.Println("userbase_error定时任务开始")
+	sql := `SELECT dfub.uid,dfub.userid,dfub.phone,dfub.source FROM 
+	dwd_f_userbase_baseinfo dfub 
+	LEFT JOIN dwd_f_crm_clue_info dfci ON dfub.uid = dfci.uid 
+	LEFT JOIN dwd_f_userbase_contacts dfuc ON dfub.uid = dfuc.baseinfo_id 
+WHERE 
+	dfci.id IS NULL 
+	AND dfub.phone IS NOT NULL 
+	AND dfub.phone != "" 
+	AND dfub.belong_to NOT LIKE "02%" 
+	AND dfub.belong_to NOT LIKE "03%" 
+	AND dfub.status NOT IN (0,2) 
+	AND dfub.source NOT IN ("0102","0103","0104","0105")`
+	data := TiDb.SelectBySql(sql)
+	if data != nil && *data != nil && len(*data) > 0 {
+		for _, v := range *data {
+			phone := common.ObjToString(v["phone"])
+			uId := common.ObjToString(v["uid"])
+			userId := common.ObjToString(v["userid"])
+			nowTime := time.Now().Format(date.Date_Full_Layout)
+			source := common.ObjToString(v["source"])
+			if phone != "" {
+				contactsData := TiDb.SelectBySql("select * from dwd_f_userbase_contacts where phone = ? and is_delete = 1", phone)
+				if contactsData == nil || len(*contactsData) == 0 {
+					TiDb.Insert("dwd_f_userbase_contacts", map[string]interface{}{
+						"status":      1,
+						"is_delete":   1,
+						"createtime":  nowTime,
+						"updatetime":  nowTime,
+						"phone":       phone,
+						"baseinfo_id": uId,
+						"SOURCE":      source,
+					})
+				}
+				count := TiDb.CountBySql("select count(1) as count from dwd_f_crm_clue_info where uid = ?", uId)
+				log.Println("userbase uid 线索数量 ", count)
+				if count == 0 {
+					clueId := TiDb.Insert("dwd_f_crm_clue_info", map[string]interface{}{
+						"userid":            userId,
+						"uid":               uId,
+						"is_assign":         0,
+						"comeintime":        nowTime,
+						"createtime":        nowTime,
+						"updatetime":        nowTime,
+						"cluename":          phone,
+						"top_cluetype":      "532",
+						"sub_cluetype":      "475",
+						"trailstatus":       "01",
+						"phone":             phone,
+						"comeintime_open":   nowTime,
+						"comeinsource_open": 1,
+					})
+					if clueId > 0 {
+						TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
+							"clue_id":     clueId,
+							"position_id": -1,
+							"change_type": "创建线索",
+							"new_value":   "系统自动创建",
+							"createtime":  nowTime,
+							"BCPCID":      common.GetRandom(32),
+							"operator_id": -1,
+						})
+					}
+				}
+			}
+		}
+	}
+	log.Println("userbase_error定时任务结束")
+}