diff --git a/domain/model/groupPower_m/family.go b/domain/model/groupPower_m/family.go index 1a590792eb9571d4fc18120cb5501d423537e21e..bdcf6dcb4cdb0cd796d772155eeedd535b5e1440 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 be271377f7526a158b698f181ff049e4fa36d8e2..d74e4bdc4d1c6d8c1293f77725c78aa776183c88 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 +}