diff --git a/internal/business/api/business_ext.go b/internal/business/api/business_ext.go index 638ce19..2b4067a 100644 --- a/internal/business/api/business_ext.go +++ b/internal/business/api/business_ext.go @@ -42,6 +42,6 @@ func (s *BusinessExtServer) UpdateUser(ctx context.Context, req *pb.UpdateUserRe } func (s *BusinessExtServer) SearchUser(ctx context.Context, req *pb.SearchUserReq) (*pb.SearchUserResp, error) { - users, err := app.UserApp.Search(ctx, req.Key) + users, err := app.UserApp.Search(ctx, req.Key, req.MasterId) return &pb.SearchUserResp{Users: users}, err } diff --git a/internal/business/app/user_app.go b/internal/business/app/user_app.go index 7b58ef2..e28cb22 100644 --- a/internal/business/app/user_app.go +++ b/internal/business/app/user_app.go @@ -51,8 +51,8 @@ func (*userApp) GetByIds(ctx context.Context, userIds []int64) (map[int64]*pb.Us return pbUsers, nil } -func (*userApp) Search(ctx context.Context, key string) ([]*pb.User, error) { - users, err := repo.UserRepo.Search(key) +func (*userApp) Search(ctx context.Context, key string, masterId int) ([]*pb.User, error) { + users, err := repo.UserRepo.Search(key, masterId) if err != nil { return nil, err } diff --git a/internal/business/domain/user/repo/user_dao.go b/internal/business/domain/user/repo/user_dao.go index 6421265..274431b 100644 --- a/internal/business/domain/user/repo/user_dao.go +++ b/internal/business/domain/user/repo/user_dao.go @@ -47,9 +47,9 @@ func (*userDao) Save(user *model.User) error { } // GetByPhoneNumber 根据手机号获取用户信息 -func (*userDao) GetByPhoneNumber(phoneNumber string) (*model.User, error) { +func (*userDao) GetByPhoneNumber(phoneNumber string, masterId int) (*model.User, error) { var user model.User - err := db.DB.First(&user, "phone_number = ?", phoneNumber).Error + err := db.DB.First(&user, "phone_number = ? and master_id = ?", phoneNumber, masterId).Error if err != nil && err != gorm.ErrRecordNotFound { return nil, gerrors.WrapError(err) } @@ -70,10 +70,10 @@ func (*userDao) GetByIds(userIds []int64) ([]model.User, error) { } // Search 查询用户,这里简单实现,生产环境建议使用ES -func (*userDao) Search(key string) ([]model.User, error) { +func (*userDao) Search(key string, masterId int) ([]model.User, error) { var users []model.User key = "%" + key + "%" - err := db.DB.Where("phone_number like ? or nickname like ?", key, key).Find(&users).Error + err := db.DB.Where("phone_number like ? or nickname like ? and master_id = ?", key, key, masterId).Find(&users).Error if err != nil { return nil, gerrors.WrapError(err) } diff --git a/internal/business/domain/user/repo/user_dao_test.go b/internal/business/domain/user/repo/user_dao_test.go index bafcee2..ef5d67e 100644 --- a/internal/business/domain/user/repo/user_dao_test.go +++ b/internal/business/domain/user/repo/user_dao_test.go @@ -34,11 +34,11 @@ func TestUserDao_GetByIds(t *testing.T) { } func TestUserDao_GetByPhoneNumber(t *testing.T) { - user, err := UserDao.GetByPhoneNumber("18829291351") + user, err := UserDao.GetByPhoneNumber("18829291351", 123456) fmt.Printf("%+v\n %+v\n ", user, err) } func TestUserDao_Search(t *testing.T) { - users, err := UserDao.Search("18229") + users, err := UserDao.Search("18229", 123456) fmt.Printf("%+v\n %+v\n ", users, err) } diff --git a/internal/business/domain/user/repo/user_repo.go b/internal/business/domain/user/repo/user_repo.go index 0ccdfb4..03c805e 100644 --- a/internal/business/domain/user/repo/user_repo.go +++ b/internal/business/domain/user/repo/user_repo.go @@ -32,8 +32,8 @@ func (*userRepo) Get(userId int64) (*model.User, error) { return user, err } -func (*userRepo) GetByPhoneNumber(phoneNumber string) (*model.User, error) { - return UserDao.GetByPhoneNumber(phoneNumber) +func (*userRepo) GetByPhoneNumber(phoneNumber string, masterId int) (*model.User, error) { + return UserDao.GetByPhoneNumber(phoneNumber, masterId) } // GetByIds 获取多个用户 @@ -42,8 +42,8 @@ func (*userRepo) GetByIds(userIds []int64) ([]model.User, error) { } // Search 搜索用户 -func (*userRepo) Search(key string) ([]model.User, error) { - return UserDao.Search(key) +func (*userRepo) Search(key string, masterId int) ([]model.User, error) { + return UserDao.Search(key, masterId) } // Save 保存用户 diff --git a/internal/business/domain/user/service/auth.go b/internal/business/domain/user/service/auth.go index cdb8ed1..e127183 100644 --- a/internal/business/domain/user/service/auth.go +++ b/internal/business/domain/user/service/auth.go @@ -21,7 +21,7 @@ func (*authService) SignIn(ctx context.Context, phoneNumber, code string, master return false, 0, "", 0, gerrors.ErrBadCode } - user, err := repo.UserRepo.GetByPhoneNumber(phoneNumber) + user, err := repo.UserRepo.GetByPhoneNumber(phoneNumber, masterId) if err != nil { return false, 0, "", 0, err } diff --git a/pkg/pb/business.ext.pb.go b/pkg/pb/business.ext.pb.go index 5f9c234..916e180 100644 --- a/pkg/pb/business.ext.pb.go +++ b/pkg/pb/business.ext.pb.go @@ -432,7 +432,8 @@ type SearchUserReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + MasterId int `protobuf:"varint,2,opt,name=master_id,json=masterId,proto3" json:"master_id,omitempty"` // 站长id } func (x *SearchUserReq) Reset() {