feat 添加折扣属性

This commit is contained in:
timerzz 2024-05-23 20:42:37 +08:00
parent 0653521e73
commit 7957d28fe0

View File

@ -41,6 +41,7 @@ type Product struct {
DWPrice float64 `json:"dwPrice"`
Freight float64 `json:"freight"` //运费
ExchangeRate float64 `json:"exchangeRate" gorm:"-"` //汇率
Discount int `json:"discount" gorm:"-"` //折扣
Rate float64 `json:"rate" gorm:"index"` //利润率
PriceStatus PriceStatus `json:"priceStatus"` //价格状态
Remark string `json:"remark"` //备注
@ -79,23 +80,30 @@ func (p *Product) CalRate() {
if p.Freight == 0 {
p.Freight = defaultFreight
}
if p.Discount == 0 {
p.Discount = 100
}
//先计算打九折的价格
tmpPrice := p.USPrice * 0.9 // 这是打九折的价格
p.CNYPrice = tmpPrice*p.ExchangeRate + p.Freight
calculationProcess = append(calculationProcess, fmt.Sprintf("【九折】%.2f * 0.9 * %.2f + %.2f = %.2f", p.USPrice, p.ExchangeRate, p.Freight, p.CNYPrice))
if p.USPrice >= 150 {
calculationProcess = append(calculationProcess, fmt.Sprintf("【150 -20 】(%.2f - 20) * %.2f + %.2f = %.2f", p.USPrice, p.ExchangeRate, p.Freight, (p.USPrice-20)*p.ExchangeRate+p.Freight))
if p.USPrice-20 < tmpPrice {
var discountPrice = p.USPrice
if 0 < p.Discount && p.Discount < 100 {
discountPrice = p.USPrice * float64(p.Discount) / 100
}
if discountPrice >= 150 {
calculationProcess = append(calculationProcess, fmt.Sprintf("【150 -20】(%.2f * %d%% - 20) * %.2f + %.2f = %.2f", p.USPrice, p.Discount, p.ExchangeRate, p.Freight, (discountPrice-20)*p.ExchangeRate+p.Freight))
if discountPrice-20 < tmpPrice {
// 符合满150-20,而且比九折便宜
tmpPrice = p.USPrice - 20
tmpPrice = discountPrice - 20
p.CNYPrice = tmpPrice*p.ExchangeRate + p.Freight
}
} else if p.USPrice >= 100 {
calculationProcess = append(calculationProcess, fmt.Sprintf("【100 -10 】(%.2f - 10) * %.2f + %.2f = %.2f", p.USPrice, p.ExchangeRate, p.Freight, (p.USPrice-10)*p.ExchangeRate+p.Freight))
if p.USPrice-10 < tmpPrice {
} else if discountPrice >= 100 {
calculationProcess = append(calculationProcess, fmt.Sprintf("【100 -10】(%.2f * %d%% - 10) * %.2f + %.2f = %.2f", p.USPrice, p.Discount, p.ExchangeRate, p.Freight, (discountPrice-10)*p.ExchangeRate+p.Freight))
if discountPrice-10 < tmpPrice {
// 符合满100 -10,而且比九折便宜
tmpPrice = p.USPrice - 10
tmpPrice = discountPrice - 10
p.CNYPrice = tmpPrice*p.ExchangeRate + p.Freight
}
}