Commit 033d3d04 authored by chenweijian's avatar chenweijian

设置家族管理员

parent e4ff5c27
......@@ -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
}
......@@ -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{})
......
......@@ -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
}
......@@ -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")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment