feat 添加新的商品
This commit is contained in:
parent
63633ede61
commit
bec654c8ce
@ -269,6 +269,13 @@ func (c *Controller) saveProducts(articles []v2.Article) {
|
||||
}
|
||||
|
||||
func (c *Controller) FetchArticleDetail(ctx context.Context, pid string) error {
|
||||
old, err := c.storage.ProviderArticle().Get(storage.NewGetProviderArticleQuery().SetProviderId(c.providerId).SetPid(pid))
|
||||
if err == nil {
|
||||
return fmt.Errorf("该商品已经存在")
|
||||
}
|
||||
if !errors.As(err, &gorm.ErrRecordNotFound) {
|
||||
return err
|
||||
}
|
||||
resp, err := c.client.RequestProductDetail(ctx, pid)
|
||||
if err != nil {
|
||||
return fmt.Errorf("请求商品信息失败: %v", err)
|
||||
@ -279,8 +286,8 @@ func (c *Controller) FetchArticleDetail(ctx context.Context, pid string) error {
|
||||
EnglishName: resp.Name,
|
||||
Pid: resp.Id,
|
||||
Brand: v2.Brand_Coach,
|
||||
Providers: []v2.ProviderArticle{
|
||||
{
|
||||
}
|
||||
pArticle := v2.ProviderArticle{
|
||||
ProviderId: c.providerId,
|
||||
Brand: v2.Brand_Coach,
|
||||
Pid: pid,
|
||||
@ -288,9 +295,16 @@ func (c *Controller) FetchArticleDetail(ctx context.Context, pid string) error {
|
||||
Available: resp.Inventory.Orderable,
|
||||
Ast: resp.Inventory.Ats,
|
||||
Link: fmt.Sprintf("%s/%s", "https://www.coachoutlet.com", resp.Url),
|
||||
},
|
||||
},
|
||||
Cost: utils.CalculateProviderPrice(
|
||||
append(c.provider.CalculateProcess, old.CalculateProcess...),
|
||||
map[string]float64{
|
||||
"originalPrice": resp.Prices.CurrentPrice,
|
||||
"freight": c.provider.Config.Freight,
|
||||
"exchangeRate": c.provider.Config.ExchangeRate,
|
||||
}),
|
||||
}
|
||||
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
|
||||
}
|
||||
@ -298,7 +312,7 @@ func (c *Controller) FetchArticleDetail(ctx context.Context, pid string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Controller)FetchArticleAts(ctx context.Context, pid string) error {
|
||||
func (c *Controller) FetchArticleAts(ctx context.Context, pid string) error {
|
||||
pArticle, err := c.storage.ProviderArticle().Get(storage.NewGetProviderArticleQuery().SetProviderId(c.providerId).SetPid(pid))
|
||||
if err != nil {
|
||||
return fmt.Errorf("获取商品信息失败: %v", err)
|
||||
|
Loading…
Reference in New Issue
Block a user