feat(listing): 优化优质号主发布与极品专区体验
This commit is contained in:
@@ -182,9 +182,10 @@ type PublishDepositSkinGroupRule struct {
|
||||
}
|
||||
|
||||
type PublishRatioConfig struct {
|
||||
InsuranceBaseRatios []PublishInsuranceBaseRatio `json:"insurance_base_ratios"`
|
||||
ConfigItems []PublishRatioConfigItem `json:"config_items"`
|
||||
CoinCorrections []PublishCoinCorrection `json:"coin_corrections"`
|
||||
QualityOwnerRatioDiscount float64 `json:"quality_owner_ratio_discount"`
|
||||
InsuranceBaseRatios []PublishInsuranceBaseRatio `json:"insurance_base_ratios"`
|
||||
ConfigItems []PublishRatioConfigItem `json:"config_items"`
|
||||
CoinCorrections []PublishCoinCorrection `json:"coin_corrections"`
|
||||
}
|
||||
|
||||
type PublishInsuranceBaseRatio struct {
|
||||
|
||||
@@ -105,6 +105,7 @@ func DefaultPublishOptions() PublishOptionsDTO {
|
||||
},
|
||||
},
|
||||
RatioConfig: PublishRatioConfig{
|
||||
QualityOwnerRatioDiscount: 1,
|
||||
InsuranceBaseRatios: []PublishInsuranceBaseRatio{
|
||||
{Insurance: "3*3", Ratio: 40},
|
||||
{Insurance: "2*3", Ratio: 42},
|
||||
|
||||
@@ -106,6 +106,54 @@ func TestNormalizePublishOptionsValuePreservesCurrentSchema(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizePublishOptionsValueDefaultsQualityOwnerRatioDiscount(t *testing.T) {
|
||||
legacy := `{
|
||||
"schema_version": 2,
|
||||
"ratio_config": {
|
||||
"insurance_base_ratios": [{"insurance": "3*3", "ratio": 40}]
|
||||
}
|
||||
}`
|
||||
|
||||
normalized, err := normalizePublishOptionsValue(legacy)
|
||||
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.RatioConfig.QualityOwnerRatioDiscount != 1 {
|
||||
t.Fatalf(
|
||||
"quality_owner_ratio_discount = %v, want 1",
|
||||
got.RatioConfig.QualityOwnerRatioDiscount,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizePublishOptionsValuePreservesExplicitZeroQualityOwnerDiscount(t *testing.T) {
|
||||
options := DefaultPublishOptions()
|
||||
options.RatioConfig.QualityOwnerRatioDiscount = 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)
|
||||
}
|
||||
if got.RatioConfig.QualityOwnerRatioDiscount != 0 {
|
||||
t.Fatalf(
|
||||
"quality_owner_ratio_discount = %v, want explicit 0",
|
||||
got.RatioConfig.QualityOwnerRatioDiscount,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizePublishOptionsValueMigratesSchemaV1Switches(t *testing.T) {
|
||||
legacy := `{"schema_version":1,"next_season_pass_enabled":false,"server_options":["QQ"]}`
|
||||
|
||||
|
||||
@@ -333,6 +333,10 @@ func normalizePublishOptionsValue(value string) (string, error) {
|
||||
if err := json.Unmarshal([]byte(value), &fields); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if !hasNestedJSONField(fields, "ratio_config", "quality_owner_ratio_discount") {
|
||||
options.RatioConfig.QualityOwnerRatioDiscount =
|
||||
DefaultPublishOptions().RatioConfig.QualityOwnerRatioDiscount
|
||||
}
|
||||
originalVersion := options.SchemaVersion
|
||||
if options.SchemaVersion < publishOptionsSchemaVersion {
|
||||
if hasLegacyPublishQuantityItem(options.QuantityItems) {
|
||||
@@ -360,6 +364,19 @@ func normalizePublishOptionsValue(value string) (string, error) {
|
||||
return string(raw), nil
|
||||
}
|
||||
|
||||
func hasNestedJSONField(fields map[string]json.RawMessage, parent, child string) bool {
|
||||
raw, ok := fields[parent]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
var nested map[string]json.RawMessage
|
||||
if err := json.Unmarshal(raw, &nested); err != nil {
|
||||
return false
|
||||
}
|
||||
_, ok = nested[child]
|
||||
return ok
|
||||
}
|
||||
|
||||
func hasLegacyPublishQuantityItem(items []PublishQuantityItem) bool {
|
||||
for _, item := range items {
|
||||
if item.Key == "kit5" {
|
||||
|
||||
Reference in New Issue
Block a user