diff --git a/pkg/coach-client/ca.go b/pkg/coach-client/ca.go index 865eac0..e4d8e7c 100644 --- a/pkg/coach-client/ca.go +++ b/pkg/coach-client/ca.go @@ -5,6 +5,7 @@ import ( "fmt" "net/url" "os" + "strings" "time" "gitea.timerzz.com/kedaya_haitao/common/pkg/proxy" @@ -98,6 +99,20 @@ func (c *ca) RequestProductDetail(ctx context.Context, pid string) (data Product return } +func (c *ca) RequestProductDetailList(ctx context.Context, pids ...string) (list []*ProductData, err error) { + sctx, cancel := context.WithTimeout(ctx, c.defaultTimeOut) + defer cancel() + var resp ProductDataResponse + var ids = strings.Join(pids, ",") + urlPath := fmt.Sprintf("/api/get-products?ids=%s&includeInventory=false", url.QueryEscape(ids)) + err = tryRequest(sctx, c.baseUrl, urlPath, &resp, c.pool.RandomIterator()) + if len(resp.ProductData) == 0 && err != nil { + err = fmt.Errorf("获取详情信息为空") + return + } + return resp.ProductData, nil +} + func (c *ca) ViewAllBags(ctx context.Context, page int) (resp PageDataResponse, err error) { if page < 1 { page = 1 diff --git a/pkg/coach-client/ca_test.go b/pkg/coach-client/ca_test.go index d1338ff..26ab401 100644 --- a/pkg/coach-client/ca_test.go +++ b/pkg/coach-client/ca_test.go @@ -22,9 +22,9 @@ func TestCAClient(t *testing.T) { //} //t.Log(resp) - inv, err := client.RequestProductDetail(ctx, "CP150-LHBLK") + resp, err := client.RequestProductDetailList(ctx, "CK535-WEC", "CP081-SVVSW", "C9949-SVVDT", "CM235-SVELC", "CP081-JIBLK", "CAA92-IMCHR", "C9949-SVQVE", "CW637-B4CED") if err != nil { t.Fatal(err) } - t.Log(inv) + t.Log(resp) } diff --git a/pkg/coach-client/us.go b/pkg/coach-client/us.go index 4a038ec..cdab408 100644 --- a/pkg/coach-client/us.go +++ b/pkg/coach-client/us.go @@ -5,6 +5,7 @@ import ( "fmt" "net/url" "os" + "strings" "time" "gitea.timerzz.com/kedaya_haitao/common/pkg/proxy" @@ -108,6 +109,7 @@ func (u *USClientBuilder) CreateByType(clientType string) USCAClient { type USCAClient interface { RequestInventory(ctx context.Context, pid string) (inv Inventory, err error) RequestProductDetail(ctx context.Context, pid string) (data ProductData, err error) + RequestProductDetailList(ctx context.Context, pids ...string) (list []*ProductData, err error) ViewAllBags(ctx context.Context, page int) (resp PageDataResponse, err error) BaseUrl() string } @@ -236,6 +238,20 @@ func (c *us) RequestProductDetail(ctx context.Context, pid string) (data Product return } +func (c *us) RequestProductDetailList(ctx context.Context, pids ...string) (list []*ProductData, err error) { + sctx, cancel := context.WithTimeout(ctx, c.defaultTimeOut) + defer cancel() + var resp ProductDataResponse + var ids = strings.Join(pids, ",") + urlPath := fmt.Sprintf("/api/get-products?ids=%s&includeInventory=false", url.QueryEscape(ids)) + err = tryRequest(sctx, c.baseUrl, urlPath, &resp, c.pool.RandomIterator()) + if len(resp.ProductData) == 0 && err != nil { + err = fmt.Errorf("获取详情信息为空") + return + } + return resp.ProductData, nil +} + type PageDataResponse struct { PageData struct { Total int `json:"total"` diff --git a/pkg/coach-client/us_test.go b/pkg/coach-client/us_test.go index 04c360e..fbbd357 100644 --- a/pkg/coach-client/us_test.go +++ b/pkg/coach-client/us_test.go @@ -15,7 +15,7 @@ func TestClient(t *testing.T) { Interval: 10 * time.Minute, }) client := US(pool).CreateByType(USClient_Type_Coach) - resp, err := client.ViewAllBags(context.Background(), 1) + resp, err := client.RequestProductDetailList(context.Background(), "CK535-WEC", "CP081-SVVSW", "C9949-SVVDT", "CM235-SVELC", "CP081-JIBLK", "CAA92-IMCHR", "C9949-SVQVE", "CW637-B4CED") if err != nil { t.Fatal(err) }