feat 添加折扣属性
Some checks failed
Build image / build (push) Failing after 26m21s

This commit is contained in:
timerzz 2024-05-23 20:48:04 +08:00
parent 582ed37908
commit 88e6febe37
5 changed files with 40 additions and 14 deletions

View File

@ -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
- 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

16
.ko.yaml Normal file
View 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
View File

@ -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

2
go.sum
View File

@ -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=

View File

@ -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
}
// 保存对当前批记录的修改