作者 陈志颖

fix:修改注册方法

@@ -404,10 +404,10 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom @@ -404,10 +404,10 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
404 return 404 return
405 } 405 }
406 406
407 - if len(loginSvr.PartnerInfo) == 0 {  
408 - err = protocol.NewErrWithMessage(10008)  
409 - return  
410 - } 407 + //if len(loginSvr.PartnerInfo) == 0 {
  408 + // err = protocol.NewErrWithMessage(10008)
  409 + // return
  410 + //}
411 411
412 switch request.GrantType { 412 switch request.GrantType {
413 case protocol.LoginByPassword: 413 case protocol.LoginByPassword:
@@ -529,7 +529,7 @@ func CompaniesLoginByCredential(header *protocol.RequestHeader, request *protoco @@ -529,7 +529,7 @@ func CompaniesLoginByCredential(header *protocol.RequestHeader, request *protoco
529 _ = loginSvr.InitPartner(claim.Phone) 529 _ = loginSvr.InitPartner(claim.Phone)
530 530
531 if len(loginSvr.PartnerInfo) == 0 && len(loginSvr.Users) == 0 { 531 if len(loginSvr.PartnerInfo) == 0 && len(loginSvr.Users) == 0 {
532 - err = protocol.NewErrWithMessage(10006) 532 + err = protocol.NewErrWithMessage(4104)
533 return 533 return
534 } 534 }
535 535
@@ -545,7 +545,13 @@ func CompaniesLoginByCredential(header *protocol.RequestHeader, request *protoco @@ -545,7 +545,13 @@ func CompaniesLoginByCredential(header *protocol.RequestHeader, request *protoco
545 return 545 return
546 } 546 }
547 547
548 -// 登录 548 +/**
  549 + * @Author SteveChan
  550 + * @Description //TODO 登录
  551 + * @Date 15:05 2021/1/15
  552 + * @Param
  553 + * @return
  554 + **/
549 func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) (rsp *protocol.LoginResponse, err error) { 555 func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) (rsp *protocol.LoginResponse, err error) {
550 var ( 556 var (
551 claim *utils.UserTokenClaims 557 claim *utils.UserTokenClaims
@@ -613,7 +619,7 @@ func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) ( @@ -613,7 +619,7 @@ func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) (
613 // 用户信息检索 619 // 用户信息检索
614 if p, e := UsersRepository.FindOne(map[string]interface{}{"phone": claim.Phone, "companyId": request.Cid, "deleteAtIsNull": true}); e == nil { 620 if p, e := UsersRepository.FindOne(map[string]interface{}{"phone": claim.Phone, "companyId": request.Cid, "deleteAtIsNull": true}); e == nil {
615 userId = p.Id 621 userId = p.Id
616 - if !p.IsEnable() { 622 + if !p.IsEnable() || !p.IsUserSenior() {
617 err = protocol.NewErrWithMessage(10006, err) //当前账号已被禁用 623 err = protocol.NewErrWithMessage(10006, err) //当前账号已被禁用
618 return 624 return
619 } 625 }
@@ -73,6 +73,11 @@ func (m *Users) IsEnable() bool { @@ -73,6 +73,11 @@ func (m *Users) IsEnable() bool {
73 return m.Status == 1 73 return m.Status == 1
74 } 74 }
75 75
  76 +// 账号是否是高管
  77 +func (m *Users) IsUserSenior() bool {
  78 + return m.IsSenior == 1
  79 +}
  80 +
76 func (m *Users) Identify() interface{} { 81 func (m *Users) Identify() interface{} {
77 if m.Id == 0 { 82 if m.Id == 0 {
78 return nil 83 return nil
@@ -412,56 +412,108 @@ func computeBonusPercent(totalBonus float64, bonus float64) float64 { @@ -412,56 +412,108 @@ func computeBonusPercent(totalBonus float64, bonus float64) float64 {
412 **/ 412 **/
413 func (svr *PgLoginService) RegistryUser(phone string) error { 413 func (svr *PgLoginService) RegistryUser(phone string) error {
414 var ( 414 var (
415 - PartnerInfoService, _ = repository.NewPartnerInfoRepository(svr.transactionContext)  
416 - UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext) 415 + PartnerInfoService, _ = repository.NewPartnerInfoRepository(svr.transactionContext)
  416 + UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext)
  417 + isPartner bool
  418 + isPartnerAvailable bool
  419 + isGuestPartner bool
  420 + isGuestPartnerAvailable bool
  421 + isUser bool
  422 + isUserAvailable bool
  423 + isUserSenior bool
417 ) 424 )
418 425
419 - partnerInfo, errPartner := PartnerInfoService.FindOne(map[string]interface{}{"account": phone, "isNot": constant.DEFAULT_GUEST_COMPANY}) // 合伙人是否存在  
420 - guestInfo, _ := PartnerInfoService.FindOne(map[string]interface{}{"account": phone, "companyId": constant.DEFAULT_GUEST_COMPANY}) // 合伙人是否存在游客公司  
421 - user, errUser := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "deleteAtIsNull": true}) // 用户是否存在  
422 - senior, errSenior := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "isSenior": 2, "deleteAtIsNull": true}) // 用户是否是高管 426 + partnerInfo, _ := PartnerInfoService.FindOne(map[string]interface{}{"account": phone, "isNot": constant.DEFAULT_GUEST_COMPANY}) // 合伙人在正常公司是否存在
  427 + if partnerInfo == nil {
  428 + isPartner = false
  429 + } else {
  430 + isPartner = true
  431 + }
  432 + partnerAvailableInfo, errPartner := PartnerInfoService.FindOne(map[string]interface{}{"account": phone, "status": 1, "isNot": constant.DEFAULT_GUEST_COMPANY}) // 合伙人在正常公司是否有效
  433 + if partnerAvailableInfo == nil {
  434 + isPartnerAvailable = false
  435 + } else {
  436 + isPartnerAvailable = true
  437 + }
423 438
424 - fmt.Print("存在合伙人身份:", partnerInfo != nil, "\n")  
425 - fmt.Print("用户存在:", user != nil, "\n")  
426 - fmt.Print("高管:", senior != nil, "\n") 439 + guestInfo, _ := PartnerInfoService.FindOne(map[string]interface{}{"account": phone, "companyId": constant.DEFAULT_GUEST_COMPANY}) // 合伙人是否存在游客公司
  440 + if guestInfo == nil {
  441 + isGuestPartner = false
  442 + } else {
  443 + isGuestPartner = true
  444 + }
  445 + guestAvailableInfo, _ := PartnerInfoService.FindOne(map[string]interface{}{"account": phone, "status": 1, "companyId": constant.DEFAULT_GUEST_COMPANY}) // 合伙人在游客公司是否有效
  446 + if guestAvailableInfo == nil {
  447 + isGuestPartnerAvailable = false
  448 + } else {
  449 + isGuestPartnerAvailable = true
  450 + }
427 451
428 - // 游客公司合伙人存在,更新合伙人  
429 - //if guestInfo != nil {  
430 - // _, err := svr.transactionContext.PgTx.Model(&models.PartnerInfo{  
431 - // CompanyId: int64(constant.DEFAULT_GUEST_COMPANY),  
432 - // PartnerName: phone,  
433 - // Account: phone,  
434 - // Password: "7c4a8d09ca3762af61e59520943dc26494f8941b",  
435 - // PartnerCategory: 1,  
436 - // RegionInfo: &domain.RegionInfo{  
437 - // RegionName: "客户区域",  
438 - // RegionId: 0,  
439 - // },  
440 - // Status: guestInfo.Status,  
441 - // CooperateTime: time.Now(),  
442 - // CreateAt: time.Now(),  
443 - // UpdateAt: time.Now(),  
444 - // PartnerCategoryInfos: []*models.PartnerCategoryInfo{&models.PartnerCategoryInfo{Id: 1, Code: phone}},  
445 - // Salesman: []*domain.Salesman{&domain.Salesman{Name: phone, Telephone: phone}}}).  
446 - // Where("partner_info.account = ?", phone).  
447 - // Where("partner_info.company_id = ?", constant.DEFAULT_GUEST_COMPANY).  
448 - // Update()  
449 - // if err != nil {  
450 - // return err  
451 - // }  
452 - //} 452 + user, _ := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "deleteAtIsNull": true}) // 用户是否存在
  453 + if user == nil {
  454 + isUser = false
  455 + } else {
  456 + isUser = true
  457 + }
  458 + userAvailable, _ := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "status": 1, "deleteAtIsNull": true}) // 用户是否有效
  459 + if userAvailable == nil {
  460 + isUserAvailable = false
  461 + } else {
  462 + isUserAvailable = true
  463 + }
  464 + senior, _ := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "status": 1, "isSenior": 1, "deleteAtIsNull": true}) // 用户是否是高管
  465 + if senior == nil {
  466 + isUserSenior = false
  467 + } else {
  468 + isUserSenior = true
  469 + }
  470 +
  471 + fmt.Print("合伙人在正常公司存在?", isPartner, "\n")
  472 + fmt.Print("合伙人在正常公司有效?", isPartnerAvailable, "\n")
  473 +
  474 + fmt.Print("合伙人在游客公司存在?", isGuestPartner, "\n")
  475 + fmt.Print("合伙人在游客公司有效?", isGuestPartnerAvailable, "\n")
  476 +
  477 + fmt.Print("用户存在?", isUser, "\n")
  478 + fmt.Print("用户有效?", isUserAvailable, "\n")
  479 + fmt.Print("用户高管?", isUserSenior, "\n")
  480 +
  481 + // 用户在正常公司存在且无效或者不存在、合伙人在正常公司存在且无效或者不存在、合伙人在游客公司存在且无效,更新游客公司合伙人状态
  482 + if (isUser && !isUserAvailable || !isUser) && (isPartner && !isPartnerAvailable || !isPartner) && (isGuestPartner && !isGuestPartnerAvailable) {
  483 + _, err := svr.transactionContext.PgTx.Model(&models.PartnerInfo{
  484 + CompanyId: int64(constant.DEFAULT_GUEST_COMPANY),
  485 + PartnerName: phone,
  486 + Account: phone,
  487 + Password: "7c4a8d09ca3762af61e59520943dc26494f8941b",
  488 + PartnerCategory: 1,
  489 + RegionInfo: &domain.RegionInfo{
  490 + RegionName: "客户区域",
  491 + RegionId: 0,
  492 + },
  493 + Status: 1,
  494 + CooperateTime: time.Now(),
  495 + CreateAt: time.Now(),
  496 + UpdateAt: time.Now(),
  497 + PartnerCategoryInfos: []*models.PartnerCategoryInfo{&models.PartnerCategoryInfo{Id: 1, Code: phone}},
  498 + Salesman: []*domain.Salesman{&domain.Salesman{Name: phone, Telephone: phone}}}).
  499 + Where("partner_info.account = ?", phone).
  500 + Where("partner_info.company_id = ?", constant.DEFAULT_GUEST_COMPANY).
  501 + Update()
  502 + if err != nil {
  503 + return err
  504 + }
  505 + }
453 506
454 // 合伙人存在、用户存在、是高管(高管合伙人) 507 // 合伙人存在、用户存在、是高管(高管合伙人)
455 // 合伙人不存在、用户存在、是高管(高管)|| partnerInfo == nil && user != nil && senior != nil 508 // 合伙人不存在、用户存在、是高管(高管)|| partnerInfo == nil && user != nil && senior != nil
456 // 合伙人存在、用户存在、非高管(合伙人) 509 // 合伙人存在、用户存在、非高管(合伙人)
457 // 游客公司合伙人存在 510 // 游客公司合伙人存在
458 - if partnerInfo != nil && user != nil && senior != nil || partnerInfo != nil && user != nil && senior == nil || guestInfo != nil {  
459 - return nil  
460 - } 511 + //if partnerInfo != nil && user != nil && senior != nil || partnerInfo != nil && user != nil && senior == nil || guestInfo != nil {
  512 + // return nil
  513 + //}
461 514
462 - // 合伙人不存在、用户存在、非高管(普通用户)-> 注册用户  
463 - // 合伙人不存在、用户不存在(游客)-> 注册用户  
464 - if errPartner != nil && errUser == nil && errSenior == nil || errPartner != nil && errUser != nil { 515 + // 用户在正常公司存在且无效或者存在非高管或者不存在、合伙人在正常公司存在且无效或者不存在、合伙人在游客公司不存在、注册合伙人到游客公司
  516 + if !isGuestPartner && (isUser && !isUserAvailable || isUser && !isUserSenior || !isUser) && (isPartner && !isPartnerAvailable || !isPartner) {
465 id := time.Now().Unix() 517 id := time.Now().Unix()
466 errPartner = svr.transactionContext.PgDd.Insert(&models.PartnerInfo{ 518 errPartner = svr.transactionContext.PgDd.Insert(&models.PartnerInfo{
467 Id: id, 519 Id: id,
@@ -483,6 +535,30 @@ func (svr *PgLoginService) RegistryUser(phone string) error { @@ -483,6 +535,30 @@ func (svr *PgLoginService) RegistryUser(phone string) error {
483 }) 535 })
484 } 536 }
485 537
  538 + // 合伙人不存在、用户存在、非高管(普通用户)-> 注册用户
  539 + // 合伙人不存在、用户不存在(游客)-> 注册用户
  540 + //if errPartner != nil && errUser == nil && errSenior == nil || errPartner != nil && errUser != nil {
  541 + // id := time.Now().Unix()
  542 + // errPartner = svr.transactionContext.PgDd.Insert(&models.PartnerInfo{
  543 + // Id: id,
  544 + // CompanyId: int64(constant.DEFAULT_GUEST_COMPANY),
  545 + // PartnerName: phone,
  546 + // Account: phone,
  547 + // Password: "7c4a8d09ca3762af61e59520943dc26494f8941b",
  548 + // Status: 1,
  549 + // PartnerCategory: 1,
  550 + // RegionInfo: &domain.RegionInfo{
  551 + // RegionName: "客户区域",
  552 + // RegionId: 0,
  553 + // },
  554 + // CooperateTime: time.Now(),
  555 + // CreateAt: time.Now(),
  556 + // UpdateAt: time.Now(),
  557 + // PartnerCategoryInfos: []*models.PartnerCategoryInfo{&models.PartnerCategoryInfo{Id: 1, Code: phone}},
  558 + // Salesman: []*domain.Salesman{&domain.Salesman{Name: phone, Telephone: phone}},
  559 + // })
  560 + //}
  561 +
486 return errPartner 562 return errPartner
487 } 563 }
488 564