wucan 9 mesiacov pred
rodič
commit
0b6cfa3a80

+ 8 - 1
app/common/response/response.go

@@ -38,7 +38,12 @@ func Success(c *gin.Context, data gin.H) {
 	//
 	//}
 	data["code"] = 0
-
+	if data["data"] == nil {
+		data["data"] = "success"
+	}
+	if data["msg"] == nil {
+		data["msg"] = "success"
+	}
 	//fmt.Println(data)
 
 	c.JSON(http.StatusOK, data)
@@ -77,10 +82,12 @@ func Fail(c *gin.Context, errorCode int, e interface{}) {
 		c.JSON(http.StatusOK, gin.H{
 			"code":  errorCode,
 			"msg":   msg,
+			"data":  "",
 			"stack": stack,
 		})
 	} else {
 		c.JSON(http.StatusOK, gin.H{
+			"data": "",
 			"code": errorCode,
 			"msg":  msg,
 		})

+ 1 - 1
config/app.go

@@ -9,7 +9,7 @@ func App() *ConfigNode {
 
 		"app_secret":       env("APP_SECRET", "6YJSuc50uJ18zj45"),
 		"app_check_secret": env("APP_CHECK_SECRET", "6YJSuc50uJ18zj45"), //检测数据篡改密钥
-		"api_expiry":       env("API_EXPIRY", "12000"),                  //
+		"api_expiry":       env("API_EXPIRY", "120000"),                 //
 		"max_content":      env("MAX_CONTENT", "50000"),                 //最大请求内容长度
 		"api_exp":          env("API_EXP", "6000"),                      //api 过期时间
 		"api_limit_key":    env("API_LIMIT_KEY", "api_limit_key"),       //api限制key  api_limit_key:gid:openid:apipath

+ 11 - 11
controller/v1/blackList.go

@@ -23,12 +23,12 @@ const (
 // AddUserToBlackList 将玩家加入黑名单
 func AddUserToBlackList(c *gin.Context) {
 	form := request.Check(c, &struct {
-		Code string `json:"code" binding:"required"`
-		Gid  string `json:"gid" binding:"required"`
-		Pf   string `json:"pf" binding:"required"`
+		OpenId string `json:"openId" binding:"required"`
+		Gid    string `json:"gid" binding:"required"`
+		Pf     string `json:"pf" binding:"required"`
 	}{})
 
-	userKey := form.Gid + ":" + form.Pf + ":" + config.Get("app.user_table_key") + form.Code
+	userKey := form.Gid + ":" + form.Pf + ":" + config.Get("app.user_table_key") + form.OpenId
 
 	//存在用户 读取数据
 	userdata, err := global.App.Redis.HGetAll(context.Background(), userKey).Result()
@@ -42,12 +42,12 @@ func AddUserToBlackList(c *gin.Context) {
 	rankDataKeys := form.Gid + ":" + form.Pf + ":" + config.Get("app.rank_province_table_key") + curHid + ":" + strconv.Itoa(RankTypeByEver) + ":*"
 	keys, _ := global.App.Redis.Keys(context.Background(), rankDataKeys).Result()
 	for _, val := range keys {
-		defScore, _ := global.App.Redis.ZScore(context.Background(), val, form.Code).Result()
+		defScore, _ := global.App.Redis.ZScore(context.Background(), val, form.OpenId).Result()
 		lastindex := strings.LastIndex(val, ":")
 		if lastindex != -1 {
 			curField := val[lastindex+1:]
 			//删除出省排行数据
-			global.App.Redis.ZRem(context.Background(), val, form.Code)
+			global.App.Redis.ZRem(context.Background(), val, form.OpenId)
 			//处理省排行汇总数据
 			rankSumDataKey := form.Gid + ":" + form.Pf + ":" + config.Get("app.rank_province_table_key") + "Sum" + ":" + curField
 			global.App.Redis.ZIncrBy(context.Background(), rankSumDataKey, -defScore, curHid).Result()
@@ -61,7 +61,7 @@ func AddUserToBlackList(c *gin.Context) {
 		lastindex := strings.LastIndex(val, ":")
 		if lastindex != -1 {
 			//清除排行榜数据
-			global.App.Redis.ZRem(context.Background(), val, form.Code)
+			global.App.Redis.ZRem(context.Background(), val, form.OpenId)
 		}
 	}
 
@@ -81,12 +81,12 @@ func AddUserToBlackList(c *gin.Context) {
 // DeleteUserFormBlackList 将玩家从从黑名单中去掉
 func DeleteUserFormBlackList(c *gin.Context) {
 	form := request.Check(c, &struct {
-		Code string `json:"code" binding:"required"`
-		Gid  string `json:"gid" binding:"required"`
-		Pf   string `json:"pf" binding:"required"`
+		OpenId string `json:"openId" binding:"required"`
+		Gid    string `json:"gid" binding:"required"`
+		Pf     string `json:"pf" binding:"required"`
 	}{})
 
-	userKey := form.Gid + ":" + form.Pf + ":" + config.Get("app.user_table_key") + form.Code
+	userKey := form.Gid + ":" + form.Pf + ":" + config.Get("app.user_table_key") + form.OpenId
 
 	//存在用户 读取数据
 	_, err := global.App.Redis.HGetAll(context.Background(), userKey).Result()

+ 259 - 0
controller/v1/interfaceLog.go

@@ -0,0 +1,259 @@
+package v1
+
+import (
+	"context"
+	"designs/app/common/request"
+	"designs/app/common/response"
+	"designs/global"
+	"github.com/gin-gonic/gin"
+	"strconv"
+	"time"
+)
+
+// 总览,返回当天的 接口访问总数,登录人数,新增用户数
+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 {
+		global.App.Log.Error("redis get error", "err", err)
+	}
+
+	response.Success(c, gin.H{
+		"data": map[string]interface{}{
+			"dayCount":       dayCount,
+			"dayLoginLog":    dayLoginLog,
+			"dayRegisterLog": dayRegisterLog,
+		},
+	})
+}
+
+// 获取指定接口的请求次数 (小时的, 天的)
+// 后期还可以根据游戏,平台 ,甚至用户等参数,去获取接口访问的频率
+func GetInterfaceLog(c *gin.Context) {
+	form := request.Check(c, &struct {
+		Day       string `form:"day" json:"day" binding:""`
+		Hour      string `form:"hour" json:"hour" binding:""`
+		Interface string `form:"interface" json:"interface" binding:"required"`
+		Pf        string `form:"pf" json:"pf" binding:""`
+		Gid       string `form:"gid" json:"gid" binding:""`
+	}{})
+
+	if form.Hour == "" && form.Day == "" {
+		response.Fail(c, 1003, "day ,和hour 参数必须选一个传")
+	}
+	var key string
+	if form.Day != "" {
+		key = "dayLog:"
+	} else if form.Hour != "" {
+		key = "hourInterfaceLog:"
+	}
+
+	if form.Pf != "" && form.Gid != "" {
+		key = key + form.Gid + ":" + form.Pf
+	}
+	key = key + ":" + form.Interface
+
+	if form.Day != "" {
+		key = key + ":" + form.Day
+	} else if form.Hour != "" {
+		key = key + ":" + form.Hour
+	}
+
+	//查询新注册人数
+	res, err := global.App.Redis.Get(context.Background(), key).Result()
+	if err != nil {
+		global.App.Log.Error("redis get error", "err", err)
+	}
+
+	response.Success(c, gin.H{
+		"data": res,
+	})
+}
+
+// 获取所有的接口,以及接口的名字
+func GetInterfaceInfo(c *gin.Context) {
+
+	//router.Use(middleware.Logmiddleware())
+	//router.POST("/v1/user/login", v1.Login)                                                        //游戏登录
+	//router.POST("/v1/user/refreshToken", middleware.RefreshTokenAuthMiddleware(), v1.RefreshToken) //token刷新
+	//router.POST("/v1/user/addGidConfig", v1.AddGidConfig)
+	//router.POST("/v1/user/getGidConfig", v1.GetGidConfig)
+	//router.POST("/v1/user/getSysTime", v1.GetSysTime) //添加游戏配置数据
+	//
+	//router.POST("/v1/user/getTodayLog", v1.GetTodayLog)
+	//
+	//GroupV1 := router.Group("/v1")
+	//GroupV1.Use(middleware.TokenAuthMiddleware()).Use()
+	//{
+	//	GroupV1.POST("/user/getUserData", v1.GetUserData)                       //获取用户数据
+	//	GroupV1.POST("/user/setGameData", v1.SetGameData)                       //设置游戏数据
+	//	GroupV1.POST("/user/getGameData", v1.GetGameData)                       //获取游戏数据
+	//	GroupV1.POST("/user/setRankData", v1.SetRankData)                       //设置排行数据
+	//	GroupV1.POST("/user/getRankData", v1.GetRankData)                       //获取排行数据
+	//	GroupV1.POST("/user/updateUserInfo", v1.UpdateUserInfo)                 //更新用户数据
+	//	GroupV1.POST("/user/setProvinceRankData", v1.SetProvinceRankData)       //设置省内排行数据
+	//	GroupV1.POST("/user/getProvinceRankData", v1.GetProvinceRankData)       //获取排行数据
+	//	GroupV1.POST("/user/getProvinceRankSumData", v1.GetProvinceRankSumData) //获取省份排行数据
+	//	GroupV1.POST("/user/updateUserlocation", v1.UpdateUserlocation)         //更新位置数据
+	//
+	//	GroupV1.POST("/user/addUserToBlackList", v1.AddUserToBlackList)
+	//	GroupV1.POST("/user/deleteUserFormBlackList", v1.DeleteUserFormBlackList)
+	//	GroupV1.POST("/user/readBlackList", v1.ReadBlackList)
+
+	response.Success(c, gin.H{
+		"data": []struct {
+			Name string `json:"name"`
+			Path string `json:"path"`
+		}{
+			{Name: "登录", Path: "/v1/user/login"},
+			{Name: "刷新", Path: "/v1/user/refreshToken"},
+			{Name: "添加游戏配置", Path: "/v1/user/addGidConfig"},
+			{Name: "查看游戏配置", Path: "/v1/user/getGidConfig"},
+			{Name: "查看系统时间", Path: "/v1/user/getSysTime"},
+			{Name: "获取用户数据", Path: "/v1/user/getUserData"},
+			{Name: "设置游戏数据", Path: "/v1/user/setGameData"},
+			{Name: "获取游戏数据", Path: "/v1/user/getGameData"},
+			{Name: "更新用户信息", Path: "/v1/user/updateUserInfo"},
+			{Name: "设置排行数据", Path: "/v1/user/SetRankData"},
+			{Name: "获取排行数据", Path: "/v1/user/getRankData"},
+			{Name: "设置省内排行数据", Path: "/v1/user/setProvinceRankData"},
+			{Name: "获取省内排行数据", Path: "/v1/user/getProvinceRankData"},
+			{Name: "更新用户位置数据", Path: "/v1/user/getProvinceRankSumData"},
+			{Name: "获取省内排行总榜数据", Path: "/v1/user/updateUserlocation"},
+		},
+	})
+}
+
+// 获取某一日内,接口每个小时的访问数
+func GetInterfaceData(c *gin.Context) {
+	form := request.Check(c, &struct {
+		Day       string `form:"day" json:"day" binding:""`
+		Interface string `form:"interface" json:"interface" binding:"required"`
+		Pf        string `form:"pf" json:"pf" binding:""`
+		Gid       string `form:"gid" json:"gid" binding:""`
+	}{})
+
+	type hourDara struct {
+		Hour int `json:"hour"`
+		Data int `json:"data"`
+	}
+
+	var res []hourDara
+	for i := 1; i <= 24; i++ {
+		key := "hourInterfaceLog:" + form.Interface + ":" + form.Day + strconv.Itoa(i)
+		if form.Pf != "" && form.Gid != "" {
+			key = "hourInterfaceLog:" + form.Gid + ":" + form.Pf + ":" + form.Interface + ":" + form.Day + strconv.Itoa(i)
+		}
+
+		data, err := global.App.Redis.Get(context.Background(), key).Result()
+		if err != nil {
+			global.App.Log.Error("redis get error", "err", err)
+		}
+		dataInt, _ := strconv.Atoi(data)
+		res = append(res, hourDara{
+			Hour: i,
+			Data: dataInt,
+		})
+	}
+
+	response.Success(c, gin.H{
+		"data": res,
+	})
+
+}
+
+// 获取某一区间内,接口每天的访问数
+func GetInterfaceDataByDay(c *gin.Context) {
+	form := request.Check(c, &struct {
+		Start     string `form:"start" json:"start" binding:""`
+		End       string `form:"end" json:"end" binding:""`
+		Interface string `form:"interface" json:"interface" binding:"required"`
+		Pf        string `form:"pf" json:"pf" binding:""`
+		Gid       string `form:"gid" json:"gid" binding:""`
+	}{})
+
+	dayRange, err := GenerateDaysBetween(form.Start, form.End)
+	if err != nil {
+		response.Fail(c, 1003, err.Error())
+		return
+	}
+
+	type dayData struct {
+		Day  string `json:"day"`
+		Data int    `json:"data"`
+	}
+	var res []dayData
+	for _, v := range dayRange {
+		key := "dayLog:" + form.Interface + ":" + v
+
+		if form.Pf != "" && form.Gid != "" {
+			key = "dayLog:" + form.Gid + ":" + form.Pf + ":" + form.Interface + ":" + v
+		}
+
+		data, err := global.App.Redis.Get(context.Background(), key).Result()
+		if err != nil {
+			global.App.Log.Error("redis get error", "err", err)
+		}
+		dataInt, _ := strconv.Atoi(data)
+		res = append(res, dayData{
+			Day:  v,
+			Data: dataInt,
+		})
+	}
+
+	response.Success(c, gin.H{
+		"data": res,
+	})
+
+}
+
+func GenerateDaysBetween(startDate, endDate string) ([]string, error) {
+	start, err := time.Parse("20060102", startDate)
+	if err != nil {
+		return nil, err
+	}
+	end, err := time.Parse("20060102", endDate)
+	if err != nil {
+		return nil, err
+	}
+
+	var days []time.Time
+	for curr := start; !curr.After(end); curr = curr.AddDate(0, 0, 1) {
+		days = append(days, curr)
+	}
+
+	var res []string
+	for _, v := range days {
+		res = append(res, v.Format("20060102"))
+	}
+
+	return res, nil
+}

+ 2 - 2
controller/v1/user.go

@@ -8,7 +8,6 @@ import (
 	"designs/config"
 	"designs/global"
 	"designs/utils"
-	"errors"
 	"strings"
 	"time"
 
@@ -64,7 +63,8 @@ func Login(c *gin.Context) {
 	adminSecret := config.Get("app.admin_secret")
 
 	if form.UserName != adminUser || form.Password != adminSecret {
-		response.Fail(c, 1000, errors.New("账号密码错误"))
+		response.Fail(c, 1000, "账号密码错误")
+		return
 	}
 
 	//获取token

+ 8 - 1
route/api.go

@@ -23,11 +23,18 @@ func SetApiGroupRoutes(router *gin.RouterGroup) {
 		GroupV1.POST("/user/getGidConfig", v1.GetGidConfig)
 
 		GroupV1.POST("/user/addUserToBlackList", v1.AddUserToBlackList)
-		GroupV1.POST("/user/deleteUserFormBlackList", v1.DeleteUserFormBlackList)
+		GroupV1.POST("/user/deleteUserToBlackList", v1.DeleteUserFormBlackList)
 		GroupV1.POST("/user/readBlackList", v1.ReadBlackList)
 
 		GroupV1.POST("/user/addUserOption", v1.AddUserOption)
 		GroupV1.POST("/user/getUserOption", v1.GetUserOption)
+
+		GroupV1.POST("/user/overview", v1.Overview)
+		GroupV1.POST("/user/getInterfaceLog", v1.GetInterfaceLog)
+		GroupV1.POST("/user/getInterfaceInfo", v1.GetInterfaceInfo)
+		GroupV1.POST("/user/getInterfaceData", v1.GetInterfaceData)
+		GroupV1.POST("/user/getInterfaceDataByDay", v1.GetInterfaceDataByDay)
+
 	}
 
 }