common/structs/utils/calculate-process.go

45 lines
1.2 KiB
Go
Raw Permalink Normal View History

2024-08-31 16:01:46 +08:00
package utils
import (
"strings"
2024-09-03 17:41:10 +08:00
"time"
2024-08-31 16:01:46 +08:00
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")
2024-09-03 17:41:10 +08:00
p.CreatedAt = time.Now()
2024-08-31 16:01:46 +08:00
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")
2024-09-03 17:41:10 +08:00
p.CreatedAt = time.Now()
2024-08-31 16:01:46 +08:00
return
}