From dfed859594c21b87ef26214e3942e1ac4faec8d3 Mon Sep 17 00:00:00 2001 From: hujiebin Date: Fri, 9 Jun 2023 17:42:57 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E7=94=A8=E6=88=B7cp=E5=85=B3?= =?UTF-8?q?=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cv/cp_cv/cp.go | 7 +++++++ route/router.go | 1 + route/user_r/inner.go | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/cv/cp_cv/cp.go b/cv/cp_cv/cp.go index 82def33..4525dd3 100644 --- a/cv/cp_cv/cp.go +++ b/cv/cp_cv/cp.go @@ -8,3 +8,10 @@ type CvCp struct { CpLevel CvCpLevel `json:"cpLevel"` // cp等级 MyPrivilegeList []CvPrivilege `json:"myPrivilegeList"` // 等级特权 } + +// cp关系 +type CvCpRelation struct { + CpId uint64 `json:"cpId"` + UserId uint64 `json:"userId"` + CpUserId uint64 `json:"cpUserId"` +} diff --git a/route/router.go b/route/router.go index be5a1ce..3074dc2 100755 --- a/route/router.go +++ b/route/router.go @@ -50,6 +50,7 @@ func InitRouter() *gin.Engine { innerUser.GET("/levels", wrapper(user_r.MGetUserLevels)) innerUser.GET("/bag/id", wrapper(user_r.GetUserBagId)) innerUser.GET("/cp", wrapper(user_r.GetUserCp)) + innerUser.GET("/cpRelation", wrapper(user_r.GetUserCpRelation)) } // 道具相关 innerProp := inner.Group("/prop") diff --git a/route/user_r/inner.go b/route/user_r/inner.go index 4ed1ca7..c2a5e9c 100644 --- a/route/user_r/inner.go +++ b/route/user_r/inner.go @@ -116,6 +116,7 @@ func GetUserCp(c *gin.Context) (*mycontext.MyContext, error) { cpRelation, exists := cp_m.GetCpRelation(model, userId) if !exists { resp.ResponseOk(c, response) + return myContext, nil } var myPrivilegeList []cp_cv.CvPrivilege level := cp_m.GetCpLevel(model, cpRelation.ID) @@ -160,3 +161,35 @@ func GetUserCp(c *gin.Context) (*mycontext.MyContext, error) { resp.ResponseOk(c, response) return myContext, nil } + +// @Tags 用户-内部 +// @Summary 获取用户cp关系 +// @Param id query int true "用户id" +// @Success 200 {object} cp_cv.CvCpRelation +// @Router /inner/user/cpRelation [get] +func GetUserCpRelation(c *gin.Context) (*mycontext.MyContext, error) { + myContext := mycontext.CreateMyContext(c.Keys) + var model = domain.CreateModelContext(myContext) + var req GetUserCpReq + if err := c.ShouldBindQuery(&req); err != nil { + return myContext, err + } + userId := req.Id + var response cp_cv.CvCpRelation + cpRelation, exists := cp_m.GetCpRelation(model, userId) + if !exists { + resp.ResponseOk(c, response) + return myContext, nil + } + cpUserId := cpRelation.UserId2 + if cpUserId == userId { + cpUserId = cpRelation.UserId1 + } + response = cp_cv.CvCpRelation{ + CpId: cpRelation.ID, + UserId: userId, + CpUserId: cpUserId, + } + resp.ResponseOk(c, response) + return myContext, nil +} -- 2.22.0