common/structs/utils/calculate-process.go

42 lines
1.1 KiB
Go

package utils
import (
"strings"
v2 "gitea.timerzz.com/kedaya_haitao/common/structs/v2"
)
func CalculateProviderPrice(calculates []v2.CalculateProcess, env map[string]float64) (p v2.ProviderPrice) {
p.OriginalPrice = env["originalPrice"]
var calculateStrings = make([]string, 0, len(calculates))
for _, c := range calculates {
process, price := c.Run(env)
if process != "" {
calculateStrings = append(calculateStrings, process)
if p.FinalPrice == 0 {
p.FinalPrice = price
}
p.FinalPrice = min(p.FinalPrice, price)
}
}
p.CalMark = strings.Join(calculateStrings, "\n")
return
}
func CalculateSellerPrice(calculates []v2.CalculateProcess, env map[string]float64) (p v2.SellerPrice) {
p.OriginalPrice = env["originalPrice"]
var calculateStrings = make([]string, 0, len(calculates))
for _, c := range calculates {
process, price := c.Run(env)
if process != "" {
calculateStrings = append(calculateStrings, process)
if p.FinalPrice == 0 {
p.FinalPrice = price
}
p.FinalPrice = min(p.FinalPrice, price)
}
}
p.CalMark = strings.Join(calculateStrings, "\n")
return
}