Jelajahi Sumber

修改接口格式

wucan 1 tahun lalu
induk
melakukan
9a7d5565c3
3 mengubah file dengan 17 tambahan dan 21 penghapusan
  1. 0 16
      controller/v1/interfaceLog.go
  2. 17 4
      controller/v1/user.go
  3. 0 1
      route/api.go

+ 0 - 16
controller/v1/interfaceLog.go

@@ -15,31 +15,15 @@ func Overview(c *gin.Context) {
 	form := request.Check(c, &struct {
 		Day string `form:"day" json:"day" binding:"required"`
 	}{})
-
-	//start := time.Now()
-	//day := start.Format("20060102")
-	//hour := start.Format("2006010215")
-
 	//查询接口访问次数
 	dayCount, err := global.App.Redis.Get(context.Background(), "dayLog:"+form.Day).Result()
 	if err != nil {
 		global.App.Log.Error("redis incr error", "err", err)
 	}
-	//hourCount, err := global.App.Redis.Get(context.Background(), "hourInterfaceLog:"+hour).Result()
-	//if err != nil {
-	//	global.App.Log.Error("redis incr error", "err", err)
-	//}
-
-	//查询登录人数
-	//hourLoginLog, err := global.App.Redis.Get(context.Background(), "hourLoginLog:"+hour).Result()
-	//if err != nil {
-	//	global.App.Log.Error("redis incr error", "err", err)
-	//}
 	dayLoginLog, err := global.App.Redis.Get(context.Background(), "dayLog:"+form.Day).Result()
 	if err != nil {
 		global.App.Log.Error("redis get error", "err", err)
 	}
-
 	//查询新注册人数
 	dayRegisterLog, err := global.App.Redis.Get(context.Background(), "registerDayLog:"+form.Day).Result()
 	if err != nil {

+ 17 - 4
controller/v1/user.go

@@ -126,13 +126,25 @@ type User struct {
 
 func UserList(c *gin.Context) {
 	form := request.Check(c, &struct {
-		Offset int `form:"offset" json:"offset" binding:""`
-		Limit  int `form:"limit" json:"limit" binding:"required"`
+		Gid    string `form:"gid" json:"gid" binding:"required"`
+		Pf     string `form:"pf" json:"pf" binding:"required"`
+		Offset int    `form:"offset" json:"offset" binding:""`
+		Limit  int    `form:"limit" json:"limit" binding:"required"`
 	}{})
 
 	//读取表
 	userTotalKey := config.Get("app.user_total")
-	data, err := global.App.Redis.ZRevRangeWithScores(context.Background(), userTotalKey, int64(form.Offset), int64(form.Offset+form.Limit)).Result()
+	if form.Gid != "" && form.Pf != "" {
+		userTotalKey = config.Get("app.user_total") + ":" + form.Gid + ":" + form.Pf
+	}
+
+	data, err := global.App.Redis.ZRevRangeWithScores(context.Background(), userTotalKey, int64(form.Offset), int64(form.Offset+form.Limit)-1).Result()
+	if err != nil {
+		response.Fail(c, 1001, err.Error())
+		return
+	}
+
+	count, err := global.App.Redis.ZCard(context.Background(), userTotalKey).Result()
 	if err != nil {
 		response.Fail(c, 1001, err.Error())
 		return
@@ -188,6 +200,7 @@ func UserList(c *gin.Context) {
 	}
 
 	response.Success(c, gin.H{
-		"data": res,
+		"data":  res,
+		"count": count,
 	})
 }

+ 0 - 1
route/api.go

@@ -36,5 +36,4 @@ func SetApiGroupRoutes(router *gin.RouterGroup) {
 		GroupV1.POST("/user/getInterfaceDataByDay", v1.GetInterfaceDataByDay)
 
 	}
-
 }