nav.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/interface/main/web/model"
  5. accmdl "go-common/app/service/main/account/api"
  6. coupon "go-common/app/service/main/coupon/model"
  7. "go-common/library/log"
  8. "go-common/library/sync/errgroup"
  9. )
  10. // Nav api service
  11. func (s *Service) Nav(c context.Context, mid int64, cookie string) (resp *model.NavResp, err error) {
  12. var (
  13. wallet *model.Wallet
  14. hasShop bool
  15. shopURL string
  16. allowance int
  17. )
  18. profile := new(accmdl.ProfileStatReply)
  19. eg, egCtx := errgroup.WithContext(c)
  20. eg.Go(func() error {
  21. var e error
  22. if profile, e = s.accClient.ProfileWithStat3(egCtx, &accmdl.MidReq{Mid: mid}); e != nil {
  23. log.Error("s.accClient.ProfileWithStat3(%d) error %v", mid, e)
  24. profile = model.DefaultProfile
  25. profile.Profile.Mid = mid
  26. }
  27. return nil
  28. })
  29. eg.Go(func() error {
  30. var shop *model.ShopInfo
  31. var e error
  32. if shop, e = s.dao.ShopInfo(egCtx, mid); e == nil && shop != nil {
  33. hasShop = true
  34. shopURL = shop.JumpURL
  35. } else {
  36. log.Warn("s.dao.ShopInfo(%v) error(%+v)", mid, e)
  37. }
  38. return nil
  39. })
  40. eg.Go(func() error {
  41. var e error
  42. if wallet, e = s.dao.Wallet(egCtx, mid); e != nil || wallet == nil {
  43. log.Error("s.dao.Wallet(%d) error(%v)", mid, e)
  44. if wallet, e = s.dao.OldWallet(egCtx, mid); e != nil || wallet == nil {
  45. log.Error("s.dao.OldWallet(%d) error(%v)", mid, e)
  46. }
  47. } else {
  48. log.Info("account wallet mid(%d)", mid)
  49. }
  50. return nil
  51. })
  52. eg.Go(func() error {
  53. var e error
  54. if allowance, e = s.coupon.AllowanceCount(egCtx, &coupon.ArgAllowanceMid{Mid: mid}); e != nil {
  55. log.Error("s.coupon.AllowanceCount(%d) error(%v)", mid, e)
  56. }
  57. return nil
  58. })
  59. eg.Wait()
  60. resp = &model.NavResp{
  61. IsLogin: true,
  62. EmailVerified: int(profile.Profile.EmailStatus),
  63. Face: profile.Profile.Face,
  64. Mid: profile.Profile.Mid,
  65. MobileVerified: int(profile.Profile.TelStatus),
  66. Coins: profile.Coins,
  67. Moral: float32(profile.Profile.Moral),
  68. Pendant: profile.Profile.Pendant,
  69. Uname: profile.Profile.Name,
  70. VipDueDate: profile.Profile.Vip.DueDate,
  71. VipStatus: int(profile.Profile.Vip.Status),
  72. VipType: int(profile.Profile.Vip.Type),
  73. VipPayType: profile.Profile.Vip.VipPayType,
  74. Wallet: wallet,
  75. HasShop: hasShop,
  76. ShopURL: shopURL,
  77. AllowanceCount: allowance,
  78. }
  79. if profile.Profile.Official.Role == 0 {
  80. resp.OfficialVerify.Type = -1
  81. } else {
  82. if profile.Profile.Official.Role <= 2 {
  83. resp.OfficialVerify.Type = 0
  84. } else {
  85. resp.OfficialVerify.Type = 1
  86. }
  87. resp.OfficialVerify.Desc = profile.Profile.Official.Title
  88. }
  89. resp.LevelInfo.Cur = int(profile.LevelInfo.Cur)
  90. resp.LevelInfo.Min = int(profile.LevelInfo.Min)
  91. resp.LevelInfo.NowExp = int(profile.LevelInfo.NowExp)
  92. resp.LevelInfo.NextExp = profile.LevelInfo.NextExp
  93. if profile.LevelInfo.NextExp == -1 {
  94. resp.LevelInfo.NextExp = "--"
  95. }
  96. return
  97. }