fix version 1
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
)
|
||||
|
||||
// 申请加群
|
||||
@@ -19,39 +20,84 @@ func DoJoin(ctx context.Context, in *pb.DoJoinRequest) (reply *pb.DataStatusRepl
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//生成唯一标识
|
||||
identity := utils.UUID()
|
||||
if in.GetIdentity() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
//判断是否需要加群验证
|
||||
if models.GetGroupEnableAnyJoin(auth.ID, in.Identity) {
|
||||
// 直接加入群成员
|
||||
apply := &models.GroupMember{
|
||||
GroupID: uint(in.Id),
|
||||
// 校验群组是否存在
|
||||
var group models.GroupBasic
|
||||
if err = impl.DBService.Where("identity=?", in.Identity).First(&group).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrRecordNotFound
|
||||
}
|
||||
|
||||
// 重复入群防护:已是成员直接返回成功
|
||||
var memberCnt int64
|
||||
if err = impl.DBService.Model(&models.GroupMember{}).
|
||||
Where("group_identity=? and passport_id=?", in.Identity, auth.ID).Count(&memberCnt).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
if memberCnt > 0 {
|
||||
return &pb.DataStatusReply{Data: vars.OK, Timeseq: time.Now().UnixMilli()}, nil
|
||||
}
|
||||
|
||||
// 成员上限校验(MemberLimit 为 0 表示不限)
|
||||
if group.MemberLimit > 0 && group.MemberTotal >= group.MemberLimit {
|
||||
return nil, errcode.ErrResourceExhausted
|
||||
}
|
||||
|
||||
// 是否免验证入群
|
||||
enableAnyJoin, err := models.GetGroupEnableAnyJoin(in.Identity)
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
var identity string
|
||||
if enableAnyJoin {
|
||||
// 免验证直接加入群成员
|
||||
member := &models.GroupMember{
|
||||
GroupID: group.ID,
|
||||
GroupIdentity: in.Identity,
|
||||
Role: ROLE_MEMBER,
|
||||
}
|
||||
apply.Identity = utils.UUID()
|
||||
apply.PassportID = auth.ID
|
||||
apply.PassportIdentity = auth.Identity
|
||||
|
||||
err = impl.DBService.Create(&apply).Error
|
||||
member.Identity = utils.UUID()
|
||||
member.PassportID = auth.ID
|
||||
member.PassportIdentity = auth.Identity
|
||||
if err = impl.DBService.Create(member).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
identity = member.Identity
|
||||
// 更新群组表数据统计
|
||||
models.UpsetGroupMemberTotal(in.Identity, "+")
|
||||
} else {
|
||||
// 避免重复提交待处理申请
|
||||
var applyCnt int64
|
||||
if err = impl.DBService.Model(&models.GroupApply{}).
|
||||
Where("group_identity=? and from_id=? and status=?", in.Identity, auth.ID, 0).Count(&applyCnt).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
if applyCnt > 0 {
|
||||
return &pb.DataStatusReply{Data: vars.OK, Timeseq: time.Now().UnixMilli()}, nil
|
||||
}
|
||||
|
||||
// 写入加群申请表
|
||||
apply := &models.GroupApply{
|
||||
FromID: uint(auth.ID),
|
||||
FromID: auth.ID,
|
||||
FromIdentity: auth.Identity,
|
||||
GroupID: uint(in.Id),
|
||||
GroupID: group.ID,
|
||||
GroupIdentity: in.Identity,
|
||||
Message: in.Message,
|
||||
}
|
||||
apply.Identity = utils.UUID()
|
||||
|
||||
err = impl.DBService.Create(&apply).Error
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
if err = impl.DBService.Create(apply).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
identity = apply.Identity
|
||||
}
|
||||
|
||||
return &pb.DataStatusReply{
|
||||
|
||||
Reference in New Issue
Block a user