From 1367b729b092c93cf1be60631059fa103b527349 Mon Sep 17 00:00:00 2001 From: timerzz Date: Fri, 29 Nov 2024 16:01:12 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E8=8E=B7=E5=8F=96=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E6=97=B6=E8=8E=B7=E5=8F=96=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 2 +- go.sum | 2 ++ spider/controller.go | 9 ++++++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 407d26c..502c6ba 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.22.2 toolchain go1.22.3 require ( - gitea.timerzz.com/kedaya_haitao/common v0.0.0-20241120131415-18ceb8a07738 + gitea.timerzz.com/kedaya_haitao/common v0.0.0-20241129074538-3eb2ed0d82fb github.com/gofiber/fiber/v3 v3.0.0-beta.3 github.com/golang/glog v1.2.1 github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index 95c249b..79f1cac 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= gitea.timerzz.com/kedaya_haitao/common v0.0.0-20241120131415-18ceb8a07738 h1:H9qFYOZuFamcvNYBDiQ8AIXSu7oBujon3Vd3wndFyqg= gitea.timerzz.com/kedaya_haitao/common v0.0.0-20241120131415-18ceb8a07738/go.mod h1:BIz+IMGznPiyLnV1+Ntw1zf8rEIcbymmGq+EfvDsSgE= +gitea.timerzz.com/kedaya_haitao/common v0.0.0-20241129074538-3eb2ed0d82fb h1:TRUAHaoTMr9DIxtnOJHouObMfh1vcaKHK3XnMiwRd8o= +gitea.timerzz.com/kedaya_haitao/common v0.0.0-20241129074538-3eb2ed0d82fb/go.mod h1:BIz+IMGznPiyLnV1+Ntw1zf8rEIcbymmGq+EfvDsSgE= github.com/3andne/restls-client-go v0.1.6 h1:tRx/YilqW7iHpgmEL4E1D8dAsuB0tFF3uvncS+B6I08= github.com/3andne/restls-client-go v0.1.6/go.mod h1:iEdTZNt9kzPIxjIGSMScUFSBrUH6bFRNg0BWlP4orEY= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= diff --git a/spider/controller.go b/spider/controller.go index 007c3ee..ba4813e 100644 --- a/spider/controller.go +++ b/spider/controller.go @@ -164,6 +164,7 @@ func (c *Controller) productsToArticles(products []coach_client.Product) (articl Pid: color.VgId, SkuID: color.VgId, Available: color.Orderable, + Image: color.Media.Thumbnail.Src, Link: fmt.Sprintf("%s/%s", "https://www.coachoutlet.com", color.Url), } // 拿到现在的价格 @@ -287,6 +288,9 @@ func (c *Controller) FetchArticleDetail(ctx context.Context, pid string) error { Pid: resp.Id, Brand: v2.Brand_Coach, } + if len(resp.ImageGroups) > 0 { + article.Image = resp.ImageGroups[0].Images[0].Src + } pArticle := v2.ProviderArticle{ ProviderId: c.providerId, Brand: v2.Brand_Coach, @@ -294,6 +298,7 @@ func (c *Controller) FetchArticleDetail(ctx context.Context, pid string) error { SkuID: pid, Available: resp.Inventory.Orderable, Ast: resp.Inventory.Ats, + Image: article.Image, Link: fmt.Sprintf("%s/%s", "https://www.coachoutlet.com", resp.Url), Cost: utils.CalculateProviderPrice( append(c.provider.CalculateProcess, old.CalculateProcess...), @@ -305,9 +310,7 @@ func (c *Controller) FetchArticleDetail(ctx context.Context, pid string) error { } pArticle.HistoryPrice = append(pArticle.HistoryPrice, pArticle.Cost) article.Providers = append(article.Providers, pArticle) - if len(resp.ImageGroups) > 0 { - article.Image = resp.ImageGroups[0].Images[0].Src - } + c.saveProducts([]v2.Article{article}) return nil }