feat(publish): 增加等级与特殊皮肤价格修正
This commit is contained in:
@@ -144,9 +144,11 @@ type PublishOptionsDTO struct {
|
||||
}
|
||||
|
||||
type PublishOptionGroup struct {
|
||||
Key string `json:"key"`
|
||||
Title string `json:"title"`
|
||||
Options []string `json:"options"`
|
||||
Key string `json:"key"`
|
||||
Title string `json:"title"`
|
||||
Options []string `json:"options"`
|
||||
SpecialPriceOptions []string `json:"special_price_options"`
|
||||
SpecialRatioAdjustment float64 `json:"special_ratio_adjustment"`
|
||||
}
|
||||
|
||||
type PublishQuantityItem struct {
|
||||
@@ -188,6 +190,7 @@ type PublishRatioConfig struct {
|
||||
QualityOwnerRatioDiscount float64 `json:"quality_owner_ratio_discount"`
|
||||
PremiumReviewRatioMarkup float64 `json:"premium_review_ratio_markup"`
|
||||
InsuranceBaseRatios []PublishInsuranceBaseRatio `json:"insurance_base_ratios"`
|
||||
LevelRatioRules []PublishLevelRatioRule `json:"level_ratio_rules"`
|
||||
ConfigItems []PublishRatioConfigItem `json:"config_items"`
|
||||
CoinCorrections []PublishCoinCorrection `json:"coin_corrections"`
|
||||
}
|
||||
@@ -205,6 +208,13 @@ type PublishRatioConfigItem struct {
|
||||
MissingPenalty float64 `json:"missing_penalty"`
|
||||
}
|
||||
|
||||
type PublishLevelRatioRule struct {
|
||||
Key string `json:"key"`
|
||||
Field string `json:"field"`
|
||||
Level string `json:"level"`
|
||||
RatioAdjustment float64 `json:"ratio_adjustment"`
|
||||
}
|
||||
|
||||
type PublishCoinCorrection struct {
|
||||
ThresholdM float64 `json:"threshold_m"`
|
||||
Correction float64 `json:"correction"`
|
||||
|
||||
@@ -222,9 +222,7 @@ func normalizePublishOptions(options *PublishOptionsDTO) {
|
||||
if len(options.RegionOptions) == 0 {
|
||||
options.RegionOptions = defaults.RegionOptions
|
||||
}
|
||||
if len(options.SkinGroups) == 0 {
|
||||
options.SkinGroups = defaults.SkinGroups
|
||||
}
|
||||
normalizePublishOptionGroups(options, defaults.SkinGroups)
|
||||
if len(options.QuantityItems) == 0 {
|
||||
options.QuantityItems = defaults.QuantityItems
|
||||
}
|
||||
@@ -276,6 +274,10 @@ func normalizePublishOptions(options *PublishOptionsDTO) {
|
||||
if len(options.RatioConfig.InsuranceBaseRatios) == 0 {
|
||||
options.RatioConfig.InsuranceBaseRatios = defaults.RatioConfig.InsuranceBaseRatios
|
||||
}
|
||||
if options.RatioConfig.LevelRatioRules == nil {
|
||||
options.RatioConfig.LevelRatioRules = defaults.RatioConfig.LevelRatioRules
|
||||
}
|
||||
normalizeLevelRatioRules(options.RatioConfig.LevelRatioRules)
|
||||
if len(options.RatioConfig.ConfigItems) == 0 {
|
||||
options.RatioConfig.ConfigItems = defaults.RatioConfig.ConfigItems
|
||||
}
|
||||
@@ -287,6 +289,92 @@ func normalizePublishOptions(options *PublishOptionsDTO) {
|
||||
)
|
||||
}
|
||||
|
||||
// NormalizePublishOptions 为其他模块提供与公开接口一致的配置兼容归一化。
|
||||
func NormalizePublishOptions(options *PublishOptionsDTO) {
|
||||
normalizePublishOptions(options)
|
||||
}
|
||||
|
||||
func normalizePublishOptionGroups(options *PublishOptionsDTO, defaults []PublishOptionGroup) {
|
||||
if len(options.SkinGroups) == 0 {
|
||||
options.SkinGroups = clonePublishOptionGroups(defaults)
|
||||
return
|
||||
}
|
||||
defaultByKey := make(map[string]PublishOptionGroup, len(defaults))
|
||||
for _, group := range defaults {
|
||||
defaultByKey[group.Key] = group
|
||||
}
|
||||
for index := range options.SkinGroups {
|
||||
group := &options.SkinGroups[index]
|
||||
group.Key = strings.TrimSpace(group.Key)
|
||||
group.Title = strings.TrimSpace(group.Title)
|
||||
group.Options = normalizeStringValues(group.Options)
|
||||
if group.SpecialPriceOptions == nil {
|
||||
if fallback, ok := defaultByKey[group.Key]; ok {
|
||||
group.SpecialPriceOptions = append([]string(nil), fallback.SpecialPriceOptions...)
|
||||
group.SpecialRatioAdjustment = fallback.SpecialRatioAdjustment
|
||||
} else {
|
||||
group.SpecialPriceOptions = []string{}
|
||||
group.SpecialRatioAdjustment = -1
|
||||
}
|
||||
} else {
|
||||
group.SpecialPriceOptions = normalizeStringValues(group.SpecialPriceOptions)
|
||||
group.SpecialRatioAdjustment = normalizeSignedRatioAdjustment(
|
||||
group.SpecialRatioAdjustment,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func normalizeLevelRatioRules(rules []PublishLevelRatioRule) {
|
||||
for index := range rules {
|
||||
rule := &rules[index]
|
||||
rule.Key = strings.TrimSpace(rule.Key)
|
||||
rule.Field = strings.ToLower(strings.TrimSpace(rule.Field))
|
||||
rule.Level = strings.TrimSpace(rule.Level)
|
||||
rule.RatioAdjustment = normalizeSignedRatioAdjustment(rule.RatioAdjustment)
|
||||
}
|
||||
}
|
||||
|
||||
func normalizeStringValues(values []string) []string {
|
||||
result := make([]string, 0, len(values))
|
||||
seen := make(map[string]struct{}, len(values))
|
||||
for _, value := range values {
|
||||
value = strings.TrimSpace(value)
|
||||
if value == "" {
|
||||
continue
|
||||
}
|
||||
if _, ok := seen[value]; ok {
|
||||
continue
|
||||
}
|
||||
seen[value] = struct{}{}
|
||||
result = append(result, value)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func clonePublishOptionGroups(groups []PublishOptionGroup) []PublishOptionGroup {
|
||||
result := make([]PublishOptionGroup, len(groups))
|
||||
for index, group := range groups {
|
||||
result[index] = group
|
||||
result[index].Options = append([]string(nil), group.Options...)
|
||||
result[index].SpecialPriceOptions = append([]string(nil), group.SpecialPriceOptions...)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func normalizeSignedRatioAdjustment(value float64) float64 {
|
||||
if math.IsNaN(value) || math.IsInf(value, 0) {
|
||||
return 0
|
||||
}
|
||||
if value < -10 {
|
||||
return -10
|
||||
}
|
||||
if value > 10 {
|
||||
return 10
|
||||
}
|
||||
return math.Round(value*10) / 10
|
||||
}
|
||||
|
||||
func normalizePremiumReviewRatioMarkup(value float64) float64 {
|
||||
if value < 0 || math.IsNaN(value) || math.IsInf(value, 0) {
|
||||
return 0
|
||||
|
||||
@@ -3,9 +3,9 @@ package systemconfig
|
||||
import "encoding/json"
|
||||
|
||||
const (
|
||||
// publishOptionsSchemaVersion 发布选项结构版本;v2 新增「是否解锁德穆兰」开关(默认关闭),
|
||||
// 并把「下赛季是否购买通行证」默认打开。
|
||||
publishOptionsSchemaVersion = 2
|
||||
// publishOptionsSchemaVersion 发布选项结构版本;v3 新增体力/负重命中比例修正
|
||||
// 与皮肤分类特殊价格子集。
|
||||
publishOptionsSchemaVersion = 3
|
||||
publishOptionsConfigKey = "listing.publish_options"
|
||||
)
|
||||
|
||||
@@ -20,13 +20,13 @@ func defaultPublishOptionsConfigValue() string {
|
||||
func DefaultPublishOptions() PublishOptionsDTO {
|
||||
return PublishOptionsDTO{
|
||||
SchemaVersion: publishOptionsSchemaVersion,
|
||||
UnlockDemulanEnabled: false,
|
||||
NextSeasonPassEnabled: true,
|
||||
ServerOptions: []string{"QQ", "微信", "Steam"},
|
||||
UnlockDemulanEnabled: true,
|
||||
NextSeasonPassEnabled: false,
|
||||
ServerOptions: []string{"QQ", "微信"},
|
||||
FaceOptions: []string{"是", "否"},
|
||||
RankOptions: []string{"青铜", "白银", "黄金", "铂金", "钻石", "黑鹰", "三角洲巅峰"},
|
||||
InsuranceOptions: []string{"2*1", "2*2", "2*3", "3*3"},
|
||||
LevelOptions: []string{"1级", "2级", "3级", "4级", "5级", "6级", "7级"},
|
||||
LevelOptions: []string{"4级", "5级", "6级", "7级"},
|
||||
LoginMethodOptions: []string{"扫码", "账号密码"},
|
||||
RegionOptions: []string{
|
||||
"北京", "天津", "河北", "山西", "内蒙古", "辽宁", "吉林", "黑龙江",
|
||||
@@ -40,38 +40,50 @@ func DefaultPublishOptions() PublishOptionsDTO {
|
||||
Key: "melee",
|
||||
Title: "近战皮肤",
|
||||
Options: []string{
|
||||
"坠星者", "暗星", "龙牙", "信条", "怜悯", "赤枭", "影锋", "黑海", "北极星", "电锯惊魂", "处刑者",
|
||||
"坠星者", "暗星", "龙牙", "信条", "怜悯", "赤霄", "影锋", "黑海", "北极星", "电锯惊魂", "处刑者",
|
||||
"挽歌", "重塑", "黑伤",
|
||||
},
|
||||
SpecialPriceOptions: []string{"龙牙", "赤霄"},
|
||||
SpecialRatioAdjustment: -1,
|
||||
},
|
||||
{
|
||||
Key: "operatorGold",
|
||||
Title: "干员金皮",
|
||||
Key: "operatorGold",
|
||||
Title: "干员金皮",
|
||||
SpecialPriceOptions: []string{},
|
||||
SpecialRatioAdjustment: -1,
|
||||
Options: []string{
|
||||
"露娜-古墓丽影联动", "蛊-不羁人生", "红狼-电锯惊魂", "露娜-金牌射手",
|
||||
"牧羊人-街头之星", "蜂医-危险物质", "蜂医-送葬人", "无名-夜鹰",
|
||||
"威龙-壮志凌云", "威龙-蛟龙特战队", "威龙-铁面判官", "威龙-吴彦祖",
|
||||
"疾风-西部往事", "骇爪-骇客少女", "比特-沙漠孤星",
|
||||
},
|
||||
},
|
||||
{
|
||||
Key: "operatorRed",
|
||||
Title: "干员红皮",
|
||||
Key: "operatorRed",
|
||||
Title: "干员红皮",
|
||||
SpecialPriceOptions: []string{},
|
||||
SpecialRatioAdjustment: -1,
|
||||
Options: []string{
|
||||
"凌霄成卫", "蚀金玫瑰", "水墨云图", "午夜邮差", "天际线", "维什戴尔",
|
||||
"狂怒", "安魂牧羊人", "雷霆之息",
|
||||
},
|
||||
},
|
||||
{
|
||||
Key: "weapon",
|
||||
Title: "武器皮肤",
|
||||
Key: "weapon",
|
||||
Title: "武器皮肤",
|
||||
SpecialPriceOptions: []string{},
|
||||
SpecialRatioAdjustment: -1,
|
||||
Options: []string{
|
||||
"M7棱镜攻势S2", "腾龙气象感应", "MP7电玩高手S2", "M250电玩高手S2",
|
||||
"AS Val悬赏令", "K416命运", "M4A1棱镜攻势", "SCAR-H电玩高手",
|
||||
"QBZ95王牌之剑", "AUG气象感应", "Vector美杜莎", "KC17-造物纪元",
|
||||
"AKM-群星", "MK4冲锋枪-疾光魅影", "K437突击步枪-王者之剑", "禁卫14",
|
||||
},
|
||||
},
|
||||
},
|
||||
QuantityItems: []PublishQuantityItem{
|
||||
{Key: "level6Ammo", Label: "6级弹", Price: "0.1元/发", Placeholder: "按单发数量填写,60发=6元"},
|
||||
{Key: "awmAmmo", Label: "AWM子弹", Price: "0.6元/发"},
|
||||
{Key: "awmAmmo", Label: "AWM子弹", Price: "0.7元/发"},
|
||||
{Key: "barrettAmmo", Label: "巴雷特子弹", Price: "0.3元/发"},
|
||||
{Key: "armor6", Label: "6甲", Price: "2.5元/个"},
|
||||
{Key: "helmet6", Label: "6头", Price: "1.5元/个"},
|
||||
@@ -84,7 +96,7 @@ func DefaultPublishOptions() PublishOptionsDTO {
|
||||
{Key: "coin", Label: "纯币截图", Required: true, Hint: "请上传纯币截图(必传)"},
|
||||
{Key: "gameId", Label: "游戏ID截图", Required: true, Hint: "请上传游戏ID截图(必传)"},
|
||||
{Key: "totalAsset", Label: "总资产截图", Required: true, Hint: "请上传总资产截图(必传)"},
|
||||
{Key: "tencentSecurity", Label: "腾讯安全中心截图", Required: false, Hint: "有封禁记录时必传"},
|
||||
{Key: "tencentSecurity", Label: "腾讯安全中心截图", Required: true, Hint: "腾讯安全中心截图"},
|
||||
{Key: "skin", Label: "皮肤截图", Required: false, Hint: "请上传皮肤截图(选传)"},
|
||||
},
|
||||
BanRecordOptions: []string{"无封禁记录", "有封禁记录"},
|
||||
@@ -99,22 +111,22 @@ func DefaultPublishOptions() PublishOptionsDTO {
|
||||
|
||||
2. 系统推荐押金未覆盖项目(需自行评估)
|
||||
|
||||
请注意,系统推荐押金暂不包含以下资产类型,您需要根据实际情况额外评估其价值:
|
||||
请注意,系统推荐押金只包含了皮肤评估的价值!暂不包含以下资产类型,您需要根据实际情况额外评估其价值:
|
||||
|
||||
- 收藏室内的稀有物品
|
||||
- 其他具有个人纪念意义或情怀价值的虚拟资产(如限定称号、绝版道具等)
|
||||
|
||||
3. 未出租价值折算规则(重点)
|
||||
|
||||
请在「收藏室及不出租部分哈弗币价值」中填写收藏室等不出租资产折合的哈弗币。系统按 1元=50万 计算参考值,并自动更新推荐押金:低于参考值时覆盖为参考值,否则追加参考值的 50%。
|
||||
请在「收藏室及不出租部分哈弗币价值,如150m纯币只出50m纯币」中填写收藏室等不出租资产折合的哈弗币。系统按 1元=50万 计算参考值,并自动更新推荐押金:低于参考值时覆盖为参考值,否则追加参考值的 50%。
|
||||
|
||||
示例:基础推荐押金 200 元、收藏室价值 200M → 参考值 400 元,200<400,推荐押金更新为 400 元。
|
||||
|
||||
目的:该举能够有效覆盖租客可能出现的洗号、违规操作导致账号封禁等风险带来的损失,为您提供充分的风险缓冲。
|
||||
目的:该举能够有效覆盖租客可能出现的洗号、违规操作导致账号封禁等风险带来的损失,为您提供充分的风险缓冲。也不用担心押金高账号出不去,只要其账号配置是符合押金的,一样的可以正常租出。
|
||||
|
||||
4. 额外保障选项
|
||||
|
||||
若您在设置足额押金后仍感不放心,可选择购买平台提供的《全额包赔服务》。一旦发生封号损失,将获得账号市场价值的全额赔付,让您的出租过程后顾无忧。`,
|
||||
若您在设置足额押金后仍感不放心,可选择购买平台提供的《无忧租号保险》。一旦发生封号损失,将获得账号市场价值的全额赔付,让您的出租过程后顾无忧。但选择《无忧租号保险》,在结算是会产生额外保险服务费,具体可阅读《无忧租号保险》条例。`,
|
||||
PremiumZoneTooltip: `极品专区是面向优质号主和高价值账号的专属展示区。
|
||||
|
||||
1. 发布条件:仅已认证且有效的优质号主可以开启;未开通时需先缴纳平台要求的信用保证金并完成优质号主认证。
|
||||
@@ -122,26 +134,33 @@ func DefaultPublishOptions() PublishOptionsDTO {
|
||||
3. 价格规则:系统会按后台配置在基础比例上计算极品专区专享比例,审核页展示的最终价格通过后不再改价。
|
||||
4. 保险服务:可选择无忧租号保险,服务费率按优质号主及极品专区的当前配置执行,并按实际纯币结算金额计算,额外物品不计入保险基数。
|
||||
5. 责任说明:开启专区不会免除商品审核、资料真实性及发布协议中的责任,请如实填写账号资产与出租条件。`,
|
||||
CompensationNote: "普通赔付方案如下:账号在租期内或祖期外出现封禁,追回、洗号等情况,最高可获赔全款相金+押金\n\n无忧保险赔付方案:按账号市场价值进行赔付(可参照螃蟹,盼之等主流交易平台)。无忧保险服务费按实际纯币结算金额计算,额外物品不计入计费基数;具体费率以当前配置为准。押金须达到推荐押金方可购买。",
|
||||
CompensationNote: "普通赔付方案如下:账号在租期内或祖期外出现封禁30天和十年等情况,最高可获赔全款相金+押金\n\n无忧保险赔付方案:按账号市场价值进行赔付(可参照螃蟹,盼之等主流交易平台)。无忧保险服务费按实际纯币结算金额计算,额外物品不计入计费基数;具体费率以当前配置为准。押金须达到推荐押金以上方可购买。",
|
||||
PricePlaceholder: "填写币数、保险、体力和负重后自动计算;发布总价=纯币基础价+额外消耗品",
|
||||
RatioDescription: "1:xx 表示 1 元人民币(RMB)等价兑换 xx 万哈夫币",
|
||||
},
|
||||
DepositRecommend: PublishDepositRecommend{
|
||||
BaseAmount: 50,
|
||||
BaseAmount: 200,
|
||||
SkinGroupRules: []PublishDepositSkinGroupRule{
|
||||
{GroupKey: "melee", Label: "刀皮", AmountPerItem: 5},
|
||||
{GroupKey: "operatorGold", Label: "干员金皮", AmountPerItem: 10},
|
||||
{GroupKey: "operatorRed", Label: "干员红皮", AmountPerItem: 30},
|
||||
{GroupKey: "melee", Label: "刀皮", AmountPerItem: 150},
|
||||
{GroupKey: "operatorGold", Label: "干员金皮", AmountPerItem: 0},
|
||||
{GroupKey: "operatorRed", Label: "干员红皮", AmountPerItem: 150},
|
||||
{GroupKey: "weapon", Label: "武器皮肤", AmountPerItem: 200},
|
||||
},
|
||||
},
|
||||
RatioConfig: PublishRatioConfig{
|
||||
QualityOwnerRatioDiscount: 1,
|
||||
PremiumReviewRatioMarkup: 1,
|
||||
PremiumReviewRatioMarkup: 0,
|
||||
InsuranceBaseRatios: []PublishInsuranceBaseRatio{
|
||||
{Insurance: "3*3", Ratio: 40},
|
||||
{Insurance: "2*3", Ratio: 42},
|
||||
{Insurance: "2*2", Ratio: 47},
|
||||
{Insurance: "2*1", Ratio: 48},
|
||||
{Insurance: "3*3", Ratio: 45},
|
||||
{Insurance: "2*3", Ratio: 47},
|
||||
{Insurance: "2*2", Ratio: 51},
|
||||
{Insurance: "2*1", Ratio: 51},
|
||||
},
|
||||
LevelRatioRules: []PublishLevelRatioRule{
|
||||
{Key: "stamina7", Field: "stamina", Level: "7级", RatioAdjustment: -1},
|
||||
{Key: "stamina6", Field: "stamina", Level: "6级", RatioAdjustment: -0.5},
|
||||
{Key: "load7", Field: "load", Level: "7级", RatioAdjustment: -1},
|
||||
{Key: "load6", Field: "load", Level: "6级", RatioAdjustment: -0.5},
|
||||
},
|
||||
ConfigItems: []PublishRatioConfigItem{
|
||||
{Key: "operatorRed", Label: "干员红皮", Kind: "skin_group", GroupKey: "operatorRed", MissingPenalty: 1},
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user