...
|
...
|
@@ -2,6 +2,10 @@ package auth |
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
|
|
|
"github.com/tiptok/gocomm/xa/eda"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/userAuth"
|
...
|
...
|
@@ -14,9 +18,6 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
|
|
|
protocolx "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/auth"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
// 该方法废弃
|
...
|
...
|
@@ -345,20 +346,21 @@ func PasswordLogin(header *protocol.RequestHeader, request *protocol.LoginReques |
|
|
|
|
|
/**
|
|
|
* @Author SteveChan
|
|
|
* @Description //TODO 企业平台-多公司登录,判断是否高管
|
|
|
* @Description // 企业平台-多公司登录,判断是否高管
|
|
|
* @Date 15:01 2021/1/12
|
|
|
* @Param
|
|
|
* @return
|
|
|
**/
|
|
|
func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCompanysRequest) (v interface{}, err error) {
|
|
|
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
imInfo *domain.ImInfo
|
|
|
loginSvr = domain_service.NewPgLoginService(transactionContext)
|
|
|
isSenior bool
|
|
|
//isPartner bool
|
|
|
)
|
|
|
|
|
|
// 转换手机号码
|
|
|
phoneId, e := strconv.Atoi(request.Phone)
|
|
|
if e != nil {
|
|
|
log.Error(e)
|
...
|
...
|
@@ -367,6 +369,8 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom |
|
|
}
|
|
|
|
|
|
rsp := &protocolx.CenterCompanysResponse{}
|
|
|
|
|
|
// 启动事务
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
log.Error(err)
|
|
|
return nil, err
|
...
|
...
|
@@ -376,53 +380,27 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 通过短信验证码登录的游客,注册一个账号到配置的公司去(ios审核使用)
|
|
|
if request.GrantType == protocol.LoginBySmsCode {
|
|
|
guestLoginErr := loginSvr.RegistryGuest(request.Phone)
|
|
|
if guestLoginErr != nil {
|
|
|
log.Error(guestLoginErr)
|
|
|
// 通过短信验证码登录的游客或者普通用户,注册一个账号到配置的公司去(ios审核使用)
|
|
|
if request.GrantType == protocol.LoginBySmsCode || request.GrantType == protocol.LoginByPassword {
|
|
|
e := loginSvr.RegistryGuest(request.Phone)
|
|
|
if e != nil {
|
|
|
log.Error(e)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// loginSvr 初始化
|
|
|
_ = loginSvr.Init(request.Phone)
|
|
|
if len(loginSvr.Users) == 0 && len(loginSvr.PartnerInfo) == 0 { // 用户且合伙人不存在
|
|
|
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
|
|
|
}
|
|
|
// 高管初始化
|
|
|
_ = loginSvr.InitSenior(request.Phone)
|
|
|
if len(loginSvr.Users) == 0 {
|
|
|
isSenior = false
|
|
|
} else {
|
|
|
isSenior = true
|
|
|
}
|
|
|
|
|
|
switch request.GrantType {
|
...
|
...
|
@@ -490,17 +468,17 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom |
|
|
// 添加手机对应的凭证
|
|
|
userAuth.NewRedisUserCredential(request.Phone).AddAuth(rsp.Credentials)
|
|
|
|
|
|
//v = map[string]interface{}{"center": rsp}
|
|
|
|
|
|
// 判断是否高管
|
|
|
if !isSenior { // 用户非高管非合伙人
|
|
|
rsp.Partner.(map[string]interface{})["companys"] = rsp.Manager.(map[string]interface{})["companys"]
|
|
|
rsp.Manager.(map[string]interface{})["companys"] = []struct{}{}
|
|
|
if isSenior {
|
|
|
v = map[string]interface{}{"center": rsp}
|
|
|
} else {
|
|
|
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}
|
|
|
}
|
|
|
|
|
|
//v = map[string]interface{}{"center": rsp}
|
|
|
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
return
|
|
|
}
|
...
|
...
|
@@ -543,11 +521,7 @@ func CompaniesLoginByCredential(header *protocol.RequestHeader, request *protoco |
|
|
loginSvr.Init(claim.Phone)
|
|
|
|
|
|
// 判断是否高管
|
|
|
ok, loginErr := loginSvr.CheckIsSenior(claim.Phone, 0)
|
|
|
if loginErr != nil {
|
|
|
err = protocol.NewErrWithMessage(10001)
|
|
|
return
|
|
|
}
|
|
|
ok, _ := loginSvr.CheckIsSenior(claim.Phone, claim.CompanyId)
|
|
|
|
|
|
rsp.Partner, _ = loginSvr.PartnerStaticInfo()
|
|
|
rsp.Manager, _ = loginSvr.ManagerStaticInfo()
|
...
|
...
|
|