作者 陈志颖

合并分支 'dev' 到 'test'

fix:判断高管



查看合并请求 !19
appname = partner
runmode = "${RUN_MODE||dev}"
httpport = "${HTTP_PORT||8082}"
httpport = "${HTTP_PORT||8083}"
#开启监控
EnableAdmin = false
... ...
... ... @@ -8,8 +8,6 @@ import (
_ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg"
_ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/redis"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/sarama"
//"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/ginsvr"
_ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr"
)
... ... @@ -26,7 +24,7 @@ func main() {
event.InitEventCenter()
//启动kafaka消息订阅
go sarama.Run()
//go sarama.Run()
beego.Run()
}
... ...
... ... @@ -350,20 +350,24 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
imInfo *domain.ImInfo
loginSvr = domain_service.NewPgLoginService(transactionContext)
)
phoneId, e := strconv.Atoi(request.Phone)
if e != nil {
log.Error(e)
e = protocol.NewErrWithMessage(2)
return
}
rsp := &protocolx.CenterCompanysResponse{}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
// 通过短信验证码登录的游客,注册一个账号到配置的公司去(ios审核使用)
if request.GrantType == protocol.LoginBySmsCode {
e := loginSvr.RegistryGuest(request.Phone)
... ... @@ -371,22 +375,38 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
log.Error(e)
}
}
// loginSvr 初始化
loginSvr.Init(request.Phone)
if len(loginSvr.Users) == 0 && len(loginSvr.PartnerInfo) == 0 {
err = protocol.NewErrWithMessage(10001)
return
}
switch request.GrantType {
case protocol.LoginByPassword:
if len(request.Password) == 0 {
err = protocol.NewCustomMessage(1, "密码不能为空!")
return
}
if loginSvr.ManagerLogin(request.Phone, request.Password) != nil && loginSvr.PartnerLogin(request.Phone, request.Password) != nil {
err = protocol.NewCustomMessage(1, "密码输入有误!")
// 判断是否高管
ok, loginErr := loginSvr.CheckIsSenior(request.Phone, 0)
if loginErr != nil {
err = protocol.NewErrWithMessage(10001)
return
}
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
}
}
break
case protocol.LoginBySmsCode:
if _, err = CheckSmsCode(request.Phone, request.Captcha); err != nil {
... ...
... ... @@ -2,4 +2,4 @@ package constant
const TOPIC_UCENT_USER_CHANGE_PHONE = "ucent-user-changePhone"
const KAFKA_HOSTS = "106.52.15.41:9092"
const KAFKA_HOSTS = "127.0.0.1:9092"
... ...
... ... @@ -46,6 +46,8 @@ type Users struct {
AccessPartners []*PartnerInfo
// 1普通用户 2主管理员
AdminType int8 `json:"adminType"`
// 是否高管
IsSenior int8 `json:"isSenior"`
}
func (Users *Users) AccessPartnerIds() []int64 {
... ...
... ... @@ -38,6 +38,31 @@ func (svr *PgLoginService) Init(phone string) (err error) {
return nil
}
/**
* @Author SteveChan
* @Description // 判断是否是高管
* @Date 10:44 2021/1/12
* @Param
* @return
**/
func (svr *PgLoginService) CheckIsSenior(phone string, companyId int64) (ok bool, err error) {
var (
UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext)
)
svr.Phone = phone
user, err := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "status": 1})
if err != nil {
return false, err
} else {
if user.IsSenior == 1 {
ok = true
} else if user.IsSenior == 2 {
ok = false
}
}
return ok, nil
}
//合伙人登录
func (svr *PgLoginService) PartnerLogin(phone string, password string) (err error) {
if len(svr.PartnerInfo) == 0 {
... ... @@ -173,6 +198,7 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) {
response["companys"] = companys
return response, nil
}
func (svr *PgLoginService) ManagerStaticInfo() (interface{}, error) {
response := make(map[string]interface{})
response["id"] = protocolx.AdminTypeManager
... ...
... ... @@ -50,4 +50,6 @@ type Users struct {
AccessPartners []*domain.PartnerInfo
// 1普通用户 2主管理员
AdminType int8
// 是否高管
IsSenior int8
}
... ...