作者 陈志颖

fix:测试高管权限

@@ -356,6 +356,7 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom @@ -356,6 +356,7 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
356 imInfo *domain.ImInfo 356 imInfo *domain.ImInfo
357 loginSvr = domain_service.NewPgLoginService(transactionContext) 357 loginSvr = domain_service.NewPgLoginService(transactionContext)
358 isSenior bool 358 isSenior bool
  359 + //isPartner bool
359 ) 360 )
360 361
361 phoneId, e := strconv.Atoi(request.Phone) 362 phoneId, e := strconv.Atoi(request.Phone)
@@ -384,10 +385,44 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom @@ -384,10 +385,44 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
384 } 385 }
385 386
386 // loginSvr 初始化 387 // loginSvr 初始化
387 - loginSvr.Init(request.Phone)  
388 - if len(loginSvr.Users) == 0 && len(loginSvr.PartnerInfo) == 0 { 388 + _ = loginSvr.Init(request.Phone)
  389 + if len(loginSvr.Users) == 0 && len(loginSvr.PartnerInfo) == 0 { // 用户且合伙人不存在
389 err = protocol.NewErrWithMessage(10001) 390 err = protocol.NewErrWithMessage(10001)
390 return 391 return
  392 + } else if len(loginSvr.Users) > 0 && len(loginSvr.PartnerInfo) == 0 { // 用户存在,合伙人不存在
  393 + // 注册合伙人到非高管公司
  394 + userLoginErr := loginSvr.RegistryPartner(request.Phone, loginSvr.Users)
  395 + if userLoginErr != nil {
  396 + log.Error(userLoginErr)
  397 + }
  398 +
  399 + cnt := 0
  400 +
  401 + for _, user := range loginSvr.Users {
  402 + if user.IsSenior == 2 {
  403 + cnt++
  404 + }
  405 + }
  406 +
  407 + if cnt == len(loginSvr.Users) {
  408 + isSenior = false
  409 + } else {
  410 + isSenior = true
  411 + }
  412 + } else if len(loginSvr.Users) > 0 && len(loginSvr.PartnerInfo) > 0 {
  413 + cnt := 0
  414 +
  415 + for _, user := range loginSvr.Users {
  416 + if user.IsSenior == 2 {
  417 + cnt++
  418 + }
  419 + }
  420 +
  421 + if cnt == len(loginSvr.Users) {
  422 + isSenior = false
  423 + } else {
  424 + isSenior = true
  425 + }
391 } 426 }
392 427
393 switch request.GrantType { 428 switch request.GrantType {
@@ -397,31 +432,10 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom @@ -397,31 +432,10 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
397 return 432 return
398 } 433 }
399 434
400 - // 判断是否高管  
401 - ok, loginErr := loginSvr.CheckIsSenior(request.Phone, 0)  
402 - if loginErr != nil {  
403 - err = protocol.NewErrWithMessage(10001) 435 + if loginSvr.ManagerLogin(request.Phone, request.Password) != nil && loginSvr.PartnerLogin(request.Phone, request.Password) != nil {
  436 + err = protocol.NewCustomMessage(1, "密码输入有误!")
404 return 437 return
405 } 438 }
406 -  
407 - isSenior = ok  
408 -  
409 - if ok { // 高管  
410 - if loginSvr.ManagerLogin(request.Phone, request.Password) != nil && loginSvr.PartnerLogin(request.Phone, request.Password) != nil {  
411 - err = protocol.NewCustomMessage(1, "密码输入有误!")  
412 - return  
413 - }  
414 - } else { // 普通用户登录  
415 - //guestErr := loginSvr.RegistryGuest(request.Phone)  
416 - //if guestErr != nil {  
417 - // err = protocol.NewCustomMessage(1, "普通用户登录错误")  
418 - // return  
419 - //}  
420 - if loginSvr.ManagerLogin(request.Phone, request.Password) != nil {  
421 - err = protocol.NewCustomMessage(1, "密码输入有误!")  
422 - return  
423 - }  
424 - }  
425 break 439 break
426 case protocol.LoginBySmsCode: 440 case protocol.LoginBySmsCode:
427 if _, err = CheckSmsCode(request.Phone, request.Captcha); err != nil { 441 if _, err = CheckSmsCode(request.Phone, request.Captcha); err != nil {
@@ -449,6 +463,7 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom @@ -449,6 +463,7 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
449 // 获取统计信息(合伙人/高管) 463 // 获取统计信息(合伙人/高管)
450 rsp.Partner, _ = loginSvr.PartnerStaticInfo() 464 rsp.Partner, _ = loginSvr.PartnerStaticInfo()
451 rsp.Manager, _ = loginSvr.ManagerStaticInfo() 465 rsp.Manager, _ = loginSvr.ManagerStaticInfo()
  466 +
452 if !loginSvr.HasAvailableCompany { 467 if !loginSvr.HasAvailableCompany {
453 err = protocol.NewErrWithMessage(10008) //账号禁用 468 err = protocol.NewErrWithMessage(10008) //账号禁用
454 return 469 return
@@ -476,21 +491,23 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom @@ -476,21 +491,23 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
476 userAuth.NewRedisUserCredential(request.Phone).AddAuth(rsp.Credentials) 491 userAuth.NewRedisUserCredential(request.Phone).AddAuth(rsp.Credentials)
477 492
478 // 判断是否高管 493 // 判断是否高管
479 - if isSenior {  
480 - v = map[string]interface{}{"center": rsp}  
481 - } else { 494 + if !isSenior { // 用户非高管非合伙人
482 rsp.Partner.(map[string]interface{})["companys"] = rsp.Manager.(map[string]interface{})["companys"] 495 rsp.Partner.(map[string]interface{})["companys"] = rsp.Manager.(map[string]interface{})["companys"]
483 rsp.Manager.(map[string]interface{})["companys"] = []struct{}{} 496 rsp.Manager.(map[string]interface{})["companys"] = []struct{}{}
484 v = map[string]interface{}{"center": rsp} 497 v = map[string]interface{}{"center": rsp}
  498 + } else {
  499 + v = map[string]interface{}{"center": rsp}
485 } 500 }
486 501
  502 + //v = map[string]interface{}{"center": rsp}
  503 +
487 err = transactionContext.CommitTransaction() 504 err = transactionContext.CommitTransaction()
488 return 505 return
489 } 506 }
490 507
491 /** 508 /**
492 * @Author SteveChan 509 * @Author SteveChan
493 - * @Description //TODO 企业平台-多公司登录 - 通过凭证,判断是否高管 510 + * @Description // 企业平台-多公司登录 - 通过凭证,判断是否高管
494 * @Date 15:00 2021/1/12 511 * @Date 15:00 2021/1/12
495 * @Param 512 * @Param
496 * @return 513 * @return
@@ -196,7 +196,7 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques @@ -196,7 +196,7 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques
196 UsersRepository, _ = factory.CreateUsersRepository(transactionContext) 196 UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
197 company *domain.Company 197 company *domain.Company
198 user *domain.Users 198 user *domain.Users
199 - loginSvr = domain_service.NewPgLoginService(transactionContext) 199 + //loginSvr = domain_service.NewPgLoginService(transactionContext)
200 ) 200 )
201 201
202 if err = transactionContext.StartTransaction(); err != nil { 202 if err = transactionContext.StartTransaction(); err != nil {
@@ -305,22 +305,13 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques @@ -305,22 +305,13 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques
305 rsp = rspMap 305 rsp = rspMap
306 } 306 }
307 307
308 - phone := strconv.Itoa(header.SimNum)  
309 -  
310 - // 判断是否高管  
311 - ok, loginErr := loginSvr.CheckIsSenior(phone, 0)  
312 - if loginErr != nil {  
313 - err = protocol.NewErrWithMessage(10001)  
314 - return  
315 - } 308 + //判断是否高管
  309 + //phone := strconv.Itoa(header.SimNum)
  310 + //ok, _ := loginSvr.CheckIsSenior(phone, header.CompanyId)
316 311
317 switch header.AdminType { 312 switch header.AdminType {
318 case int(protocolx.AdminTypePartner): 313 case int(protocolx.AdminTypePartner):
319 - if ok { // 身份为高管,则默认登录合伙人  
320 - funcPartnerInfo()  
321 - } else { // 身份非高管  
322 - funcManagerInfo()  
323 - } 314 + funcPartnerInfo()
324 break 315 break
325 case int(protocolx.AdminTypeManager): 316 case int(protocolx.AdminTypeManager):
326 funcManagerInfo() 317 funcManagerInfo()
@@ -50,7 +50,7 @@ func (svr *PgLoginService) CheckIsSenior(phone string, companyId int64) (ok bool @@ -50,7 +50,7 @@ func (svr *PgLoginService) CheckIsSenior(phone string, companyId int64) (ok bool
50 UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext) 50 UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext)
51 ) 51 )
52 svr.Phone = phone 52 svr.Phone = phone
53 - user, err := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "status": 1, "deleteAtIsNull": true}) 53 + user, err := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "status": 1, "companyId": companyId, "deleteAtIsNull": true})
54 if err != nil { 54 if err != nil {
55 return false, err 55 return false, err
56 } else { 56 } else {
@@ -63,6 +63,31 @@ func (svr *PgLoginService) CheckIsSenior(phone string, companyId int64) (ok bool @@ -63,6 +63,31 @@ func (svr *PgLoginService) CheckIsSenior(phone string, companyId int64) (ok bool
63 return ok, nil 63 return ok, nil
64 } 64 }
65 65
  66 +/**
  67 + * @Author SteveChan
  68 + * @Description // 判断是否合伙人
  69 + * @Date 13:25 2021/1/13
  70 + * @Param
  71 + * @return
  72 + **/
  73 +func (svr *PgLoginService) CheckIsPartner(phone string, companyId int64) (ok bool, err error) {
  74 + var (
  75 + PartnerInfoRepository, _ = repository.NewPartnerInfoRepository(svr.transactionContext)
  76 + )
  77 + svr.Phone = phone
  78 + user, err := PartnerInfoRepository.FindOne(map[string]interface{}{"account": phone, "status": 1})
  79 + if err != nil {
  80 + return false, err
  81 + }
  82 + if user != nil {
  83 + ok = true
  84 + } else {
  85 + ok = false
  86 + }
  87 +
  88 + return ok, nil
  89 +}
  90 +
66 //合伙人登录 91 //合伙人登录
67 func (svr *PgLoginService) PartnerLogin(phone string, password string) (err error) { 92 func (svr *PgLoginService) PartnerLogin(phone string, password string) (err error) {
68 if len(svr.PartnerInfo) == 0 { 93 if len(svr.PartnerInfo) == 0 {
@@ -311,6 +336,57 @@ func computeBonusPercent(totalBonus float64, bonus float64) float64 { @@ -311,6 +336,57 @@ func computeBonusPercent(totalBonus float64, bonus float64) float64 {
311 return utils.Decimal(bonus / totalBonus) 336 return utils.Decimal(bonus / totalBonus)
312 } 337 }
313 338
  339 +/**
  340 + * @Author SteveChan
  341 + * @Description //TODO 注册用户到合伙人
  342 + * @Date 13:52 2021/1/13
  343 + * @Param
  344 + * @return
  345 + **/
  346 +func (svr *PgLoginService) RegistryPartner(phone string, users []*domain.Users) error {
  347 + var (
  348 + PartnerInfoService, _ = repository.NewPartnerInfoRepository(svr.transactionContext)
  349 + //UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext)
  350 + )
  351 +
  352 + partnerInfo, errPartner := PartnerInfoService.FindOne(map[string]interface{}{"account": phone})
  353 +
  354 + //user, errUser := UsersRepository.FindOne(map[string]interface{}{"phone": phone})
  355 +
  356 + if partnerInfo != nil {
  357 + return nil
  358 + }
  359 +
  360 + for _, user := range users {
  361 + if user.IsSenior == 2 { // 插入合伙人到非高管公司
  362 + if errPartner != nil {
  363 + id := time.Now().Unix()
  364 + errPartner = svr.transactionContext.PgDd.Insert(&models.PartnerInfo{
  365 + Id: id,
  366 + CompanyId: user.CompanyId,
  367 + PartnerName: phone,
  368 + Account: phone,
  369 + Password: "7c4a8d09ca3762af61e59520943dc26494f8941b",
  370 + Status: 1,
  371 + PartnerCategory: 1,
  372 + RegionInfo: &domain.RegionInfo{
  373 + RegionName: "客户区域",
  374 + RegionId: 0,
  375 + },
  376 + CooperateTime: time.Now(),
  377 + CreateAt: time.Now(),
  378 + UpdateAt: time.Now(),
  379 + PartnerCategoryInfos: []*models.PartnerCategoryInfo{&models.PartnerCategoryInfo{Id: 1}},
  380 + Salesman: []*domain.Salesman{&domain.Salesman{Name: phone, Telephone: phone}},
  381 + })
  382 + }
  383 + }
  384 + }
  385 +
  386 + return errPartner
  387 +}
  388 +
  389 +// 注册游客到指定的公司
314 func (svr *PgLoginService) RegistryGuest(phone string) error { 390 func (svr *PgLoginService) RegistryGuest(phone string) error {
315 var ( 391 var (
316 PartnerInfoService, _ = repository.NewPartnerInfoRepository(svr.transactionContext) 392 PartnerInfoService, _ = repository.NewPartnerInfoRepository(svr.transactionContext)