From f697b10e2b5649dfe8bee706dbf1778ec28e5484 Mon Sep 17 00:00:00 2001 From: yml Date: Wed, 25 Nov 2026 21:22:04 +0800 Subject: [PATCH] =?UTF-8?q?feat(publish):=20=E6=8E=A8=E8=8D=90=E6=8A=BC?= =?UTF-8?q?=E9=87=91=E6=94=AF=E6=8C=81=E7=AC=AC=E4=BA=8C=E4=BB=B6=E6=8A=98?= =?UTF-8?q?=E6=89=A3=E5=B9=B6=E6=94=BE=E5=AE=BD=E6=8A=BC=E9=87=91=E4=B8=8B?= =?UTF-8?q?=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 推荐押金皮肤规则新增「第2件起计价」比例,组内首件按原价、后续件按比例计入 - 押金低于推荐押金允许发布,弹窗提示并禁用无忧租号保险 - 用户主动改低押金后不再被推荐值覆盖,点「使用推荐」恢复自动跟随 --- backend/internal/modules/systemconfig/dto.go | 4 + .../modules/systemconfig/normalize.go | 22 +++ .../modules/systemconfig/publish_options.go | 8 +- .../systemconfig/publish_options_test.go | 48 +++++++ .../admin/components/PublishOptionsDialog.vue | 17 ++- .../listings/api/listingOptions.spec.ts | 39 ++++++ .../features/listings/api/listingOptions.ts | 11 +- .../seller/composables/usePublishDraft.ts | 4 + .../seller/composables/usePublishForm.ts | 116 ++++++++++++++-- .../views/MobileSellerListingCreateView.css | 21 +++ .../views/MobileSellerListingCreateView.vue | 23 +++- .../seller/views/SellerListingCreateView.css | 21 +++ .../seller/views/SellerListingCreateView.vue | 24 +++- frontend/src/shared/types/publish.ts | 4 + .../shared/utils/__tests__/pricing.spec.ts | 128 +++++++++++++++++- frontend/src/shared/utils/pricing.ts | 83 ++++++++++-- 16 files changed, 532 insertions(+), 41 deletions(-) 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 件起按设置的比例计入。 +

添加押金规则 + + +