作者 陈志颖

test:普通用户

1 appname = partner 1 appname = partner
2 runmode = "${RUN_MODE||dev}" 2 runmode = "${RUN_MODE||dev}"
3 -httpport = "${HTTP_PORT||8082}" 3 +httpport = "${HTTP_PORT||8083}"
4 4
5 #开启监控 5 #开启监控
6 EnableAdmin = false 6 EnableAdmin = false
@@ -8,8 +8,6 @@ import ( @@ -8,8 +8,6 @@ import (
8 _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg" 8 _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg"
9 _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/redis" 9 _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/redis"
10 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" 10 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
11 - "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/sarama"  
12 -  
13 //"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/ginsvr" 11 //"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/ginsvr"
14 _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr" 12 _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr"
15 ) 13 )
@@ -26,7 +24,7 @@ func main() { @@ -26,7 +24,7 @@ func main() {
26 event.InitEventCenter() 24 event.InitEventCenter()
27 25
28 //启动kafaka消息订阅 26 //启动kafaka消息订阅
29 - go sarama.Run() 27 + //go sarama.Run()
30 28
31 beego.Run() 29 beego.Run()
32 } 30 }
@@ -345,38 +345,57 @@ func PasswordLogin(header *protocol.RequestHeader, request *protocol.LoginReques @@ -345,38 +345,57 @@ func PasswordLogin(header *protocol.RequestHeader, request *protocol.LoginReques
345 345
346 // 企业平台-多公司登录 346 // 企业平台-多公司登录
347 func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCompanysRequest) (v interface{}, err error) { 347 func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCompanysRequest) (v interface{}, err error) {
  348 +
348 var ( 349 var (
349 transactionContext, _ = factory.CreateTransactionContext(nil) 350 transactionContext, _ = factory.CreateTransactionContext(nil)
350 imInfo *domain.ImInfo 351 imInfo *domain.ImInfo
351 loginSvr = domain_service.NewPgLoginService(transactionContext) 352 loginSvr = domain_service.NewPgLoginService(transactionContext)
  353 + isSenior bool
352 ) 354 )
  355 +
  356 + // 转换手机号码
353 phoneId, e := strconv.Atoi(request.Phone) 357 phoneId, e := strconv.Atoi(request.Phone)
354 if e != nil { 358 if e != nil {
355 log.Error(e) 359 log.Error(e)
356 e = protocol.NewErrWithMessage(2) 360 e = protocol.NewErrWithMessage(2)
357 return 361 return
358 } 362 }
  363 +
359 rsp := &protocolx.CenterCompanysResponse{} 364 rsp := &protocolx.CenterCompanysResponse{}
  365 +
  366 + // 启动事务
360 if err = transactionContext.StartTransaction(); err != nil { 367 if err = transactionContext.StartTransaction(); err != nil {
361 log.Error(err) 368 log.Error(err)
362 return nil, err 369 return nil, err
363 } 370 }
  371 +
364 defer func() { 372 defer func() {
365 transactionContext.RollbackTransaction() 373 transactionContext.RollbackTransaction()
366 }() 374 }()
367 - // 通过短信验证码登录的游客,注册一个账号到配置的公司去(ios审核使用)  
368 - if request.GrantType == protocol.LoginBySmsCode { 375 +
  376 + // 通过短信验证码登录的游客或者普通用户,注册一个账号到配置的公司去(ios审核使用)
  377 + if request.GrantType == protocol.LoginBySmsCode || request.GrantType == protocol.LoginByPassword {
369 e := loginSvr.RegistryGuest(request.Phone) 378 e := loginSvr.RegistryGuest(request.Phone)
370 if e != nil { 379 if e != nil {
371 log.Error(e) 380 log.Error(e)
372 } 381 }
373 } 382 }
  383 +
374 // loginSvr 初始化 384 // loginSvr 初始化
375 - loginSvr.Init(request.Phone) 385 + _ = loginSvr.Init(request.Phone)
376 if len(loginSvr.Users) == 0 && len(loginSvr.PartnerInfo) == 0 { 386 if len(loginSvr.Users) == 0 && len(loginSvr.PartnerInfo) == 0 {
377 err = protocol.NewErrWithMessage(10001) 387 err = protocol.NewErrWithMessage(10001)
378 return 388 return
379 } 389 }
  390 +
  391 + // 高管初始化
  392 + _ = loginSvr.InitSenior(request.Phone)
  393 + if len(loginSvr.Users) == 0 {
  394 + isSenior = false
  395 + } else {
  396 + isSenior = true
  397 + }
  398 +
380 switch request.GrantType { 399 switch request.GrantType {
381 case protocol.LoginByPassword: 400 case protocol.LoginByPassword:
382 if len(request.Password) == 0 { 401 if len(request.Password) == 0 {
@@ -414,6 +433,7 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom @@ -414,6 +433,7 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
414 // 获取统计信息(合伙人/高管) 433 // 获取统计信息(合伙人/高管)
415 rsp.Partner, _ = loginSvr.PartnerStaticInfo() 434 rsp.Partner, _ = loginSvr.PartnerStaticInfo()
416 rsp.Manager, _ = loginSvr.ManagerStaticInfo() 435 rsp.Manager, _ = loginSvr.ManagerStaticInfo()
  436 +
417 if !loginSvr.HasAvailableCompany { 437 if !loginSvr.HasAvailableCompany {
418 err = protocol.NewErrWithMessage(10008) //账号禁用 438 err = protocol.NewErrWithMessage(10008) //账号禁用
419 return 439 return
@@ -440,7 +460,17 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom @@ -440,7 +460,17 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
440 //添加手机对应的凭证 460 //添加手机对应的凭证
441 userAuth.NewRedisUserCredential(request.Phone).AddAuth(rsp.Credentials) 461 userAuth.NewRedisUserCredential(request.Phone).AddAuth(rsp.Credentials)
442 462
  463 + //v = map[string]interface{}{"center": rsp}
  464 +
  465 + // 判断是否高管
  466 + if isSenior {
443 v = map[string]interface{}{"center": rsp} 467 v = map[string]interface{}{"center": rsp}
  468 + } else {
  469 + rsp.Partner.(map[string]interface{})["companys"] = rsp.Manager.(map[string]interface{})["companys"]
  470 + rsp.Manager.(map[string]interface{})["companys"] = []struct{}{}
  471 + v = map[string]interface{}{"center": rsp}
  472 + }
  473 +
444 err = transactionContext.CommitTransaction() 474 err = transactionContext.CommitTransaction()
445 return 475 return
446 } 476 }
@@ -2,4 +2,4 @@ package constant @@ -2,4 +2,4 @@ package constant
2 2
3 const TOPIC_UCENT_USER_CHANGE_PHONE = "ucent-user-changePhone" 3 const TOPIC_UCENT_USER_CHANGE_PHONE = "ucent-user-changePhone"
4 4
5 -const KAFKA_HOSTS = "106.52.15.41:9092" 5 +const KAFKA_HOSTS = "127.0.0.1:9092"
@@ -46,6 +46,8 @@ type Users struct { @@ -46,6 +46,8 @@ type Users struct {
46 AccessPartners []*PartnerInfo 46 AccessPartners []*PartnerInfo
47 // 1普通用户 2主管理员 47 // 1普通用户 2主管理员
48 AdminType int8 `json:"adminType"` 48 AdminType int8 `json:"adminType"`
  49 + // 是否高管
  50 + IsSenior int8 `json:"isSenior"`
49 } 51 }
50 52
51 func (Users *Users) AccessPartnerIds() []int64 { 53 func (Users *Users) AccessPartnerIds() []int64 {
@@ -32,9 +32,24 @@ func (svr *PgLoginService) Init(phone string) (err error) { @@ -32,9 +32,24 @@ func (svr *PgLoginService) Init(phone string) (err error) {
32 PartnerInfoService, _ = repository.NewPartnerInfoRepository(svr.transactionContext) 32 PartnerInfoService, _ = repository.NewPartnerInfoRepository(svr.transactionContext)
33 UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext) 33 UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext)
34 ) 34 )
  35 +
35 svr.Phone = phone 36 svr.Phone = phone
  37 +
36 _, svr.PartnerInfo, err = PartnerInfoService.Find(map[string]interface{}{"account": phone, "status": 1, "sortByCreateTime": "ASC"}) 38 _, svr.PartnerInfo, err = PartnerInfoService.Find(map[string]interface{}{"account": phone, "status": 1, "sortByCreateTime": "ASC"})
37 _, svr.Users, err = UsersRepository.Find(map[string]interface{}{"phone": phone, "status": 1, "sortByCreateTime": "ASC", "deleteAtIsNull": true}) 39 _, svr.Users, err = UsersRepository.Find(map[string]interface{}{"phone": phone, "status": 1, "sortByCreateTime": "ASC", "deleteAtIsNull": true})
  40 +
  41 + return nil
  42 +}
  43 +
  44 +func (svr *PgLoginService) InitSenior(phone string) (err error) {
  45 + var (
  46 + UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext)
  47 + )
  48 +
  49 + svr.Phone = phone
  50 +
  51 + _, svr.Users, err = UsersRepository.Find(map[string]interface{}{"phone": phone, "status": 1, "sortByCreateTime": "ASC", "deleteAtIsNull": true, "isSenior": 1})
  52 +
38 return nil 53 return nil
39 } 54 }
40 55
@@ -73,10 +88,12 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) { @@ -73,10 +88,12 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) {
73 response := make(map[string]interface{}) 88 response := make(map[string]interface{})
74 response["id"] = protocolx.AdminTypePartner 89 response["id"] = protocolx.AdminTypePartner
75 response["name"] = protocolx.AdminTypePartnerName 90 response["name"] = protocolx.AdminTypePartnerName
  91 +
76 if len(svr.PartnerInfo) == 0 { 92 if len(svr.PartnerInfo) == 0 {
77 response["companys"] = make([]struct{}, 0) 93 response["companys"] = make([]struct{}, 0)
78 return response, nil 94 return response, nil
79 } 95 }
  96 +
80 var ( 97 var (
81 OrderDao, _ = dao.NewOrderBaseDao(svr.transactionContext) 98 OrderDao, _ = dao.NewOrderBaseDao(svr.transactionContext)
82 BusinessBonusDao, _ = dao.NewBusinessBonusDao(svr.transactionContext) 99 BusinessBonusDao, _ = dao.NewBusinessBonusDao(svr.transactionContext)
@@ -87,6 +104,7 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) { @@ -87,6 +104,7 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) {
87 UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext) 104 UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext)
88 adminApiGateway = http_gateway.NewHttplibBusinessAdminApiServiceGateway() 105 adminApiGateway = http_gateway.NewHttplibBusinessAdminApiServiceGateway()
89 ) 106 )
  107 +
90 doGetCompanyIds := func() []int64 { 108 doGetCompanyIds := func() []int64 {
91 var companies []int64 109 var companies []int64
92 for i := range svr.PartnerInfo { 110 for i := range svr.PartnerInfo {
@@ -94,6 +112,7 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) { @@ -94,6 +112,7 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) {
94 } 112 }
95 return companies 113 return companies
96 } 114 }
  115 +
97 doGetPartnerIds := func() []int64 { 116 doGetPartnerIds := func() []int64 {
98 var array []int64 117 var array []int64
99 for i := range svr.PartnerInfo { 118 for i := range svr.PartnerInfo {
@@ -101,17 +120,21 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) { @@ -101,17 +120,21 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) {
101 } 120 }
102 return array 121 return array
103 } 122 }
  123 +
104 companyList = svr.GetCompanyList(doGetCompanyIds) 124 companyList = svr.GetCompanyList(doGetCompanyIds)
105 if len(companyList) == 0 { 125 if len(companyList) == 0 {
106 return response, nil 126 return response, nil
107 } 127 }
  128 +
108 totalBonus, e := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{InPartnerIds: doGetPartnerIds(), OrderTypes: domain.UserOrderTypes(domain.Career)}) 129 totalBonus, e := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{InPartnerIds: doGetPartnerIds(), OrderTypes: domain.UserOrderTypes(domain.Career)})
109 if e != nil { 130 if e != nil {
110 return response, e 131 return response, e
111 } 132 }
  133 +
