diff --git a/backend/internal/modules/systemconfig/dto.go b/backend/internal/modules/systemconfig/dto.go index 521f7d3a..74a88aae 100644 --- a/backend/internal/modules/systemconfig/dto.go +++ b/backend/internal/modules/systemconfig/dto.go @@ -184,6 +184,10 @@ type PublishDepositSkinGroupRule struct { GroupKey string `json:"group_key"` Label string `json:"label"` AmountPerItem float64 `json:"amount_per_item"` + // DiscountPercent 组内第 2 件起的计价百分比(0-100)。 + // 0 表示不开启折扣,每件都按 AmountPerItem 计入; + // 50 表示第 1 件按原价计入,第 2 件起按原价的 50% 计入。 + DiscountPercent float64 `json:"discount_percent"` } type PublishRatioConfig struct { diff --git a/backend/internal/modules/systemconfig/normalize.go b/backend/internal/modules/systemconfig/normalize.go index 9a424045..06b230db 100644 --- a/backend/internal/modules/systemconfig/normalize.go +++ b/backend/internal/modules/systemconfig/normalize.go @@ -271,6 +271,7 @@ func normalizePublishOptions(options *PublishOptionsDTO) { if len(options.DepositRecommend.SkinGroupRules) == 0 { options.DepositRecommend.SkinGroupRules = defaults.DepositRecommend.SkinGroupRules } + normalizeDepositSkinGroupRules(options.DepositRecommend.SkinGroupRules) if len(options.RatioConfig.InsuranceBaseRatios) == 0 { options.RatioConfig.InsuranceBaseRatios = defaults.RatioConfig.InsuranceBaseRatios } @@ -375,6 +376,27 @@ func normalizeSignedRatioAdjustment(value float64) float64 { return math.Round(value*10) / 10 } +// normalizeDepositSkinGroupRules 收敛押金皮肤规则的折扣比例。 +// 0 表示不开启折扣(每件按原价计入),上限 100 表示第 2 件起不再加价。 +func normalizeDepositSkinGroupRules(rules []PublishDepositSkinGroupRule) { + for index := range rules { + rules[index].DiscountPercent = normalizeDepositDiscountPercent(rules[index].DiscountPercent) + } +} + +func normalizeDepositDiscountPercent(value float64) float64 { + if math.IsNaN(value) || math.IsInf(value, 0) { + return 0 + } + if value <= 0 { + return 0 + } + if value >= 100 { + return 100 + } + return math.Round(value*10) / 10 +} + func normalizePremiumReviewRatioMarkup(value float64) float64 { if value < 0 || math.IsNaN(value) || math.IsInf(value, 0) { return 0 diff --git a/backend/internal/modules/systemconfig/publish_options.go b/backend/internal/modules/systemconfig/publish_options.go index b50bc8b7..a73078d5 100644 --- a/backend/internal/modules/systemconfig/publish_options.go +++ b/backend/internal/modules/systemconfig/publish_options.go @@ -141,10 +141,10 @@ func DefaultPublishOptions() PublishOptionsDTO { DepositRecommend: PublishDepositRecommend{ BaseAmount: 200, SkinGroupRules: []PublishDepositSkinGroupRule{ - {GroupKey: "melee", Label: "刀皮", AmountPerItem: 150}, - {GroupKey: "operatorGold", Label: "干员金皮", AmountPerItem: 0}, - {GroupKey: "operatorRed", Label: "干员红皮", AmountPerItem: 150}, - {GroupKey: "weapon", Label: "武器皮肤", AmountPerItem: 200}, + {GroupKey: "melee", Label: "刀皮", AmountPerItem: 150, DiscountPercent: 0}, + {GroupKey: "operatorGold", Label: "干员金皮", AmountPerItem: 0, DiscountPercent: 0}, + {GroupKey: "operatorRed", Label: "干员红皮", AmountPerItem: 150, DiscountPercent: 0}, + {GroupKey: "weapon", Label: "武器皮肤", AmountPerItem: 200, DiscountPercent: 0}, }, }, RatioConfig: PublishRatioConfig{ diff --git a/backend/internal/modules/systemconfig/publish_options_test.go b/backend/internal/modules/systemconfig/publish_options_test.go index 0610b853..bc0a96d3 100644 --- a/backend/internal/modules/systemconfig/publish_options_test.go +++ b/backend/internal/modules/systemconfig/publish_options_test.go @@ -309,6 +309,54 @@ func TestNormalizePublishOptionsValueDefaultsQualityOwnerRatioDiscount(t *testin } } +func TestNormalizePublishOptionsValueKeepsDepositSkinGroupDiscount(t *testing.T) { + raw := `{ + "schema_version": 3, + "deposit_recommend_config": { + "base_amount": 200, + "skin_group_rules": [ + {"group_key": "melee", "label": "刀皮", "amount_per_item": 100, "discount_percent": 50}, + {"group_key": "weapon", "label": "武器皮肤", "amount_per_item": 200, "discount_percent": 120}, + {"group_key": "operatorRed", "label": "干员红皮", "amount_per_item": 150, "discount_percent": -10} + ] + } + }` + + 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) + } + rules := got.DepositRecommend.SkinGroupRules + if len(rules) != 3 { + t.Fatalf("skin_group_rules = %#v, want 3 rules", rules) + } + if rules[0].DiscountPercent != 50 { + t.Fatalf("折扣比例被覆盖: %#v", rules[0]) + } + if rules[1].DiscountPercent != 100 { + t.Fatalf("超范围折扣比例未收敛: %#v", rules[1]) + } + if rules[2].DiscountPercent != 0 { + t.Fatalf("负数折扣比例未收敛: %#v", rules[2]) + } +} + +func TestDefaultPublishOptionsKeepsDepositSkinGroupDiscountDisabled(t *testing.T) { + options := DefaultPublishOptions() + if len(options.DepositRecommend.SkinGroupRules) != 4 { + t.Fatalf("skin_group_rules = %#v, want 4 rules", options.DepositRecommend.SkinGroupRules) + } + for _, rule := range options.DepositRecommend.SkinGroupRules { + if rule.DiscountPercent != 0 { + t.Fatalf("默认不应开启第二件折扣: %#v", rule) + } + } +} + func TestNormalizePublishOptionsValueDefaultsDepositTooltip(t *testing.T) { normalized, err := normalizePublishOptionsValue(`{"schema_version":2}`) if err != nil { diff --git a/frontend/src/features/admin/components/PublishOptionsDialog.vue b/frontend/src/features/admin/components/PublishOptionsDialog.vue index 555b0525..f1d07e1b 100644 --- a/frontend/src/features/admin/components/PublishOptionsDialog.vue +++ b/frontend/src/features/admin/components/PublishOptionsDialog.vue @@ -196,6 +196,7 @@ function addDepositSkinGroupRule() { group_key: '', label: '', amount_per_item: 0, + discount_percent: 0, }) } @@ -634,7 +635,10 @@ async function handleSave() {

推荐押金皮肤规则

-

按选中皮肤件数累加,与收号比例的特殊分组规则相互独立。

+

+ 按选中皮肤件数累加,与收号比例的特殊分组规则相互独立。开启「第2件起计价」后, + 该分组第 1 件按原价计入,第 2 件起按设置的比例计入。 +

添加押金规则 + + +