common/structs/utils/calculate-process.go

45 lines
1.2 KiB
Go

package utils
import (
"strings"
"time"
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")
p.CreatedAt = time.Now()
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")
p.CreatedAt = time.Now()
return
}