From 033d3d048e1b0ec3bdd606679326bc89cb960932 Mon Sep 17 00:00:00 2001 From: chenweijian <820961417@qq.com> Date: Mon, 13 Mar 2023 16:18:06 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=AE=B6=E6=97=8F=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domain/model/groupPower_m/family.go | 9 ++++ myerr/bizerr/bizCode.go | 29 ++++++------ route/group_power_r/group_power.go | 72 +++++++++++++++++++++++++++++ route/router.go | 1 + 4 files changed, 97 insertions(+), 14 deletions(-) diff --git a/domain/model/groupPower_m/family.go b/domain/model/groupPower_m/family.go index 08e36b9..9871b0e 100644 --- a/domain/model/groupPower_m/family.go +++ b/domain/model/groupPower_m/family.go @@ -4,6 +4,7 @@ import ( "git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/resource/mysql" "gorm.io/gorm" + "hilo-group/_const/enum/groupPower_e" "hilo-group/common" "hilo-group/common/utime" "time" @@ -103,3 +104,11 @@ func GroupPowerQuitList(model *domain.Model, familyId uint64, pageSize, pageInde nextIdx, hasNext := common.PageNext(count, pageIndex, pageSize) return rows, nextIdx, hasNext, nil } + +func UpdateFamilyAdmin(model *domain.Model, userId, familyId uint64, role groupPower_e.GroupPowerUserRole) error { + err := model.Db.Exec("update group_power_user set role = ? where group_power_id = ? and user_id = ?", role, familyId, userId).Error + if err != nil { + return err + } + return nil +} diff --git a/myerr/bizerr/bizCode.go b/myerr/bizerr/bizCode.go index df59a3c..2a6ca80 100644 --- a/myerr/bizerr/bizCode.go +++ b/myerr/bizerr/bizCode.go @@ -71,20 +71,21 @@ var ( GroupNoPowerToSvip6 = myerr.NewBusinessCode(14026, "Cannot use this permission for SVIP6", myerr.BusinessData{}) // 踢出,无法对SVIP6使用此权限 // 家族 - GroupPowerHasJoinOther = myerr.NewBusinessCode(15001, "You already have joined power, please exit first", myerr.BusinessData{}) // 已经加入了其它国家势力 - GroupPowerHasJoinMy = myerr.NewBusinessCode(15002, "You already have joined power, please exit first", myerr.BusinessData{}) // 已经加入了该国家势力 - GroupPowerOwnerLeave = myerr.NewBusinessCode(15003, "power owner cannot exit", myerr.BusinessData{}) // 势力主不能退出 - GroupPowerNotExist = myerr.NewBusinessCode(15004, "国家势力不存在", myerr.BusinessData{}) // 国家势力不存在 - GroupPowerNoOwner = myerr.NewBusinessCode(15005, "power owner not exits or unique", myerr.BusinessData{}) // 国家势力主不存在或不唯一 - GroupPowerStayTooShort = myerr.NewBusinessCode(15006, "You joined this power not more than 10 days ago", myerr.BusinessData{}) // 加入国家势力不超过10天 - GroupPowerDealerNotMember = myerr.NewBusinessCode(15007, "Not family member", myerr.BusinessData{}) // 代理转账失败-非家族成员 - GroupPowerDealerCanNotSole = myerr.NewBusinessCode(15008, "This user already has a family agent and cannot sell diamonds", myerr.BusinessData{}) // 代理转账失败-此用户已有家族代理,不能出售钻石 - GroupPowerDealerCanNotBuy = myerr.NewBusinessCode(15009, "Buy diamonds from your family agent", myerr.BusinessData{}) // 请向本家族代理购买钻石 - GroupPowerDealerNeedJoin = myerr.NewBusinessCode(15010, "Please join the agent's family to purchase", myerr.BusinessData{}) // 请加入代理的家族后进行购买 - GroupPowerHaveNoJoin = myerr.NewBusinessCode(15011, "You have no joined power", myerr.BusinessData{}) // 还未加入国家势力 - GroupPowerHaveNoPower = myerr.NewBusinessCode(15012, "You have no power", myerr.BusinessData{}) // 没有权限 - GroupPowerHaveNoApply = myerr.NewBusinessCode(15013, "User have no apply", myerr.BusinessData{}) // 没有找到申请 - GroupPowerHaveAlreadyApply = myerr.NewBusinessCode(15014, "Already applied", myerr.BusinessData{}) // 已经申请过 + GroupPowerHasJoinOther = myerr.NewBusinessCode(15001, "You already have joined power, please exit first", myerr.BusinessData{}) // 已经加入了其它国家势力 + GroupPowerHasJoinMy = myerr.NewBusinessCode(15002, "You already have joined power, please exit first", myerr.BusinessData{}) // 已经加入了该国家势力 + GroupPowerOwnerLeave = myerr.NewBusinessCode(15003, "power owner cannot exit", myerr.BusinessData{}) // 势力主不能退出 + GroupPowerNotExist = myerr.NewBusinessCode(15004, "国家势力不存在", myerr.BusinessData{}) // 国家势力不存在 + GroupPowerNoOwner = myerr.NewBusinessCode(15005, "power owner not exits or unique", myerr.BusinessData{}) // 国家势力主不存在或不唯一 + GroupPowerStayTooShort = myerr.NewBusinessCode(15006, "You joined this power not more than 10 days ago", myerr.BusinessData{}) // 加入国家势力不超过10天 + GroupPowerDealerNotMember = myerr.NewBusinessCode(15007, "Not family member", myerr.BusinessData{}) // 代理转账失败-非家族成员 + GroupPowerDealerCanNotSole = myerr.NewBusinessCode(15008, "This user already has a family agent and cannot sell diamonds", myerr.BusinessData{}) // 代理转账失败-此用户已有家族代理,不能出售钻石 + GroupPowerDealerCanNotBuy = myerr.NewBusinessCode(15009, "Buy diamonds from your family agent", myerr.BusinessData{}) // 请向本家族代理购买钻石 + GroupPowerDealerNeedJoin = myerr.NewBusinessCode(15010, "Please join the agent's family to purchase", myerr.BusinessData{}) // 请加入代理的家族后进行购买 + GroupPowerHaveNoJoin = myerr.NewBusinessCode(15011, "You have no joined power", myerr.BusinessData{}) // 还未加入国家势力 + GroupPowerHaveNoPower = myerr.NewBusinessCode(15012, "You have no power", myerr.BusinessData{}) // 没有权限 + GroupPowerHaveNoApply = myerr.NewBusinessCode(15013, "User have no apply", myerr.BusinessData{}) // 没有找到申请 + GroupPowerHaveAlreadyApply = myerr.NewBusinessCode(15014, "Already applied", myerr.BusinessData{}) // 已经申请过 + GroupPowerHaveAlreadyChange = myerr.NewBusinessCode(15015, "Already changed", myerr.BusinessData{}) // 已经改变了 TaskHasAward = myerr.NewBusinessCode(19001, "task has award", myerr.BusinessData{}) diff --git a/route/group_power_r/group_power.go b/route/group_power_r/group_power.go index 7f6cde5..80de632 100644 --- a/route/group_power_r/group_power.go +++ b/route/group_power_r/group_power.go @@ -1184,3 +1184,75 @@ func GroupPowerQuitList(c *gin.Context) (*mycontext.MyContext, error) { resp.ResponsePageBaseOk(c, result, nextPageIndex, hasNextPage) return myContext, nil } + +// @Tags 家族 +// @Summary 设置/取消管理员 +// @Param userExtId formData string false "用户extId" +// @Param type formData int true "1.设置为管理员,2.取消管理员" +// @Success 200 +// @Router /v1/groupPower/admin [post] +func GroupPowerSetAdmin(c *gin.Context) (*mycontext.MyContext, error) { + myContext := mycontext.CreateMyContext(c.Keys) + userId, err := req.GetUserId(c) + if err != nil { + return myContext, err + } + optType, err := strconv.Atoi(c.PostForm("type")) + if err != nil { + return myContext, bizerr.InvalidParameter + } + if optType < 1 || optType > 2 { + return myContext, bizerr.InvalidParameter + } + userExtId := c.PostForm("userExtId") + if userExtId == "" { + return myContext, bizerr.InvalidParameter + } + model := domain.CreateModelContext(myContext) + optUser, err := user_c.GetUserByExternalId(model, userExtId) + if err != nil { + return myContext, err + } + + // 判断是否加入了家族 + gpU := groupPower_m.GroupPowerUser{UserId: userId} + myGroupPUser, err := gpU.GetGroupPowerUser(model) + if err != nil { + return myContext, err + } + // 操作者是否加入了家族,是否有操作权限 + if myGroupPUser == nil { + return myContext, bizerr.GroupPowerHaveNoJoin + } + if myGroupPUser.Role != groupPower_e.GroupPowerUserRoleMgr { + return myContext, bizerr.GroupPowerHaveNoPower + } + // 被操作者是否加入了家族 + gpOptUser := groupPower_m.GroupPowerUser{UserId: optUser.ID} + optGroupPUser, err := gpOptUser.GetGroupPowerUser(model) + if err != nil { + return myContext, err + } + if optGroupPUser == nil { + return myContext, bizerr.GroupPowerHaveNoJoin + } + // 目标身份 + var targetRole groupPower_e.GroupPowerUserRole + if optType == 1 { + targetRole = groupPower_e.GroupPowerUserRoleAdmin + } else { + targetRole = groupPower_e.GroupPowerUserRoleUser + } + // 和原来的身份是否一致 + if optGroupPUser.Role == targetRole { + return myContext, bizerr.GroupPowerHaveAlreadyChange + } + // 变更 + err = groupPower_m.UpdateFamilyAdmin(model, userId, optGroupPUser.GroupPowerId, targetRole) + if optGroupPUser == nil { + return myContext, myerr.WrapErr(err) + } + + resp.ResponseOk(c, nil) + return myContext, nil +} diff --git a/route/router.go b/route/router.go index c7f178f..2c31d17 100644 --- a/route/router.go +++ b/route/router.go @@ -134,6 +134,7 @@ func InitRouter() *gin.Engine { groupPower.GET("/apply/list", wrapper(group_power_r.GroupPowerApplyList)) groupPower.POST("/quit", wrapper(group_power_r.GroupPowerQuit)) groupPower.GET("/quit/list", wrapper(group_power_r.GroupPowerQuitList)) + groupPower.POST("/admin", wrapper(group_power_r.GroupPowerSetAdmin)) } charge := v1.Group("/charge") -- 2.22.0