feat 把价格改为float64
This commit is contained in:
parent
a6c9c0b448
commit
fd1f982cd8
@ -6,7 +6,7 @@ import (
|
|||||||
v2 "gitea.timerzz.com/kedaya_haitao/common/structs/v2"
|
v2 "gitea.timerzz.com/kedaya_haitao/common/structs/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CalculateProviderPrice(calculates []v2.CalculateProcess, env map[string]int) (p v2.ProviderPrice) {
|
func CalculateProviderPrice(calculates []v2.CalculateProcess, env map[string]float64) (p v2.ProviderPrice) {
|
||||||
var calculateStrings = make([]string, 0, len(calculates))
|
var calculateStrings = make([]string, 0, len(calculates))
|
||||||
for _, c := range calculates {
|
for _, c := range calculates {
|
||||||
process, price := c.Run(env)
|
process, price := c.Run(env)
|
||||||
@ -22,7 +22,7 @@ func CalculateProviderPrice(calculates []v2.CalculateProcess, env map[string]int
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func CalculateSellerPrice(calculates []v2.CalculateProcess, env map[string]int) (p v2.SellerPrice) {
|
func CalculateSellerPrice(calculates []v2.CalculateProcess, env map[string]float64) (p v2.SellerPrice) {
|
||||||
var calculateStrings = make([]string, 0, len(calculates))
|
var calculateStrings = make([]string, 0, len(calculates))
|
||||||
for _, c := range calculates {
|
for _, c := range calculates {
|
||||||
process, price := c.Run(env)
|
process, price := c.Run(env)
|
||||||
|
@ -31,12 +31,12 @@ type Article struct {
|
|||||||
Available bool `json:"available"`
|
Available bool `json:"available"`
|
||||||
// 排除
|
// 排除
|
||||||
Exclude bool `json:"exclude"`
|
Exclude bool `json:"exclude"`
|
||||||
// 最低成本价(单位为分)
|
// 最低成本价
|
||||||
CostPrice int `json:"costPrice"`
|
CostPrice float64 `json:"costPrice"`
|
||||||
// 供应商报价列表
|
// 供应商报价列表
|
||||||
Providers []ProviderArticle `json:"providers" gorm:"foreignKey:ArticleID"`
|
Providers []ProviderArticle `json:"providers" gorm:"foreignKey:ArticleID"`
|
||||||
// 最低出售价 (单位为分)
|
// 最低出售价
|
||||||
SellPrice int `json:"sellPrice"`
|
SellPrice float64 `json:"sellPrice"`
|
||||||
// 销售商报价列表
|
// 销售商报价列表
|
||||||
Sellers []SellerArticle `json:"sellers" gorm:"foreignKey:ArticleID"`
|
Sellers []SellerArticle `json:"sellers" gorm:"foreignKey:ArticleID"`
|
||||||
// 利润率
|
// 利润率
|
||||||
|
@ -25,7 +25,7 @@ type CalculateProcess struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 计算过程
|
// 计算过程
|
||||||
func (c *CalculateProcess) Run(env map[string]int) (string, int) {
|
func (c *CalculateProcess) Run(env map[string]float64) (string, float64) {
|
||||||
if c.Condition != "" {
|
if c.Condition != "" {
|
||||||
condition, err := expr.Compile(c.Condition, expr.AsBool())
|
condition, err := expr.Compile(c.Condition, expr.AsBool())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -48,9 +48,9 @@ func (c *CalculateProcess) Run(env map[string]int) (string, int) {
|
|||||||
}
|
}
|
||||||
var replaceList = make([]string, 0, 2*len(env))
|
var replaceList = make([]string, 0, 2*len(env))
|
||||||
for k, v := range env {
|
for k, v := range env {
|
||||||
replaceList = append(replaceList, k, fmt.Sprintf("%.2f", float64(v/100)))
|
replaceList = append(replaceList, k, fmt.Sprintf("%.2f", v))
|
||||||
}
|
}
|
||||||
replacer := strings.NewReplacer(replaceList...)
|
replacer := strings.NewReplacer(replaceList...)
|
||||||
var resp = output.(int)
|
var resp = output.(float64)
|
||||||
return replacer.Replace(fmt.Sprintf("【%s】 %s = %.2f", c.Name, c.Process, float64(resp/100))), resp
|
return replacer.Replace(fmt.Sprintf("【%s】 %s = %.2f", c.Name, c.Process, resp)), resp
|
||||||
}
|
}
|
||||||
|
@ -79,9 +79,9 @@ type ProviderPrice struct {
|
|||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
|
||||||
ProviderArticleID uint `gorm:"index"`
|
ProviderArticleID uint `gorm:"index"`
|
||||||
// 供应商原始价格,美元、人名币、加元,单位为分
|
// 供应商原始价格,美元、人名币、加元
|
||||||
OriginalPrice int `json:"originalPrice"`
|
OriginalPrice float64 `json:"originalPrice"`
|
||||||
// 计算优惠后最终价格,人名币,单位为分
|
// 计算优惠后最终价格,人名币,单位为分
|
||||||
FinalPrice int `json:"finalPrice"` // 计算完优惠的最终的价格
|
FinalPrice float64 `json:"finalPrice"` // 计算完优惠的最终的价格
|
||||||
CalMark string `json:"calMark"` //计算优惠的过程
|
CalMark string `json:"calMark"` //计算优惠的过程
|
||||||
}
|
}
|
||||||
|
@ -76,10 +76,10 @@ type SellerPrice struct {
|
|||||||
ID uint `gorm:"primary_key" json:"-"`
|
ID uint `gorm:"primary_key" json:"-"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
SellerArticleID uint `gorm:"index"`
|
SellerArticleID uint `gorm:"index"`
|
||||||
// 出售最低价,单位为分
|
// 出售最低价
|
||||||
OriginalPrice int `json:"originalPrice"`
|
OriginalPrice float64 `json:"originalPrice"`
|
||||||
// 能拿到手的最终价格,单位为分
|
// 能拿到手的最终价格
|
||||||
FinalPrice int `json:"finalPrice"`
|
FinalPrice float64 `json:"finalPrice"`
|
||||||
//计算过程
|
//计算过程
|
||||||
CalMark string `json:"calMark"`
|
CalMark string `json:"calMark"`
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user