diff --git a/.gitea/workflows/build-push.yml b/.gitea/workflows/build-push.yml index 397d824..231cfa7 100644 --- a/.gitea/workflows/build-push.yml +++ b/.gitea/workflows/build-push.yml @@ -4,13 +4,13 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: https://gitea.timerzz.com/timerzz/setup-go@v4 + - uses: http://192.168.31.55:13000/timerzz/setup-go@v4 env: HTTPS_PROXY: http://192.168.31.55:10809 with: go-version: '1.22.x' - - uses: https://gitea.timerzz.com/timerzz/checkout@v4 - - uses: https://gitea.timerzz.com/timerzz/setup-ko@v0.6 + - uses: http://192.168.31.55:13000/timerzz/checkout@v4 + - uses: http://192.168.31.55:13000/timerzz/setup-ko@v0.6 with: version: v0.15.4 env: diff --git a/spider/controller.go b/spider/controller.go index 3c7fa2e..b7c41a8 100644 --- a/spider/controller.go +++ b/spider/controller.go @@ -3,6 +3,8 @@ package spider import ( "context" "fmt" + "time" + "gitea.timerzz.com/kedaya_haitao/cn-coach-spider/pkg/options" "gitea.timerzz.com/kedaya_haitao/common/model/product" coach_client "gitea.timerzz.com/kedaya_haitao/common/pkg/coach-client" @@ -10,7 +12,6 @@ import ( "github.com/samber/lo" "gorm.io/gorm" "gorm.io/gorm/clause" - "time" ) type Controller struct { @@ -97,12 +98,18 @@ func (c *Controller) saveRespData(list []coach_client.CNItem) error { for _, item := range list { var savedProduct productv1.Product c.db.Model(&savedProduct).Where("pid = ?", item.Code).Select("dw_price").Scan(&savedProduct) + var img string + if len(item.Images) > 0 && len(item.Images[0].Imgs) > 0 { + img = item.Images[0].Imgs[0].Img + } else { + glog.Warningf("%s img不存在 %v", item.Code, item) + } p := productv1.Product{ UpdatedAt: time.Now(), Name: item.Title, Pid: item.Code, Link: fmt.Sprintf("%s%s", c.linkPrefix, item.Code), - Image: item.Images[0].Imgs[0].Img, + Image: img, Orderable: item.Stock > 0, DiscPercent: 100 - int(item.DiscountRateMin*100), OriginalPrice: item.SkuMaxPrice,