feat 添加查询库存工具
All checks were successful
Build image / build (push) Successful in 2m3s

This commit is contained in:
timerzz 2024-11-21 17:21:17 +08:00
parent bec654c8ce
commit eb0b51c2f3
2 changed files with 21 additions and 0 deletions

View File

@ -28,6 +28,7 @@ func (s *SpiderSvc) Registry(r fiber.Router) {
api.Post(fmt.Sprintf("provider/%s/price/fetch/:id", s.providerId), s.FetchArticlePrice) api.Post(fmt.Sprintf("provider/%s/price/fetch/:id", s.providerId), s.FetchArticlePrice)
api.Post(fmt.Sprintf("provider/%s/detail/fetch/:pid", s.providerId), s.FetchArticleDetail) api.Post(fmt.Sprintf("provider/%s/detail/fetch/:pid", s.providerId), s.FetchArticleDetail)
api.Post(fmt.Sprintf("provider/%s/ats/fetch/:pid", s.providerId), s.FetchArticleAts) api.Post(fmt.Sprintf("provider/%s/ats/fetch/:pid", s.providerId), s.FetchArticleAts)
api.Get(fmt.Sprintf("provider/%s/ats/:pid", s.providerId), s.GetArticleAts)
//r.Post("spider/us/coach-outlet/calculate", s.UpsertCalculate) //r.Post("spider/us/coach-outlet/calculate", s.UpsertCalculate)
//r.Delete("spider/us/coach-outlet/calculate/u/:id", s.DelCalculate) //r.Delete("spider/us/coach-outlet/calculate/u/:id", s.DelCalculate)
@ -73,6 +74,18 @@ func (s *SpiderSvc) FetchArticleAts(ctx fiber.Ctx) error {
return ctx.JSON(web.NewResponse("ok")) return ctx.JSON(web.NewResponse("ok"))
} }
func (s *SpiderSvc) GetArticleAts(ctx fiber.Ctx) error {
pid := ctx.Params("pid")
if pid == "" {
return fmt.Errorf("pid is empty")
}
ats, err := s.ctl.GetArticleAts(ctx.Context(), pid)
if err != nil {
return err
}
return ctx.JSON(web.NewResponse(ats))
}
//func (s *SpiderSvc) DelCalculate(ctx fiber.Ctx) error { //func (s *SpiderSvc) DelCalculate(ctx fiber.Ctx) error {
// idStr := ctx.Params("id") // idStr := ctx.Params("id")
// if idStr == "" { // if idStr == "" {

View File

@ -325,6 +325,14 @@ func (c *Controller) FetchArticleAts(ctx context.Context, pid string) error {
return c.storage.ProviderArticle().Update(pArticle, "ast") return c.storage.ProviderArticle().Update(pArticle, "ast")
} }
func (c *Controller) GetArticleAts(ctx context.Context, pid string) (int, error) {
inv, err := c.client.RequestInventory(ctx, pid)
if err != nil {
return 0, fmt.Errorf("请求商品库存失败: %v", err)
}
return inv.Ats, nil
}
// 更新某个商品的价格 // 更新某个商品的价格
func (c *Controller) FetchArticlePrice(ctx context.Context, id uint) error { func (c *Controller) FetchArticlePrice(ctx context.Context, id uint) error {
pArticle, err := c.storage.ProviderArticle().Get(storage.NewGetProviderArticleQuery().SetProviderId(c.providerId).SetID(id)) pArticle, err := c.storage.ProviderArticle().Get(storage.NewGetProviderArticleQuery().SetProviderId(c.providerId).SetID(id))