feat product 添加dw的skuid字段

This commit is contained in:
timerzz 2024-07-24 15:06:31 +08:00
parent a7d6c7c666
commit 2ec2db45d8

View File

@ -2,11 +2,12 @@ package productv1
import ( import (
"fmt" "fmt"
"github.com/expr-lang/expr"
"gorm.io/gorm"
"math" "math"
"strings" "strings"
"time" "time"
"github.com/expr-lang/expr"
"gorm.io/gorm"
) )
const ( const (
@ -49,6 +50,7 @@ type Product struct {
CNYPrice float64 `json:"cnyPrice"` // 最终的价格 CNYPrice float64 `json:"cnyPrice"` // 最终的价格
CalMark string `json:"calMark"` //计算价格的过程 CalMark string `json:"calMark"` //计算价格的过程
DWPrice float64 `json:"dwPrice"` DWPrice float64 `json:"dwPrice"`
DWSkuId int64 `json:"dwSkuId"` // 得物sku_id
Freight float64 `json:"freight"` //运费 Freight float64 `json:"freight"` //运费
ExchangeRate float64 `json:"exchangeRate" gorm:"-"` //汇率 ExchangeRate float64 `json:"exchangeRate" gorm:"-"` //汇率
Rate float64 `json:"rate" gorm:"index"` //利润率 Rate float64 `json:"rate" gorm:"index"` //利润率
@ -110,62 +112,6 @@ func (p *Product) CalCNY(calculateProcess []CalculateProcess) {
p.CalMark = strings.Join(calculateStrings, "\n") p.CalMark = strings.Join(calculateStrings, "\n")
} }
//func (p *Product) CalRate() {
// switch p.Website {
// case WebSite_US_Coach_Outlet:
// p.CalRateUSCoach()
// case WebSite_CN_Coach:
// p.CalRateCNCoach()
// }
//}
//func (p *Product) CalRateUSCoach() {
// calculationProcess := make([]string, 0, 2) //存放计算过程
// if p.ExchangeRate == 0 {
// p.ExchangeRate = defaultExchangeRate
// }
// 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))
// 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 = discountPrice - 20
// p.CNYPrice = tmpPrice*p.ExchangeRate + p.Freight
// }
// } 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 = discountPrice - 10
// p.CNYPrice = tmpPrice*p.ExchangeRate + p.Freight
// }
// } else if p.Discount < 90 {
// calculationProcess = append(calculationProcess, fmt.Sprintf("【打折扣】%.2f * %d%% * %.2f + %.2f = %.2f", p.USPrice, p.Discount, p.ExchangeRate, p.Freight, p.USPrice*float64(p.Discount)/100*p.ExchangeRate+p.Freight))
// p.CNYPrice = p.USPrice*float64(p.Discount)/100*p.ExchangeRate + p.Freight
// }
// p.CalMark = strings.Join(calculationProcess, "\n")
// if p.DWPrice > 0 {
// // 如果有得物价格,就计算收益率
// p.Rate = Decimal((p.DWPrice - p.CNYPrice) / p.CNYPrice * 100)
// }
//
// p.CNYPrice = Decimal(p.CNYPrice)
//}
// CalRate 计算收益率 // CalRate 计算收益率
func (p *Product) CalRate() { func (p *Product) CalRate() {
if p.DWPrice > 0 && p.CNYPrice > 0 { if p.DWPrice > 0 && p.CNYPrice > 0 {