作者 陈志颖

fix:修改普通用户登录

@@ -358,6 +358,7 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom @@ -358,6 +358,7 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
358 imInfo *domain.ImInfo 358 imInfo *domain.ImInfo
359 loginSvr = domain_service.NewPgLoginService(transactionContext) 359 loginSvr = domain_service.NewPgLoginService(transactionContext)
360 isSenior bool 360 isSenior bool
  361 + isPartner bool
361 ) 362 )
362 363
363 // 转换手机号码 364 // 转换手机号码
@@ -381,15 +382,15 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom @@ -381,15 +382,15 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
381 }() 382 }()
382 383
383 // 通过短信验证码登录的游客,注册一个账号到配置的公司去(ios审核使用) 384 // 通过短信验证码登录的游客,注册一个账号到配置的公司去(ios审核使用)
384 - if request.GrantType == protocol.LoginBySmsCode {  
385 - guestErr := loginSvr.RegistryGuest(request.Phone)  
386 - if guestErr != nil {  
387 - log.Error(guestErr)  
388 - }  
389 - } 385 + //if request.GrantType == protocol.LoginBySmsCode {
  386 + // guestErr := loginSvr.RegistryGuest(request.Phone)
  387 + // if guestErr != nil {
  388 + // log.Error(guestErr)
  389 + // }
  390 + //}
