This commit is contained in:
parent
582ed37908
commit
88e6febe37
@ -4,13 +4,15 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- uses: https://gitea.timerzz.com/timerzz/setup-go@v4
|
||||||
uses: https://gitea.timerzz.com/timerzz/checkout@v4
|
env:
|
||||||
- name: build
|
HTTPS_PROXY: http://192.168.31.55:10809
|
||||||
run: docker build -t ${{ vars.DOCKER_REGISTRY }}/${{ vars.IMAGE_NAME }}:1.3 -f Dockerfile .
|
with:
|
||||||
- name: tag
|
go-version: '1.22.x'
|
||||||
run: docker tag ${{ vars.DOCKER_REGISTRY }}/${{ vars.IMAGE_NAME }}:1.3 ${{ vars.DOCKER_REGISTRY }}/${{ vars.IMAGE_NAME }}:latest
|
- uses: https://gitea.timerzz.com/timerzz/checkout@v4
|
||||||
- name: push 1.3
|
- uses: https://gitea.timerzz.com/timerzz/setup-ko@v0.6
|
||||||
run: docker push ${{ vars.DOCKER_REGISTRY }}/${{ vars.IMAGE_NAME }}:1.3
|
with:
|
||||||
- name: push latest
|
version: v0.15.4
|
||||||
run: docker push ${{ vars.DOCKER_REGISTRY }}/${{ vars.IMAGE_NAME }}:latest
|
env:
|
||||||
|
KO_DOCKER_REPO: 192.168.31.55:5000/kedaya/spider
|
||||||
|
- run: ko build --bare ./cmd
|
16
.ko.yaml
Normal file
16
.ko.yaml
Normal file
@ -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"
|
2
go.mod
2
go.mod
@ -5,7 +5,7 @@ go 1.22.2
|
|||||||
toolchain go1.22.3
|
toolchain go1.22.3
|
||||||
|
|
||||||
require (
|
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/gofiber/fiber/v3 v3.0.0-beta.2
|
||||||
github.com/golang/glog v1.2.1
|
github.com/golang/glog v1.2.1
|
||||||
github.com/samber/lo v1.39.0
|
github.com/samber/lo v1.39.0
|
||||||
|
2
go.sum
2
go.sum
@ -1,6 +1,8 @@
|
|||||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
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 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-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 h1:tRx/YilqW7iHpgmEL4E1D8dAsuB0tFF3uvncS+B6I08=
|
||||||
github.com/3andne/restls-client-go v0.1.6/go.mod h1:iEdTZNt9kzPIxjIGSMScUFSBrUH6bFRNg0BWlP4orEY=
|
github.com/3andne/restls-client-go v0.1.6/go.mod h1:iEdTZNt9kzPIxjIGSMScUFSBrUH6bFRNg0BWlP4orEY=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
|
@ -11,10 +11,11 @@ type Option struct {
|
|||||||
Interval time.Duration `yaml:"interval" json:"interval"`
|
Interval time.Duration `yaml:"interval" json:"interval"`
|
||||||
ExchangeRate float64 `yaml:"exchangeRate" json:"exchangeRate"` //汇率
|
ExchangeRate float64 `yaml:"exchangeRate" json:"exchangeRate"` //汇率
|
||||||
Freight float64 `yaml:"freight" json:"freight"` //运费
|
Freight float64 `yaml:"freight" json:"freight"` //运费
|
||||||
|
Discount int `yaml:"discount" json:"discount"` //折扣
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) LoadOption() {
|
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) {
|
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
|
c.Option.Freight, oldFreight = opt.Freight, c.Option.Freight
|
||||||
change = true
|
change = true
|
||||||
}
|
}
|
||||||
|
if opt.Discount > 0 && opt.Discount != c.Option.Discount {
|
||||||
|
c.Option.Discount = opt.Discount
|
||||||
|
change = true
|
||||||
|
}
|
||||||
opt.ID = 1
|
opt.ID = 1
|
||||||
c.db.Updates(opt)
|
c.db.Updates(opt)
|
||||||
if change {
|
if change {
|
||||||
c.updateExchangeRateAndFreight(oldFreight)
|
c.updateRate(oldFreight)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) updateExchangeRateAndFreight(oldFreight float64) {
|
func (c *Controller) updateRate(oldFreight float64) {
|
||||||
var results []*productv1.Product
|
var results []*productv1.Product
|
||||||
c.db.FindInBatches(&results, 20, func(tx *gorm.DB, batch int) error {
|
c.db.FindInBatches(&results, 20, func(tx *gorm.DB, batch int) error {
|
||||||
for _, result := range results {
|
for _, result := range results {
|
||||||
@ -46,6 +51,7 @@ func (c *Controller) updateExchangeRateAndFreight(oldFreight float64) {
|
|||||||
result.Freight = c.Option.Freight
|
result.Freight = c.Option.Freight
|
||||||
}
|
}
|
||||||
result.ExchangeRate = c.Option.ExchangeRate
|
result.ExchangeRate = c.Option.ExchangeRate
|
||||||
|
result.Discount = c.Option.Discount
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存对当前批记录的修改
|
// 保存对当前批记录的修改
|
||||||
|
Loading…
Reference in New Issue
Block a user