package service import ( "context" "github.com/sirupsen/logrus" "net/url" "strconv" "strings" "youngee_b_api/db" "youngee_b_api/model/http_model" ) var Talent *talent type talent struct { } func (*talent) GetGoodsTalentList(ctx context.Context, request http_model.GetGoodsTalentRequest) (*http_model.GetGoodsTalentListData, error) { res, err := db.GetGoodstalentList(ctx, request) if err != nil { logrus.WithContext(ctx).Errorf("[talent service] call GetGoodsTalentList error,err:%+v", err) return nil, err } return res, nil } func (*talent) GetProjectTalentList(ctx context.Context, request http_model.GetProjectTalentRequest) (*http_model.GetProjectTalentListData, error) { res, err := db.GetProjecttalentList(ctx, request) if err != nil { logrus.WithContext(ctx).Errorf("[talent service] call GetProjectTalentList error,err:%+v", err) return nil, err } return res, nil } func (*talent) GetLocallifeTalentList(ctx context.Context, request http_model.GetLocallifeTalentRequest) (*http_model.GetLocallifeTalentListData, error) { res, err := db.GetLocallifetalentList(ctx, request) if err != nil { logrus.WithContext(ctx).Errorf("[talent service] call GetLocallifeTalentList error,err:%+v", err) return nil, err } return res, nil } // GetHistoryDataList 历史作品列表 func (*talent) GetHistoryDataList(ctx context.Context, request *http_model.HistoryDataListRequest) (*http_model.HistoryDataListData, error) { var historyRespList *http_model.HistoryDataListData historyRespList = &http_model.HistoryDataListData{} // 1. 查找达人第三方平台授权信息 platformUserInfo, platformUserErr := db.FindUserInfoById(ctx, request.PlatformUserId) if platformUserErr != nil { return nil, platformUserErr } if platformUserInfo != nil { // 2. 查找平台历史作品列表 // 小红书 if platformUserInfo.PlatformId == 1 { // 取出主页链接中的uid u, uidErr := url.Parse(platformUserInfo.HomePageUrl) if uidErr != nil { return nil, uidErr } pathParts := strings.Split(u.Path, "/") uId := pathParts[len(pathParts)-1] // fmt.Print(uId) historyList, historyErr := GetRedBookHistoryList(ctx, uId) if historyErr != nil { return nil, historyErr } if historyList != nil { for _, history := range historyList { var historyResp *http_model.HistoryDataList historyResp = &http_model.HistoryDataList{} like, likeErr := strconv.Atoi(history.Likes) if likeErr != nil { return nil, likeErr } comments, commentErr := strconv.Atoi(history.Comments) if commentErr != nil { return nil, commentErr } collect, collectErr := strconv.Atoi(history.Collects) if collectErr != nil { return nil, collectErr } historyResp.LikeCount = like historyResp.CommitCount = comments historyResp.CollectCount = collect historyResp.CreatedAt = history.CreatedAt historyResp.Name = history.Text historyResp.MainPhotoUrl = history.CoverImageUrl historyRespList.TalentLocalDataListInfo = append(historyRespList.TalentLocalDataListInfo, historyResp) } } } else if platformUserInfo.PlatformId == 3 { // 微博 historyList, err := GetWeiBoHistoryList(ctx, platformUserInfo.HomePageUrl) if err != nil { return nil, err } if historyList != nil { for _, history := range historyList { var historyResp *http_model.HistoryDataList historyResp = &http_model.HistoryDataList{} historyResp.LikeCount = history.Likes historyResp.CommitCount = history.Comments historyResp.CollectCount = history.Reposts historyResp.CreatedAt = history.CreatedAt historyResp.Name = history.Text historyRespList.TalentLocalDataListInfo = append(historyRespList.TalentLocalDataListInfo, historyResp) } historyRespList.Total = int64(len(historyRespList.TalentLocalDataListInfo)) } } } return historyRespList, nil }