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
@@ -106,6 +106,179 @@ func TestNormalizePublishOptionsValuePreservesCurrentSchema(t *testing.T) {
}
}
func TestNormalizePublishOptionsValueAddsSpecialSkinAndLevelRules(t *testing.T) {
options := DefaultPublishOptions()
options.SchemaVersion = 2
for index := range options.SkinGroups {
options.SkinGroups[index].SpecialPriceOptions = nil
options.SkinGroups[index].SpecialRatioAdjustment = 0
}
options.RatioConfig.LevelRatioRules = nil
raw, err := json.Marshal(options)
if err != nil {
t.Fatalf("构造旧版配置失败: %v", err)
}
normalized, err := normalizePublishOptionsValue(string(raw))
if err != nil {
t.Fatalf("规范化失败: %v", err)
}
var got PublishOptionsDTO
if err := json.Unmarshal([]byte(normalized), &got); err != nil {
t.Fatalf("解析规范化结果失败: %v", err)
}
if got.SchemaVersion != publishOptionsSchemaVersion {
t.Fatalf("schema_version = %d, want %d", got.SchemaVersion, publishOptionsSchemaVersion)
}
if len(got.RatioConfig.LevelRatioRules) != 4 {
t.Fatalf("level_ratio_rules = %#v, want 4 default rules", got.RatioConfig.LevelRatioRules)
}
var melee *PublishOptionGroup
for index := range got.SkinGroups {
if got.SkinGroups[index].Key == "melee" {
melee = &got.SkinGroups[index]
break
}
}
if melee == nil || len(melee.SpecialPriceOptions) != 2 ||
melee.SpecialPriceOptions[0] != "龙牙" ||
melee.SpecialPriceOptions[1] != "赤霄" ||
melee.SpecialRatioAdjustment != -1 {
t.Fatalf("melee special pricing = %#v", melee)
}
}
func TestDefaultPublishOptionsMatchesCurrentProductionBaseline(t *testing.T) {
options := DefaultPublishOptions()
if len(options.ServerOptions) != 2 || options.ServerOptions[0] != "QQ" ||
options.ServerOptions[1] != "微信" {
t.Fatalf("server_options = %#v", options.ServerOptions)
}
if len(options.LevelOptions) != 4 || options.LevelOptions[0] != "4级" ||
options.LevelOptions[3] != "7级" {
t.Fatalf("level_options = %#v", options.LevelOptions)
}
awmPrice := ""
for _, item := range options.QuantityItems {
if item.Key == "awmAmmo" {
awmPrice = item.Price
}
}
if awmPrice != "0.7元/发" {
t.Fatalf("awm price = %q, want 0.7元/发", awmPrice)
}
if options.DepositRecommend.BaseAmount != 200 {
t.Fatalf("deposit base amount = %v, want 200", options.DepositRecommend.BaseAmount)
}
if len(options.RatioConfig.InsuranceBaseRatios) != 4 ||
options.RatioConfig.InsuranceBaseRatios[0].Ratio != 45 ||
options.RatioConfig.InsuranceBaseRatios[3].Ratio != 51 {
t.Fatalf("insurance ratios = %#v", options.RatioConfig.InsuranceBaseRatios)
}
melee := options.SkinGroups[0]
if len(melee.Options) != 14 ||
melee.Options[5] != "赤霄" ||
len(melee.SpecialPriceOptions) != 2 ||
melee.SpecialPriceOptions[0] != "龙牙" {
t.Fatalf("melee production baseline = %#v", melee)
}
}
func TestNormalizePublishOptionsValuePreservesExplicitEmptySpecialSkins(t *testing.T) {
options := DefaultPublishOptions()
options.SchemaVersion = publishOptionsSchemaVersion
for index := range options.SkinGroups {
if options.SkinGroups[index].Key == "melee" {
options.SkinGroups[index].SpecialPriceOptions = []string{}
options.SkinGroups[index].SpecialRatioAdjustment = 0
}
}
raw, err := json.Marshal(options)
if err != nil {
t.Fatalf("构造配置失败: %v", err)
}
normalized, err := normalizePublishOptionsValue(string(raw))
if err != nil {
t.Fatalf("规范化失败: %v", err)
}
var got PublishOptionsDTO
if err := json.Unmarshal([]byte(normalized), &got); err != nil {
t.Fatalf("解析规范化结果失败: %v", err)
}
for _, group := range got.SkinGroups {
if group.Key != "melee" {
continue
}
if len(group.SpecialPriceOptions) != 0 || group.SpecialRatioAdjustment != 0 {
t.Fatalf("显式清空的特殊皮肤配置被覆盖: %#v", group)
}
return
}
t.Fatal("未找到 melee 皮肤分组")
}
func TestNormalizePublishOptionsValuePreservesProductionFieldsWhenAddingV3Defaults(t *testing.T) {
raw := `{
"schema_version": 2,
"unlock_demulan_enabled": true,
"next_season_pass_enabled": false,
"server_options": ["QQ", "微信"],
"level_options": ["4级", "5级", "6级", "7级"],
"skin_groups": [{
"key": "melee",
"title": "近战皮肤",
"options": ["北极星", "龙牙", "赤霄"]
}],
"quantity_items": [{"key": "awmAmmo", "label": "AWM子弹", "price": "0.7元/发"}],
"deposit_recommend_config": {
"base_amount": 999,
"skin_group_rules": [{"group_key": "melee", "label": "刀皮", "amount_per_item": 321}]
},
"ratio_config": {
"premium_review_ratio_markup": 0,
"insurance_base_ratios": [{"insurance": "3*3", "ratio": 123}],
"config_items": [{"key": "melee", "label": "刀皮", "kind": "skin_group", "group_key": "melee", "missing_penalty": 1}]
}
}`
normalized, err := normalizePublishOptionsValue(raw)
if err != nil {
t.Fatalf("规范化失败: %v", err)
}
var got PublishOptionsDTO
if err := json.Unmarshal([]byte(normalized), &got); err != nil {
t.Fatalf("解析规范化结果失败: %v", err)
}
if !got.UnlockDemulanEnabled || got.NextSeasonPassEnabled {
t.Fatalf("生产布尔开关被覆盖: unlock=%v next=%v", got.UnlockDemulanEnabled, got.NextSeasonPassEnabled)
}
if len(got.ServerOptions) != 2 || got.ServerOptions[1] != "微信" {
t.Fatalf("生产区服被覆盖: %#v", got.ServerOptions)
}
if len(got.QuantityItems) != 1 || got.QuantityItems[0].Price != "0.7元/发" {
t.Fatalf("生产消耗品配置被覆盖: %#v", got.QuantityItems)
}
if got.DepositRecommend.BaseAmount != 999 ||
len(got.DepositRecommend.SkinGroupRules) != 1 ||
got.DepositRecommend.SkinGroupRules[0].AmountPerItem != 321 {
t.Fatalf("生产推荐押金配置被覆盖: %#v", got.DepositRecommend)
}
if got.RatioConfig.PremiumReviewRatioMarkup != 0 ||
len(got.RatioConfig.InsuranceBaseRatios) != 1 ||
got.RatioConfig.InsuranceBaseRatios[0].Ratio != 123 {
t.Fatalf("生产价格配置被覆盖: %#v", got.RatioConfig)
}
if len(got.RatioConfig.LevelRatioRules) != 4 {
t.Fatalf("v3 等级规则未补齐: %#v", got.RatioConfig.LevelRatioRules)
}
if len(got.SkinGroups) != 1 ||
len(got.SkinGroups[0].SpecialPriceOptions) != 2 ||
got.SkinGroups[0].SpecialRatioAdjustment != -1 {
t.Fatalf("v3 特殊皮肤配置未补齐或覆盖了生产皮肤名单: %#v", got.SkinGroups)
}
}
func TestNormalizePublishOptionsValueDefaultsQualityOwnerRatioDiscount(t *testing.T) {
legacy := `{
"schema_version": 2,
@@ -128,9 +301,9 @@ func TestNormalizePublishOptionsValueDefaultsQualityOwnerRatioDiscount(t *testin
got.RatioConfig.QualityOwnerRatioDiscount,
)
}
if got.RatioConfig.PremiumReviewRatioMarkup != 1 {
if got.RatioConfig.PremiumReviewRatioMarkup != 0 {
t.Fatalf(
"premium_review_ratio_markup = %v, want 1",
"premium_review_ratio_markup = %v, want 0",
got.RatioConfig.PremiumReviewRatioMarkup,
)
}