作者 陈志颖

test:普通用户

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()
}
... ...
... ... @@ -345,38 +345,57 @@ func PasswordLogin(header *protocol.RequestHeader, request *protocol.LoginReques
// 企业平台-多公司登录
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
)
// 转换手机号码
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 {
// 通过短信验证码登录的游客或者普通用户,注册一个账号到配置的公司去(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)
_ = loginSvr.Init(request.Phone)
if len(loginSvr.Users) == 0 && len(loginSvr.PartnerInfo) == 0 {
err = protocol.NewErrWithMessage(10001)
return
}
// 高管初始化
_ = loginSvr.InitSenior(request.Phone)
if len(loginSvr.Users) == 0 {
isSenior = false
} else {
isSenior = true
}
switch request.GrantType {
case protocol.LoginByPassword:
if len(request.Password) == 0 {
... ... @@ -414,6 +433,7 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
// 获取统计信息(合伙人/高管)
rsp.Partner, _ = loginSvr.PartnerStaticInfo()
rsp.Manager, _ = loginSvr.ManagerStaticInfo()
if !loginSvr.HasAvailableCompany {
err = protocol.NewErrWithMessage(10008) //账号禁用
return
... ... @@ -440,7 +460,17 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
//添加手机对应的凭证
userAuth.NewRedisUserCredential(request.Phone).AddAuth(rsp.Credentials)
v = map[string]interface{}{"center": rsp}
//v = map[string]interface{}{"center": rsp}
// 判断是否高管
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}
}
err = transactionContext.CommitTransaction()
return
}
... ...
... ... @@ -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 {
... ...
... ... @@ -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
}
... ... @@ -73,10 +88,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)
... ... @@ -87,6 +104,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 {
... ... @@ -94,6 +112,7 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) {
}
return companies
}
doGetPartnerIds := func() []int64 {
var array []int64
for i := range svr.PartnerInfo {
... ... @@ -101,17 +120,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 {
... ... @@ -173,6 +196,8 @@ 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
... ... @@ -290,11 +315,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{
... ...
... ... @@ -50,4 +50,6 @@ type Users struct {
AccessPartners []*domain.PartnerInfo
// 1普通用户 2主管理员
AdminType int8
// 是否高管
IsSenior int8
}
... ...
... ... @@ -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")
... ...