作者 陈志颖

合并分支 'dev' 到 'test'

Dev



查看合并请求 !25
... ... @@ -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()
... ...
... ... @@ -32,9 +32,24 @@ func (svr *PgLoginService) Init(phone string) (err error) {
PartnerInfoService, _ = repository.NewPartnerInfoRepository(svr.transactionContext)
UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext)
)
svr.Phone = phone
_, svr.PartnerInfo, err = PartnerInfoService.Find(map[string]interface{}{"account": phone, "status": 1, "sortByCreateTime": "ASC"})
_, svr.Users, err = UsersRepository.Find(map[string]interface{}{"phone": phone, "status": 1, "sortByCreateTime": "ASC", "deleteAtIsNull": true})
return nil
}
func (svr *PgLoginService) InitSenior(phone string) (err error) {
var (
UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext)
)
svr.Phone = phone
_, svr.Users, err = UsersRepository.Find(map[string]interface{}{"phone": phone, "status": 1, "sortByCreateTime": "ASC", "deleteAtIsNull": true, "isSenior": 1})
return nil
}
... ... @@ -123,10 +138,12 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) {
response := make(map[string]interface{})
response["id"] = protocolx.AdminTypePartner
response["name"] = protocolx.AdminTypePartnerName
if len(svr.PartnerInfo) == 0 {
response["companys"] = make([]struct{}, 0)
return response, nil
}
var (
OrderDao, _ = dao.NewOrderBaseDao(svr.transactionContext)
BusinessBonusDao, _ = dao.NewBusinessBonusDao(svr.transactionContext)
... ... @@ -137,6 +154,7 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) {
UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext)
adminApiGateway = http_gateway.NewHttplibBusinessAdminApiServiceGateway()
)
doGetCompanyIds := func() []int64 {
var companies []int64
for i := range svr.PartnerInfo {
... ... @@ -144,6 +162,7 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) {
}
return companies
}
doGetPartnerIds := func() []int64 {
var array []int64
for i := range svr.PartnerInfo {
... ... @@ -151,17 +170,21 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) {
}
return array
}
companyList = svr.GetCompanyList(doGetCompanyIds)
if len(companyList) == 0 {
return response, nil
}
totalBonus, e := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{InPartnerIds: doGetPartnerIds(), OrderTypes: domain.UserOrderTypes(domain.Career)})
if e != nil {
return response, e
}
if businessBonus, e := BusinessBonusDao.OrderBonusStatics(domain.OrderBonusQuery{InPartnerIds: doGetPartnerIds(), IsDisable: 1}); e == nil {
totalBonus.Bonus += businessBonus.Bonus
}
_, allPartnerCategory, e = PartnerCategoryInfoRepository.Find(map[string]interface{}{"sortById": domain.ASC})
var mapPartnerBussinessBonus = make(map[int64]*domain.BusinessBonus)
if _, bussinessBonus, e := BusinessBonusRepository.Find(map[string]interface{}{"inPartnerIds": doGetPartnerIds(), "isDisable": 1}); e == nil {
... ... @@ -224,6 +247,7 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) {
return response, nil
}
// 高管统计信息
func (svr *PgLoginService) ManagerStaticInfo() (interface{}, error) {
response := make(map[string]interface{})
response["id"] = protocolx.AdminTypeManager
... ... @@ -392,11 +416,14 @@ func (svr *PgLoginService) RegistryGuest(phone string) error {
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 || user != nil {
return nil
}
if errUser != nil && errPartner != nil {
id := time.Now().Unix()
errPartner = svr.transactionContext.PgDd.Insert(&models.PartnerInfo{
... ...
... ... @@ -74,6 +74,7 @@ func (repository *UsersRepository) Find(queryOptions map[string]interface{}) (in
SetWhere("company_id = ?", "companyId").
SetWhere(`status = ?`, "status").
SetWhere(`delete_at is null`, "deleteAtIsNull").
SetWhere("is_senior = ?", "isSenior").
SetOrder("create_at", "sortByCreateTime").
SetOrder("update_at", "sortByUpdateTime")
... ...