合并分支 'dev' 到 'test'
Dev 查看合并请求 !25
正在显示
3 个修改的文件
包含
56 行增加
和
54 行删除
| @@ -2,6 +2,10 @@ package auth | @@ -2,6 +2,10 @@ package auth | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "strconv" | ||
| 6 | + "strings" | ||
| 7 | + "time" | ||
| 8 | + | ||
| 5 | "github.com/tiptok/gocomm/xa/eda" | 9 | "github.com/tiptok/gocomm/xa/eda" |
| 6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory" | 10 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory" |
| 7 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/userAuth" | 11 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/userAuth" |
| @@ -14,9 +18,6 @@ import ( | @@ -14,9 +18,6 @@ import ( | ||
| 14 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" | 18 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" |
| 15 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" | 19 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" |
| 16 | protocolx "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/auth" | 20 | protocolx "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/auth" |
| 17 | - "strconv" | ||
| 18 | - "strings" | ||
| 19 | - "time" | ||
| 20 | ) | 21 | ) |
| 21 | 22 | ||
| 22 | // 该方法废弃 | 23 | // 该方法废弃 |
| @@ -345,20 +346,21 @@ func PasswordLogin(header *protocol.RequestHeader, request *protocol.LoginReques | @@ -345,20 +346,21 @@ func PasswordLogin(header *protocol.RequestHeader, request *protocol.LoginReques | ||
| 345 | 346 | ||
| 346 | /** | 347 | /** |
| 347 | * @Author SteveChan | 348 | * @Author SteveChan |
| 348 | - * @Description //TODO 企业平台-多公司登录,判断是否高管 | 349 | + * @Description // 企业平台-多公司登录,判断是否高管 |
| 349 | * @Date 15:01 2021/1/12 | 350 | * @Date 15:01 2021/1/12 |
| 350 | * @Param | 351 | * @Param |
| 351 | * @return | 352 | * @return |
| 352 | **/ | 353 | **/ |
| 353 | func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCompanysRequest) (v interface{}, err error) { | 354 | func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCompanysRequest) (v interface{}, err error) { |
| 355 | + | ||
| 354 | var ( | 356 | var ( |
| 355 | transactionContext, _ = factory.CreateTransactionContext(nil) | 357 | transactionContext, _ = factory.CreateTransactionContext(nil) |
| 356 | imInfo *domain.ImInfo | 358 | imInfo *domain.ImInfo |
| 357 | loginSvr = domain_service.NewPgLoginService(transactionContext) | 359 | loginSvr = domain_service.NewPgLoginService(transactionContext) |
| 358 | isSenior bool | 360 | isSenior bool |
| 359 | - //isPartner bool | ||
| 360 | ) | 361 | ) |
| 361 | 362 | ||
| 363 | + // 转换手机号码 | ||
| 362 | phoneId, e := strconv.Atoi(request.Phone) | 364 | phoneId, e := strconv.Atoi(request.Phone) |
| 363 | if e != nil { | 365 | if e != nil { |
| 364 | log.Error(e) | 366 | log.Error(e) |
| @@ -367,6 +369,8 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom | @@ -367,6 +369,8 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom | ||
| 367 | } | 369 | } |
| 368 | 370 | ||
| 369 | rsp := &protocolx.CenterCompanysResponse{} | 371 | rsp := &protocolx.CenterCompanysResponse{} |
| 372 | + | ||
| 373 | + // 启动事务 | ||
| 370 | if err = transactionContext.StartTransaction(); err != nil { | 374 | if err = transactionContext.StartTransaction(); err != nil { |
| 371 | log.Error(err) | 375 | log.Error(err) |
| 372 | return nil, err | 376 | return nil, err |
| @@ -376,53 +380,27 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom | @@ -376,53 +380,27 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom | ||
| 376 | transactionContext.RollbackTransaction() | 380 | transactionContext.RollbackTransaction() |
| 377 | }() | 381 | }() |
| 378 | 382 | ||
| 379 | - // 通过短信验证码登录的游客,注册一个账号到配置的公司去(ios审核使用) | ||
| 380 | - if request.GrantType == protocol.LoginBySmsCode { | ||
| 381 | - guestLoginErr := loginSvr.RegistryGuest(request.Phone) | ||
| 382 | - if guestLoginErr != nil { | ||
| 383 | - log.Error(guestLoginErr) | 383 | + // 通过短信验证码登录的游客或者普通用户,注册一个账号到配置的公司去(ios审核使用) |
| 384 | + if request.GrantType == protocol.LoginBySmsCode || request.GrantType == protocol.LoginByPassword { | ||
| 385 | + e := loginSvr.RegistryGuest(request.Phone) | ||
| 386 | + if e != nil { | ||
| 387 | + log.Error(e) | ||
| 384 | } | 388 | } |
| 385 | } | 389 | } |
| 386 | 390 | ||
| 387 | // loginSvr 初始化 | 391 | // loginSvr 初始化 |
| 388 | _ = loginSvr.Init(request.Phone) | 392 | _ = loginSvr.Init(request.Phone) |
| 389 | - if len(loginSvr.Users) == 0 && len(loginSvr.PartnerInfo) == 0 { // 用户且合伙人不存在 | 393 | + if len(loginSvr.Users) == 0 && len(loginSvr.PartnerInfo) == 0 { |
| 390 | err = protocol.NewErrWithMessage(10001) | 394 | err = protocol.NewErrWithMessage(10001) |
| 391 | return | 395 | 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 | - } | 396 | + } |
| 420 | 397 | ||
| 421 | - if cnt == len(loginSvr.Users) { | ||
| 422 | - isSenior = false | ||
| 423 | - } else { | ||
| 424 | - isSenior = true | ||
| 425 | - } | 398 | + // 高管初始化 |
| 399 | + _ = loginSvr.InitSenior(request.Phone) | ||
| 400 | + if len(loginSvr.Users) == 0 { | ||
| 401 | + isSenior = false | ||
| 402 | + } else { | ||
| 403 | + isSenior = true | ||
| 426 | } | 404 | } |
| 427 | 405 | ||
| 428 | switch request.GrantType { | 406 | switch request.GrantType { |
| @@ -490,17 +468,17 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom | @@ -490,17 +468,17 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom | ||
| 490 | // 添加手机对应的凭证 | 468 | // 添加手机对应的凭证 |
| 491 | userAuth.NewRedisUserCredential(request.Phone).AddAuth(rsp.Credentials) | 469 | userAuth.NewRedisUserCredential(request.Phone).AddAuth(rsp.Credentials) |
| 492 | 470 | ||
| 471 | + //v = map[string]interface{}{"center": rsp} | ||
| 472 | + | ||
| 493 | // 判断是否高管 | 473 | // 判断是否高管 |
| 494 | - if !isSenior { // 用户非高管非合伙人 | ||
| 495 | - rsp.Partner.(map[string]interface{})["companys"] = rsp.Manager.(map[string]interface{})["companys"] | ||
| 496 | - rsp.Manager.(map[string]interface{})["companys"] = []struct{}{} | 474 | + if isSenior { |
| 497 | v = map[string]interface{}{"center": rsp} | 475 | v = map[string]interface{}{"center": rsp} |
| 498 | } else { | 476 | } else { |
| 477 | + rsp.Partner.(map[string]interface{})["companys"] = rsp.Manager.(map[string]interface{})["companys"] | ||
| 478 | + rsp.Manager.(map[string]interface{})["companys"] = []struct{}{} | ||
| 499 | v = map[string]interface{}{"center": rsp} | 479 | v = map[string]interface{}{"center": rsp} |
| 500 | } | 480 | } |
| 501 | 481 | ||
| 502 | - //v = map[string]interface{}{"center": rsp} | ||
| 503 | - | ||
| 504 | err = transactionContext.CommitTransaction() | 482 | err = transactionContext.CommitTransaction() |
| 505 | return | 483 | return |
| 506 | } | 484 | } |
| @@ -543,11 +521,7 @@ func CompaniesLoginByCredential(header *protocol.RequestHeader, request *protoco | @@ -543,11 +521,7 @@ func CompaniesLoginByCredential(header *protocol.RequestHeader, request *protoco | ||
| 543 | loginSvr.Init(claim.Phone) | 521 | loginSvr.Init(claim.Phone) |
| 544 | 522 | ||
| 545 | // 判断是否高管 | 523 | // 判断是否高管 |
| 546 | - ok, loginErr := loginSvr.CheckIsSenior(claim.Phone, 0) | ||
| 547 | - if loginErr != nil { | ||
| 548 | - err = protocol.NewErrWithMessage(10001) | ||
| 549 | - return | ||
| 550 | - } | 524 | + ok, _ := loginSvr.CheckIsSenior(claim.Phone, claim.CompanyId) |
| 551 | 525 | ||
| 552 | rsp.Partner, _ = loginSvr.PartnerStaticInfo() | 526 | rsp.Partner, _ = loginSvr.PartnerStaticInfo() |
| 553 | rsp.Manager, _ = loginSvr.ManagerStaticInfo() | 527 | rsp.Manager, _ = loginSvr.ManagerStaticInfo() |
| @@ -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 | ||
| @@ -123,10 +138,12 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) { | @@ -123,10 +138,12 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) { | ||
| 123 | response := make(map[string]interface{}) | 138 | response := make(map[string]interface{}) |
| 124 | response["id"] = protocolx.AdminTypePartner | 139 | response["id"] = protocolx.AdminTypePartner |
| 125 | response["name"] = protocolx.AdminTypePartnerName | 140 | response["name"] = protocolx.AdminTypePartnerName |
| 141 | + | ||
| 126 | if len(svr.PartnerInfo) == 0 { | 142 | if len(svr.PartnerInfo) == 0 { |
| 127 | response["companys"] = make([]struct{}, 0) | 143 | response["companys"] = make([]struct{}, 0) |
| 128 | return response, nil | 144 | return response, nil |
| 129 | } | 145 | } |
| 146 | + | ||
| 130 | var ( | 147 | var ( |
| 131 | OrderDao, _ = dao.NewOrderBaseDao(svr.transactionContext) | 148 | OrderDao, _ = dao.NewOrderBaseDao(svr.transactionContext) |
| 132 | BusinessBonusDao, _ = dao.NewBusinessBonusDao(svr.transactionContext) | 149 | BusinessBonusDao, _ = dao.NewBusinessBonusDao(svr.transactionContext) |
| @@ -137,6 +154,7 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) { | @@ -137,6 +154,7 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) { | ||
| 137 | UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext) | 154 | UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext) |
| 138 | adminApiGateway = http_gateway.NewHttplibBusinessAdminApiServiceGateway() | 155 | adminApiGateway = http_gateway.NewHttplibBusinessAdminApiServiceGateway() |
| 139 | ) | 156 | ) |
| 157 | + | ||
| 140 | doGetCompanyIds := func() []int64 { | 158 | doGetCompanyIds := func() []int64 { |
| 141 | var companies []int64 | 159 | var companies []int64 |
| 142 | for i := range svr.PartnerInfo { | 160 | for i := range svr.PartnerInfo { |
| @@ -144,6 +162,7 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) { | @@ -144,6 +162,7 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) { | ||
| 144 | } | 162 | } |
| 145 | return companies | 163 | return companies |
| 146 | } | 164 | } |
| 165 | + | ||
| 147 | doGetPartnerIds := func() []int64 { | 166 | doGetPartnerIds := func() []int64 { |
| 148 | var array []int64 | 167 | var array []int64 |
| 149 | for i := range svr.PartnerInfo { | 168 | for i := range svr.PartnerInfo { |
| @@ -151,17 +170,21 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) { | @@ -151,17 +170,21 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) { | ||
| 151 | } | 170 | } |
| 152 | return array | 171 | return array |
| 153 | } | 172 | } |
| 173 | + | ||
| 154 | companyList = svr.GetCompanyList(doGetCompanyIds) | 174 | companyList = svr.GetCompanyList(doGetCompanyIds) |
| 155 | if len(companyList) == 0 { | 175 | if len(companyList) == 0 { |
| 156 | return response, nil | 176 | return response, nil |
| 157 | } | 177 | } |
| 178 | + | ||
| 158 | totalBonus, e := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{InPartnerIds: doGetPartnerIds(), OrderTypes: domain.UserOrderTypes(domain.Career)}) | 179 | totalBonus, e := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{InPartnerIds: doGetPartnerIds(), OrderTypes: domain.UserOrderTypes(domain.Career)}) |
| 159 | if e != nil { | 180 | if e != nil { |
| 160 | return response, e | 181 | return response, e |
| 161 | } | 182 | } |
| 183 | + | ||
| 162 | if businessBonus, e := BusinessBonusDao.OrderBonusStatics(domain.OrderBonusQuery{InPartnerIds: doGetPartnerIds(), IsDisable: 1}); e == nil { | 184 | if businessBonus, e := BusinessBonusDao.OrderBonusStatics(domain.OrderBonusQuery{InPartnerIds: doGetPartnerIds(), IsDisable: 1}); e == nil { |
| 163 | totalBonus.Bonus += businessBonus.Bonus | 185 | totalBonus.Bonus += businessBonus.Bonus |
| 164 | } | 186 | } |
| 187 | + | ||
| 165 | _, allPartnerCategory, e = PartnerCategoryInfoRepository.Find(map[string]interface{}{"sortById": domain.ASC}) | 188 | _, allPartnerCategory, e = PartnerCategoryInfoRepository.Find(map[string]interface{}{"sortById": domain.ASC}) |
| 166 | var mapPartnerBussinessBonus = make(map[int64]*domain.BusinessBonus) | 189 | var mapPartnerBussinessBonus = make(map[int64]*domain.BusinessBonus) |
| 167 | if _, bussinessBonus, e := BusinessBonusRepository.Find(map[string]interface{}{"inPartnerIds": doGetPartnerIds(), "isDisable": 1}); e == nil { | 190 | if _, bussinessBonus, e := BusinessBonusRepository.Find(map[string]interface{}{"inPartnerIds": doGetPartnerIds(), "isDisable": 1}); e == nil { |
| @@ -224,6 +247,7 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) { | @@ -224,6 +247,7 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) { | ||
| 224 | return response, nil | 247 | return response, nil |
| 225 | } | 248 | } |
| 226 | 249 | ||
| 250 | +// 高管统计信息 | ||
| 227 | func (svr *PgLoginService) ManagerStaticInfo() (interface{}, error) { | 251 | func (svr *PgLoginService) ManagerStaticInfo() (interface{}, error) { |
| 228 | response := make(map[string]interface{}) | 252 | response := make(map[string]interface{}) |
| 229 | response["id"] = protocolx.AdminTypeManager | 253 | response["id"] = protocolx.AdminTypeManager |
| @@ -392,11 +416,14 @@ func (svr *PgLoginService) RegistryGuest(phone string) error { | @@ -392,11 +416,14 @@ func (svr *PgLoginService) RegistryGuest(phone string) error { | ||
| 392 | PartnerInfoService, _ = repository.NewPartnerInfoRepository(svr.transactionContext) | 416 | PartnerInfoService, _ = repository.NewPartnerInfoRepository(svr.transactionContext) |
| 393 | UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext) | 417 | UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext) |
| 394 | ) | 418 | ) |
| 419 | + | ||
| 395 | partnerInfo, errPartner := PartnerInfoService.FindOne(map[string]interface{}{"account": phone}) | 420 | partnerInfo, errPartner := PartnerInfoService.FindOne(map[string]interface{}{"account": phone}) |
| 396 | user, errUser := UsersRepository.FindOne(map[string]interface{}{"phone": phone}) | 421 | user, errUser := UsersRepository.FindOne(map[string]interface{}{"phone": phone}) |
| 422 | + | ||
| 397 | if partnerInfo != nil || user != nil { | 423 | if partnerInfo != nil || user != nil { |
| 398 | return nil | 424 | return nil |
| 399 | } | 425 | } |
| 426 | + | ||
| 400 | if errUser != nil && errPartner != nil { | 427 | if errUser != nil && errPartner != nil { |
| 401 | id := time.Now().Unix() | 428 | id := time.Now().Unix() |
| 402 | errPartner = svr.transactionContext.PgDd.Insert(&models.PartnerInfo{ | 429 | errPartner = svr.transactionContext.PgDd.Insert(&models.PartnerInfo{ |
| @@ -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 |
-
请 注册 或 登录 后发表评论