390 391
391 - // 通过密码登录的普通用户,注册一个账号到配置的公司去  
392 - if request.GrantType == protocol.LoginByPassword { 392 + // 通过密码或校验码登录的普通用户或通过校验码登录的游客,注册一个账号到配置的公司去
  393 + if request.GrantType == protocol.LoginBySmsCode || request.GrantType == protocol.LoginByPassword {
393 userErr := loginSvr.RegistryUser(request.Phone) 394 userErr := loginSvr.RegistryUser(request.Phone)
394 if userErr != nil { 395 if userErr != nil {
395 log.Error(userErr) 396 log.Error(userErr)
@@ -403,14 +404,25 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom @@ -403,14 +404,25 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
403 return 404 return
404 } 405 }
405 406
406 - // 高管初始化 407 + // 高管标志位初始化
407 _ = loginSvr.InitSenior(request.Phone) 408 _ = loginSvr.InitSenior(request.Phone)
408 - if len(loginSvr.Users) == 0 { 409 + if len(loginSvr.IsSenior) == 0 {
409 isSenior = false 410 isSenior = false
410 } else { 411 } else {
411 isSenior = true 412 isSenior = true
412 } 413 }
413 414
  415 + // 合伙人标志位初始化
  416 + _ = loginSvr.InitPartner(request.Phone)
  417 + if len(loginSvr.IsPartnerInfo) == 0 {
  418 + isPartner = false
  419 + } else {
  420 + isPartner = true
  421 + }
  422 +
  423 + fmt.Print(isPartner, "\n")
  424 + fmt.Print(isSenior, "\n")
  425 +
414 switch request.GrantType { 426 switch request.GrantType {
415 case protocol.LoginByPassword: 427 case protocol.LoginByPassword:
416 if len(request.Password) == 0 { 428 if len(request.Password) == 0 {
@@ -422,6 +434,19 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom @@ -422,6 +434,19 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
422 err = protocol.NewCustomMessage(1, "密码输入有误!") 434 err = protocol.NewCustomMessage(1, "密码输入有误!")
423 return 435 return
424 } 436 }
  437 +
  438 + //if isPartner { // 合伙人登录
  439 + // if loginSvr.ManagerLogin(request.Phone, request.Password) != nil && loginSvr.PartnerLogin(request.Phone, request.Password) != nil {
  440 + // err = protocol.NewCustomMessage(1, "密码输入有误!")
  441 + // return
  442 + // }
  443 + //} else { // 非合伙人高管或者非合伙人非高管
  444 + // if loginSvr.ManagerLogin(request.Phone, request.Password) != nil {
  445 + // err = protocol.NewCustomMessage(1, "密码输入有错误!")
  446 + // return
  447 + // }
  448 + //}
  449 +
425 break 450 break
426 case protocol.LoginBySmsCode: 451 case protocol.LoginBySmsCode:
427 if _, err = CheckSmsCode(request.Phone, request.Captcha); err != nil { 452 if _, err = CheckSmsCode(request.Phone, request.Captcha); err != nil {
@@ -477,23 +502,32 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom @@ -477,23 +502,32 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
477 userAuth.NewRedisUserCredential(request.Phone).AddAuth(rsp.Credentials) 502 userAuth.NewRedisUserCredential(request.Phone).AddAuth(rsp.Credentials)
478 503
479 // 判断是否高管 504 // 判断是否高管
480 - if isSenior { 505 + if isSenior && isPartner { // 高管且合伙人
481 v = map[string]interface{}{"center": rsp} 506 v = map[string]interface{}{"center": rsp}
482 - } else { 507 + } else if isSenior && !isPartner { // 高管非合伙人
483 var companies []interface{} 508 var companies []interface{}
484 509
485 - if rsp.Partner.(map[string]interface{})["companys"] != nil {  
486 - for _, company := range rsp.Partner.(map[string]interface{})["companys"].([]*domain_service.Company) { 510 + if rsp.Manager.(map[string]interface{})["companys"] != nil {
  511 + for _, company := range rsp.Manager.(map[string]interface{})["companys"].([]protocol.CompanyBase) {
487 companies = append(companies, company) 512 companies = append(companies, company)
488 } 513 }
489 } else { 514 } else {
490 companies = []interface{}{} 515 companies = []interface{}{}
491 } 516 }
492 517
493 - if rsp.Manager.(map[string]interface{})["companys"] != nil {  
494 - for _, company := range rsp.Manager.(map[string]interface{})["companys"].([]struct{}) { 518 + rsp.Partner.(map[string]interface{})["companys"] = []struct{}{}
  519 + rsp.Manager.(map[string]interface{})["companys"] = companies
  520 +
  521 + v = map[string]interface{}{"center": rsp}
  522 + } else { // 非高管合伙人
  523 + var companies []interface{}
  524 +
  525 + if rsp.Partner.(map[string]interface{})["companys"] != nil {
  526 + for _, company := range rsp.Partner.(map[string]interface{})["companys"].([]*domain_service.Company) {
495 companies = append(companies, company) 527 companies = append(companies, company)
496 } 528 }
  529 + } else {
  530 + companies = []interface{}{}
497 } 531 }
498 532
499 rsp.Partner.(map[string]interface{})["companys"] = companies 533 rsp.Partner.(map[string]interface{})["companys"] = companies
@@ -519,6 +553,7 @@ func CompaniesLoginByCredential(header *protocol.RequestHeader, request *protoco @@ -519,6 +553,7 @@ func CompaniesLoginByCredential(header *protocol.RequestHeader, request *protoco
519 loginSvr = domain_service.NewPgLoginService(transactionContext) 553 loginSvr = domain_service.NewPgLoginService(transactionContext)
520 claim *utils.UserTokenClaims 554 claim *utils.UserTokenClaims
521 isSenior bool 555 isSenior bool
  556 + isPartner bool
522 ) 557 )
523 rsp = &protocolx.CompanysResponse{} 558 rsp = &protocolx.CompanysResponse{}
524 if err = transactionContext.StartTransaction(); err != nil { 559 if err = transactionContext.StartTransaction(); err != nil {
@@ -528,10 +563,12 @@ func CompaniesLoginByCredential(header *protocol.RequestHeader, request *protoco @@ -528,10 +563,12 @@ func CompaniesLoginByCredential(header *protocol.RequestHeader, request *protoco
528 defer func() { 563 defer func() {
529 transactionContext.RollbackTransaction() 564 transactionContext.RollbackTransaction()
530 }() 565 }()
  566 +
531 if claim, err = utils.ParseJWTToken(request.Credentials); err != nil { 567 if claim, err = utils.ParseJWTToken(request.Credentials); err != nil {
532 err = protocol.NewErrWithMessage(4140, err) 568 err = protocol.NewErrWithMessage(4140, err)
533 return 569 return
534 } 570 }
  571 +
535 //凭证是否存在 572 //凭证是否存在
536 if constant.DISENABLE_MULTI_DEVICE_LOGIN { 573 if constant.DISENABLE_MULTI_DEVICE_LOGIN {
537 if credential, e := userAuth.NewRedisUserCredential(claim.Phone).GetAuth(); e != nil || !strings.EqualFold(credential, request.Credentials) { 574 if credential, e := userAuth.NewRedisUserCredential(claim.Phone).GetAuth(); e != nil || !strings.EqualFold(credential, request.Credentials) {
@@ -544,27 +581,41 @@ func CompaniesLoginByCredential(header *protocol.RequestHeader, request *protoco @@ -544,27 +581,41 @@ func CompaniesLoginByCredential(header *protocol.RequestHeader, request *protoco
544 // loginSvr 初始化 581 // loginSvr 初始化
545 loginSvr.Init(claim.Phone) 582 loginSvr.Init(claim.Phone)
546 583
547 - // 高管初始化 584 + // 高管标志位初始化
548 _ = loginSvr.InitSenior(claim.Phone) 585 _ = loginSvr.InitSenior(claim.Phone)
549 - if len(loginSvr.Users) == 0 { 586 + if len(loginSvr.IsSenior) == 0 {
550 isSenior = false 587 isSenior = false
551 } else { 588 } else {
552 isSenior = true 589 isSenior = true
553 } 590 }
554 591
  592 + // 合伙人标志位初始化
  593 + _ = loginSvr.InitPartner(claim.Phone)
  594 + if len(loginSvr.IsPartnerInfo) == 0 {
  595 + isPartner = false
  596 + } else {
  597 + isPartner = true
  598 + }
  599 +
555 rsp.Partner, _ = loginSvr.PartnerStaticInfo() 600 rsp.Partner, _ = loginSvr.PartnerStaticInfo()
556 rsp.Manager, _ = loginSvr.ManagerStaticInfo() 601 rsp.Manager, _ = loginSvr.ManagerStaticInfo()
557 602
558 - if !isSenior { // 非高管普通用户 603 + if !isSenior { // 非高管普通用户, 显示游客公司
559 var companies []interface{} 604 var companies []interface{}
560 - for _, company := range rsp.Manager.(map[string]interface{})["companys"].([]struct{}) {  
561 - companies = append(companies, company)  
562 - }  
563 - for _, company := range rsp.Partner.(map[string]interface{})["companys"].([]*domain_service.Company) {  
564 - companies = append(companies, company) 605 + //for _, company := range rsp.Manager.(map[string]interface{})["companys"].([]protocol.CompanyBase) {
  606 + // companies = append(companies, company)
  607 + //}
  608 + if rsp.Partner.(map[string]interface{})["companys"] != nil {
  609 + for _, company := range rsp.Partner.(map[string]interface{})["companys"].([]*domain_service.Company) {
  610 + companies = append(companies, company)
  611 + }
  612 + } else {
  613 + companies = []interface{}{}
565 } 614 }
566 rsp.Partner.(map[string]interface{})["companys"] = companies 615 rsp.Partner.(map[string]interface{})["companys"] = companies
567 rsp.Manager.(map[string]interface{})["companys"] = []struct{}{} 616 rsp.Manager.(map[string]interface{})["companys"] = []struct{}{}
  617 + } else if isSenior && !isPartner { // 高管非合伙人,显示高管公司
  618 + rsp.Partner.(map[string]interface{})["companys"] = []struct{}{}
568 } 619 }
569 620
570 if !loginSvr.HasAvailableCompany { 621 if !loginSvr.HasAvailableCompany {
1 package domain_service 1 package domain_service
2 2
3 import ( 3 import (
  4 + "fmt"
4 "github.com/tiptok/gocomm/xa/eda" 5 "github.com/tiptok/gocomm/xa/eda"
5 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant" 6 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant"
6 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" 7 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
@@ -21,7 +22,9 @@ type PgLoginService struct { @@ -21,7 +22,9 @@ type PgLoginService struct {
21 Phone string 22 Phone string
22 eda.EventCenterPublisher 23 eda.EventCenterPublisher
23 PartnerInfo []*domain.PartnerInfo 24 PartnerInfo []*domain.PartnerInfo
  25 + IsPartnerInfo []*domain.PartnerInfo
24 Users []*domain.Users 26 Users []*domain.Users
  27 + IsSenior []*domain.Users
25 transactionContext *transaction.TransactionContext 28 transactionContext *transaction.TransactionContext
26 // 标识:登录的账号信息是否有可用的公司, true:有 false:没有 29 // 标识:登录的账号信息是否有可用的公司, true:有 false:没有
27 HasAvailableCompany bool 30 HasAvailableCompany bool
@@ -49,7 +52,19 @@ func (svr *PgLoginService) InitSenior(phone string) (err error) { @@ -49,7 +52,19 @@ func (svr *PgLoginService) InitSenior(phone string) (err error) {
49 52
50 svr.Phone = phone 53 svr.Phone = phone
51 54
52 - _, svr.Users, err = UsersRepository.Find(map[string]interface{}{"phone": phone, "status": 1, "sortByCreateTime": "ASC", "deleteAtIsNull": true, "isSenior": 1}) 55 + _, svr.IsSenior, err = UsersRepository.Find(map[string]interface{}{"phone": phone, "status": 1, "sortByCreateTime": "ASC", "deleteAtIsNull": true, "isSenior": 1})
  56 +
  57 + return nil
  58 +}
  59 +
  60 +func (svr *PgLoginService) InitPartner(phone string) (err error) {
  61 + var (
  62 + PartnerInfoService, _ = repository.NewPartnerInfoRepository(svr.transactionContext)
  63 + )
  64 +
  65 + svr.Phone = phone
  66 +
  67 + _, svr.IsPartnerInfo, err = PartnerInfoService.Find(map[string]interface{}{"account": phone, "status": 1, "sortByCreateTime": "ASC", "isNot": constant.DEFAULT_GUEST_COMPANY})
53 68
54 return nil 69 return nil
55 } 70 }
@@ -374,15 +389,24 @@ func (svr *PgLoginService) RegistryUser(phone string) error { @@ -374,15 +389,24 @@ func (svr *PgLoginService) RegistryUser(phone string) error {
374 UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext) 389 UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext)
375 ) 390 )
376 391
377 - partnerInfo, errPartner := PartnerInfoService.FindOne(map[string]interface{}{"account": phone}) // 合伙人是否存在  
378 - user, errUser := UsersRepository.FindOne(map[string]interface{}{"phone": phone}) // 用户是否存在  
379 - _, errSenior := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "isSenior": 2}) // 用户是否是高管 392 + partnerInfo, errPartner := PartnerInfoService.FindOne(map[string]interface{}{"account": phone, "isNot": constant.DEFAULT_GUEST_COMPANY}) // 合伙人是否存在
  393 + user, errUser := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "deleteAtIsNull": true}) // 用户是否存在
  394 + senior, errSenior := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "isSenior": 2, "deleteAtIsNull": true}) // 用户是否是高管
  395 +
  396 + fmt.Print(partnerInfo, "\n")
  397 + fmt.Print(user, "\n")
  398 + fmt.Print(senior, "\n")
380 399
381 - if partnerInfo != nil && user != nil { // 用户存在且合伙人存在,不注册合伙人 400 + // 合伙人存在、用户存在、是高管(高管合伙人)
  401 + // 合伙人不存在、用户存在、是高管(高管)|| partnerInfo == nil && user != nil && senior != nil
  402 + // 合伙人存在、用户存在、非高管(合伙人)
  403 + if partnerInfo != nil && user != nil && senior != nil || partnerInfo != nil && user != nil && senior == nil {
382 return nil 404 return nil
383 } 405 }
384 406
385 - if errPartner != nil && errUser == nil && errSenior == nil { // 合伙人不存在、用户存在且不是高管,注册合伙人 407 + // 合伙人不存在、用户存在、非高管(普通用户)-> 注册用户
  408 + // 合伙人不存在、用户不存在(游客)-> 注册用户
  409 + if errPartner != nil && errUser == nil && errSenior == nil || errPartner != nil && errUser != nil {
386 id := time.Now().Unix() 410 id := time.Now().Unix()
387 errPartner = svr.transactionContext.PgDd.Insert(&models.PartnerInfo{ 411 errPartner = svr.transactionContext.PgDd.Insert(&models.PartnerInfo{
388 Id: id, 412 Id: id,
@@ -415,7 +439,7 @@ func (svr *PgLoginService) RegistryGuest(phone string) error { @@ -415,7 +439,7 @@ func (svr *PgLoginService) RegistryGuest(phone string) error {
415 ) 439 )
416 440
417 partnerInfo, errPartner := PartnerInfoService.FindOne(map[string]interface{}{"account": phone}) 441 partnerInfo, errPartner := PartnerInfoService.FindOne(map[string]interface{}{"account": phone})
418 - user, errUser := UsersRepository.FindOne(map[string]interface{}{"phone": phone}) 442 + user, errUser := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "deleteAtIsNull": true})
419 443
420 if partnerInfo != nil || user != nil { 444 if partnerInfo != nil || user != nil {
421 return nil 445 return nil
@@ -57,6 +57,7 @@ func (repository *PartnerInfoRepository) FindOne(queryOptions map[string]interfa @@ -57,6 +57,7 @@ func (repository *PartnerInfoRepository) FindOne(queryOptions map[string]interfa
57 query.SetWhere("partner_info.account = ?", "account") 57 query.SetWhere("partner_info.account = ?", "account")
58 query.SetWhere("partner_info.status = ?", "status") 58 query.SetWhere("partner_info.status = ?", "status")
59 query.SetWhere("partner_info.company_id = ?", "companyId") 59 query.SetWhere("partner_info.company_id = ?", "companyId")
  60 + query.SetWhere("partner_info.company_id <> ?", "isNot")
60 //if inParterIds,ok :=queryOptions["inParterIds"];ok{ 61 //if inParterIds,ok :=queryOptions["inParterIds"];ok{
61 // query.Relation("PartnerInfo", func(q *orm.Query) (*orm.Query, error) { 62 // query.Relation("PartnerInfo", func(q *orm.Query) (*orm.Query, error) {
62 // return q.Where("id in (?)",pg.In(inParterIds.([]int64))),nil 63 // return q.Where("id in (?)",pg.In(inParterIds.([]int64))),nil
@@ -80,6 +81,7 @@ func (repository *PartnerInfoRepository) Find(queryOptions map[string]interface{ @@ -80,6 +81,7 @@ func (repository *PartnerInfoRepository) Find(queryOptions map[string]interface{
80 SetWhere("partner_info.account = ?", "account"). 81 SetWhere("partner_info.account = ?", "account").
81 SetWhere(`partner_info.status = ?`, "status"). 82 SetWhere(`partner_info.status = ?`, "status").
82 SetWhere(`partner_info.partner_category = ?`, "partnerCategory"). 83 SetWhere(`partner_info.partner_category = ?`, "partnerCategory").
  84 + SetWhere("partner_info.company_id <> ?", "isNot").
83 SetLimit(). 85 SetLimit().
84 SetOrder("partner_info.create_at", "sortByCreateTime"). 86 SetOrder("partner_info.create_at", "sortByCreateTime").
85 SetOrder("partner_info.update_at", "sortByUpdateTime") 87 SetOrder("partner_info.update_at", "sortByUpdateTime")