us-coach-spider/product/option.go
timerzz 9a916cc85e
Some checks failed
Build image / build (push) Failing after 1m51s
feat 添加修改spider 配置的方式
2024-05-14 21:18:24 +08:00

33 lines
805 B
Go

package product
import "time"
type Option struct {
ID uint `gorm:"primary_key" json:"id"`
Interval time.Duration `yaml:"interval" json:"interval"`
ExchangeRate float64 `yaml:"exchangeRate" json:"exchangeRate"` //汇率
Freight float64 `yaml:"freight" json:"freight"` //运费
}
func (c *Controller) LoadOption() {
c.db.FirstOrCreate(&c.Option, Option{Interval: time.Hour * 30, ExchangeRate: 7.3, Freight: 100})
}
func (c *Controller) SaveOption(opt Option) {
if opt.Interval > 0 {
c.Option.Interval = opt.Interval
}
if opt.ExchangeRate > 0 {
c.Option.ExchangeRate = opt.ExchangeRate
}
if opt.Freight > 0 {
c.Option.Freight = opt.Freight
}
opt.ID = 1
c.db.Updates(opt)
}
func (c *Controller) GetOption() Option {
return c.Option
}