diff --git a/internal/business/domain/user/repo/im_package_repo.go b/internal/business/domain/user/repo/im_package_repo.go index 1c2744a..2bc9016 100644 --- a/internal/business/domain/user/repo/im_package_repo.go +++ b/internal/business/domain/user/repo/im_package_repo.go @@ -9,8 +9,8 @@ type imPackageRepo struct{} var ImPackageRepo = new(imPackageRepo) // Get 获取单个套餐包 -func (*imPackageRepo) Get(masterId int64) (*model.ImPackage, error) { - imPackage, err := ImPackageDao.Get(masterId) +func (*imPackageRepo) Get(id int64) (*model.ImPackage, error) { + imPackage, err := ImPackageDao.Get(id) if err != nil { return nil, err } diff --git a/internal/logic/api/logic_ext.go b/internal/logic/api/logic_ext.go index 88953a2..3a445f5 100644 --- a/internal/logic/api/logic_ext.go +++ b/internal/logic/api/logic_ext.go @@ -250,8 +250,12 @@ func (s *LogicExtServer) AddGroupMembers(ctx context.Context, in *pb.AddGroupMem if err != nil { return nil, err } + masterId, err := grpclib.GetCtxMasterId(ctx) + if err != nil { + return nil, err + } - userIds, err := app.GroupApp.AddMembers(ctx, userId, in.GroupId, in.UserIds) + userIds, err := app.GroupApp.AddMembers(ctx, userId, in.GroupId, in.UserIds, masterId) return &pb.AddGroupMembersResp{UserIds: userIds}, err } diff --git a/internal/logic/app/group_app.go b/internal/logic/app/group_app.go index 6a9cf05..05fd772 100644 --- a/internal/logic/app/group_app.go +++ b/internal/logic/app/group_app.go @@ -5,6 +5,7 @@ import ( "database/sql" "errors" "gim/internal/business/comm/utils" + repo2 "gim/internal/business/domain/user/repo" "gim/internal/logic/domain/group/model" "gim/internal/logic/domain/group/repo" "gim/pkg/db" @@ -129,11 +130,23 @@ func (*groupApp) Update(ctx context.Context, userId int64, update *pb.UpdateGrou } // AddMembers 添加群组成员 -func (*groupApp) AddMembers(ctx context.Context, userId, groupId int64, userIds []int64) ([]int64, error) { +func (*groupApp) AddMembers(ctx context.Context, userId, groupId int64, userIds []int64, masterId string) ([]int64, error) { group, err := repo.GroupRepo.Get(groupId) if err != nil { return nil, err } + master, err := repo2.MasterRepo.Get(utils.StrToInt64(masterId)) + if err != nil { + return nil, err + } + imPackage, err := repo2.ImPackageRepo.Get(master.PackageId) + if err != nil { + return nil, err + } + if imPackage.GroupNum <= int64(group.UserNum) { + return nil, errors.New("群人员数量已满!") + } + existIds, addedIds, err := group.AddMembers(ctx, userIds) if err != nil { return nil, err