作者 陈志颖

fix:修复普通用户进入公司获取不到用户信息问题

# 合伙人项目
### 系统架构
### 领域驱动设计
### 核心登录流程
... ...
... ... @@ -396,22 +396,29 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
err = protocol.NewCustomMessage(1, "密码不能为空!")
return
}
// 判断是否高管
ok, loginErr := loginSvr.CheckIsSenior(request.Phone, 0)
if loginErr != nil {
err = protocol.NewErrWithMessage(10001)
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, "普通用户登录错误")
} 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
}
}
... ...
... ... @@ -196,25 +196,33 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques
UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
company *domain.Company
user *domain.Users
loginSvr = domain_service.NewPgLoginService(transactionContext)
)
if err = transactionContext.StartTransaction(); err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
rsp = &protocol.UserInfoResponse{}
rspMap := make(map[string]interface{})
// 获取合伙人信息
funcPartnerInfo := func() {
if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"id": header.UserId}); err != nil {
err = protocol.NewErrWithMessage(502, err) //账号不存在
return
}
if company, err = CompanyRepository.FindOne(map[string]interface{}{"id": header.CompanyId}); err != nil {
return
}
var miniProgram map[string]interface{}
if len(company.Applets) > 0 {
if company.Applets[0].Valid() {
miniProgram = make(map[string]interface{})
... ... @@ -228,6 +236,7 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques
miniProgram["title"] = company.Applets[0].Name
}
}
u := userx.User{
Id: partnerInfo.Id,
PartnerName: partnerInfo.PartnerName,
... ... @@ -265,18 +274,22 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques
} else {
u.CooperateCompany.Salesman = map[string]interface{}{}
}
rspMap["user"] = u
rsp = rspMap
}
// 获取管理员信息
funcManagerInfo := func() {
if user, err = UsersRepository.FindOne(map[string]interface{}{"id": header.UserId}); err != nil {
err = protocol.NewErrWithMessage(502, err) //账号不存在
return
}
if company, err = CompanyRepository.FindOne(map[string]interface{}{"id": header.CompanyId}); err != nil {
return
}
rspMap["user"] = userx.User{
Id: user.Id,
PartnerName: user.Name,
... ... @@ -288,12 +301,26 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques
MiniProgram: nil,
},
}
rsp = rspMap
}
phone := strconv.Itoa(header.SimNum)
// 判断是否高管
ok, loginErr := loginSvr.CheckIsSenior(phone, 0)
if loginErr != nil {
err = protocol.NewErrWithMessage(10001)
return
}
switch header.AdminType {
case int(protocolx.AdminTypePartner):
if ok { // 身份为高管,则默认登录合伙人
funcPartnerInfo()
} else { // 身份非高管
funcManagerInfo()
}
break
case int(protocolx.AdminTypeManager):
funcManagerInfo()
... ... @@ -302,6 +329,7 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques
funcPartnerInfo()
break
}
err = transactionContext.CommitTransaction()
return
}
... ...
... ... @@ -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": 1})
user, err := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "status": 1, "deleteAtIsNull": true})
if err != nil {
return false, err
} else {
... ...