package playletser import ( "fmt" "net/url" "strconv" "videoweb/app/service/upstream" "github.com/gin-gonic/gin" ) const boughtListPath = "/api/app/playlet/bought/list" // PlayletBoughtData 对应 proto.PlayletBoughtData;只列出页面所需字段。 type PlayletBoughtData struct { ID int64 `json:"id"` Title string `json:"title"` PlayName string `json:"playName"` Slug string `json:"slug"` Cover string `json:"cover"` ThemeNames []string `json:"themeNames"` TotalEpisode int `json:"totalEpisode"` BoughtChapterCount int `json:"boughtChapterCount"` CostCoins int64 `json:"costCoins"` BoughtAt string `json:"boughtAt"` LastChapterID int64 `json:"lastChapterId"` LastEpisode int `json:"lastEpisode"` WatchedCount int `json:"watchedCount"` } type PlayletBoughtListResp struct { List []PlayletBoughtData `json:"list"` PageNum int `json:"pageNum"` PageSize int `json:"pageSize"` TotalCount int64 `json:"totalCount"` } func FetchBoughtList(c *gin.Context, pageNum, pageSize int) (*PlayletBoughtListResp, int, error) { if pageNum < 1 { pageNum = 1 } if pageSize < 1 { pageSize = 20 } params := url.Values{} params.Set("pageNum", strconv.Itoa(pageNum)) params.Set("pageSize", strconv.Itoa(pageSize)) var env APIEnvelope[PlayletBoughtListResp] if err := upstream.GetJSON(c, boughtListPath+"?"+params.Encode(), &env); err != nil { return nil, 0, err } if env.Code != 200 { return nil, env.Code, fmt.Errorf("playlet bought list code=%d msg=%s", env.Code, env.Msg) } return &env.Data, env.Code, nil }