作者 yangfu

企业注册修改

... ... @@ -26,6 +26,9 @@ func (s *PgCreateCompanyService) CreateCompany(optUser *domain.User, registerPho
}
var err error
var company *domain.Company
companyRepository, _ := repository.NewCompanyRepository(s.transactionContext)
// 1.检查账号是否被注册过,一个手机号只能注册一家企业
var userBase *domain.UserBase
userBaseRepository, _ := repository.NewUserBaseRepository(s.transactionContext)
... ... @@ -33,17 +36,20 @@ func (s *PgCreateCompanyService) CreateCompany(optUser *domain.User, registerPho
userRepository, _ := repository.NewUserRepository(s.transactionContext)
if _, users, _ := userRepository.Find(map[string]interface{}{"userBaseId": userBase.UserBaseId}); len(users) > 0 {
for i := 0; i < len(users); i++ {
if users[i].UserType&domain.RoleTypeAdmin > 0 {
return nil, fmt.Errorf("该手机号已注册")
if users[i].UserType&domain.RoleTypeAdmin > 0 && users[i].Company != nil {
if company, err = companyRepository.FindOne(map[string]interface{}{"companyId": users[i].Company.CompanyId}); err != nil {
return nil, err
} else if company.Status != domain.CompanyUnauthenticated {
return nil, fmt.Errorf("该手机号已注册")
}
}
}
}
}
// 2.企业名称检查
var company *domain.Company
companyRepository, _ := repository.NewCompanyRepository(s.transactionContext)
if company, err = companyRepository.FindOne(map[string]interface{}{"companyName": companyInfo.CompanyName}); err != nil && err != domain.ErrorNotFound {
if company, err = companyRepository.FindOne(map[string]interface{}{"companyName": companyInfo.CompanyName, "statusNotIn": []int{domain.CompanyUnauthenticated}}); err != nil && err != domain.ErrorNotFound {
return nil, fmt.Errorf("该企业已经注册")
} else if company != nil && company.CompanyInfo.CompanyName == companyInfo.CompanyName {
return nil, fmt.Errorf("该企业已经注册")
... ...
... ... @@ -122,6 +122,9 @@ func (repository *CompanyRepository) FindOne(queryOptions map[string]interface{}
if v, ok := queryOptions["companyName"]; ok {
query.Where(fmt.Sprintf(`company_info @>'{"companyName":"%v"}'`, v))
}
if v, ok := queryOptions["statusNotIn"]; ok {
query.Where("status not in (?)", pg.In(v))
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, domain.ErrorNotFound
... ...