From 6de10476380a8c4d4e355142c23520eb3a44c0cb Mon Sep 17 00:00:00 2001 From: chenweijian <820961417@qq.com> Date: Mon, 13 Mar 2023 15:24:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=B6=E6=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domain/model/groupPower_m/family.go | 2 +- route/group_power_r/group_power.go | 77 ++++++++++++++++++++++++++++- 2 files changed, 76 insertions(+), 3 deletions(-) diff --git a/domain/model/groupPower_m/family.go b/domain/model/groupPower_m/family.go index 1a59079..bdcf6dc 100644 --- a/domain/model/groupPower_m/family.go +++ b/domain/model/groupPower_m/family.go @@ -40,7 +40,7 @@ func (this *GroupPower) Get(model *domain.Model) (*GroupPower, error) { func (gpu *GroupPowerUser) GetBy(model *domain.Model, pageSize, pageIndex int) ([]*GroupPowerUser, int, bool, error) { rows := make([]*GroupPowerUser, 0) - db := model.Db.Where(gpu).Order("field(`role`, 2, 3, 1)") + db := model.Db.Model(GroupPowerUser{}).Where(gpu).Order("field(`role`, 2, 3, 1)") var count int64 err := db.Count(&count).Error if err != nil { diff --git a/route/group_power_r/group_power.go b/route/group_power_r/group_power.go index be27137..d74e4bd 100644 --- a/route/group_power_r/group_power.go +++ b/route/group_power_r/group_power.go @@ -714,12 +714,12 @@ func GroupPowerInfo(c *gin.Context) (*mycontext.MyContext, error) { gp := &groupPower_m.GroupPower{Entity: mysql.Entity{ID: familyId}} gpInfo, err := gp.Get(model) if err != nil { - return myContext, err + return myContext, myerr.WrapErr(err) } gpU := &groupPower_m.GroupPowerUser{GroupPowerId: gpInfo.ID} members, _, _, err := gpU.GetBy(model, 5, 0) if err != nil { - return myContext, err + return myContext, myerr.WrapErr(err) } uids := make([]uint64, 0, len(members)) for _, v := range members { @@ -1034,3 +1034,76 @@ func GroupPowerApplyList(c *gin.Context) (*mycontext.MyContext, error) { resp.ResponsePageBaseOk(c, result, nextPageIndex, hasNextPage) return myContext, nil } + +// @Tags 家族 +// @Summary 退出/踢出家族 +// @Param type formData int true "1.自己退出,2.踢人" +// @Param userExtId formData string false "用户extId" +// @Success 200 +// @Router /v1/groupPower/quit [post] +func GroupPowerQuit(c *gin.Context) (*mycontext.MyContext, error) { + myContext := mycontext.CreateMyContext(c.Keys) + userId, err := req.GetUserId(c) + if err != nil { + return myContext, err + } + quitType, err := strconv.Atoi(c.Query("type")) + if err != nil { + return myContext, err + } + if quitType < 1 || quitType > 2 { + return myContext, bizerr.InvalidParameter + } + model := domain.CreateModelContext(myContext) + + if quitType == 1 { // 主动退出 + // 判断是否加入了家族 + gpU := groupPower_m.GroupPowerUser{UserId: userId} + groupPUser, err := gpU.GetGroupPowerUser(model) + if err != nil { + return myContext, err + } + if groupPUser == nil { + return myContext, bizerr.GroupPowerHaveNoJoin + } + // 退出家族 + // log + + resp.ResponseOk(c, nil) + return myContext, nil + } + // 判断是否加入了家族 + 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 == 0 || myGroupPUser.Role == groupPower_e.GroupPowerUserRoleUser { + return myContext, bizerr.GroupPowerHaveNoPower + } + // 被踢人信息 + userExtId := c.Query("userExtId") + if userExtId == "" { + return myContext, bizerr.InvalidParameter + } + u, err := user_c.GetUserByExternalId(model, userExtId) + if err != nil { + return myContext, err + } + groupPUser, err := gpU.GetGroupPowerUser(model) + if err != nil { + return myContext, err + } + if groupPUser == nil { + return myContext, bizerr.GroupPowerHaveNoJoin + } + // 退出家族 + // log + + resp.ResponseOk(c, u) + return myContext, nil +} -- 2.22.0