作者 陈志颖

fix:修改普通用户登录

... ... @@ -358,6 +358,7 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
imInfo *domain.ImInfo
loginSvr = domain_service.NewPgLoginService(transactionContext)
isSenior bool
isPartner bool
)
// 转换手机号码
... ... @@ -381,15 +382,15 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
}()
// 通过短信验证码登录的游客,注册一个账号到配置的公司去(ios审核使用)
if request.GrantType == protocol.LoginBySmsCode {
guestErr := loginSvr.RegistryGuest(request.Phone)
if guestErr != nil {
log.Error(guestErr)
}
}
//if request.GrantType == protocol.LoginBySmsCode {
// guestErr := loginSvr.RegistryGuest(request.Phone)
// if guestErr != nil {
// log.Error(guestErr)
// }
//}
// 通过密码登录的普通用户,注册一个账号到配置的公司去
if request.GrantType == protocol.LoginByPassword {
// 通过密码或校验码登录的普通用户或通过校验码登录的游客,注册一个账号到配置的公司去
if request.GrantType == protocol.LoginBySmsCode || request.GrantType == protocol.LoginByPassword {
userErr := loginSvr.RegistryUser(request.Phone)
if userErr != nil {
log.Error(userErr)
... ... @@ -403,14 +404,25 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
return
}
// 高管初始化
// 高管标志位初始化
_ = loginSvr.InitSenior(request.Phone)
if len(loginSvr.Users) == 0 {
if len(loginSvr.IsSenior) == 0 {
isSenior = false
} else {
isSenior = true
}
// 合伙人标志位初始化
_ = loginSvr.InitPartner(request.Phone)
if len(loginSvr.IsPartnerInfo) == 0 {
isPartner = false
} else {
isPartner = true
}
fmt.Print(isPartner, "\n")
fmt.Print(isSenior, "\n")
switch request.GrantType {
case protocol.LoginByPassword:
if len(request.Password) == 0 {
... ... @@ -422,6 +434,19 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
err = protocol.NewCustomMessage(1, "密码输入有误!")
return
}
//if isPartner { // 合伙人登录
// if loginSvr.ManagerLogin(request.Phone, request.Password) != nil && loginSvr.PartnerLogin(request.Phone, request.Password) != nil {
// err = protocol.NewCustomMessage(1, "密码输入有误!")
// return
// }
//} else { // 非合伙人高管或者非合伙人非高管
// 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 {
... ... @@ -477,23 +502,32 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
userAuth.NewRedisUserCredential(request.Phone).AddAuth(rsp.Credentials)
// 判断是否高管
if isSenior {
if isSenior && isPartner { // 高管且合伙人
v = map[string]interface{}{"center": rsp}
} else {
} else if isSenior && !isPartner { // 高管非合伙人
var companies []interface{}
if rsp.Partner.(map[string]interface{})["companys"] != nil {
for _, company := range rsp.Partner.(map[string]interface{})["companys"].([]*domain_service.Company) {
if rsp.Manager.(map[string]interface{})["companys"] != nil {
for _, company := range rsp.Manager.(map[string]interface{})["companys"].([]protocol.CompanyBase) {
companies = append(companies, company)
}
} else {
companies = []interface{}{}
}
if rsp.Manager.(map[string]interface{})["companys"] != nil {
for _, company := range rsp.Manager.(map[string]interface{})["companys"].([]struct{}) {
rsp.Partner.(map[string]interface{})["companys"] = []struct{}{}
rsp.Manager.(map[string]interface{})["companys"] = companies
v = map[string]interface{}{"center": rsp}
} else { // 非高管合伙人
var companies []interface{}
if rsp.Partner.(map[string]interface{})["companys"] != nil {
for _, company := range rsp.Partner.(map[string]interface{})["companys"].([]*domain_service.Company) {
companies = append(companies, company)
}
} else {
companies = []interface{}{}
}
rsp.Partner.(map[string]interface{})["companys"] = companies
... ... @@ -519,6 +553,7 @@ func CompaniesLoginByCredential(header *protocol.RequestHeader, request *protoco
loginSvr = domain_service.NewPgLoginService(transactionContext)
claim *utils.UserTokenClaims
isSenior bool
isPartner bool
)
rsp = &protocolx.CompanysResponse{}
if err = transactionContext.StartTransaction(); err != nil {
... ... @@ -528,10 +563,12 @@ func CompaniesLoginByCredential(header *protocol.RequestHeader, request *protoco
defer func() {
transactionContext.RollbackTransaction()
}()
if claim, err = utils.ParseJWTToken(request.Credentials); err != nil {
err = protocol.NewErrWithMessage(4140, err)
return
}
//凭证是否存在
if constant.DISENABLE_MULTI_DEVICE_LOGIN {
if credential, e := userAuth.NewRedisUserCredential(claim.Phone).GetAuth(); e != nil || !strings.EqualFold(credential, request.Credentials) {
... ... @@ -544,27 +581,41 @@ func CompaniesLoginByCredential(header *protocol.RequestHeader, request *protoco
// loginSvr 初始化
loginSvr.Init(claim.Phone)
// 高管初始化
// 高管标志位初始化
_ = loginSvr.InitSenior(claim.Phone)
if len(loginSvr.Users) == 0 {
if len(loginSvr.IsSenior) == 0 {
isSenior = false
} else {
isSenior = true
}
// 合伙人标志位初始化
_ = loginSvr.InitPartner(claim.Phone)
if len(loginSvr.IsPartnerInfo) == 0 {
isPartner = false
} else {
isPartner = true
}
rsp.Partner, _ = loginSvr.PartnerStaticInfo()
rsp.Manager, _ = loginSvr.ManagerStaticInfo()
if !isSenior { // 非高管普通用户
if !isSenior { // 非高管普通用户, 显示游客公司
var companies []interface{}
for _, company := range rsp.Manager.(map[string]interface{})["companys"].([]struct{}) {
companies = append(companies, company)
}
//for _, company := range rsp.Manager.(map[string]interface{})["companys"].([]protocol.CompanyBase) {
// companies = append(companies, company)
//}
if rsp.Partner.(map[string]interface{})["companys"] != nil {
for _, company := range rsp.Partner.(map[string]interface{})["companys"].([]*domain_service.Company) {
companies = append(companies, company)
}
} else {
companies = []interface{}{}
}
rsp.Partner.(map[string]interface{})["companys"] = companies
rsp.Manager.(map[string]interface{})["companys"] = []struct{}{}
} else if isSenior && !isPartner { // 高管非合伙人,显示高管公司
rsp.Partner.(map[string]interface{})["companys"] = []struct{}{}
}
if !loginSvr.HasAvailableCompany {
... ...
package domain_service
import (
"fmt"
"github.com/tiptok/gocomm/xa/eda"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
... ... @@ -21,7 +22,9 @@ type PgLoginService struct {
Phone string
eda.EventCenterPublisher
PartnerInfo []*domain.PartnerInfo
IsPartnerInfo []*domain.PartnerInfo
Users []*domain.Users
IsSenior []*domain.Users
transactionContext *transaction.TransactionContext
// 标识:登录的账号信息是否有可用的公司, true:有 false:没有
HasAvailableCompany bool
... ... @@ -49,7 +52,19 @@ func (svr *PgLoginService) InitSenior(phone string) (err error) {
svr.Phone = phone
_, svr.Users, err = UsersRepository.Find(map[string]interface{}{"phone": phone, "status": 1, "sortByCreateTime": "ASC", "deleteAtIsNull": true, "isSenior": 1})
_, svr.IsSenior, err = UsersRepository.Find(map[string]interface{}{"phone": phone, "status": 1, "sortByCreateTime": "ASC", "deleteAtIsNull": true, "isSenior": 1})
return nil
}
func (svr *PgLoginService) InitPartner(phone string) (err error) {
var (
PartnerInfoService, _ = repository.NewPartnerInfoRepository(svr.transactionContext)
)
svr.Phone = phone
_, svr.IsPartnerInfo, err = PartnerInfoService.Find(map[string]interface{}{"account": phone, "status": 1, "sortByCreateTime": "ASC", "isNot": constant.DEFAULT_GUEST_COMPANY})
return nil
}
... ... @@ -374,15 +389,24 @@ func (svr *PgLoginService) RegistryUser(phone string) error {
UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext)
)
partnerInfo, errPartner := PartnerInfoService.FindOne(map[string]interface{}{"account": phone}) // 合伙人是否存在
user, errUser := UsersRepository.FindOne(map[string]interface{}{"phone": phone}) // 用户是否存在
_, errSenior := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "isSenior": 2}) // 用户是否是高管
partnerInfo, errPartner := PartnerInfoService.FindOne(map[string]interface{}{"account": phone, "isNot": 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}) // 用户是否是高管
fmt.Print(partnerInfo, "\n")
fmt.Print(user, "\n")
fmt.Print(senior, "\n")
if partnerInfo != nil && user != nil { // 用户存在且合伙人存在,不注册合伙人
// 合伙人存在、用户存在、是高管(高管合伙人)
// 合伙人不存在、用户存在、是高管(高管)|| partnerInfo == nil && user != nil && senior != nil
// 合伙人存在、用户存在、非高管(合伙人)
if partnerInfo != nil && user != nil && senior != nil || partnerInfo != nil && user != nil && senior == nil {
return nil
}
if errPartner != nil && errUser == nil && errSenior == nil { // 合伙人不存在、用户存在且不是高管,注册合伙人
// 合伙人不存在、用户存在、非高管(普通用户)-> 注册用户
// 合伙人不存在、用户不存在(游客)-> 注册用户
if errPartner != nil && errUser == nil && errSenior == nil || errPartner != nil && errUser != nil {
id := time.Now().Unix()
errPartner = svr.transactionContext.PgDd.Insert(&models.PartnerInfo{
Id: id,
... ... @@ -415,7 +439,7 @@ func (svr *PgLoginService) RegistryGuest(phone string) error {
)
partnerInfo, errPartner := PartnerInfoService.FindOne(map[string]interface{}{"account": phone})
user, errUser := UsersRepository.FindOne(map[string]interface{}{"phone": phone})
user, errUser := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "deleteAtIsNull": true})
if partnerInfo != nil || user != nil {
return nil
... ...
... ... @@ -57,6 +57,7 @@ func (repository *PartnerInfoRepository) FindOne(queryOptions map[string]interfa
query.SetWhere("partner_info.account = ?", "account")
query.SetWhere("partner_info.status = ?", "status")
query.SetWhere("partner_info.company_id = ?", "companyId")
query.SetWhere("partner_info.company_id <> ?", "isNot")
//if inParterIds,ok :=queryOptions["inParterIds"];ok{
// query.Relation("PartnerInfo", func(q *orm.Query) (*orm.Query, error) {
// return q.Where("id in (?)",pg.In(inParterIds.([]int64))),nil
... ... @@ -80,6 +81,7 @@ func (repository *PartnerInfoRepository) Find(queryOptions map[string]interface{
SetWhere("partner_info.account = ?", "account").
SetWhere(`partner_info.status = ?`, "status").
SetWhere(`partner_info.partner_category = ?`, "partnerCategory").
SetWhere("partner_info.company_id <> ?", "isNot").
SetLimit().
SetOrder("partner_info.create_at", "sortByCreateTime").
SetOrder("partner_info.update_at", "sortByUpdateTime")
... ...