Commit 6de10476 authored by chenweijian's avatar chenweijian

家族

parent 8d492956
......@@ -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 {
......
......@@ -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
}
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