anniversary.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. "math"
  6. "strconv"
  7. "strings"
  8. "go-common/app/interface/openplatform/article/model"
  9. account "go-common/app/service/main/account/model"
  10. )
  11. // AnniversaryInfo get reader and author info in passed year
  12. func (s *Service) AnniversaryInfo(c context.Context, mid int64) (res *model.AnniversaryInfo, err error) {
  13. if res, err = s.dao.CacheAnniversary(c, mid); err != nil {
  14. return
  15. }
  16. if res == nil {
  17. res = new(model.AnniversaryInfo)
  18. }
  19. res.Mid = mid
  20. user, _ := s.accountRPC.Info3(c, &account.ArgMid{Mid: mid})
  21. if user != nil {
  22. res.Uname = user.Name
  23. res.Face = user.Face
  24. }
  25. if res.AuthorInfo != nil && res.AuthorInfo.ReaderMid != 0 {
  26. user, _ := s.accountRPC.Info3(c, &account.ArgMid{Mid: res.AuthorInfo.ReaderMid})
  27. if user != nil {
  28. res.AuthorInfo.ReaderUname = user.Name
  29. res.AuthorInfo.ReaderFace = user.Face
  30. }
  31. }
  32. if res.ReaderInfo != nil && res.ReaderInfo.AuthorMid != 0 {
  33. wordsFloat := float64(res.ReaderInfo.Words) / 1000
  34. res.ReaderInfo.Words = int64(math.Pow(wordsFloat, 2))
  35. rankFloat, _ := strconv.ParseFloat(strings.Split(res.ReaderInfo.Rank, "%")[0], 10)
  36. rankFloat = rankFloat / 100
  37. rankFloat = math.Pow(rankFloat, 2)
  38. res.ReaderInfo.Rank = fmt.Sprintf("%.2f", rankFloat*100) + "%"
  39. user, _ := s.accountRPC.Info3(c, &account.ArgMid{Mid: res.ReaderInfo.AuthorMid})
  40. if user != nil {
  41. res.ReaderInfo.AuthorUname = user.Name
  42. }
  43. }
  44. return
  45. }