112 if businessBonus, e := BusinessBonusDao.OrderBonusStatics(domain.OrderBonusQuery{InPartnerIds: doGetPartnerIds(), IsDisable: 1}); e == nil { 134 if businessBonus, e := BusinessBonusDao.OrderBonusStatics(domain.OrderBonusQuery{InPartnerIds: doGetPartnerIds(), IsDisable: 1}); e == nil {
113 totalBonus.Bonus += businessBonus.Bonus 135 totalBonus.Bonus += businessBonus.Bonus
114 } 136 }
  137 +
115 _, allPartnerCategory, e = PartnerCategoryInfoRepository.Find(map[string]interface{}{"sortById": domain.ASC}) 138 _, allPartnerCategory, e = PartnerCategoryInfoRepository.Find(map[string]interface{}{"sortById": domain.ASC})
116 var mapPartnerBussinessBonus = make(map[int64]*domain.BusinessBonus) 139 var mapPartnerBussinessBonus = make(map[int64]*domain.BusinessBonus)
117 if _, bussinessBonus, e := BusinessBonusRepository.Find(map[string]interface{}{"inPartnerIds": doGetPartnerIds(), "isDisable": 1}); e == nil { 140 if _, bussinessBonus, e := BusinessBonusRepository.Find(map[string]interface{}{"inPartnerIds": doGetPartnerIds(), "isDisable": 1}); e == nil {
@@ -173,6 +196,8 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) { @@ -173,6 +196,8 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) {
173 response["companys"] = companys 196 response["companys"] = companys
174 return response, nil 197 return response, nil
175 } 198 }
  199 +
  200 +// 高管统计信息
