From c7813a486334d38f7379895cc394ae05dc790e0e Mon Sep 17 00:00:00 2001 From: wuchao <1272174216@qq.com> Date: Tue, 7 May 2024 09:59:56 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/constants/common/common.go | 3 ++- app/http/controllers/backend/user.go | 30 ++++++++++++++++++++++++++++ app/http/controllers/user.go | 7 ------- app/http/entities/backend/user.go | 16 +++++++++++++++ app/http/middlewares/base.go | 24 ++++++++++++++++------ app/http/requestmapping/backend.go | 1 - app/http/routes/admin.go | 7 +++++-- app/http/routes/route.go | 3 ++- app/models/userinfomodel/domain.go | 15 ++++++++++++++ 9 files changed, 88 insertions(+), 18 deletions(-) create mode 100644 app/http/controllers/backend/user.go delete mode 100644 app/http/controllers/user.go create mode 100644 app/http/entities/backend/user.go create mode 100644 app/models/userinfomodel/domain.go diff --git a/app/constants/common/common.go b/app/constants/common/common.go index 67f2b4c..693b7e2 100644 --- a/app/constants/common/common.go +++ b/app/constants/common/common.go @@ -1,5 +1,6 @@ package common const ( - TOKEN_PRE = "player_token_" + TOKEN_PRE = "player_token_" + TOKEN_Admin = "Admin_token_" ) diff --git a/app/http/controllers/backend/user.go b/app/http/controllers/backend/user.go new file mode 100644 index 0000000..2a00c84 --- /dev/null +++ b/app/http/controllers/backend/user.go @@ -0,0 +1,30 @@ +package backend + +import ( + "github.com/gin-gonic/gin" + "qteam/app/constants/errorcode" + "qteam/app/http/controllers" + "qteam/app/http/entities/backend" + "qteam/app/services" +) + +func Login(c *gin.Context) { + +} + +func UserList(c *gin.Context) { + request := new(backend.UserListRequest) + err := controllers.GenRequest(c, request) + if err != nil { + controllers.Error(c, errorcode.ParamError, err.Error()) + return + } + + where := map[string]interface{}{ + "Mobile": request.Mobile, + } + count, list, err := services.GetListByWhere(where, request.Page, request.Limit) + + controllers.Success(c, gin.H{"data": list, "count": count}, "成功") + return +} diff --git a/app/http/controllers/user.go b/app/http/controllers/user.go deleted file mode 100644 index 83f02a4..0000000 --- a/app/http/controllers/user.go +++ /dev/null @@ -1,7 +0,0 @@ -package controllers - -import "github.com/gin-gonic/gin" - -func Login(c *gin.Context) { - -} diff --git a/app/http/entities/backend/user.go b/app/http/entities/backend/user.go new file mode 100644 index 0000000..9497f00 --- /dev/null +++ b/app/http/entities/backend/user.go @@ -0,0 +1,16 @@ +package backend + +type UserListRequest struct { + Page int `json:"page" validate:"required"` + Limit int `json:"limit" validate:"required"` + Mobile string `json:"mobile"` +} + +type UserListResponse struct { + Id int `xorm:"'Id' int(11)"` + Clientuniqueidentification string `xorm:"'ClientUniqueIdentification' varchar(255)"` + Mobile string `xorm:"'Mobile' varchar(13)"` + Status int `xorm:"'Status' TINYINT"` + Aer string + Createtime string +} diff --git a/app/http/middlewares/base.go b/app/http/middlewares/base.go index 423a00d..9c9d543 100644 --- a/app/http/middlewares/base.go +++ b/app/http/middlewares/base.go @@ -37,7 +37,21 @@ func Auth() gin.HandlerFunc { func AdminAuth() gin.HandlerFunc { return func(c *gin.Context) { - + var token = c.GetHeader("token") + //将token放入redis + var playerId, err = redis.GetRedis().Get(context.Background(), utils.GetRealKey(common.TOKEN_Admin+token)).Result() + if rs, errRedis := redis.GetRedis().SIsMember(context.Background(), "disabled_uids", playerId).Result(); errRedis == nil && rs { + err = errors.New(errorcode.GetMsg(errorcode.NotFound, "")) + redis.GetRedis().SRem(context.Background(), "disabled_uids", playerId) + } + if err == nil { + c.Set("playerId", playerId) + c.Next() + return + } else { + controllers.HandCodeRes(c, nil, errorcode.Forbidden) + c.Abort() + } } } @@ -54,14 +68,12 @@ func ValidateRequest() gin.HandlerFunc { utils.Log(c, "path", path) controllers.HandCodeRes(c, nil, errorcode.NotFound) } else { - value := handler() - err := controllers.GenRequest(c, value) + err := controllers.GenRequest(c, handler()) if err != nil { utils.Log(c, "path", path) - controllers.Error(c, errorcode.ParamError, err.Error()) - //controllers.HandCodeRes(c, nil, errorcode.ParamError) + controllers.HandCodeRes(c, nil, errorcode.ParamError) } else { - c.Set("request", value) + c.Set("request", handler()) c.Next() } diff --git a/app/http/requestmapping/backend.go b/app/http/requestmapping/backend.go index b313bb1..0467ec8 100644 --- a/app/http/requestmapping/backend.go +++ b/app/http/requestmapping/backend.go @@ -9,5 +9,4 @@ var BackendRequestMap = map[string]func() interface{}{ "/admin/api/v1/product/create": func() interface{} { return new(backend.ProductCreateRequest) }, - //"/admin/api/v1/product/query": func() interface{} { return new(domains.ProductFilter) }, } diff --git a/app/http/routes/admin.go b/app/http/routes/admin.go index b32f65f..595cf1e 100644 --- a/app/http/routes/admin.go +++ b/app/http/routes/admin.go @@ -22,9 +22,12 @@ func RegisterAdminRoute(router *gin.Engine) { router.Use(middlewares.Trace()) } } - //api := router.Group("/api") + admin := router.Group("/admin") { - //api.GET("/banner_list", controllers.GetBannerList) + api := admin.Group("/api") + { + api.POST("/userList", backend.UserList) + } } v1 := router.Group("/admin/api/v1") diff --git a/app/http/routes/route.go b/app/http/routes/route.go index a130012..c8d4b5e 100644 --- a/app/http/routes/route.go +++ b/app/http/routes/route.go @@ -5,6 +5,7 @@ package routes */ import ( "qteam/app/http/controllers" + "qteam/app/http/controllers/backend" "qteam/app/http/middlewares" "qteam/app/http/trace" "qteam/app/utils/metric" @@ -45,7 +46,7 @@ func RegisterRoute(router *gin.Engine) { //api版本 v1 := router.Group("/v1", middlewares.ValidateRequest()) { - v1.GET("/login", controllers.Login) + v1.GET("/login", backend.Login) } router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) diff --git a/app/models/userinfomodel/domain.go b/app/models/userinfomodel/domain.go new file mode 100644 index 0000000..bf21a3b --- /dev/null +++ b/app/models/userinfomodel/domain.go @@ -0,0 +1,15 @@ +package userinfomodel + +import ( + "qteam/app/http/entities/backend" + "time" +) + +func (m *UserInfo) ToDomain() (do backend.UserListResponse) { + do.Id = m.Id + do.Clientuniqueidentification = m.Clientuniqueidentification + do.Mobile = m.Mobile + do.Status = m.Status + do.Createtime = m.Createtime.Format(time.DateTime) + return +}