作者 yangfu

1.review code

@@ -13,3 +13,7 @@ require ( @@ -13,3 +13,7 @@ require (
13 github.com/shopspring/decimal v1.2.0 13 github.com/shopspring/decimal v1.2.0
14 github.com/tiptok/gocomm v1.0.2 14 github.com/tiptok/gocomm v1.0.2
15 ) 15 )
  16 +
  17 +replace (
  18 + github.com/tiptok/gocomm v1.0.2 => F:\go\src\learn_project\gocomm
  19 +)
@@ -19,6 +19,7 @@ import ( @@ -19,6 +19,7 @@ import (
19 "time" 19 "time"
20 ) 20 )
21 21
  22 +// 该方法废弃
22 func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp *protocol.LoginResponse, err error) { 23 func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp *protocol.LoginResponse, err error) {
23 var ( 24 var (
24 transactionContext, _ = factory.CreateTransactionContext(nil) 25 transactionContext, _ = factory.CreateTransactionContext(nil)
@@ -222,7 +223,7 @@ func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshT @@ -222,7 +223,7 @@ func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshT
222 return 223 return
223 } 224 }
224 225
225 -//验证短信验证码 T 226 +// 验证短信验证码 T
226 func CheckSmsCode(phone, code string) (result bool, err error) { 227 func CheckSmsCode(phone, code string) (result bool, err error) {
227 sms, _ := factory.CreateSmsCodeService() 228 sms, _ := factory.CreateSmsCodeService()
228 var data map[string]interface{} 229 var data map[string]interface{}
@@ -236,7 +237,7 @@ func CheckSmsCode(phone, code string) (result bool, err error) { @@ -236,7 +237,7 @@ func CheckSmsCode(phone, code string) (result bool, err error) {
236 return 237 return
237 } 238 }
238 239
239 -//验证手机号码(修改手机号码、重置密码的前一步) 240 +// 验证手机号码(修改手机号码、重置密码的前一步)
240 func AuthCheckSmsCode(header *protocol.RequestHeader, request *protocol.AuthCheckSmsCodeRequest) (rsp *protocol.AuthCheckSmsCodeResponse, err error) { 241 func AuthCheckSmsCode(header *protocol.RequestHeader, request *protocol.AuthCheckSmsCodeRequest) (rsp *protocol.AuthCheckSmsCodeResponse, err error) {
241 var () 242 var ()
242 if _, err = CheckSmsCode(request.Phone, request.Captcha); err != nil { 243 if _, err = CheckSmsCode(request.Phone, request.Captcha); err != nil {
@@ -248,7 +249,7 @@ func AuthCheckSmsCode(header *protocol.RequestHeader, request *protocol.AuthChec @@ -248,7 +249,7 @@ func AuthCheckSmsCode(header *protocol.RequestHeader, request *protocol.AuthChec
248 return 249 return
249 } 250 }
250 251
251 -//注销登录 252 +// 注销登录
252 func Revoke(header *protocol.RequestHeader, request *protocol.RevokeRequest) (rsp *protocol.RevokeResponse, err error) { 253 func Revoke(header *protocol.RequestHeader, request *protocol.RevokeRequest) (rsp *protocol.RevokeResponse, err error) {
253 //auth := userAuth.NewRedisUserAuth(userAuth.WithUserId(header.UserId)) 254 //auth := userAuth.NewRedisUserAuth(userAuth.WithUserId(header.UserId))
254 //rsp = &protocol.RevokeResponse{} 255 //rsp = &protocol.RevokeResponse{}
@@ -263,7 +264,7 @@ func Revoke(header *protocol.RequestHeader, request *protocol.RevokeRequest) (rs @@ -263,7 +264,7 @@ func Revoke(header *protocol.RequestHeader, request *protocol.RevokeRequest) (rs
263 return 264 return
264 } 265 }
265 266
266 -//注销登录 267 +// 注销登录
267 func UCenterRevoke(header *protocol.RequestHeader, userId int64) (rsp *protocol.RevokeResponse, err error) { 268 func UCenterRevoke(header *protocol.RequestHeader, userId int64) (rsp *protocol.RevokeResponse, err error) {
268 var ( 269 var (
269 transactionContext, _ = factory.CreateTransactionContext(nil) 270 transactionContext, _ = factory.CreateTransactionContext(nil)
@@ -300,7 +301,8 @@ func UCenterRevoke(header *protocol.RequestHeader, userId int64) (rsp *protocol. @@ -300,7 +301,8 @@ func UCenterRevoke(header *protocol.RequestHeader, userId int64) (rsp *protocol.
300 return 301 return
301 } 302 }
302 303
303 -func CenterCompanys(header *protocol.RequestHeader, request *protocolx.CenterCompanysRequest) (v interface{}, err error) { 304 +// 企业平台-多公司登录
  305 +func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCompanysRequest) (v interface{}, err error) {
304 var ( 306 var (
305 transactionContext, _ = factory.CreateTransactionContext(nil) 307 transactionContext, _ = factory.CreateTransactionContext(nil)
306 imInfo *domain.ImInfo 308 imInfo *domain.ImInfo
@@ -320,14 +322,14 @@ func CenterCompanys(header *protocol.RequestHeader, request *protocolx.CenterCom @@ -320,14 +322,14 @@ func CenterCompanys(header *protocol.RequestHeader, request *protocolx.CenterCom
320 defer func() { 322 defer func() {
321 transactionContext.RollbackTransaction() 323 transactionContext.RollbackTransaction()
322 }() 324 }()
323 - 325 + // 通过短信验证码登录的游客,注册一个账号到配置的公司去(ios审核使用)
324 if request.GrantType == protocol.LoginBySmsCode { 326 if request.GrantType == protocol.LoginBySmsCode {
325 e := loginSvr.RegistryGuest(request.Phone) 327 e := loginSvr.RegistryGuest(request.Phone)
326 if e != nil { 328 if e != nil {
327 log.Error(e) 329 log.Error(e)
328 } 330 }
329 } 331 }
330 - 332 + // loginSvr 初始化
331 loginSvr.Init(request.Phone) 333 loginSvr.Init(request.Phone)
332 if len(loginSvr.Users) == 0 && len(loginSvr.PartnerInfo) == 0 { 334 if len(loginSvr.Users) == 0 && len(loginSvr.PartnerInfo) == 0 {
333 err = protocol.NewErrWithMessage(10001) 335 err = protocol.NewErrWithMessage(10001)
@@ -365,22 +367,21 @@ func CenterCompanys(header *protocol.RequestHeader, request *protocolx.CenterCom @@ -365,22 +367,21 @@ func CenterCompanys(header *protocol.RequestHeader, request *protocolx.CenterCom
365 break 367 break
366 } 368 }
367 369
368 - //获取统计信息 370 + // 获取统计信息(合伙人/高管)
369 rsp.Partner, _ = loginSvr.PartnerStaticInfo() 371 rsp.Partner, _ = loginSvr.PartnerStaticInfo()
370 rsp.Manager, _ = loginSvr.ManagerStaticInfo() 372 rsp.Manager, _ = loginSvr.ManagerStaticInfo()
371 - //没有有效人的时候  
372 - if !loginSvr.AvailableCompany { 373 + if !loginSvr.HasAvailableCompany {
373 err = protocol.NewErrWithMessage(10008) //账号禁用 374 err = protocol.NewErrWithMessage(10008) //账号禁用
374 return 375 return
375 } 376 }
376 377
  378 + // 初始化网易IM信息
377 var nickName string 379 var nickName string
378 if len(loginSvr.Users) > 0 { 380 if len(loginSvr.Users) > 0 {
379 nickName = loginSvr.Users[0].Name 381 nickName = loginSvr.Users[0].Name
380 } else if len(loginSvr.PartnerInfo) > 0 { 382 } else if len(loginSvr.PartnerInfo) > 0 {
381 nickName = loginSvr.PartnerInfo[0].PartnerName 383 nickName = loginSvr.PartnerInfo[0].PartnerName
382 } 384 }
383 - //初始化im信息  
384 if imInfo, err = InitOrUpdateUserIMInfo(int64(phoneId), nickName, transactionContext); err != nil { 385 if imInfo, err = InitOrUpdateUserIMInfo(int64(phoneId), nickName, transactionContext); err != nil {
385 log.Error(err) 386 log.Error(err)
386 return 387 return
@@ -395,12 +396,13 @@ func CenterCompanys(header *protocol.RequestHeader, request *protocolx.CenterCom @@ -395,12 +396,13 @@ func CenterCompanys(header *protocol.RequestHeader, request *protocolx.CenterCom
395 //添加手机对应的凭证 396 //添加手机对应的凭证
396 userAuth.NewRedisUserCredential(request.Phone).AddAuth(rsp.Credentials) 397 userAuth.NewRedisUserCredential(request.Phone).AddAuth(rsp.Credentials)
397 398
398 - err = transactionContext.CommitTransaction()  
399 v = map[string]interface{}{"center": rsp} 399 v = map[string]interface{}{"center": rsp}
  400 + err = transactionContext.CommitTransaction()
400 return 401 return
401 } 402 }
402 403
403 -func Companys(header *protocol.RequestHeader, request *protocolx.CompanysRequest) (rsp *protocolx.CompanysResponse, err error) { 404 +// 企业平台-多公司登录 - 通过凭证
  405 +func CompaniesLoginByCredential(header *protocol.RequestHeader, request *protocolx.CompanysRequest) (rsp *protocolx.CompanysResponse, err error) {
404 var ( 406 var (
405 transactionContext, _ = factory.CreateTransactionContext(nil) 407 transactionContext, _ = factory.CreateTransactionContext(nil)
406 loginSvr = domain_service.NewPgLoginService(transactionContext) 408 loginSvr = domain_service.NewPgLoginService(transactionContext)
@@ -424,11 +426,12 @@ func Companys(header *protocol.RequestHeader, request *protocolx.CompanysRequest @@ -424,11 +426,12 @@ func Companys(header *protocol.RequestHeader, request *protocolx.CompanysRequest
424 err = protocol.NewErrWithMessage(4140, err) 426 err = protocol.NewErrWithMessage(4140, err)
425 return 427 return
426 } 428 }
  429 +
  430 + // loginSvr 初始化
427 loginSvr.Init(claim.Phone) 431 loginSvr.Init(claim.Phone)
428 rsp.Partner, _ = loginSvr.PartnerStaticInfo() 432 rsp.Partner, _ = loginSvr.PartnerStaticInfo()
429 rsp.Manager, _ = loginSvr.ManagerStaticInfo() 433 rsp.Manager, _ = loginSvr.ManagerStaticInfo()
430 - //没有有效人的时候  
431 - if !loginSvr.AvailableCompany { 434 + if !loginSvr.HasAvailableCompany {
432 err = protocol.NewErrWithMessage(4140, err) //账号禁用 435 err = protocol.NewErrWithMessage(4140, err) //账号禁用
433 return 436 return
434 } 437 }
@@ -437,6 +440,7 @@ func Companys(header *protocol.RequestHeader, request *protocolx.CompanysRequest @@ -437,6 +440,7 @@ func Companys(header *protocol.RequestHeader, request *protocolx.CompanysRequest
437 return 440 return
438 } 441 }
439 442
  443 +// 登录
440 func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) (rsp *protocol.LoginResponse, err error) { 444 func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) (rsp *protocol.LoginResponse, err error) {
441 var ( 445 var (
442 claim *utils.UserTokenClaims 446 claim *utils.UserTokenClaims
@@ -477,12 +481,12 @@ func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) ( @@ -477,12 +481,12 @@ func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) (
477 return 481 return
478 } 482 }
479 } 483 }
480 - //验证公司模块权限  
481 - if _, adminUsers, e := UsersRepository.Find(map[string]interface{}{"inCompanyIds": []int64{int64(request.Cid)}, "adminType": 2, "deleteAtIsNull": true}); e == nil {  
482 - if len(adminUsers) > 0 {  
483 - au := adminUsers[0]  
484 - if code, e := adminApiGateway.UserAuth(au.Id, constant.BUSINESS_ADMIN_PLATFORM_ID); e != nil || code != 0 {  
485 - log.Debug("【合伙人检查权限】", claim.Phone, "【公司】", request.Cid, au.Id, code, e.Error()) 484 + //合伙人 需要验证对应公司模块权限(查询该公司的主管理员是否有权限)
  485 + if _, admins, e := UsersRepository.Find(map[string]interface{}{"inCompanyIds": []int64{int64(request.Cid)}, "adminType": 2, "deleteAtIsNull": true}); e == nil {
  486 + if len(admins) > 0 {
  487 + admin := admins[0]
  488 + if code, e := adminApiGateway.UserAuth(admin.Id, constant.BUSINESS_ADMIN_PLATFORM_ID); e != nil || code != 0 {
  489 + log.Debug("【合伙人检查权限】", claim.Phone, "【公司】", request.Cid, admin.Id, code, e.Error())
486 err = protocol.NewErrWithMessage(10008, err) // 抱歉,企业管理员未帮您开通权限 490 err = protocol.NewErrWithMessage(10008, err) // 抱歉,企业管理员未帮您开通权限
487 return 491 return
488 } 492 }
@@ -497,7 +501,7 @@ func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) ( @@ -497,7 +501,7 @@ func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) (
497 return 501 return
498 } 502 }
499 } 503 }
500 - //校验模块权限 504 + //高管 需要校验高管是否模块权限
501 if userId != 0 { 505 if userId != 0 {
502 if code, e := adminApiGateway.UserAuth(userId, constant.BUSINESS_ADMIN_PLATFORM_ID); e != nil || code != 0 { 506 if code, e := adminApiGateway.UserAuth(userId, constant.BUSINESS_ADMIN_PLATFORM_ID); e != nil || code != 0 {
503 log.Debug("【检查权限】", userId, "【公司】", request.Cid, "【错误】:", code, e.Error()) 507 log.Debug("【检查权限】", userId, "【公司】", request.Cid, "【错误】:", code, e.Error())
@@ -514,7 +518,8 @@ func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) ( @@ -514,7 +518,8 @@ func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) (
514 err = protocol.NewErrWithMessage(10001, err) //账号不存在 518 err = protocol.NewErrWithMessage(10001, err) //账号不存在
515 return 519 return
516 } 520 }
517 - //根据simnum + cid 521 +
  522 + // 生成授权码
518 userClaims := utils.UserTokenClaims{ 523 userClaims := utils.UserTokenClaims{
519 UserId: userId, 524 UserId: userId,
520 CompanyId: int64(request.Cid), 525 CompanyId: int64(request.Cid),
@@ -2,6 +2,7 @@ package company @@ -2,6 +2,7 @@ package company
2 2
3 import ( 3 import (
4 "github.com/tiptok/gocomm/pkg/log" 4 "github.com/tiptok/gocomm/pkg/log"
  5 + "github.com/tiptok/gocomm/sync/task"
5 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory" 6 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory"
6 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" 7 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
7 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" 8 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction"
@@ -11,6 +12,7 @@ import ( @@ -11,6 +12,7 @@ import (
11 "strings" 12 "strings"
12 ) 13 )
13 14
  15 +// 公司属性 合伙人类型/区域
14 func Property(header *protocol.RequestHeader, request *protocolx.PropertyRequest) (rsp *protocolx.PropertyResponse, err error) { 16 func Property(header *protocol.RequestHeader, request *protocolx.PropertyRequest) (rsp *protocolx.PropertyResponse, err error) {
15 var ( 17 var (
16 transactionContext, _ = factory.CreateTransactionContext(nil) 18 transactionContext, _ = factory.CreateTransactionContext(nil)
@@ -24,14 +26,19 @@ func Property(header *protocol.RequestHeader, request *protocolx.PropertyRequest @@ -24,14 +26,19 @@ func Property(header *protocol.RequestHeader, request *protocolx.PropertyRequest
24 transactionContext.RollbackTransaction() 26 transactionContext.RollbackTransaction()
25 }() 27 }()
26 28
27 - //用户查询区域  
28 - if (request.Action & 0x01) > 0 {  
29 - rsp.Districts, _ = getDistricts(header.UserId, transactionContext)  
30 - }  
31 - //查询合伙人类型  
32 - if (request.Action & 0x02) > 0 {  
33 - rsp.JoinWays, _ = getJoinWays(transactionContext)  
34 - } 29 + //并行查询区域/合伙人类型
  30 + task.Parallel(
  31 + func() {
  32 + if (request.Action & 0x01) > 0 {
  33 + rsp.Districts, _ = getDistricts(header.UserId, transactionContext)
  34 + }
  35 + },
  36 + func() {
  37 + if (request.Action & 0x02) > 0 {
  38 + rsp.JoinWays, _ = getJoinWays(transactionContext)
  39 + }
  40 + },
  41 + )
35 err = transactionContext.CommitTransaction() 42 err = transactionContext.CommitTransaction()
36 return 43 return
37 } 44 }
@@ -205,6 +212,32 @@ func getPartners(userId int64, request *protocolx.PartnersRequest, transactionCo @@ -205,6 +212,32 @@ func getPartners(userId int64, request *protocolx.PartnersRequest, transactionCo
205 } 212 }
206 } 213 }
207 214
  215 + queryOption := newQueryOption(request)
  216 +
  217 + if partners, e := PartnerInfo.Partners(user.AccessPartnerIds(), queryOption); e == nil {
  218 + var array []interface{}
  219 + for i := range partners {
  220 + mapPartner := make(map[string]interface{})
  221 + p := partners[i]
  222 + mapPartner["uid"] = p.Id
  223 + mapPartner["uname"] = p.PartnerName
  224 + mapPartner["joinWays"] = newJoinWays(mapCategoryInfo, p)
  225 + if p.RegionInfo != nil {
  226 + mapPartner["district"] = protocolx.Districts{Id: p.RegionInfo.RegionId, Name: p.RegionInfo.RegionName}
  227 + }
  228 + mapPartner["cooperationTime"] = p.CooperateTime.Unix() * 1000
  229 + mapPartner["dividend"] = utils.Decimal(p.Bonus)
  230 + mapPartner["ordersCount"] = p.Total
  231 + mapPartner["ordersMoney"] = utils.Decimal(p.Amount)
  232 + array = append(array, mapPartner)
  233 + }
  234 + return array, nil
  235 + }
  236 + return nil, nil
  237 +}
  238 +
  239 +// 查询参数
  240 +func newQueryOption(request *protocolx.PartnersRequest) map[string]interface{} {
208 queryOption := make(map[string]interface{}) 241 queryOption := make(map[string]interface{})
209 242
210 if len(request.Districts) > 0 { 243 if len(request.Districts) > 0 {
@@ -234,33 +267,16 @@ func getPartners(userId int64, request *protocolx.PartnersRequest, transactionCo @@ -234,33 +267,16 @@ func getPartners(userId int64, request *protocolx.PartnersRequest, transactionCo
234 if request.SortBy != 0 { 267 if request.SortBy != 0 {
235 queryOption["sortByBonus"] = domain.ASC 268 queryOption["sortByBonus"] = domain.ASC
236 } 269 }
  270 + return queryOption
  271 +}
237 272
238 - if partners, e := PartnerInfo.Partners(user.AccessPartnerIds(), queryOption); e == nil {  
239 - var array []interface{}  
240 - for i := range partners {  
241 - mapPartners := make(map[string]interface{})  
242 - p := partners[i]  
243 - mapPartners["uid"] = p.Id  
244 - mapPartners["uname"] = p.PartnerName  
245 -  
246 - var joinWays []protocolx.JoinWays  
247 - for j := range p.PartnerCategoryInfos {  
248 - c := p.PartnerCategoryInfos[j]  
249 - if v, ok := mapCategoryInfo[c.Id]; ok {  
250 - joinWays = append(joinWays, protocolx.JoinWays{Type: v.Id, Name: v.Name})  
251 - }  
252 - }  
253 - mapPartners["joinWays"] = joinWays  
254 - if p.RegionInfo != nil {  
255 - mapPartners["district"] = protocolx.Districts{Id: p.RegionInfo.RegionId, Name: p.RegionInfo.RegionName}  
256 - }  
257 - mapPartners["cooperationTime"] = p.CooperateTime.Unix() * 1000  
258 - mapPartners["dividend"] = utils.Decimal(p.Bonus)  
259 - mapPartners["ordersCount"] = p.Total  
260 - mapPartners["ordersMoney"] = utils.Decimal(p.Amount)  
261 - array = append(array, mapPartners) 273 +func newJoinWays(mapCategoryInfo map[int64]*domain.PartnerCategoryInfo, p *domain.PartnerStatics) []protocolx.JoinWays {
  274 + var joinWays []protocolx.JoinWays
  275 + for j := range p.PartnerCategoryInfos {
  276 + c := p.PartnerCategoryInfos[j]
  277 + if v, ok := mapCategoryInfo[c.Id]; ok {
  278 + joinWays = append(joinWays, protocolx.JoinWays{Type: v.Id, Name: v.Name})
262 } 279 }
263 - return array, nil  
264 } 280 }
265 - return nil, nil 281 + return joinWays
266 } 282 }
@@ -48,8 +48,8 @@ func getPartnersV2(userId int64, request *protocolx.PartnersRequest, transaction @@ -48,8 +48,8 @@ func getPartnersV2(userId int64, request *protocolx.PartnersRequest, transaction
48 } 48 }
49 49
50 var company *domain.Company 50 var company *domain.Company
51 - var CompanyResponsitory, _ = factory.CreateCompanyRepository(transactionContext)  
52 - if company, err = CompanyResponsitory.FindOne(map[string]interface{}{"id": user.CompanyId}); err != nil { 51 + var CompanyRepository, _ = factory.CreateCompanyRepository(transactionContext)
  52 + if company, err = CompanyRepository.FindOne(map[string]interface{}{"id": user.CompanyId}); err != nil {
53 return nil, err 53 return nil, err
54 } 54 }
55 55
@@ -63,7 +63,31 @@ func getPartnersV2(userId int64, request *protocolx.PartnersRequest, transaction @@ -63,7 +63,31 @@ func getPartnersV2(userId int64, request *protocolx.PartnersRequest, transaction
63 } 63 }
64 } 64 }
65 65
  66 + queryOption := newQueryOptionV2(request)
  67 + if partners, e := PartnerInfo.Partners(user.AccessPartnerIds(), queryOption); e == nil {
  68 + var array []interface{}
  69 + for i := range partners {
  70 + mapPartners := make(map[string]interface{})
  71 + p := partners[i]
  72 + mapPartners["uid"] = p.Id
  73 + mapPartners["uname"] = p.PartnerName
  74 + mapPartners["joinWays"] = newJoinWays(mapCategoryInfo, p)
  75 + mapPartners["dividend"] = utils.Decimal(p.Bonus)
  76 + mapPartners["ordersCount"] = p.Total
  77 + mapPartners["ordersMoney"] = utils.Decimal(p.Amount)
  78 + mapPartners["phone"] = p.Account
  79 + mapPartners["company"] = newCompany(company, p)
  80 + array = append(array, mapPartners)
  81 + }
  82 + return array, nil
  83 + }
  84 + return nil, nil
  85 +}
  86 +
  87 +// 查询参数
  88 +func newQueryOptionV2(request *protocolx.PartnersRequest) map[string]interface{} {
66 queryOption := make(map[string]interface{}) 89 queryOption := make(map[string]interface{})
  90 +
67 if len(request.Districts) > 0 { 91 if len(request.Districts) > 0 {
68 var districts []string 92 var districts []string
69 for i := 0; i < len(request.Districts); i++ { 93 for i := 0; i < len(request.Districts); i++ {
@@ -91,77 +115,23 @@ func getPartnersV2(userId int64, request *protocolx.PartnersRequest, transaction @@ -91,77 +115,23 @@ func getPartnersV2(userId int64, request *protocolx.PartnersRequest, transaction
91 if request.SortBy != 0 { 115 if request.SortBy != 0 {
92 queryOption["sortByBonus"] = domain.ASC 116 queryOption["sortByBonus"] = domain.ASC
93 } 117 }
94 -  
95 - if partners, e := PartnerInfo.Partners(user.AccessPartnerIds(), queryOption); e == nil {  
96 - var array []interface{}  
97 - for i := range partners {  
98 - mapPartners := make(map[string]interface{})  
99 - p := partners[i]  
100 - mapPartners["uid"] = p.Id  
101 - mapPartners["uname"] = p.PartnerName  
102 -  
103 - var joinWays []protocolx.JoinWays  
104 - for j := range p.PartnerCategoryInfos {  
105 - c := p.PartnerCategoryInfos[j]  
106 - if v, ok := mapCategoryInfo[c.Id]; ok {  
107 - joinWays = append(joinWays, protocolx.JoinWays{Type: v.Id, Name: v.Name})  
108 - }  
109 - }  
110 - mapPartners["joinWays"] = joinWays  
111 -  
112 - mapPartners["dividend"] = utils.Decimal(p.Bonus)  
113 - mapPartners["ordersCount"] = p.Total  
114 - mapPartners["ordersMoney"] = utils.Decimal(p.Amount)  
115 - mapPartners["phone"] = p.Account  
116 -  
117 - partnerCompany := userx.Company{  
118 - Id: company.Id,  
119 - Name: company.Name,  
120 - Phone: company.Phone,  
121 - SerialNo: p.Id,  
122 - CooperateTime: p.CooperateTime.Unix() * 1000,  
123 - MiniProgram: nil,  
124 - District: map[string]interface{}{"id": p.RegionInfo.RegionId, "name": p.RegionInfo.RegionName},  
125 - }  
126 - if len(p.Salesman) > 0 {  
127 - partnerCompany.Salesman = map[string]interface{}{"uname": p.Salesman[0].Name, "phone": p.Salesman[0].Telephone}  
128 - } else {  
129 - partnerCompany.Salesman = map[string]interface{}{}  
130 - }  
131 - mapPartners["company"] = partnerCompany  
132 -  
133 - array = append(array, mapPartners)  
134 - }  
135 - return array, nil  
136 - }  
137 - return nil, nil 118 + return queryOption
138 } 119 }
139 120
140 -func funcPartnerCompanyInfo(companyId int64, transactionContext *transaction.TransactionContext) (partnerCompany userx.Company, err error) {  
141 - var (  
142 - CompanyResponsitory, _ = factory.CreateCompanyRepository(transactionContext)  
143 - company *domain.Company  
144 - )  
145 - if company, err = CompanyResponsitory.FindOne(map[string]interface{}{"id": companyId}); err != nil {  
146 - return 121 +func newCompany(company *domain.Company, p *domain.PartnerStatics) userx.Company {
  122 + partnerCompany := userx.Company{
  123 + Id: company.Id,
  124 + Name: company.Name,
  125 + Phone: company.Phone,
  126 + SerialNo: p.Id,
  127 + CooperateTime: p.CooperateTime.Unix() * 1000,
  128 + MiniProgram: nil,
  129 + District: map[string]interface{}{"id": p.RegionInfo.RegionId, "name": p.RegionInfo.RegionName},
147 } 130 }
148 -  
149 - partnerCompany = userx.Company{  
150 - Id: company.Id,  
151 - Name: company.Name,  
152 - Phone: company.Phone,  
153 - //SerialNo: partnerInfo.Id,  
154 - //CooperateTime: partnerInfo.CooperateTime.Unix() * 1000,  
155 - MiniProgram: nil,  
156 - //District: map[string]interface{}{"id": partnerInfo.RegionInfo.RegionId, "name": partnerInfo.RegionInfo.RegionName}, 131 + if len(p.Salesman) > 0 {
  132 + partnerCompany.Salesman = map[string]interface{}{"uname": p.Salesman[0].Name, "phone": p.Salesman[0].Telephone}
  133 + } else {
  134 + partnerCompany.Salesman = map[string]interface{}{}
157 } 135 }
158 -  
159 - //if len(partnerInfo.Salesman) > 0 {  
160 - // u.CooperateCompany.Salesman = map[string]interface{}{"uname": partnerInfo.Salesman[0].Name, "phone": partnerInfo.Salesman[0].Telephone}  
161 - //} else {  
162 - // u.CooperateCompany.Salesman = map[string]interface{}{}  
163 - //}  
164 - //rspMap["user"] = u  
165 - //rsp = rspMap  
166 - return 136 + return partnerCompany
167 } 137 }
@@ -124,11 +124,10 @@ func OrderList(header *protocol.RequestHeader, request *protocol.DividendOrdersR @@ -124,11 +124,10 @@ func OrderList(header *protocol.RequestHeader, request *protocol.DividendOrdersR
124 rsp = &protocol.DividendOrdersResponse{List: make([]*protocol.DividendOrderListItem, 0)} 124 rsp = &protocol.DividendOrdersResponse{List: make([]*protocol.DividendOrderListItem, 0)}
125 125
126 count, orders, err = OrderDao.DividendOrders(&domain.DividendOrdersQueryOption{ 126 count, orders, err = OrderDao.DividendOrders(&domain.DividendOrdersQueryOption{
127 - OrderTypes: domain.UserOrderTypes(domain.Career),  
128 - PartnerId: request.PartnerId,  
129 - DetailAction: request.DetailAction,  
130 - DividendAction: request.DividendAction,  
131 - //IsDisable: "0", 127 + OrderTypes: domain.UserOrderTypes(domain.Career),
  128 + PartnerId: request.PartnerId,
  129 + DetailAction: request.DetailAction,
  130 + DividendAction: request.DividendAction,
132 StartTime: request.StartTime, 131 StartTime: request.StartTime,
133 EndTime: request.EndTime, 132 EndTime: request.EndTime,
134 Offset: request.PageIndex * request.PageSize, 133 Offset: request.PageIndex * request.PageSize,
@@ -145,7 +144,7 @@ func OrderList(header *protocol.RequestHeader, request *protocol.DividendOrdersR @@ -145,7 +144,7 @@ func OrderList(header *protocol.RequestHeader, request *protocol.DividendOrdersR
145 item := &protocol.DividendOrderListItem{ 144 item := &protocol.DividendOrderListItem{
146 Id: o.Id, 145 Id: o.Id,
147 DeliveryNo: o.DeliveryCode, 146 DeliveryNo: o.DeliveryCode,
148 - OrderAmount: s.PlanOrderAmount, //s.OrderAmount(), 147 + OrderAmount: s.PlanOrderAmount,
149 DividendReceivable: utils.Decimal(s.OrderTotalReceivable()), 148 DividendReceivable: utils.Decimal(s.OrderTotalReceivable()),
150 } 149 }
151 rsp.List = append(rsp.List, item) 150 rsp.List = append(rsp.List, item)
1 package order 1 package order
2 2
3 import ( 3 import (
  4 + "github.com/tiptok/gocomm/sync/task"
4 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory" 5 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory"
5 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" 6 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
6 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" 7 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils"
@@ -23,9 +24,8 @@ func StatisticsV2(header *protocol.RequestHeader, request *protocol.OrderStatist @@ -23,9 +24,8 @@ func StatisticsV2(header *protocol.RequestHeader, request *protocol.OrderStatist
23 rsp = &protocol.OrderStatisticsResponse{} 24 rsp = &protocol.OrderStatisticsResponse{}
24 25
25 //事业分红/业务分红 26 //事业分红/业务分红
26 - var total float64 //,developBonus,appBonus,careerBonus, businessBonus, 27 + var total float64
27 if bonus, e := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{PartnerId: request.PartnerId, OrderTypes: domain.UserOrderTypes(domain.Career)}); e == nil { 28 if bonus, e := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{PartnerId: request.PartnerId, OrderTypes: domain.UserOrderTypes(domain.Career)}); e == nil {
28 - //careerBonus = bonus.Bonus  
29 total += bonus.Bonus 29 total += bonus.Bonus
30 } 30 }
31 calcOrderStatic := func(catId int, total float64) protocol.OrderStatic { 31 calcOrderStatic := func(catId int, total float64) protocol.OrderStatic {
@@ -55,10 +55,12 @@ func StatisticsV2(header *protocol.RequestHeader, request *protocol.OrderStatist @@ -55,10 +55,12 @@ func StatisticsV2(header *protocol.RequestHeader, request *protocol.OrderStatist
55 CumulativeMoney: utils.Decimal(cumulativeMoney), 55 CumulativeMoney: utils.Decimal(cumulativeMoney),
56 } 56 }
57 } 57 }
58 - rsp.Career = calcOrderStatic(domain.Career, total)  
59 - rsp.Business = calcOrderStatic(domain.Business, total)  
60 - rsp.Develop = calcOrderStatic(domain.Develop, total)  
61 - rsp.App = calcOrderStatic(domain.App, total) 58 + task.Parallel(
  59 + func() { rsp.Career = calcOrderStatic(domain.Career, total) },
  60 + func() { rsp.Business = calcOrderStatic(domain.Business, total) },
  61 + func() { rsp.Develop = calcOrderStatic(domain.Develop, total) },
  62 + func() { rsp.App = calcOrderStatic(domain.App, total) },
  63 + )
62 64
63 err = transactionContext.CommitTransaction() 65 err = transactionContext.CommitTransaction()
64 return 66 return
@@ -12,6 +12,7 @@ import ( @@ -12,6 +12,7 @@ import (
12 protocolx "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/partner" 12 protocolx "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/partner"
13 ) 13 )
14 14
  15 +// 模块已废弃
15 func Detail(header *protocol.RequestHeader, request *protocolx.DetailRequest) (rsp *protocolx.DetailResponse, err error) { 16 func Detail(header *protocol.RequestHeader, request *protocolx.DetailRequest) (rsp *protocolx.DetailResponse, err error) {
16 var ( 17 var (
17 transactionContext, _ = factory.CreateTransactionContext(nil) 18 transactionContext, _ = factory.CreateTransactionContext(nil)
@@ -22,14 +22,14 @@ import ( @@ -22,14 +22,14 @@ import (
22 //用户信息 22 //用户信息
23 func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) (rsp *protocol.UserInfoResponse, err error) { 23 func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) (rsp *protocol.UserInfoResponse, err error) {
24 var ( 24 var (
25 - partnerInfo *domain.PartnerInfo  
26 - transactionContext, _ = factory.CreateTransactionContext(nil)  
27 - CompanyResponsitory, _ = factory.CreateCompanyRepository(transactionContext)  
28 - PartnerInfoService, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext)  
29 - UsersRepository, _ = factory.CreateUsersRepository(transactionContext)  
30 - ImInfoRepository, _ = factory.CreateImInfoRepository(transactionContext)  
31 - company *domain.Company  
32 - user *domain.Users 25 + partnerInfo *domain.PartnerInfo
  26 + transactionContext, _ = factory.CreateTransactionContext(nil)
  27 + CompanyRepository, _ = factory.CreateCompanyRepository(transactionContext)
  28 + PartnerInfoService, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext)
  29 + UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
  30 + ImInfoRepository, _ = factory.CreateImInfoRepository(transactionContext)
  31 + company *domain.Company
  32 + user *domain.Users
33 ) 33 )
34 if err = transactionContext.StartTransaction(); err != nil { 34 if err = transactionContext.StartTransaction(); err != nil {
35 return nil, err 35 return nil, err
@@ -44,7 +44,7 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) @@ -44,7 +44,7 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest)
44 err = protocol.NewErrWithMessage(502, err) //账号不存在 44 err = protocol.NewErrWithMessage(502, err) //账号不存在
45 return 45 return
46 } 46 }
47 - if company, err = CompanyResponsitory.FindOne(map[string]interface{}{"id": header.CompanyId}); err != nil { 47 + if company, err = CompanyRepository.FindOne(map[string]interface{}{"id": header.CompanyId}); err != nil {
48 return 48 return
49 } 49 }
50 rsp.User = protocol.User{ 50 rsp.User = protocol.User{
@@ -72,7 +72,7 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) @@ -72,7 +72,7 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest)
72 err = protocol.NewErrWithMessage(502, err) //账号不存在 72 err = protocol.NewErrWithMessage(502, err) //账号不存在
73 return 73 return
74 } 74 }
75 - if company, err = CompanyResponsitory.FindOne(map[string]interface{}{"id": header.CompanyId}); err != nil { 75 + if company, err = CompanyRepository.FindOne(map[string]interface{}{"id": header.CompanyId}); err != nil {
76 return 76 return
77 } 77 }
78 rsp.User = protocol.User{ 78 rsp.User = protocol.User{
@@ -188,13 +188,13 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass @@ -188,13 +188,13 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass
188 188
189 func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoRequest) (rsp interface{}, err error) { 189 func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoRequest) (rsp interface{}, err error) {
190 var ( 190 var (
191 - partnerInfo *domain.PartnerInfo  
192 - transactionContext, _ = factory.CreateTransactionContext(nil)  
193 - CompanyResponsitory, _ = factory.CreateCompanyRepository(transactionContext)  
194 - PartnerInfoService, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext)  
195 - UsersRepository, _ = factory.CreateUsersRepository(transactionContext)  
196 - company *domain.Company  
197 - user *domain.Users 191 + partnerInfo *domain.PartnerInfo
  192 + transactionContext, _ = factory.CreateTransactionContext(nil)
  193 + CompanyRepository, _ = factory.CreateCompanyRepository(transactionContext)
  194 + PartnerInfoService, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext)
  195 + UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
  196 + company *domain.Company
  197 + user *domain.Users
198 ) 198 )
199 if err = transactionContext.StartTransaction(); err != nil { 199 if err = transactionContext.StartTransaction(); err != nil {
200 return nil, err 200 return nil, err
@@ -209,7 +209,7 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques @@ -209,7 +209,7 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques
209 err = protocol.NewErrWithMessage(502, err) //账号不存在 209 err = protocol.NewErrWithMessage(502, err) //账号不存在
210 return 210 return
211 } 211 }
212 - if company, err = CompanyResponsitory.FindOne(map[string]interface{}{"id": header.CompanyId}); err != nil { 212 + if company, err = CompanyRepository.FindOne(map[string]interface{}{"id": header.CompanyId}); err != nil {
213 return 213 return
214 } 214 }
215 var miniProgram map[string]interface{} 215 var miniProgram map[string]interface{}
@@ -253,7 +253,7 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques @@ -253,7 +253,7 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques
253 err = protocol.NewErrWithMessage(502, err) //账号不存在 253 err = protocol.NewErrWithMessage(502, err) //账号不存在
254 return 254 return
255 } 255 }
256 - if company, err = CompanyResponsitory.FindOne(map[string]interface{}{"id": header.CompanyId}); err != nil { 256 + if company, err = CompanyRepository.FindOne(map[string]interface{}{"id": header.CompanyId}); err != nil {
257 return 257 return
258 } 258 }
259 rspMap["user"] = userx.User{ 259 rspMap["user"] = userx.User{
@@ -23,7 +23,8 @@ type PgLoginService struct { @@ -23,7 +23,8 @@ type PgLoginService struct {
23 PartnerInfo []*domain.PartnerInfo 23 PartnerInfo []*domain.PartnerInfo
24 Users []*domain.Users 24 Users []*domain.Users
25 transactionContext *transaction.TransactionContext 25 transactionContext *transaction.TransactionContext
26 - AvailableCompany bool 26 + // 标识:登录的账号信息是否有可用的公司, true:有 false:没有
  27 + HasAvailableCompany bool
27 } 28 }
28 29
29 func (svr *PgLoginService) Init(phone string) (err error) { 30 func (svr *PgLoginService) Init(phone string) (err error) {
@@ -166,7 +167,7 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) { @@ -166,7 +167,7 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) {
166 companys = append(companys, item) 167 companys = append(companys, item)
167 } 168 }
168 if len(companys) > 0 { 169 if len(companys) > 0 {
169 - svr.AvailableCompany = true 170 + svr.HasAvailableCompany = true
170 } 171 }
171 172
172 response["companys"] = companys 173 response["companys"] = companys
@@ -218,7 +219,7 @@ func (svr *PgLoginService) ManagerStaticInfo() (interface{}, error) { @@ -218,7 +219,7 @@ func (svr *PgLoginService) ManagerStaticInfo() (interface{}, error) {
218 companys = append(companys, item) 219 companys = append(companys, item)
219 } 220 }
220 if len(companys) > 0 { 221 if len(companys) > 0 {
221 - svr.AvailableCompany = true 222 + svr.HasAvailableCompany = true
222 } 223 }
223 224
224 response["companys"] = companys 225 response["companys"] = companys
@@ -341,7 +342,7 @@ type joinWay struct { @@ -341,7 +342,7 @@ type joinWay struct {
341 342
342 func NewPgLoginService(ctx *transaction.TransactionContext) *PgLoginService { 343 func NewPgLoginService(ctx *transaction.TransactionContext) *PgLoginService {
343 return &PgLoginService{ 344 return &PgLoginService{
344 - transactionContext: ctx,  
345 - AvailableCompany: false, 345 + transactionContext: ctx,
  346 + HasAvailableCompany: false,
346 } 347 }
347 } 348 }
@@ -183,7 +183,7 @@ func (this *AuthController) CenterCompanys() { @@ -183,7 +183,7 @@ func (this *AuthController) CenterCompanys() {
183 return 183 return
184 } 184 }
185 header := this.GetRequestHeader(this.Ctx) 185 header := this.GetRequestHeader(this.Ctx)
186 - data, err := auth.CenterCompanys(header, request) 186 + data, err := auth.CompaniesLogin(header, request)
187 if err != nil { 187 if err != nil {
188 log.Error(err) 188 log.Error(err)
189 } 189 }
@@ -211,7 +211,7 @@ func (this *AuthController) Companys() { @@ -211,7 +211,7 @@ func (this *AuthController) Companys() {
211 return 211 return
212 } 212 }
213 header := this.GetRequestHeader(this.Ctx) 213 header := this.GetRequestHeader(this.Ctx)
214 - data, err := auth.Companys(header, request) 214 + data, err := auth.CompaniesLoginByCredential(header, request)
215 if err != nil { 215 if err != nil {
216 log.Error(err) 216 log.Error(err)
217 } 217 }
@@ -29,7 +29,7 @@ type LoginResponse struct { @@ -29,7 +29,7 @@ type LoginResponse struct {
29 29
30 type LoginRequestV2 struct { 30 type LoginRequestV2 struct {
31 Cid int `json:"cid"` 31 Cid int `json:"cid"`
32 - IdType int `json:"idType"` 32 + IdType int `json:"idType"` // 用户类型 1:合伙人 2:高管
33 Credentials string `json:"credentials"` // 登录类型 1:密码 2:验证码 33 Credentials string `json:"credentials"` // 登录类型 1:密码 2:验证码
34 ClientId string `json:"clientId"` 34 ClientId string `json:"clientId"`
35 } 35 }