|
@@ -414,54 +414,106 @@ func (svr *PgLoginService) RegistryUser(phone string) error { |
|
@@ -414,54 +414,106 @@ func (svr *PgLoginService) RegistryUser(phone string) error { |
414
|
var (
|
414
|
var (
|
415
|
PartnerInfoService, _ = repository.NewPartnerInfoRepository(svr.transactionContext)
|
415
|
PartnerInfoService, _ = repository.NewPartnerInfoRepository(svr.transactionContext)
|
416
|
UsersRepository, _ = repository.NewUsersRepository(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}) // 合伙人是否存在
|
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
|
+ }
|
|
|
438
|
+
|
420
|
guestInfo, _ := PartnerInfoService.FindOne(map[string]interface{}{"account": phone, "companyId": constant.DEFAULT_GUEST_COMPANY}) // 合伙人是否存在游客公司
|
439
|
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}) // 用户是否是高管
|
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
|
+ }
|
423
|
|
451
|
|
424
|
- fmt.Print("存在合伙人身份:", partnerInfo != nil, "\n")
|
|
|
425
|
- fmt.Print("用户存在:", user != nil, "\n")
|
|
|
426
|
- fmt.Print("高管:", senior != nil, "\n")
|
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
|
+ }
|
427
|
|
470
|
|
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
|
- //}
|
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
|
|