176 func (svr *PgLoginService) ManagerStaticInfo() (interface{}, error) { 201 func (svr *PgLoginService) ManagerStaticInfo() (interface{}, error) {
177 response := make(map[string]interface{}) 202 response := make(map[string]interface{})
178 response["id"] = protocolx.AdminTypeManager 203 response["id"] = protocolx.AdminTypeManager
@@ -290,11 +315,14 @@ func (svr *PgLoginService) RegistryGuest(phone string) error { @@ -290,11 +315,14 @@ func (svr *PgLoginService) RegistryGuest(phone string) error {
290 PartnerInfoService, _ = repository.NewPartnerInfoRepository(svr.transactionContext) 315 PartnerInfoService, _ = repository.NewPartnerInfoRepository(svr.transactionContext)
291 UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext) 316 UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext)
292 ) 317 )
  318 +
293 partnerInfo, errPartner := PartnerInfoService.FindOne(map[string]interface{}{"account": phone}) 319 partnerInfo, errPartner := PartnerInfoService.FindOne(map[string]interface{}{"account": phone})
294 user, errUser := UsersRepository.FindOne(map[string]interface{}{"phone": phone}) 320 user, errUser := UsersRepository.FindOne(map[string]interface{}{"phone": phone})
  321 +
295 if partnerInfo != nil || user != nil { 322 if partnerInfo != nil || user != nil {
296 return nil 323 return nil
297 } 324 }
  325 +
