作者 yangfu

企业注册修改

@@ -26,6 +26,9 @@ func (s *PgCreateCompanyService) CreateCompany(optUser *domain.User, registerPho @@ -26,6 +26,9 @@ func (s *PgCreateCompanyService) CreateCompany(optUser *domain.User, registerPho
26 } 26 }
27 27
28 var err error 28 var err error
  29 + var company *domain.Company
  30 + companyRepository, _ := repository.NewCompanyRepository(s.transactionContext)
  31 +
29 // 1.检查账号是否被注册过,一个手机号只能注册一家企业 32 // 1.检查账号是否被注册过,一个手机号只能注册一家企业
30 var userBase *domain.UserBase 33 var userBase *domain.UserBase
31 userBaseRepository, _ := repository.NewUserBaseRepository(s.transactionContext) 34 userBaseRepository, _ := repository.NewUserBaseRepository(s.transactionContext)
@@ -33,17 +36,20 @@ func (s *PgCreateCompanyService) CreateCompany(optUser *domain.User, registerPho @@ -33,17 +36,20 @@ func (s *PgCreateCompanyService) CreateCompany(optUser *domain.User, registerPho
33 userRepository, _ := repository.NewUserRepository(s.transactionContext) 36 userRepository, _ := repository.NewUserRepository(s.transactionContext)
34 if _, users, _ := userRepository.Find(map[string]interface{}{"userBaseId": userBase.UserBaseId}); len(users) > 0 { 37 if _, users, _ := userRepository.Find(map[string]interface{}{"userBaseId": userBase.UserBaseId}); len(users) > 0 {
35 for i := 0; i < len(users); i++ { 38 for i := 0; i < len(users); i++ {
36 - if users[i].UserType&domain.RoleTypeAdmin > 0 {  
37 - return nil, fmt.Errorf("该手机号已注册") 39 + if users[i].UserType&domain.RoleTypeAdmin > 0 && users[i].Company != nil {
  40 + if company, err = companyRepository.FindOne(map[string]interface{}{"companyId": users[i].Company.CompanyId}); err != nil {
  41 + return nil, err
  42 + } else if company.Status != domain.CompanyUnauthenticated {
  43 + return nil, fmt.Errorf("该手机号已注册")
  44 + }
38 } 45 }
39 } 46 }
40 } 47 }
41 } 48 }
42 49
43 // 2.企业名称检查 50 // 2.企业名称检查
44 - var company *domain.Company  
45 - companyRepository, _ := repository.NewCompanyRepository(s.transactionContext)  
46 - if company, err = companyRepository.FindOne(map[string]interface{}{"companyName": companyInfo.CompanyName}); err != nil && err != domain.ErrorNotFound { 51 +
  52 + if company, err = companyRepository.FindOne(map[string]interface{}{"companyName": companyInfo.CompanyName, "statusNotIn": []int{domain.CompanyUnauthenticated}}); err != nil && err != domain.ErrorNotFound {
47 return nil, fmt.Errorf("该企业已经注册") 53 return nil, fmt.Errorf("该企业已经注册")
48 } else if company != nil && company.CompanyInfo.CompanyName == companyInfo.CompanyName { 54 } else if company != nil && company.CompanyInfo.CompanyName == companyInfo.CompanyName {
49 return nil, fmt.Errorf("该企业已经注册") 55 return nil, fmt.Errorf("该企业已经注册")
@@ -122,6 +122,9 @@ func (repository *CompanyRepository) FindOne(queryOptions map[string]interface{} @@ -122,6 +122,9 @@ func (repository *CompanyRepository) FindOne(queryOptions map[string]interface{}
122 if v, ok := queryOptions["companyName"]; ok { 122 if v, ok := queryOptions["companyName"]; ok {
123 query.Where(fmt.Sprintf(`company_info @>'{"companyName":"%v"}'`, v)) 123 query.Where(fmt.Sprintf(`company_info @>'{"companyName":"%v"}'`, v))
124 } 124 }
  125 + if v, ok := queryOptions["statusNotIn"]; ok {
  126 + query.Where("status not in (?)", pg.In(v))
  127 + }
125 if err := query.First(); err != nil { 128 if err := query.First(); err != nil {
126 if err.Error() == "pg: no rows in result set" { 129 if err.Error() == "pg: no rows in result set" {
127 return nil, domain.ErrorNotFound 130 return nil, domain.ErrorNotFound