@@ -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) { | 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 | return &pb.SearchUserResp{Users: users}, err | ||||
} | } |
@@ -51,8 +51,8 @@ func (*userApp) GetByIds(ctx context.Context, userIds []int64) (map[int64]*pb.Us | |||||
return pbUsers, nil | 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 { | if err != nil { | ||||
return nil, err | return nil, err | ||||
} | } | ||||
@@ -47,9 +47,9 @@ func (*userDao) Save(user *model.User) error { | |||||
} | } | ||||
// GetByPhoneNumber 根据手机号获取用户信息 | // GetByPhoneNumber 根据手机号获取用户信息 | ||||
func (*userDao) GetByPhoneNumber(phoneNumber string) (*model.User, error) { | |||||
func (*userDao) GetByPhoneNumber(phoneNumber string, masterId int) (*model.User, error) { | |||||
var user model.User | 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 { | if err != nil && err != gorm.ErrRecordNotFound { | ||||
return nil, gerrors.WrapError(err) | return nil, gerrors.WrapError(err) | ||||
} | } | ||||
@@ -70,10 +70,10 @@ func (*userDao) GetByIds(userIds []int64) ([]model.User, error) { | |||||
} | } | ||||
// Search 查询用户,这里简单实现,生产环境建议使用ES | // Search 查询用户,这里简单实现,生产环境建议使用ES | ||||
func (*userDao) Search(key string) ([]model.User, error) { | |||||
func (*userDao) Search(key string, masterId int) ([]model.User, error) { | |||||
var users []model.User | var users []model.User | ||||
key = "%" + key + "%" | 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 { | if err != nil { | ||||
return nil, gerrors.WrapError(err) | return nil, gerrors.WrapError(err) | ||||
} | } | ||||
@@ -34,11 +34,11 @@ func TestUserDao_GetByIds(t *testing.T) { | |||||
} | } | ||||
func TestUserDao_GetByPhoneNumber(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) | fmt.Printf("%+v\n %+v\n ", user, err) | ||||
} | } | ||||
func TestUserDao_Search(t *testing.T) { | 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) | fmt.Printf("%+v\n %+v\n ", users, err) | ||||
} | } |
@@ -32,8 +32,8 @@ func (*userRepo) Get(userId int64) (*model.User, error) { | |||||
return user, err | 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 获取多个用户 | // GetByIds 获取多个用户 | ||||
@@ -42,8 +42,8 @@ func (*userRepo) GetByIds(userIds []int64) ([]model.User, error) { | |||||
} | } | ||||
// Search 搜索用户 | // 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 保存用户 | // Save 保存用户 | ||||
@@ -21,7 +21,7 @@ func (*authService) SignIn(ctx context.Context, phoneNumber, code string, master | |||||
return false, 0, "", 0, gerrors.ErrBadCode | return false, 0, "", 0, gerrors.ErrBadCode | ||||
} | } | ||||
user, err := repo.UserRepo.GetByPhoneNumber(phoneNumber) | |||||
user, err := repo.UserRepo.GetByPhoneNumber(phoneNumber, masterId) | |||||
if err != nil { | if err != nil { | ||||
return false, 0, "", 0, err | return false, 0, "", 0, err | ||||
} | } | ||||
@@ -432,7 +432,8 @@ type SearchUserReq struct { | |||||
sizeCache protoimpl.SizeCache | sizeCache protoimpl.SizeCache | ||||
unknownFields protoimpl.UnknownFields | 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() { | func (x *SearchUserReq) Reset() { | ||||