298 if errUser != nil && errPartner != nil { 326 if errUser != nil && errPartner != nil {
299 id := time.Now().Unix() 327 id := time.Now().Unix()
300 errPartner = svr.transactionContext.PgDd.Insert(&models.PartnerInfo{ 328 errPartner = svr.transactionContext.PgDd.Insert(&models.PartnerInfo{
@@ -50,4 +50,6 @@ type Users struct { @@ -50,4 +50,6 @@ type Users struct {
50 AccessPartners []*domain.PartnerInfo 50 AccessPartners []*domain.PartnerInfo
51 // 1普通用户 2主管理员 51 // 1普通用户 2主管理员
52 AdminType int8 52 AdminType int8
  53 + // 是否高管
  54 + IsSenior int8
53 } 55 }
@@ -74,6 +74,7 @@ func (repository *UsersRepository) Find(queryOptions map[string]interface{}) (in @@ -74,6 +74,7 @@ func (repository *UsersRepository) Find(queryOptions map[string]interface{}) (in
74 SetWhere("company_id = ?", "companyId"). 74 SetWhere("company_id = ?", "companyId").
75 SetWhere(`status = ?`, "status"). 75 SetWhere(`status = ?`, "status").
76 SetWhere(`delete_at is null`, "deleteAtIsNull"). 76 SetWhere(`delete_at is null`, "deleteAtIsNull").
  77 + SetWhere("is_senior = ?", "isSenior").
77 SetOrder("create_at", "sortByCreateTime"). 78 SetOrder("create_at", "sortByCreateTime").
78 SetOrder("update_at", "sortByUpdateTime") 79 SetOrder("update_at", "sortByUpdateTime")
79 80