feat 捕获通知添加库存

This commit is contained in:
timerzz 2024-09-01 17:00:09 +08:00
parent 4b02235be4
commit 7268758aec
2 changed files with 16 additions and 12 deletions

View File

@ -2,14 +2,6 @@ package main
import ( import (
"context" "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/options"
"haitao_watcher/pkg/watcher" "haitao_watcher/pkg/watcher"
"haitao_watcher/server" "haitao_watcher/server"
@ -18,6 +10,15 @@ import (
"os" "os"
"os/signal" "os/signal"
"time" "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() { func main() {
@ -59,6 +60,6 @@ func main() {
server.NewProxySvc(pool).RegistryRouter(api) server.NewProxySvc(pool).RegistryRouter(api)
if err = r.Listen(":8080"); err != nil { if err = r.Listen(":8080"); err != nil {
glog.Warningf("server over: %v", err) glog.Warningf("service over: %v", err)
} }
} }

View File

@ -21,6 +21,8 @@ type CoachOutlet struct {
ctx context.Context ctx context.Context
cancel context.CancelFunc cancel context.CancelFunc
client *coach_client.US client *coach_client.US
// 库存
ats int
} }
func NewCoachWatcher(ctx context.Context, client *coach_client.US, cfg *model.WatchInfo, db *gorm.DB) *CoachOutlet { func NewCoachWatcher(ctx context.Context, client *coach_client.US, cfg *model.WatchInfo, db *gorm.DB) *CoachOutlet {
@ -121,10 +123,11 @@ func (c *CoachOutlet) doWatch() bool {
glog.Warningf("获取coach %s 库存失败:%v", c.cfg.Pid, err) glog.Warningf("获取coach %s 库存失败:%v", c.cfg.Pid, err)
return false return false
} }
c.cfg.Orderable = inventory.Orderable c.cfg.Orderable = inventory.Orderable && inventory.Ats > 0
if !inventory.AllocationResetDate.IsZero() { if !inventory.AllocationResetDate.IsZero() {
c.cfg.AllocationResetDate = inventory.AllocationResetDate c.cfg.AllocationResetDate = inventory.AllocationResetDate
} }
c.ats = inventory.Ats
if c.cfg.Orderable { if c.cfg.Orderable {
c.cfg.Watch = false c.cfg.Watch = false
} }
@ -146,7 +149,7 @@ func (c *CoachOutlet) Push() {
resp, err := pusher.Push(c.ctx, &push.PushReq{ resp, err := pusher.Push(c.ctx, &push.PushReq{
Ids: c.cfg.ToPusherIds(), Ids: c.cfg.ToPusherIds(),
Title: "coach 补货", 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 { if err != nil {
glog.Errorf("消息推送失败:%v", err) glog.Errorf("消息推送失败:%v", err)