瀏覽代碼

wip:测试群组校验权限

wangkaiyue 2 年之前
父節點
當前提交
cab9e9c517
共有 2 個文件被更改,包括 49 次插入20 次删除
  1. 24 10
      entity/mananger/aheadManager.go
  2. 25 10
      entity/mananger/customManager.go

+ 24 - 10
entity/mananger/aheadManager.go

@@ -5,6 +5,7 @@ import (
 	"fmt"
 	"github.com/robfig/cron/v3"
 	"leadGeneration/entity/activeUsers"
+	"leadGeneration/entity/power"
 	"leadGeneration/entity/search"
 	"leadGeneration/public"
 	"leadGeneration/vars"
@@ -42,12 +43,10 @@ func InitAheadManager(conf vars.AheadConfig) *AheadManager {
 // GetData 获取查询数据
 func (this *AheadManager) GetData(userId, keyWords string, isNew bool, t int64) map[string]interface{} {
 	if !(isNew || this.checkGroupUser(userId)) {
-		log.Println("无查看权益")
 		return nil
 	}
 	//校验每日请求次数
 	cacheKey := fmt.Sprintf(AheadRequestFrequencyCacheKey, time.Now().Format(public.TimeFormat), t, userId)
-	log.Printf("已查看:%d", redis.GetInt(AheadCacheDb, cacheKey))
 	if this.Conf.DailyTimes <= redis.GetInt(AheadCacheDb, cacheKey) {
 		return nil
 	}
@@ -75,13 +74,6 @@ func (this *AheadManager) Click(userId string) bool {
 
 // CheckGroupUser 校验用户是否有资格展示
 func (this *AheadManager) checkGroupUser(userId string) (exists bool) {
-	if len(vars.Config.TestUid) > 0 {
-		for _, uid := range vars.Config.TestUid {
-			if uid == userId {
-				return true
-			}
-		}
-	}
 	this.RLock()
 	defer this.RUnlock()
 	_, exists = this.UserGroup[userId]
@@ -133,6 +125,26 @@ func (this *AheadManager) getUserGroup() (userIds []string) {
 				userIds = append(userIds, uId)
 			}
 		}
+		//是否有新增测试用户
+		if len(vars.Config.TestUid) > 0 {
+			var newTest []string
+			for _, uid := range vars.Config.TestUid {
+				has := false
+				for _, id := range userIds {
+					if uid == id {
+						has = true
+						break
+					}
+				}
+				if !has && !power.HasAheadPower(uid) {
+					newTest = append(newTest, uid)
+				}
+			}
+			if len(newTest) > 0 {
+				userIds = append(userIds, newTest...)
+				activeUsers.SaveBatchGroup(newTest, 0, this.BatchFlag, "testUser")
+			}
+		}
 	}
 	//无数据则重新生成用户群组数据
 	if len(userIds) == 0 {
@@ -155,7 +167,9 @@ func (this *AheadManager) getUserGroup() (userIds []string) {
 			defer wg.Done()
 			if len(vars.Config.TestUid) > 0 {
 				for _, uid := range vars.Config.TestUid {
-					testUserGroup = append(testUserGroup, uid)
+					if !power.HasAheadPower(uid) {
+						testUserGroup = append(testUserGroup, uid)
+					}
 				}
 			}
 			activeUsers.SaveBatchGroup(testUserGroup, 0, this.BatchFlag, "testUser")

+ 25 - 10
entity/mananger/customManager.go

@@ -150,6 +150,26 @@ func (this *CustomManager) getUserGroup() (userIds []string) {
 				userIds = append(userIds, uId)
 			}
 		}
+		//是否有新增测试用户
+		if len(vars.Config.TestUid) > 0 {
+			var newTest []string
+			for _, uid := range vars.Config.TestUid {
+				has := false
+				for _, id := range userIds {
+					if uid == id {
+						has = true
+						break
+					}
+				}
+				if !has && !power.HasPower(uid) {
+					newTest = append(newTest, uid)
+				}
+			}
+			if len(newTest) > 0 {
+				userIds = append(userIds, newTest...)
+				activeUsers.SaveBatchGroup(newTest, 1, this.BatchFlag, "testUser")
+			}
+		}
 	}
 	//无数据则重新生成用户群组数据
 	if len(userIds) == 0 {
@@ -159,17 +179,19 @@ func (this *CustomManager) getUserGroup() (userIds []string) {
 			newActiveGroup, testUserGroup []string
 		)
 		wg.Add(2)
-		//新活跃用户
+		//测试用户群组
 		go func() {
 			defer wg.Done()
 			if len(vars.Config.TestUid) > 0 {
 				for _, uid := range vars.Config.TestUid {
-					testUserGroup = append(testUserGroup, uid)
+					if !power.HasPower(uid) {
+						testUserGroup = append(testUserGroup, uid)
+					}
 				}
 			}
 			activeUsers.SaveBatchGroup(testUserGroup, 1, this.BatchFlag, "testUser")
 		}()
-		//测试用户群组
+		//新活跃用户
 		go func() {
 			defer wg.Done()
 			newActiveGroup = activeUsers.GetMonthActiveFreeUsers()
@@ -271,13 +293,6 @@ func (this *CustomManager) DoSearch() {
 
 // checkActivityUser 校验用户是否是活跃用户
 func (this *CustomManager) checkActivityUser(userId string) (exists bool) {
-	if len(vars.Config.TestUid) > 0 {
-		for _, uid := range vars.Config.TestUid {
-			if uid == userId {
-				return true
-			}
-		}
-	}
 	this.RLock()
 	defer this.RUnlock()
 	_, exists = this.UserGroup[userId]