feat 修改历史价格计算
This commit is contained in:
parent
17299b2bb8
commit
77e0c69168
@ -64,6 +64,20 @@ func (p *Product) TableName() string {
|
|||||||
|
|
||||||
func (p *Product) BeforeSave(tx *gorm.DB) (err error) {
|
func (p *Product) BeforeSave(tx *gorm.DB) (err error) {
|
||||||
p.CalRate()
|
p.CalRate()
|
||||||
|
p.fillPriceStatus(tx)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Product) fillPriceStatus(tx *gorm.DB) {
|
||||||
|
switch p.Website {
|
||||||
|
case WebSite_US_Coach_Outlet:
|
||||||
|
p.fillUSCoachPriceStatus(tx)
|
||||||
|
case WebSite_CN_Coach:
|
||||||
|
p.fillCNCoachPriceStatus(tx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Product) fillUSCoachPriceStatus(tx *gorm.DB) {
|
||||||
var lastPrice float64
|
var lastPrice float64
|
||||||
tx.Model(&HistoryPrice{}).Where("pid = ?", p.Pid).Order("created_at desc").Limit(1).Pluck("us_price", &lastPrice)
|
tx.Model(&HistoryPrice{}).Where("pid = ?", p.Pid).Order("created_at desc").Limit(1).Pluck("us_price", &lastPrice)
|
||||||
if p.USPrice != lastPrice {
|
if p.USPrice != lastPrice {
|
||||||
@ -74,10 +88,23 @@ func (p *Product) BeforeSave(tx *gorm.DB) (err error) {
|
|||||||
p.PriceStatus = PriceStatus_UP
|
p.PriceStatus = PriceStatus_UP
|
||||||
} else {
|
} else {
|
||||||
p.PriceStatus = PriceStatus_DOWN
|
p.PriceStatus = PriceStatus_DOWN
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Product) fillCNCoachPriceStatus(tx *gorm.DB) {
|
||||||
|
var lastPrice float64
|
||||||
|
tx.Model(&HistoryPrice{}).Where("pid = ?", p.Pid).Order("created_at desc").Limit(1).Pluck("cny_price", &lastPrice)
|
||||||
|
if p.CNYPrice != lastPrice {
|
||||||
|
p.HistoryPrices = append(p.HistoryPrices, HistoryPrice{
|
||||||
|
USPrice: p.CNYPrice,
|
||||||
|
})
|
||||||
|
if p.CNYPrice > lastPrice {
|
||||||
|
p.PriceStatus = PriceStatus_UP
|
||||||
|
} else {
|
||||||
|
p.PriceStatus = PriceStatus_DOWN
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Product) CalRate() {
|
func (p *Product) CalRate() {
|
||||||
|
Loading…
Reference in New Issue
Block a user