xuzhiheng 2 năm trước cách đây
mục cha
commit
c5ed1fdbe9
3 tập tin đã thay đổi với 73 bổ sung59 xóa
  1. 48 46
      clueSync/autoTask.go
  2. 23 12
      clueSync/job.go
  3. 2 1
      clueSync/main.go

+ 48 - 46
clueSync/autoTask.go

@@ -12,52 +12,52 @@ func autoTask() {
 	log.Println("超时未跟进定时任务开始")
 	t := time.Now()
 	nowTime := time.Now().Format(date.Date_Full_Layout)
-	statusMap := map[string]int{
-		"07": 5, //待签署客户
-		"06": 3, //高意向客户
-		"05": 5, //意向客户
-		"04": 7, //潜在客户
-	}
+	// statusMap := map[string]int{
+	// 	"07": 5, //待签署客户
+	// 	"06": 3, //高意向客户
+	// 	"05": 5, //意向客户
+	// 	"04": 7, //潜在客户
+	// }
 	// statusMaps := map[string]int{}
 	//判断节假日
-	for status, statusInt := range statusMap {
-		count, counts := 0, 0
-		for {
-			count++
-			currentTime := t.AddDate(0, 0, -count)
-			if currentTime.Weekday() == time.Sunday || currentTime.Weekday() == time.Saturday {
-				isok := false
-				for k, v := range DateMap {
-					if currentTime.Format(date.Date_Short_Layout) == k && v == 2 {
-						isok = true
-					}
-				}
-				if isok {
-					counts++
-				}
-			} else {
-				isok := true
-				for k, v := range DateMap {
-					if currentTime.Format(date.Date_Short_Layout) == k && v == 1 {
-						isok = false
-					}
-				}
-				if isok {
-					counts++
-				}
-			}
-			if counts >= statusInt {
-				break
-			}
-		}
-		statusMap[status] = count
-	}
-	log.Println(statusMap)
-	for trailstatus, _ := range map[string]string{
-		"07": "", //待签署客户
-		"06": "", //高意向客户
-		"05": "", //意向客户
-		"04": "", //潜在客户
+	// for status, statusInt := range statusMap {
+	// 	count, counts := 0, 0
+	// 	for {
+	// 		count++
+	// 		currentTime := t.AddDate(0, 0, -count)
+	// 		if currentTime.Weekday() == time.Sunday || currentTime.Weekday() == time.Saturday {
+	// 			isok := false
+	// 			for k, v := range DateMap {
+	// 				if currentTime.Format(date.Date_Short_Layout) == k && v == 2 {
+	// 					isok = true
+	// 				}
+	// 			}
+	// 			if isok {
+	// 				counts++
+	// 			}
+	// 		} else {
+	// 			isok := true
+	// 			for k, v := range DateMap {
+	// 				if currentTime.Format(date.Date_Short_Layout) == k && v == 1 {
+	// 					isok = false
+	// 				}
+	// 			}
+	// 			if isok {
+	// 				counts++
+	// 			}
+	// 		}
+	// 		if counts >= statusInt {
+	// 			break
+	// 		}
+	// 	}
+	// 	statusMap[status] = count
+	// }
+	// log.Println(statusMap)
+	for trailstatus, nexttime := range map[string]interface{}{
+		"07": t.AddDate(0, 0, -5), //待签署客户
+		"06": t.AddDate(0, 0, -3), //高意向客户
+		"05": t.AddDate(0, 0, -5), //意向客户
+		"04": t.AddDate(0, 0, -7), //潜在客户
 	} {
 		sql := `SELECT a.clue_id,a.position_id,a.seatNumber,a.out_task_status FROM dwd_f_crm_private_sea a 
 				LEFT JOIN dwd_f_crm_clue_info b ON a.clue_id=b.id 
@@ -65,7 +65,8 @@ func autoTask() {
 		argsSelect := []interface{}{trailstatus}
 		intime := ""
 		sql += " AND a.comeintime <?"
-		nt := t.AddDate(0, 0, -statusMap[trailstatus])
+		nt := nexttime.(time.Time)
+		// nt := t.AddDate(0, 0, -statusMap[trailstatus])
 		intime = nt.Format(date.Date_Full_Layout)
 		argsSelect = append(argsSelect, intime)
 		//
@@ -80,14 +81,15 @@ func autoTask() {
 				sql2 := `SELECT COUNT(1) FROM dwd_f_crm_trail_content WHERE clue_id = ? and position_id = ?`
 				if intime != "" {
 					sql2 += ` and createtime > ?`
-					args2 = append(args2, intime)
 					args2 = append(args2, position_id)
+					args2 = append(args2, intime)
 				}
 				//保留未跟进线索
 				// if c1, c2 := TiDb.CountBySql(sql1, clueId), TiDb.CountBySql(sql2, args2...); (c1 != 0 && c2 > 0) || out_task_status == 1 {
 				// 	log.Println("不满足线索过滤", clueId)
 				// 	continue
 				// }
+				log.Println("intime ", clueId, intime, sql2)
 				if c2 := TiDb.CountBySql(sql2, args2...); c2 > 0 || out_task_status == 1 {
 					log.Println("不满足线索过滤", clueId)
 					continue

+ 23 - 12
clueSync/job.go

@@ -45,13 +45,12 @@ func users() {
 	//新用户注册后5分钟内进入线索 C
 	log.Println("新注册用户定时任务开始")
 	session := Mgo.GetMgoConn()
-	lastUserId := cfg.LastUserId
 	defer func() {
 		Mgo.DestoryMongoConn(session)
 	}()
 	query := map[string]interface{}{}
-	if lastUserId != "" {
-		query["_id"] = map[string]interface{}{"$gt": mongodb.StringTOBsonId(lastUserId)}
+	if cfg.LastUserId != "" {
+		query["_id"] = map[string]interface{}{"$gt": mongodb.StringTOBsonId(cfg.LastUserId)}
 	}
 	// query["_id"] = map[string]interface{}{"$gt": mongodb.StringTOBsonId("6145587145042f9c6444d02c")}
 	log.Println("query :", query)
@@ -153,12 +152,7 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
 				userId = common.ObjToString((*userMapping)["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.IntAll((*userInfo)["source"])
-		}
+
 		cluename = common.ObjToString(data["company"])
 		phone = common.ObjToString(data["phone"])
 		role = common.ObjToString(data["companyType"])
@@ -167,6 +161,23 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
 		position = common.ObjToString(data["position"])
 		name = common.ObjToString(data["name"])
 		// sourceCode = common.ObjToString(data["source"])
+		contactsData := TiDb.SelectBySql("select * from dwd_f_userbase_contacts where phone = ? and is_delete = 1 and status != 0", phone)
+		if contactsData != nil && len(*contactsData) > 0 {
+			if common.ObjToString((*contactsData)[0]["baseinfo_id"]) != "" {
+				uId = common.ObjToString((*contactsData)[0]["baseinfo_id"])
+				query["uid"] = uId
+			} else {
+				query["userid"] = userId
+			}
+		} else {
+			query["userid"] = userId
+		}
+		userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
+		if userInfo != nil && len(*userInfo) > 0 {
+			uId = common.ObjToString((*userInfo)["uid"])
+			source = common.IntAll((*userInfo)["source"])
+			userId = common.ObjToString((*userInfo)["userid"])
+		}
 	}
 	//线索名称为空用手机号代替
 	if cluename == "" {
@@ -180,8 +191,8 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
 	if uId == "" {
 		if isExists, _ := redis.Exists("bidx", "bidx_userId_"+userId); isExists {
 			redisInt := redis.GetInt("bidx", "bidx_userId_"+userId)
-			if redisInt > 2 {
-				log.Println("线索分配失败,线索缺少信息,任务已执行超过3次", item, userId, phone)
+			if redisInt > 1 {
+				log.Println("线索分配失败,线索缺少信息,任务已执行超过1次", item, userId, phone)
 				return true, true
 			} else {
 				redis.Incr("bidx", "bidx_userId_"+userId)
@@ -673,7 +684,7 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 		log.Println("线索更新成功")
 		if TiDb.Count("dwd_f_userbase_contacts", map[string]interface{}{"phone": phone}) == 0 {
 			TiDb.Insert("dwd_f_userbase_contacts", map[string]interface{}{
-				"status":      0,
+				"status":      1,
 				"is_delete":   1,
 				"createtime":  nowTime,
 				"updatetime":  nowTime,

+ 2 - 1
clueSync/main.go

@@ -75,7 +75,8 @@ func main() {
 		})
 		a.Start()
 		// 新注册用户 5分钟一次
-		// users()
+		users()
+		saleLeads()
 		b := cron.New()
 		b.AddFunc(cfg.CornExp2, func() {
 			users()