common/structs/utils/calculate-process.go

42 lines
1.1 KiB
Go
Raw Normal View History

2024-08-31 16:01:46 +08:00
package utils
import (
"strings"
v2 "gitea.timerzz.com/kedaya_haitao/common/structs/v2"
)
2024-09-01 14:16:21 +08:00
func CalculateProviderPrice(calculates []v2.CalculateProcess, env map[string]float64) (p v2.ProviderPrice) {
p.OriginalPrice = env["originalPrice"]
2024-08-31 16:01:46 +08:00
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
}
2024-09-01 14:16:21 +08:00
func CalculateSellerPrice(calculates []v2.CalculateProcess, env map[string]float64) (p v2.SellerPrice) {
p.OriginalPrice = env["originalPrice"]
2024-08-31 16:01:46 +08:00
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
}