fix 解决收益率可能为无限的bug

This commit is contained in:
timerzz 2024-06-15 22:47:43 +08:00
parent 1c78e44746
commit 24baf0b387

View File

@ -100,6 +100,9 @@ func (p *Product) CalCNY(calculateProcess []CalculateProcess) {
process, price := c.Calculate(env) process, price := c.Calculate(env)
if process != "" { if process != "" {
calculateStrings = append(calculateStrings, process) calculateStrings = append(calculateStrings, process)
if p.CNYPrice == 0 {
p.CNYPrice = price
}
p.CNYPrice = min(p.CNYPrice, price) p.CNYPrice = min(p.CNYPrice, price)
} }
} }
@ -164,7 +167,7 @@ func (p *Product) CalCNY(calculateProcess []CalculateProcess) {
// CalRate 计算收益率 // CalRate 计算收益率
func (p *Product) CalRate() { func (p *Product) CalRate() {
if p.DWPrice > 0 { if p.DWPrice > 0 && p.CNYPrice > 0 {
// 如果有得物价格,就计算收益率 // 如果有得物价格,就计算收益率
p.Rate = Decimal((p.DWPrice - p.CNYPrice) / p.CNYPrice * 100) p.Rate = Decimal((p.DWPrice - p.CNYPrice) / p.CNYPrice * 100)
} else if p.Rate > 0 { } else if p.Rate > 0 {