作者 陈志颖

合并分支 'dev' 到 'test'

fix:测试高管权限



查看合并请求 !24
... ... @@ -356,6 +356,7 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
imInfo *domain.ImInfo
loginSvr = domain_service.NewPgLoginService(transactionContext)
isSenior bool
//isPartner bool
)
phoneId, e := strconv.Atoi(request.Phone)
... ... @@ -384,10 +385,44 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
}
// loginSvr 初始化
loginSvr.Init(request.Phone)
if len(loginSvr.Users) == 0 && len(loginSvr.PartnerInfo) == 0 {
_ = loginSvr.Init(request.Phone)
if len(loginSvr.Users) == 0 && len(loginSvr.PartnerInfo) == 0 { // 用户且合伙人不存在
err = protocol.NewErrWithMessage(10001)
return
} else if len(loginSvr.Users) > 0 && len(loginSvr.PartnerInfo) == 0 { // 用户存在,合伙人不存在
// 注册合伙人到非高管公司
userLoginErr := loginSvr.RegistryPartner(request.Phone, loginSvr.Users)
if userLoginErr != nil {
log.Error(userLoginErr)
}
cnt := 0
for _, user := range loginSvr.Users {
if user.IsSenior == 2 {
cnt++
}
}
if cnt == len(loginSvr.Users) {
isSenior = false
} else {
isSenior = true
}
} else if len(loginSvr.Users) > 0 && len(loginSvr.PartnerInfo) > 0 {
cnt := 0
for _, user := range loginSvr.Users {
if user.IsSenior == 2 {
cnt++
}
}
if cnt == len(loginSvr.Users) {
isSenior = false
} else {
isSenior = true
}
}
switch request.GrantType {
... ... @@ -397,31 +432,10 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
return
}
// 判断是否高管
ok, loginErr := loginSvr.CheckIsSenior(request.Phone, 0)
if loginErr != nil {
err = protocol.NewErrWithMessage(10001)
if loginSvr.ManagerLogin(request.Phone, request.Password) != nil && loginSvr.PartnerLogin(request.Phone, request.Password) != nil {
err = protocol.NewCustomMessage(1, "密码输入有误!")
return
}
isSenior = ok
if ok { // 高管
if loginSvr.ManagerLogin(request.Phone, request.Password) != nil && loginSvr.PartnerLogin(request.Phone, request.Password) != nil {
err = protocol.NewCustomMessage(1, "密码输入有误!")
return
}
} else { // 普通用户登录
//guestErr := loginSvr.RegistryGuest(request.Phone)
//if guestErr != nil {
// err = protocol.NewCustomMessage(1, "普通用户登录错误")
// return
//}
if loginSvr.ManagerLogin(request.Phone, request.Password) != nil {
err = protocol.NewCustomMessage(1, "密码输入有误!")
return
}
}
break
case protocol.LoginBySmsCode:
if _, err = CheckSmsCode(request.Phone, request.Captcha); err != nil {
... ... @@ -449,6 +463,7 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
// 获取统计信息(合伙人/高管)
rsp.Partner, _ = loginSvr.PartnerStaticInfo()
rsp.Manager, _ = loginSvr.ManagerStaticInfo()
if !loginSvr.HasAvailableCompany {
err = protocol.NewErrWithMessage(10008) //账号禁用
return
... ... @@ -476,21 +491,23 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
userAuth.NewRedisUserCredential(request.Phone).AddAuth(rsp.Credentials)
// 判断是否高管
if isSenior {
v = map[string]interface{}{"center": rsp}
} else {
if !isSenior { // 用户非高管非合伙人
rsp.Partner.(map[string]interface{})["companys"] = rsp.Manager.(map[string]interface{})["companys"]
rsp.Manager.(map[string]interface{})["companys"] = []struct{}{}
v = map[string]interface{}{"center": rsp}
} else {
v = map[string]interface{}{"center": rsp}
}
//v = map[string]interface{}{"center": rsp}
err = transactionContext.CommitTransaction()
return
}
/**
* @Author SteveChan
* @Description //TODO 企业平台-多公司登录 - 通过凭证,判断是否高管
* @Description // 企业平台-多公司登录 - 通过凭证,判断是否高管
* @Date 15:00 2021/1/12
* @Param
* @return
... ...
... ... @@ -196,7 +196,7 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques
UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
company *domain.Company
user *domain.Users
loginSvr = domain_service.NewPgLoginService(transactionContext)
//loginSvr = domain_service.NewPgLoginService(transactionContext)
)
if err = transactionContext.StartTransaction(); err != nil {
... ... @@ -305,22 +305,13 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques
rsp = rspMap
}
phone := strconv.Itoa(header.SimNum)
// 判断是否高管
ok, loginErr := loginSvr.CheckIsSenior(phone, 0)
if loginErr != nil {
err = protocol.NewErrWithMessage(10001)
return
}
//判断是否高管
//phone := strconv.Itoa(header.SimNum)
//ok, _ := loginSvr.CheckIsSenior(phone, header.CompanyId)
switch header.AdminType {
case int(protocolx.AdminTypePartner):
if ok { // 身份为高管,则默认登录合伙人
funcPartnerInfo()
} else { // 身份非高管
funcManagerInfo()
}
funcPartnerInfo()
break
case int(protocolx.AdminTypeManager):
funcManagerInfo()
... ...
... ... @@ -50,7 +50,7 @@ func (svr *PgLoginService) CheckIsSenior(phone string, companyId int64) (ok bool
UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext)
)
svr.Phone = phone
user, err := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "status": 1, "deleteAtIsNull": true})
user, err := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "status": 1, "companyId": companyId, "deleteAtIsNull": true})
if err != nil {
return false, err
} else {
... ... @@ -63,6 +63,31 @@ func (svr *PgLoginService) CheckIsSenior(phone string, companyId int64) (ok bool
return ok, nil
}
/**
* @Author SteveChan
* @Description // 判断是否合伙人
* @Date 13:25 2021/1/13
* @Param
* @return
**/
func (svr *PgLoginService) CheckIsPartner(phone string, companyId int64) (ok bool, err error) {
var (
PartnerInfoRepository, _ = repository.NewPartnerInfoRepository(svr.transactionContext)
)
svr.Phone = phone
user, err := PartnerInfoRepository.FindOne(map[string]interface{}{"account": phone, "status": 1})
if err != nil {
return false, err
}
if user != nil {
ok = true
} else {
ok = false
}
return ok, nil
}
//合伙人登录
func (svr *PgLoginService) PartnerLogin(phone string, password string) (err error) {
if len(svr.PartnerInfo) == 0 {
... ... @@ -311,6 +336,57 @@ func computeBonusPercent(totalBonus float64, bonus float64) float64 {
return utils.Decimal(bonus / totalBonus)
}
/**
* @Author SteveChan
* @Description //TODO 注册用户到合伙人
* @Date 13:52 2021/1/13
* @Param
* @return
**/
func (svr *PgLoginService) RegistryPartner(phone string, users []*domain.Users) error {
var (
PartnerInfoService, _ = repository.NewPartnerInfoRepository(svr.transactionContext)
//UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext)
)
partnerInfo, errPartner := PartnerInfoService.FindOne(map[string]interface{}{"account": phone})
//user, errUser := UsersRepository.FindOne(map[string]interface{}{"phone": phone})
if partnerInfo != nil {
return nil
}
for _, user := range users {
if user.IsSenior == 2 { // 插入合伙人到非高管公司
if errPartner != nil {
id := time.Now().Unix()
errPartner = svr.transactionContext.PgDd.Insert(&models.PartnerInfo{
Id: id,
CompanyId: user.CompanyId,
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}},
Salesman: []*domain.Salesman{&domain.Salesman{Name: phone, Telephone: phone}},
})
}
}
}
return errPartner
}
// 注册游客到指定的公司
func (svr *PgLoginService) RegistryGuest(phone string) error {
var (
PartnerInfoService, _ = repository.NewPartnerInfoRepository(svr.transactionContext)
... ...