us-coach-spider/product/option.go

33 lines
805 B
Go
Raw Normal View History

2024-05-14 15:27:40 +08:00
package product
import "time"
type Option struct {
2024-05-14 16:17:04 +08:00
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"` //运费
2024-05-14 15:27:40 +08:00
}
2024-05-14 16:17:04 +08:00
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
}