...
|
...
|
@@ -412,56 +412,108 @@ func computeBonusPercent(totalBonus float64, bonus float64) float64 { |
|
|
**/
|
|
|
func (svr *PgLoginService) RegistryUser(phone string) error {
|
|
|
var (
|
|
|
PartnerInfoService, _ = repository.NewPartnerInfoRepository(svr.transactionContext)
|
|
|
UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext)
|
|
|
PartnerInfoService, _ = repository.NewPartnerInfoRepository(svr.transactionContext)
|
|
|
UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext)
|
|
|
isPartner bool
|
|
|
isPartnerAvailable bool
|
|
|
isGuestPartner bool
|
|
|
isGuestPartnerAvailable bool
|
|
|
isUser bool
|
|
|
isUserAvailable bool
|
|
|
isUserSenior bool
|
|
|
)
|
|
|
|
|
|
partnerInfo, errPartner := PartnerInfoService.FindOne(map[string]interface{}{"account": phone, "isNot": constant.DEFAULT_GUEST_COMPANY}) // 合伙人是否存在
|
|
|
guestInfo, _ := PartnerInfoService.FindOne(map[string]interface{}{"account": phone, "companyId": constant.DEFAULT_GUEST_COMPANY}) // 合伙人是否存在游客公司
|
|
|
user, errUser := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "deleteAtIsNull": true}) // 用户是否存在
|
|
|
senior, errSenior := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "isSenior": 2, "deleteAtIsNull": true}) // 用户是否是高管
|
|
|
partnerInfo, _ := PartnerInfoService.FindOne(map[string]interface{}{"account": phone, "isNot": constant.DEFAULT_GUEST_COMPANY}) // 合伙人在正常公司是否存在
|
|
|
if partnerInfo == nil {
|
|
|
isPartner = false
|
|
|
} else {
|
|
|
isPartner = true
|
|
|
}
|
|
|
partnerAvailableInfo, errPartner := PartnerInfoService.FindOne(map[string]interface{}{"account": phone, "status": 1, "isNot": constant.DEFAULT_GUEST_COMPANY}) // 合伙人在正常公司是否有效
|
|
|
if partnerAvailableInfo == nil {
|
|
|
isPartnerAvailable = false
|
|
|
} else {
|
|
|
isPartnerAvailable = true
|
|
|
}
|
|
|
|
|
|
fmt.Print("存在合伙人身份:", partnerInfo != nil, "\n")
|
|
|
fmt.Print("用户存在:", user != nil, "\n")
|
|
|
fmt.Print("高管:", senior != nil, "\n")
|
|
|
guestInfo, _ := PartnerInfoService.FindOne(map[string]interface{}{"account": phone, "companyId": constant.DEFAULT_GUEST_COMPANY}) // 合伙人是否存在游客公司
|
|
|
if guestInfo == nil {
|
|
|
isGuestPartner = false
|
|
|
} else {
|
|
|
isGuestPartner = true
|
|
|
}
|
|
|
guestAvailableInfo, _ := PartnerInfoService.FindOne(map[string]interface{}{"account": phone, "status": 1, "companyId": constant.DEFAULT_GUEST_COMPANY}) // 合伙人在游客公司是否有效
|
|
|
if guestAvailableInfo == nil {
|
|
|
isGuestPartnerAvailable = false
|
|
|
} else {
|
|
|
isGuestPartnerAvailable = true
|
|
|
}
|
|
|
|
|
|
// 游客公司合伙人存在,更新合伙人
|
|
|
//if guestInfo != nil {
|
|
|
// _, err := svr.transactionContext.PgTx.Model(&models.PartnerInfo{
|
|
|
// CompanyId: int64(constant.DEFAULT_GUEST_COMPANY),
|
|
|
// PartnerName: phone,
|
|
|
// Account: phone,
|
|
|
// Password: "7c4a8d09ca3762af61e59520943dc26494f8941b",
|
|
|
// PartnerCategory: 1,
|
|
|
// RegionInfo: &domain.RegionInfo{
|
|
|
// RegionName: "客户区域",
|
|
|
// RegionId: 0,
|
|
|
// },
|
|
|
// Status: guestInfo.Status,
|
|
|
// CooperateTime: time.Now(),
|
|
|
// CreateAt: time.Now(),
|
|
|
// UpdateAt: time.Now(),
|
|
|
// PartnerCategoryInfos: []*models.PartnerCategoryInfo{&models.PartnerCategoryInfo{Id: 1, Code: phone}},
|
|
|
// Salesman: []*domain.Salesman{&domain.Salesman{Name: phone, Telephone: phone}}}).
|
|
|
// Where("partner_info.account = ?", phone).
|
|
|
// Where("partner_info.company_id = ?", constant.DEFAULT_GUEST_COMPANY).
|
|
|
// Update()
|
|
|
// if err != nil {
|
|
|
// return err
|
|
|
// }
|
|
|
//}
|
|
|
user, _ := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "deleteAtIsNull": true}) // 用户是否存在
|
|
|
if user == nil {
|
|
|
isUser = false
|
|
|
} else {
|
|
|
isUser = true
|
|
|
}
|
|
|
userAvailable, _ := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "status": 1, "deleteAtIsNull": true}) // 用户是否有效
|
|
|
if userAvailable == nil {
|
|
|
isUserAvailable = false
|
|
|
} else {
|
|
|
isUserAvailable = true
|
|
|
}
|
|
|
senior, _ := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "status": 1, "isSenior": 1, "deleteAtIsNull": true}) // 用户是否是高管
|
|
|
if senior == nil {
|
|
|
isUserSenior = false
|
|
|
} else {
|
|
|
isUserSenior = true
|
|
|
}
|
|
|
|
|
|
fmt.Print("合伙人在正常公司存在?", isPartner, "\n")
|
|
|
fmt.Print("合伙人在正常公司有效?", isPartnerAvailable, "\n")
|
|
|
|
|
|
fmt.Print("合伙人在游客公司存在?", isGuestPartner, "\n")
|
|
|
fmt.Print("合伙人在游客公司有效?", isGuestPartnerAvailable, "\n")
|
|
|
|
|
|
fmt.Print("用户存在?", isUser, "\n")
|
|
|
fmt.Print("用户有效?", isUserAvailable, "\n")
|
|
|
fmt.Print("用户高管?", isUserSenior, "\n")
|
|
|
|
|
|
// 用户在正常公司存在且无效或者不存在、合伙人在正常公司存在且无效或者不存在、合伙人在游客公司存在且无效,更新游客公司合伙人状态
|
|
|
if (isUser && !isUserAvailable || !isUser) && (isPartner && !isPartnerAvailable || !isPartner) && (isGuestPartner && !isGuestPartnerAvailable) {
|
|
|
_, err := svr.transactionContext.PgTx.Model(&models.PartnerInfo{
|
|
|
CompanyId: int64(constant.DEFAULT_GUEST_COMPANY),
|
|
|
PartnerName: phone,
|
|
|
Account: phone,
|
|
|
Password: "7c4a8d09ca3762af61e59520943dc26494f8941b",
|
|
|
PartnerCategory: 1,
|
|
|
RegionInfo: &domain.RegionInfo{
|
|
|
RegionName: "客户区域",
|
|
|
RegionId: 0,
|
|
|
},
|
|
|
Status: 1,
|
|
|
CooperateTime: time.Now(),
|
|
|
CreateAt: time.Now(),
|
|
|
UpdateAt: time.Now(),
|
|
|
PartnerCategoryInfos: []*models.PartnerCategoryInfo{&models.PartnerCategoryInfo{Id: 1, Code: phone}},
|
|
|
Salesman: []*domain.Salesman{&domain.Salesman{Name: phone, Telephone: phone}}}).
|
|
|
Where("partner_info.account = ?", phone).
|
|
|
Where("partner_info.company_id = ?", constant.DEFAULT_GUEST_COMPANY).
|
|
|
Update()
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 合伙人存在、用户存在、是高管(高管合伙人)
|
|
|
// 合伙人不存在、用户存在、是高管(高管)|| partnerInfo == nil && user != nil && senior != nil
|
|
|
// 合伙人存在、用户存在、非高管(合伙人)
|
|
|
// 游客公司合伙人存在
|
|
|
if partnerInfo != nil && user != nil && senior != nil || partnerInfo != nil && user != nil && senior == nil || guestInfo != nil {
|
|
|
return nil
|
|
|
}
|
|
|
//if partnerInfo != nil && user != nil && senior != nil || partnerInfo != nil && user != nil && senior == nil || guestInfo != nil {
|
|
|
// return nil
|
|
|
//}
|
|
|
|
|
|
// 合伙人不存在、用户存在、非高管(普通用户)-> 注册用户
|
|
|
// 合伙人不存在、用户不存在(游客)-> 注册用户
|
|
|
if errPartner != nil && errUser == nil && errSenior == nil || errPartner != nil && errUser != nil {
|
|
|
// 用户在正常公司存在且无效或者存在非高管或者不存在、合伙人在正常公司存在且无效或者不存在、合伙人在游客公司不存在、注册合伙人到游客公司
|
|
|
if !isGuestPartner && (isUser && !isUserAvailable || isUser && !isUserSenior || !isUser) && (isPartner && !isPartnerAvailable || !isPartner) {
|
|
|
id := time.Now().Unix()
|
|
|
errPartner = svr.transactionContext.PgDd.Insert(&models.PartnerInfo{
|
|
|
Id: id,
|
...
|
...
|
@@ -483,6 +535,30 @@ func (svr *PgLoginService) RegistryUser(phone string) error { |
|
|
})
|
|
|
}
|
|
|
|
|
|
// 合伙人不存在、用户存在、非高管(普通用户)-> 注册用户
|
|
|
// 合伙人不存在、用户不存在(游客)-> 注册用户
|
|
|
//if errPartner != nil && errUser == nil && errSenior == nil || errPartner != nil && errUser != nil {
|
|
|
// id := time.Now().Unix()
|
|
|
// errPartner = svr.transactionContext.PgDd.Insert(&models.PartnerInfo{
|
|
|
// Id: id,
|
|
|
// CompanyId: int64(constant.DEFAULT_GUEST_COMPANY),
|
|
|
// PartnerName: phone,
|
|
|
// Account: phone,
|
|
|
// Password: "7c4a8d09ca3762af61e59520943dc26494f8941b",
|
|
|
// Status: 1,
|
|
|
// PartnerCategory: 1,
|
|
|
// RegionInfo: &domain.RegionInfo{
|
|
|
// RegionName: "客户区域",
|
|
|
// RegionId: 0,
|
|
|
// },
|
|
|
// CooperateTime: time.Now(),
|
|
|
// CreateAt: time.Now(),
|
|
|
// UpdateAt: time.Now(),
|
|
|
// PartnerCategoryInfos: []*models.PartnerCategoryInfo{&models.PartnerCategoryInfo{Id: 1, Code: phone}},
|
|
|
// Salesman: []*domain.Salesman{&domain.Salesman{Name: phone, Telephone: phone}},
|
|
|
// })
|
|
|
//}
|
|
|
|
|
|
return errPartner
|
|
|
}
|
|
|
|
...
|
...
|
|