Quellcode durchsuchen

fix:新增useranaly配置 查询逻辑修改

duxin vor 1 Jahr
Ursprung
Commit
f2109cc43d

+ 4 - 4
doFreeClueSign/job/job.go

@@ -11,11 +11,11 @@ import (
 // LoadActivityUser 加载新活跃用户
 func (jm *JobManager) LoadActivityUser() {
 	var (
-		runNow = time.Now()
-		ctx    = context.TODO()
+		//runNow = time.Now()
+		ctx = context.TODO()
 	)
 	start, _ := time.Parse(time.DateTime, jm.lastRun.NewActivity)
-	val := public.GetNewActiveUser(start, runNow)
+	val, end := public.GetNewActiveUser(start)
 	if len(val) > 0 {
 		for i, msg := range val {
 			if i%10 == 0 {
@@ -27,7 +27,7 @@ func (jm *JobManager) LoadActivityUser() {
 		}
 	}
 	//更新
-	jm.lastRun.NewActivity = runNow.Format(time.DateTime)
+	jm.lastRun.NewActivity = end.Format(time.DateTime)
 	if err := jm.SaveLastRun(); err != nil {
 		g.Log().Errorf(ctx, "LoadActivityUser error %v", err)
 	}

+ 5 - 1
doFreeClueSign/job/mamager.go

@@ -145,8 +145,12 @@ func (jm *JobManager) FilterPayUserAndSaveDb(ctx context.Context, value interfac
 			return nil
 		}
 		operationTime = time.Unix(msg.TimeStamp, 0).Format(time.DateTime)
+		registerTime := jm.GetAndCacheRegisterDate(msg.MgoUserID)
+		if registerTime > time.Unix(msg.TimeStamp, 0).AddDate(0, 0, -30).Format(time.DateTime) {
+			return nil
+		}
 		sql += `(mogUserId,register_time,act_again_date,create_time)VALUES (?,?,?,?)ON DUPLICATE KEY UPDATE act_again_date=?`
-		val = append(val, msg.MgoUserID, jm.GetAndCacheRegisterDate(msg.MgoUserID), operationTime, now, operationTime)
+		val = append(val, msg.MgoUserID, registerTime, operationTime, now, operationTime)
 	} else {
 		return fmt.Errorf("未知类型")
 	}

+ 6 - 4
doFreeClueSign/public/getNewActiveUser.go

@@ -14,18 +14,20 @@ type NewActiveMsg struct {
 	TimeStamp int64 //活跃时间
 }
 
-func GetNewActiveUser(st, ed time.Time) []*NewActiveMsg {
+func GetNewActiveUser(st time.Time) ([]*NewActiveMsg, time.Time) {
 	var (
 		mgoIds []string
 		ctx    = context.Background()
 	)
+	//统计昨天的所有注册用户 过滤掉
+	end := st.AddDate(0, 0, 1)
+	ed := time.Date(end.Year(), end.Month(), end.Day(), 0, 0, 0, 0, st.Location())
 	stYear, stMonth, stDay := st.Date()
-	_, edMonth, edDay := ed.Date()
 	nst := st.AddDate(0, -1, 0)
 	_, nstMonth, nstDay := nst.Date()
 	//昨天所有活跃用户
 	res, err := g.DB("useranaly").Query(ctx, fmt.Sprintf(`SELECT DISTINCT user_mongoid FROM user_countbyhour
-WHERE CONCAT(month, '-', day) >= '%s' AND  CONCAT(month, '-', day) <= '%s'`, fmt.Sprintf("%d-%d", int(stMonth), stDay), fmt.Sprintf("%d-%d", int(edMonth), edDay)))
+WHERE CONCAT(month, '-', day) = '%s'`, fmt.Sprintf("%d-%d", int(stMonth), stDay)))
 	//res, err := g.DB().Query(ctx, fmt.Sprintf(`SELECT DISTINCT user_mongoid FROM user_countbyhour WHERE %s `, sql))
 	if err == nil && !res.IsEmpty() {
 		for _, m := range res.List() {
@@ -60,5 +62,5 @@ WHERE user_mongoid = '%s' and CONCAT(month, '-', day) >= '%s' AND  CONCAT(month,
 		}(id)
 	}
 	wait.Wait()
-	return data
+	return data, ed
 }