40 lines
1.0 KiB
Go
40 lines
1.0 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) {
|
|
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) {
|
|
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
|
|
}
|