fix version 1
This commit is contained in:
@@ -19,22 +19,40 @@ func DoKick(ctx context.Context, in *pb.GroupOPRequest) (reply *pb.DataStatusRep
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 判断是不是群管理或是创建者
|
||||
var tc int64
|
||||
if err = impl.DBService.Model(&models.GroupMember{}).Where("identity=? and role !=0 and passport_id=?", in.GroupIdentity, auth.Identity).Count(&tc).Error; err != nil {
|
||||
if in.GetGroupIdentity() == "" || in.GetIdentity() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// 判断操作者是不是该群的管理员或创建者
|
||||
var opRole int32
|
||||
if err = impl.DBService.Model(&models.GroupMember{}).
|
||||
Where("group_identity=? and passport_id=?", in.GroupIdentity, auth.ID).
|
||||
Pluck("role", &opRole).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
if tc == 0 {
|
||||
if opRole <= ROLE_MEMBER {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
err = impl.DBService.Model(&models.GroupMember{}).Delete("group_identity=? and identity=?", in.GroupIdentity, in.Identity).Error
|
||||
if err != nil {
|
||||
// 目标成员必须属于该群组
|
||||
var target models.GroupMember
|
||||
if err = impl.DBService.Where("group_identity=? and identity=?", in.GroupIdentity, in.Identity).First(&target).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrRecordNotFound
|
||||
}
|
||||
// 禁止踢创建者,以及权限不低于操作者的成员
|
||||
if target.Role >= ROLE_CREATEOR || target.Role >= opRole {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
res := impl.DBService.Where("group_identity=? and identity=?", in.GroupIdentity, in.Identity).Delete(&models.GroupMember{})
|
||||
if res.Error != nil {
|
||||
printer.Error(res.Error.Error())
|
||||
return nil, errcode.ErrDB
|
||||
} else {
|
||||
//更新群组表数据统计
|
||||
}
|
||||
if res.RowsAffected > 0 {
|
||||
// 仅在确实删除成员后更新群组数据统计
|
||||
models.UpsetGroupMemberTotal(in.GroupIdentity, "-")
|
||||
}
|
||||
return &pb.DataStatusReply{
|
||||
|
||||
Reference in New Issue
Block a user