From 7268758aeccca523a630c3745d2d3ae1eeff0023 Mon Sep 17 00:00:00 2001 From: timerzz Date: Sun, 1 Sep 2024 17:00:09 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=8D=95=E8=8E=B7=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BA=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/main.go | 19 ++++++++++--------- pkg/watcher/coach.go | 9 ++++++--- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/main/main.go b/main/main.go index e897337..0ac41c8 100644 --- a/main/main.go +++ b/main/main.go @@ -2,14 +2,6 @@ package main import ( "context" - "gitea.timerzz.com/kedaya_haitao/common/pkg/database" - "gitea.timerzz.com/kedaya_haitao/common/pkg/proxy" - "gitea.timerzz.com/kedaya_haitao/pusher/rpc/pusher" - "github.com/cloudwego/kitex/client" - "github.com/gofiber/fiber/v3" - "github.com/gofiber/fiber/v3/middleware/cors" - "github.com/golang/glog" - "gorm.io/gorm/logger" "haitao_watcher/pkg/options" "haitao_watcher/pkg/watcher" "haitao_watcher/server" @@ -18,6 +10,15 @@ import ( "os" "os/signal" "time" + + "gitea.timerzz.com/kedaya_haitao/common/pkg/database" + "gitea.timerzz.com/kedaya_haitao/common/pkg/proxy" + "gitea.timerzz.com/kedaya_haitao/pusher/rpc/pusher" + "github.com/cloudwego/kitex/client" + "github.com/gofiber/fiber/v3" + "github.com/gofiber/fiber/v3/middleware/cors" + "github.com/golang/glog" + "gorm.io/gorm/logger" ) func main() { @@ -59,6 +60,6 @@ func main() { server.NewProxySvc(pool).RegistryRouter(api) if err = r.Listen(":8080"); err != nil { - glog.Warningf("server over: %v", err) + glog.Warningf("service over: %v", err) } } diff --git a/pkg/watcher/coach.go b/pkg/watcher/coach.go index f60c19c..a2ce538 100644 --- a/pkg/watcher/coach.go +++ b/pkg/watcher/coach.go @@ -21,6 +21,8 @@ type CoachOutlet struct { ctx context.Context cancel context.CancelFunc client *coach_client.US + // 库存 + ats int } func NewCoachWatcher(ctx context.Context, client *coach_client.US, cfg *model.WatchInfo, db *gorm.DB) *CoachOutlet { @@ -54,7 +56,7 @@ func (c *CoachOutlet) Restart() { func (c *CoachOutlet) Watch() { c.ctx, c.cancel = context.WithCancel(c.fCtx) c.cfg.Watch, c.cfg.Orderable = true, false - if err := c.db.Model(c.cfg).Where("uid = ?", c.cfg.Uid).Updates(map[string]interface{}{"watch": true, "orderable": false}).Error; err != nil { + if err := c.db.Model(c.cfg).Where("uid=?", c.cfg.Uid).Updates(map[string]interface{}{"watch": true, "orderable": false}).Error; err != nil { glog.Errorf("watch update db err: %v", err) err = nil } @@ -121,10 +123,11 @@ func (c *CoachOutlet) doWatch() bool { glog.Warningf("获取coach %s 库存失败:%v", c.cfg.Pid, err) return false } - c.cfg.Orderable = inventory.Orderable + c.cfg.Orderable = inventory.Orderable && inventory.Ats > 0 if !inventory.AllocationResetDate.IsZero() { c.cfg.AllocationResetDate = inventory.AllocationResetDate } + c.ats = inventory.Ats if c.cfg.Orderable { c.cfg.Watch = false } @@ -146,7 +149,7 @@ func (c *CoachOutlet) Push() { resp, err := pusher.Push(c.ctx, &push.PushReq{ Ids: c.cfg.ToPusherIds(), Title: "coach 补货", - Content: fmt.Sprintf("coach 商品 %s 补货\n商品名:%s\n链接:%s", c.cfg.Pid, c.cfg.Name, c.cfg.Link), + Content: fmt.Sprintf("coach 商品 %s 补货\n商品名:%s\n库存:%d\n链接:%s", c.cfg.Pid, c.cfg.Name, c.ats, c.cfg.Link), }) if err != nil { glog.Errorf("消息推送失败:%v", err)