feat(publish): 增加等级与特殊皮肤价格修正

This commit is contained in:
yml
2026-11-24 20:33:22 +08:00
parent 9283a68143
commit 3ac4052ac5
14 changed files with 1744 additions and 606 deletions
@@ -268,6 +268,7 @@ func (s *Service) publishRatioOptions(ctx context.Context) (systemconfig.Publish
if len(parsed.SkinGroups) == 0 {
parsed.SkinGroups = options.SkinGroups
}
systemconfig.NormalizePublishOptions(&parsed)
return parsed, nil
}
@@ -286,10 +287,14 @@ func calculateSellerReferenceRatio(coinM float64, summary map[string]any, option
return 0
}
dailyLoss := readSummaryNumber(summary["daily_loss_m"])
return baseRatio +
ratio := baseRatio +
calculateRatioConfigPenalty(options, summary, stamina, load) +
coinCorrection(options.RatioConfig.CoinCorrections, coinM) +
calculateDailyLossRatioAdjustment(dailyLoss)
if ratio <= 0 {
return 0
}
return roundRatio(ratio)
}
func clampSaleRatio(referenceRatio, requestedRatio, minRatio float64) float64 {
@@ -322,9 +327,82 @@ func calculateRatioConfigPenalty(options systemconfig.PublishOptionsDTO, summary
if ratioConfigItemMatched(item, options, selectedSkins, stamina, load) {
continue
}
if item.Kind == "max_stamina" &&
hasMatchingLevelRatioRule(options.RatioConfig.LevelRatioRules, "stamina", stamina) {
continue
}
if item.Kind == "max_load" &&
hasMatchingLevelRatioRule(options.RatioConfig.LevelRatioRules, "load", load) {
continue
}
penalty += item.MissingPenalty
}
return penalty
penalty += calculateLevelRatioAdjustment(options.RatioConfig.LevelRatioRules, stamina, load)
penalty += calculateSpecialSkinRatioAdjustment(options.SkinGroups, selectedSkins)
return math.Round(penalty*10) / 10
}
func hasMatchingLevelRatioRule(
rules []systemconfig.PublishLevelRatioRule,
field string,
level string,
) bool {
for _, rule := range rules {
if strings.TrimSpace(rule.Field) == field && strings.TrimSpace(rule.Level) == level {
return true
}
}
return false
}
func calculateLevelRatioAdjustment(
rules []systemconfig.PublishLevelRatioRule,
stamina string,
load string,
) float64 {
adjustment := 0.0
for _, rule := range rules {
switch strings.TrimSpace(rule.Field) {
case "stamina":
if strings.TrimSpace(rule.Level) == stamina {
adjustment += rule.RatioAdjustment
}
case "load":
if strings.TrimSpace(rule.Level) == load {
adjustment += rule.RatioAdjustment
}
}
}
return adjustment
}
func calculateSpecialSkinRatioAdjustment(
groups []systemconfig.PublishOptionGroup,
selectedSkins []string,
) float64 {
if len(selectedSkins) == 0 {
return 0
}
selected := make(map[string]struct{}, len(selectedSkins))
for _, skin := range selectedSkins {
skin = strings.TrimSpace(skin)
if skin != "" {
selected[skin] = struct{}{}
}
}
adjustment := 0.0
for _, group := range groups {
if group.SpecialRatioAdjustment == 0 || len(group.SpecialPriceOptions) == 0 {
continue
}
for _, skin := range group.SpecialPriceOptions {
if _, ok := selected[strings.TrimSpace(skin)]; ok {
adjustment += group.SpecialRatioAdjustment
break
}
}
}
return adjustment
}
func ratioConfigItemMatched(