talent.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package service
  2. import (
  3. "context"
  4. "github.com/sirupsen/logrus"
  5. "net/url"
  6. "strconv"
  7. "strings"
  8. "youngee_b_api/db"
  9. "youngee_b_api/model/http_model"
  10. )
  11. var Talent *talent
  12. type talent struct {
  13. }
  14. func (*talent) GetGoodsTalentList(ctx context.Context, request http_model.GetGoodsTalentRequest) (*http_model.GetGoodsTalentListData, error) {
  15. res, err := db.GetGoodstalentList(ctx, request)
  16. if err != nil {
  17. logrus.WithContext(ctx).Errorf("[talent service] call GetGoodsTalentList error,err:%+v", err)
  18. return nil, err
  19. }
  20. return res, nil
  21. }
  22. func (*talent) GetProjectTalentList(ctx context.Context, request http_model.GetProjectTalentRequest) (*http_model.GetProjectTalentListData, error) {
  23. res, err := db.GetProjecttalentList(ctx, request)
  24. if err != nil {
  25. logrus.WithContext(ctx).Errorf("[talent service] call GetProjectTalentList error,err:%+v", err)
  26. return nil, err
  27. }
  28. return res, nil
  29. }
  30. func (*talent) GetLocallifeTalentList(ctx context.Context, request http_model.GetLocallifeTalentRequest) (*http_model.GetLocallifeTalentListData, error) {
  31. res, err := db.GetLocallifetalentList(ctx, request)
  32. if err != nil {
  33. logrus.WithContext(ctx).Errorf("[talent service] call GetLocallifeTalentList error,err:%+v", err)
  34. return nil, err
  35. }
  36. return res, nil
  37. }
  38. // GetHistoryDataList 历史作品列表
  39. func (*talent) GetHistoryDataList(ctx context.Context, request *http_model.HistoryDataListRequest) (*http_model.HistoryDataListData, error) {
  40. var historyRespList *http_model.HistoryDataListData
  41. historyRespList = &http_model.HistoryDataListData{}
  42. // 1. 查找达人第三方平台授权信息
  43. platformUserInfo, platformUserErr := db.FindUserInfoById(ctx, request.PlatformUserId)
  44. if platformUserErr != nil {
  45. return nil, platformUserErr
  46. }
  47. if platformUserInfo != nil {
  48. // 2. 查找平台历史作品列表
  49. // 小红书
  50. if platformUserInfo.PlatformId == 1 {
  51. // 取出主页链接中的uid
  52. u, uidErr := url.Parse(platformUserInfo.HomePageUrl)
  53. if uidErr != nil {
  54. return nil, uidErr
  55. }
  56. pathParts := strings.Split(u.Path, "/")
  57. uId := pathParts[len(pathParts)-1]
  58. // fmt.Print(uId)
  59. historyList, historyErr := GetRedBookHistoryList(ctx, uId)
  60. if historyErr != nil {
  61. return nil, historyErr
  62. }
  63. if historyList != nil {
  64. for _, history := range historyList {
  65. var historyResp *http_model.HistoryDataList
  66. historyResp = &http_model.HistoryDataList{}
  67. like, likeErr := strconv.Atoi(history.Likes)
  68. if likeErr != nil {
  69. return nil, likeErr
  70. }
  71. comments, commentErr := strconv.Atoi(history.Comments)
  72. if commentErr != nil {
  73. return nil, commentErr
  74. }
  75. collect, collectErr := strconv.Atoi(history.Collects)
  76. if collectErr != nil {
  77. return nil, collectErr
  78. }
  79. historyResp.LikeCount = like
  80. historyResp.CommitCount = comments
  81. historyResp.CollectCount = collect
  82. historyResp.CreatedAt = history.CreatedAt
  83. historyResp.Name = history.Text
  84. historyResp.MainPhotoUrl = history.CoverImageUrl
  85. historyRespList.TalentLocalDataListInfo = append(historyRespList.TalentLocalDataListInfo, historyResp)
  86. }
  87. }
  88. } else if platformUserInfo.PlatformId == 3 {
  89. // 微博
  90. historyList, err := GetWeiBoHistoryList(ctx, platformUserInfo.HomePageUrl)
  91. if err != nil {
  92. return nil, err
  93. }
  94. if historyList != nil {
  95. for _, history := range historyList {
  96. var historyResp *http_model.HistoryDataList
  97. historyResp = &http_model.HistoryDataList{}
  98. historyResp.LikeCount = history.Likes
  99. historyResp.CommitCount = history.Comments
  100. historyResp.CollectCount = history.Reposts
  101. historyResp.CreatedAt = history.CreatedAt
  102. historyResp.Name = history.Text
  103. historyRespList.TalentLocalDataListInfo = append(historyRespList.TalentLocalDataListInfo, historyResp)
  104. }
  105. historyRespList.Total = int64(len(historyRespList.TalentLocalDataListInfo))
  106. }
  107. }
  108. }
  109. return historyRespList, nil
  110. }