From 88e6febe371d11e40899fe41a67202981ffe8377 Mon Sep 17 00:00:00 2001 From: timerzz Date: Thu, 23 May 2024 20:48:04 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=B7=BB=E5=8A=A0=E6=8A=98=E6=89=A3?= =?UTF-8?q?=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/build-push.yml | 22 ++++++++++++---------- .ko.yaml | 16 ++++++++++++++++ go.mod | 2 +- go.sum | 2 ++ product/option.go | 12 +++++++++--- 5 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 .ko.yaml diff --git a/.gitea/workflows/build-push.yml b/.gitea/workflows/build-push.yml index f44ffb2..3d2a87a 100644 --- a/.gitea/workflows/build-push.yml +++ b/.gitea/workflows/build-push.yml @@ -4,13 +4,15 @@ jobs: build: runs-on: ubuntu-latest steps: - - name: Checkout - uses: https://gitea.timerzz.com/timerzz/checkout@v4 - - name: build - run: docker build -t ${{ vars.DOCKER_REGISTRY }}/${{ vars.IMAGE_NAME }}:1.3 -f Dockerfile . - - name: tag - run: docker tag ${{ vars.DOCKER_REGISTRY }}/${{ vars.IMAGE_NAME }}:1.3 ${{ vars.DOCKER_REGISTRY }}/${{ vars.IMAGE_NAME }}:latest - - name: push 1.3 - run: docker push ${{ vars.DOCKER_REGISTRY }}/${{ vars.IMAGE_NAME }}:1.3 - - name: push latest - run: docker push ${{ vars.DOCKER_REGISTRY }}/${{ vars.IMAGE_NAME }}:latest \ No newline at end of file + - uses: https://gitea.timerzz.com/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 + with: + version: v0.15.4 + env: + KO_DOCKER_REPO: 192.168.31.55:5000/kedaya/spider + - run: ko build --bare ./cmd \ No newline at end of file diff --git a/.ko.yaml b/.ko.yaml new file mode 100644 index 0000000..f7afd36 --- /dev/null +++ b/.ko.yaml @@ -0,0 +1,16 @@ +defaultPlatforms: + - linux/amd64 +defaultBaseImage: alpine:latest +builds: + - id: spider + dir: . # default is . + main: ./cmd + env: + - CGO_ENABLED=0 + - GOPROXY=https://goproxy.cn,direct + - GOPRIVATE=gitea.timerzz.com + - GONOSUMDB=gitea.timerzz.com + - GONOPROXY=gitea.timerzz.com + ldflags: + - -s -w + - -extldflags "-static" diff --git a/go.mod b/go.mod index 2ba9944..6d9a90c 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.22.2 toolchain go1.22.3 require ( - gitea.timerzz.com/kedaya_haitao/common v0.0.0-20240521073651-0653521e73ea + gitea.timerzz.com/kedaya_haitao/common v0.0.0-20240523124237-7957d28fe0a8 github.com/gofiber/fiber/v3 v3.0.0-beta.2 github.com/golang/glog v1.2.1 github.com/samber/lo v1.39.0 diff --git a/go.sum b/go.sum index 9728775..1c304b1 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= gitea.timerzz.com/kedaya_haitao/common v0.0.0-20240521073651-0653521e73ea h1:asjEGs0rxu+pMXEd6bWipoingfhLBG1qP3Gt6lSy2Kg= gitea.timerzz.com/kedaya_haitao/common v0.0.0-20240521073651-0653521e73ea/go.mod h1:cgLy4gB0z2UZD3kBp1IAemt28dkaKNdt4RC0LNkE1I8= +gitea.timerzz.com/kedaya_haitao/common v0.0.0-20240523124237-7957d28fe0a8 h1:aUthZ9k3epcwM//WCwSu1h3Q3tpESLz4qXFiH5d6rjk= +gitea.timerzz.com/kedaya_haitao/common v0.0.0-20240523124237-7957d28fe0a8/go.mod h1:cgLy4gB0z2UZD3kBp1IAemt28dkaKNdt4RC0LNkE1I8= github.com/3andne/restls-client-go v0.1.6 h1:tRx/YilqW7iHpgmEL4E1D8dAsuB0tFF3uvncS+B6I08= github.com/3andne/restls-client-go v0.1.6/go.mod h1:iEdTZNt9kzPIxjIGSMScUFSBrUH6bFRNg0BWlP4orEY= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= diff --git a/product/option.go b/product/option.go index 0bc87b2..e15d862 100644 --- a/product/option.go +++ b/product/option.go @@ -11,10 +11,11 @@ type Option struct { Interval time.Duration `yaml:"interval" json:"interval"` ExchangeRate float64 `yaml:"exchangeRate" json:"exchangeRate"` //汇率 Freight float64 `yaml:"freight" json:"freight"` //运费 + Discount int `yaml:"discount" json:"discount"` //折扣 } func (c *Controller) LoadOption() { - c.db.FirstOrCreate(&c.Option, Option{Interval: time.Hour * 12, ExchangeRate: 7.3, Freight: 100}) + c.db.Where("id = ?", 1).Attrs(Option{Interval: time.Hour * 12, ExchangeRate: 7.3, Freight: 100, Discount: 100}).FirstOrCreate(&c.Option) } func (c *Controller) SaveOption(opt Option) { @@ -31,14 +32,18 @@ func (c *Controller) SaveOption(opt Option) { c.Option.Freight, oldFreight = opt.Freight, c.Option.Freight change = true } + if opt.Discount > 0 && opt.Discount != c.Option.Discount { + c.Option.Discount = opt.Discount + change = true + } opt.ID = 1 c.db.Updates(opt) if change { - c.updateExchangeRateAndFreight(oldFreight) + c.updateRate(oldFreight) } } -func (c *Controller) updateExchangeRateAndFreight(oldFreight float64) { +func (c *Controller) updateRate(oldFreight float64) { var results []*productv1.Product c.db.FindInBatches(&results, 20, func(tx *gorm.DB, batch int) error { for _, result := range results { @@ -46,6 +51,7 @@ func (c *Controller) updateExchangeRateAndFreight(oldFreight float64) { result.Freight = c.Option.Freight } result.ExchangeRate = c.Option.ExchangeRate + result.Discount = c.Option.Discount } // 保存对当前批记录的修改