From 3ac4052ac5781cf511b37313db43e7c264712156 Mon Sep 17 00:00:00 2001 From: yml Date: Tue, 24 Nov 2026 20:33:22 +0800 Subject: [PATCH] =?UTF-8?q?feat(publish):=20=E5=A2=9E=E5=8A=A0=E7=AD=89?= =?UTF-8?q?=E7=BA=A7=E4=B8=8E=E7=89=B9=E6=AE=8A=E7=9A=AE=E8=82=A4=E4=BB=B7?= =?UTF-8?q?=E6=A0=BC=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listing/external_adjustment_test.go | 16 +- .../modules/listing/receive_pricing.go | 82 +- .../modules/listing/receive_pricing_test.go | 116 +- .../internal/modules/listing/service_test.go | 38 +- backend/internal/modules/systemconfig/dto.go | 16 +- .../modules/systemconfig/normalize.go | 94 +- .../modules/systemconfig/publish_options.go | 79 +- .../systemconfig/publish_options_test.go | 177 ++- docs/发布比例计算.md | 31 + .../admin/components/PublishOptionsDialog.vue | 1385 +++++++++++------ .../listings/api/listingOptions.spec.ts | 51 + .../features/listings/api/listingOptions.ts | 96 +- .../shared/utils/__tests__/pricing.spec.ts | 99 +- frontend/src/shared/utils/pricing.ts | 70 +- 14 files changed, 1744 insertions(+), 606 deletions(-) diff --git a/backend/internal/modules/listing/external_adjustment_test.go b/backend/internal/modules/listing/external_adjustment_test.go index 397dfe70..ab6bd365 100644 --- a/backend/internal/modules/listing/external_adjustment_test.go +++ b/backend/internal/modules/listing/external_adjustment_test.go @@ -37,8 +37,8 @@ func TestCalculateExternalListingAdjustmentByDiscountAmount(t *testing.T) { assertExternalAdjustmentNumber(t, "发布比例", result.SaleRatio, 44.4) assertExternalAdjustmentNumber(t, "号主纯币价", result.SellerCoinPrice, 225.2) assertExternalAdjustmentNumber(t, "实际让利", result.ActualDiscountAmount, 24.8) - assertExternalAdjustmentNumber(t, "额外物品", result.ConsumablePrice, 11.5) - assertExternalAdjustmentNumber(t, "号主合计", result.SellerTotalPrice, 236.7) + assertExternalAdjustmentNumber(t, "额外物品", result.ConsumablePrice, 12.5) + assertExternalAdjustmentNumber(t, "号主合计", result.SellerTotalPrice, 237.7) if result.SaleRatio <= result.ReferenceRatio { t.Fatalf("降价后应进入特惠状态,参考比例 %.1f,调整比例 %.1f", result.ReferenceRatio, result.SaleRatio) } @@ -91,8 +91,8 @@ func TestAdjustExternalListingSynchronizesAssetsPricesAndAudit(t *testing.T) { if updated.SourceChannel != "淘宝" { t.Fatalf("来源渠道 = %q,期望 淘宝", updated.SourceChannel) } - if updated.PriceCent != 33310 || updated.DepositAmountCent != 50000 { - t.Fatalf("商品价格/押金 = %d/%d,期望 33310/50000", updated.PriceCent, updated.DepositAmountCent) + if updated.PriceCent != 33410 || updated.DepositAmountCent != 50000 { + t.Fatalf("商品价格/押金 = %d/%d,期望 33410/50000", updated.PriceCent, updated.DepositAmountCent) } var storedAccount model.GameAccount @@ -117,10 +117,10 @@ func TestAdjustExternalListingSynchronizesAssetsPricesAndAudit(t *testing.T) { breakdown := ensurePriceBreakdown(summary) assertExternalAdjustmentNumber(t, "账号发布比例", readSummaryNumber(breakdown["seller_ratio"]), 42.9) assertExternalAdjustmentNumber(t, "号主纯币价", readSummaryNumber(breakdown["seller_coin_base_price"]), 279.7) - assertExternalAdjustmentNumber(t, "额外物品价格", readSummaryNumber(breakdown["consumable_price"]), 16.5) - assertExternalAdjustmentNumber(t, "号主合计", readSummaryNumber(breakdown["seller_total_price"]), 296.2) + assertExternalAdjustmentNumber(t, "额外物品价格", readSummaryNumber(breakdown["consumable_price"]), 17.5) + assertExternalAdjustmentNumber(t, "号主合计", readSummaryNumber(breakdown["seller_total_price"]), 297.2) assertExternalAdjustmentNumber(t, "租客比例", readSummaryNumber(breakdown["buyer_ratio"]), 37.9) - assertExternalAdjustmentNumber(t, "租客售价", readSummaryNumber(breakdown["buyer_total_price"]), 333.1) + assertExternalAdjustmentNumber(t, "租客售价", readSummaryNumber(breakdown["buyer_total_price"]), 334.1) if breakdown["external_admin_adjust_reason"] != "用户申请加入特惠" { t.Fatalf("调整原因未写入价格快照: %#v", breakdown["external_admin_adjust_reason"]) } @@ -141,7 +141,7 @@ func TestAdjustExternalListingSynchronizesAssetsPricesAndAudit(t *testing.T) { assertExternalAdjustmentNumber(t, "审计调整前纯币", readSummaryNumber(before["haf_coin_amount"]), 100000000) assertExternalAdjustmentNumber(t, "审计调整后纯币", readSummaryNumber(after["haf_coin_amount"]), 120000000) assertExternalAdjustmentNumber(t, "审计调整后比例", readSummaryNumber(after["sale_ratio"]), 42.9) - assertExternalAdjustmentNumber(t, "审计调整后售价", readSummaryNumber(after["listing_price_cent"]), 33310) + assertExternalAdjustmentNumber(t, "审计调整后售价", readSummaryNumber(after["listing_price_cent"]), 33410) if detail["request_id"] != "request-1" { t.Fatalf("审计 request_id = %#v,期望 request-1", detail["request_id"]) } diff --git a/backend/internal/modules/listing/receive_pricing.go b/backend/internal/modules/listing/receive_pricing.go index a920f6bf..67a27366 100644 --- a/backend/internal/modules/listing/receive_pricing.go +++ b/backend/internal/modules/listing/receive_pricing.go @@ -268,6 +268,7 @@ func (s *Service) publishRatioOptions(ctx context.Context) (systemconfig.Publish if len(parsed.SkinGroups) == 0 { parsed.SkinGroups = options.SkinGroups } + systemconfig.NormalizePublishOptions(&parsed) return parsed, nil } @@ -286,10 +287,14 @@ func calculateSellerReferenceRatio(coinM float64, summary map[string]any, option return 0 } dailyLoss := readSummaryNumber(summary["daily_loss_m"]) - return baseRatio + + ratio := baseRatio + calculateRatioConfigPenalty(options, summary, stamina, load) + coinCorrection(options.RatioConfig.CoinCorrections, coinM) + calculateDailyLossRatioAdjustment(dailyLoss) + if ratio <= 0 { + return 0 + } + return roundRatio(ratio) } func clampSaleRatio(referenceRatio, requestedRatio, minRatio float64) float64 { @@ -322,9 +327,82 @@ func calculateRatioConfigPenalty(options systemconfig.PublishOptionsDTO, summary if ratioConfigItemMatched(item, options, selectedSkins, stamina, load) { continue } + if item.Kind == "max_stamina" && + hasMatchingLevelRatioRule(options.RatioConfig.LevelRatioRules, "stamina", stamina) { + continue + } + if item.Kind == "max_load" && + hasMatchingLevelRatioRule(options.RatioConfig.LevelRatioRules, "load", load) { + continue + } penalty += item.MissingPenalty } - return penalty + penalty += calculateLevelRatioAdjustment(options.RatioConfig.LevelRatioRules, stamina, load) + penalty += calculateSpecialSkinRatioAdjustment(options.SkinGroups, selectedSkins) + return math.Round(penalty*10) / 10 +} + +func hasMatchingLevelRatioRule( + rules []systemconfig.PublishLevelRatioRule, + field string, + level string, +) bool { + for _, rule := range rules { + if strings.TrimSpace(rule.Field) == field && strings.TrimSpace(rule.Level) == level { + return true + } + } + return false +} + +func calculateLevelRatioAdjustment( + rules []systemconfig.PublishLevelRatioRule, + stamina string, + load string, +) float64 { + adjustment := 0.0 + for _, rule := range rules { + switch strings.TrimSpace(rule.Field) { + case "stamina": + if strings.TrimSpace(rule.Level) == stamina { + adjustment += rule.RatioAdjustment + } + case "load": + if strings.TrimSpace(rule.Level) == load { + adjustment += rule.RatioAdjustment + } + } + } + return adjustment +} + +func calculateSpecialSkinRatioAdjustment( + groups []systemconfig.PublishOptionGroup, + selectedSkins []string, +) float64 { + if len(selectedSkins) == 0 { + return 0 + } + selected := make(map[string]struct{}, len(selectedSkins)) + for _, skin := range selectedSkins { + skin = strings.TrimSpace(skin) + if skin != "" { + selected[skin] = struct{}{} + } + } + adjustment := 0.0 + for _, group := range groups { + if group.SpecialRatioAdjustment == 0 || len(group.SpecialPriceOptions) == 0 { + continue + } + for _, skin := range group.SpecialPriceOptions { + if _, ok := selected[strings.TrimSpace(skin)]; ok { + adjustment += group.SpecialRatioAdjustment + break + } + } + } + return adjustment } func ratioConfigItemMatched( diff --git a/backend/internal/modules/listing/receive_pricing_test.go b/backend/internal/modules/listing/receive_pricing_test.go index e2a3a34a..239cb7ec 100644 --- a/backend/internal/modules/listing/receive_pricing_test.go +++ b/backend/internal/modules/listing/receive_pricing_test.go @@ -34,8 +34,40 @@ func TestCalculateSellerReferenceRatioUsesMainSiteConfig(t *testing.T) { "daily_loss_m": 10, } got := calculateSellerReferenceRatio(100, summary, options) - if got != 43 { - t.Fatalf("reference ratio = %v, want 43 (base 40 + missing skin penalties 3)", got) + if got != 46 { + t.Fatalf("reference ratio = %v, want 46 (base 45 + missing skins 3 - max levels 2)", got) + } +} + +func TestCalculateSellerReferenceRatioAppliesLevelTierOnce(t *testing.T) { + options := systemconfig.DefaultPublishOptions() + summary := map[string]any{ + "season_insurance": "3*3", + "stamina_level": "6级", + "load_level": "6级", + "daily_loss_m": 10, + } + got := calculateSellerReferenceRatio(100, summary, options) + if got != 47 { + t.Fatalf("reference ratio = %v, want 47 (base 45 + missing skins 3 - level tiers 1)", got) + } +} + +func TestCalculateSellerReferenceRatioAppliesSpecialSkinGroupOnce(t *testing.T) { + options := systemconfig.DefaultPublishOptions() + summary := map[string]any{ + "season_insurance": "3*3", + "stamina_level": "7级", + "load_level": "7级", + "daily_loss_m": 10, + "skin_groups": map[string]any{ + "melee": []any{"北极星", "龙牙", "赤霄"}, + }, + } + got := calculateSellerReferenceRatio(100, summary, options) + // 45 + 红皮缺失 1 + 砖皮缺失 1 - 体力/负重 2 - 特殊刀皮分组 1 = 44 + if got != 44 { + t.Fatalf("reference ratio = %v, want 44", got) } } @@ -43,20 +75,20 @@ func TestApplyMainSiteReceivePricingOverwritesClientRatio(t *testing.T) { req := fullReceivePricingRequest(10) applyMainSiteReceivePricing(&req, systemconfig.DefaultPublishOptions(), defaultSalePriceConfig(), 0, 0, false) breakdown := ensurePriceBreakdown(req.AssetSummary) - if readSummaryNumber(breakdown["seller_ratio"]) != 43 { - t.Fatalf("seller_ratio = %v, want 43", breakdown["seller_ratio"]) + if readSummaryNumber(breakdown["seller_ratio"]) != 46 { + t.Fatalf("seller_ratio = %v, want 46", breakdown["seller_ratio"]) } - if readSummaryNumber(breakdown["seller_reference_ratio"]) != 43 { - t.Fatalf("seller_reference_ratio = %v, want 43", breakdown["seller_reference_ratio"]) + if readSummaryNumber(breakdown["seller_reference_ratio"]) != 46 { + t.Fatalf("seller_reference_ratio = %v, want 46", breakdown["seller_reference_ratio"]) } - if readSummaryNumber(breakdown["seller_coin_base_price"]) != 232.6 { - t.Fatalf("seller_coin_base_price = %v, want 232.6", breakdown["seller_coin_base_price"]) + if readSummaryNumber(breakdown["seller_coin_base_price"]) != 217.4 { + t.Fatalf("seller_coin_base_price = %v, want 217.4", breakdown["seller_coin_base_price"]) } - if readSummaryNumber(breakdown["buyer_ratio"]) != 38 { - t.Fatalf("buyer_ratio = %v, want 38", breakdown["buyer_ratio"]) + if readSummaryNumber(breakdown["buyer_ratio"]) != 41 { + t.Fatalf("buyer_ratio = %v, want 41", breakdown["buyer_ratio"]) } - if req.PriceCent != 26320 { - t.Fatalf("PriceCent = %d, want 26320", req.PriceCent) + if req.PriceCent != 24390 { + t.Fatalf("PriceCent = %d, want 24390", req.PriceCent) } } @@ -67,8 +99,8 @@ func TestApplyMainSiteReceivePricingKeepsAcceleratedRatioWithinMainSiteRange(t * if readSummaryNumber(breakdown["seller_ratio"]) != 50 { t.Fatalf("accelerated seller_ratio = %v, want 50", breakdown["seller_ratio"]) } - if readSummaryNumber(breakdown["seller_reference_ratio"]) != 43 { - t.Fatalf("seller_reference_ratio = %v, want 43", breakdown["seller_reference_ratio"]) + if readSummaryNumber(breakdown["seller_reference_ratio"]) != 46 { + t.Fatalf("seller_reference_ratio = %v, want 46", breakdown["seller_reference_ratio"]) } if got := readSummaryNumber(breakdown["seller_coin_base_price"]); got != 200 { t.Fatalf("accelerated seller_coin_base_price = %v, want 200", got) @@ -85,7 +117,9 @@ func TestApplyMainSiteReceivePricingKeepsAcceleratedRatioWithinMainSiteRange(t * func TestApplyMainSiteReceivePricingIncludesPremiumReviewMarkup(t *testing.T) { req := fullReceivePricingRequest(50) req.IsPremium = true - applyMainSiteReceivePricing(&req, systemconfig.DefaultPublishOptions(), defaultSalePriceConfig(), 0, 0, false) + options := systemconfig.DefaultPublishOptions() + options.RatioConfig.PremiumReviewRatioMarkup = 1 + applyMainSiteReceivePricing(&req, options, defaultSalePriceConfig(), 0, 0, false) breakdown := ensurePriceBreakdown(req.AssetSummary) if got := readSummaryNumber(breakdown["premium_review_ratio_markup"]); got != 1 { t.Fatalf("premium review markup = %v, want 1", got) @@ -105,13 +139,13 @@ func TestApplyMainSiteReceivePricingIncludesPremiumReviewMarkup(t *testing.T) { } func TestApplyMainSiteReceivePricingAllowsQualityOwnerExclusiveRatio(t *testing.T) { - req := fullReceivePricingRequest(42) + req := fullReceivePricingRequest(45) req.OwnerIsQualityOwner = true options := systemconfig.DefaultPublishOptions() applyMainSiteReceivePricing(&req, options, defaultSalePriceConfig(), 0, 0, false) breakdown := ensurePriceBreakdown(req.AssetSummary) - if readSummaryNumber(breakdown["seller_ratio"]) != 42 { - t.Fatalf("quality owner seller_ratio = %v, want 42", breakdown["seller_ratio"]) + if readSummaryNumber(breakdown["seller_ratio"]) != 45 { + t.Fatalf("quality owner seller_ratio = %v, want 45", breakdown["seller_ratio"]) } if readSummaryNumber(breakdown["quality_owner_ratio_discount"]) != 1 { t.Fatalf( @@ -120,11 +154,11 @@ func TestApplyMainSiteReceivePricingAllowsQualityOwnerExclusiveRatio(t *testing. ) } - ordinary := fullReceivePricingRequest(42) + ordinary := fullReceivePricingRequest(45) applyMainSiteReceivePricing(&ordinary, options, defaultSalePriceConfig(), 0, 0, false) ordinaryBreakdown := ensurePriceBreakdown(ordinary.AssetSummary) - if readSummaryNumber(ordinaryBreakdown["seller_ratio"]) != 43 { - t.Fatalf("ordinary seller_ratio = %v, want reference 43", ordinaryBreakdown["seller_ratio"]) + if readSummaryNumber(ordinaryBreakdown["seller_ratio"]) != 46 { + t.Fatalf("ordinary seller_ratio = %v, want reference 46", ordinaryBreakdown["seller_ratio"]) } } @@ -135,8 +169,8 @@ func TestQualityOwnerExclusiveRatioUsesConfiguredDiscount(t *testing.T) { options.RatioConfig.QualityOwnerRatioDiscount = 3 applyMainSiteReceivePricing(&req, options, defaultSalePriceConfig(), 0, 0, false) breakdown := ensurePriceBreakdown(req.AssetSummary) - if readSummaryNumber(breakdown["seller_ratio"]) != 40 { - t.Fatalf("configured quality owner seller_ratio = %v, want 40", breakdown["seller_ratio"]) + if readSummaryNumber(breakdown["seller_ratio"]) != 43 { + t.Fatalf("configured quality owner seller_ratio = %v, want 43", breakdown["seller_ratio"]) } } @@ -165,11 +199,11 @@ func TestDistributionReceiveCostDeltaZeroKeepsMainSitePrice(t *testing.T) { req := fullReceivePricingRequest(50) applyMainSiteReceivePricing(&req, systemconfig.DefaultPublishOptions(), defaultSalePriceConfig(), 0, 0, true) breakdown := ensurePriceBreakdown(req.AssetSummary) - if readSummaryNumber(breakdown["seller_ratio"]) != 43 { - t.Fatalf("distribution seller_ratio = %v, want main-site reference 43 when cost delta is 0", breakdown["seller_ratio"]) + if readSummaryNumber(breakdown["seller_ratio"]) != 46 { + t.Fatalf("distribution seller_ratio = %v, want main-site reference 46 when cost delta is 0", breakdown["seller_ratio"]) } - if readSummaryNumber(breakdown["buyer_total_price"]) != 263.2 { - t.Fatalf("distribution buyer_total_price = %v, want 263.2 anchored to main site", breakdown["buyer_total_price"]) + if readSummaryNumber(breakdown["buyer_total_price"]) != 243.9 { + t.Fatalf("distribution buyer_total_price = %v, want 243.9 anchored to main site", breakdown["buyer_total_price"]) } } @@ -177,24 +211,24 @@ func TestDistributionReceiveCostDeltaLowersReceivePriceKeepsSellPrice(t *testing req := fullReceivePricingRequest(50) applyMainSiteReceivePricing(&req, systemconfig.DefaultPublishOptions(), defaultSalePriceConfig(), 0, 3, true) breakdown := ensurePriceBreakdown(req.AssetSummary) - // 压价 3 点:收号比例 = R+3 = 46,号主收 217.4(低于主站 232.6)。 - if readSummaryNumber(breakdown["seller_ratio"]) != 46 { - t.Fatalf("distribution seller_ratio = %v, want 46 (R+3) under cost-decoupled model", breakdown["seller_ratio"]) + // 压价 3 点:收号比例 = R+3 = 49,号主收 204.1(低于主站 217.4)。 + if readSummaryNumber(breakdown["seller_ratio"]) != 49 { + t.Fatalf("distribution seller_ratio = %v, want 49 (R+3) under cost-decoupled model", breakdown["seller_ratio"]) } - if got := readSummaryNumber(breakdown["seller_coin_base_price"]); got != 217.4 { - t.Fatalf("seller_coin_base_price = %v, want 217.4 (lower than main site 232.6)", got) + if got := readSummaryNumber(breakdown["seller_coin_base_price"]); got != 204.1 { + t.Fatalf("seller_coin_base_price = %v, want 204.1 (lower than main site 217.4)", got) } - // 卖价锚定主站:买家比例仍为 38、买家价仍为 263.2,不随收号价下降。 - if readSummaryNumber(breakdown["buyer_ratio"]) != 38 { - t.Fatalf("buyer_ratio = %v, want 38 (decoupled from receive ratio)", breakdown["buyer_ratio"]) + // 卖价锚定主站:买家比例仍为 41、买家价仍为 243.9,不随收号价下降。 + if readSummaryNumber(breakdown["buyer_ratio"]) != 41 { + t.Fatalf("buyer_ratio = %v, want 41 (decoupled from receive ratio)", breakdown["buyer_ratio"]) } - if readSummaryNumber(breakdown["buyer_total_price"]) != 263.2 { - t.Fatalf("buyer_total_price = %v, want 263.2 unchanged by cost delta", breakdown["buyer_total_price"]) + if readSummaryNumber(breakdown["buyer_total_price"]) != 243.9 { + t.Fatalf("buyer_total_price = %v, want 243.9 unchanged by cost delta", breakdown["buyer_total_price"]) } - // 注意:发布快照的 platform_markup_amount 仍为主站口径提价(30.6,锚定价→买价); - // 压价差不在此体现,而是结算层 profit = 净付款 − 号主快照价(217.4)自动进入 35/40/25 分成池。 - if readSummaryNumber(breakdown["platform_markup_amount"]) != 30.6 { - t.Fatalf("platform_markup_amount = %v, want 30.6 (main-site anchored markup)", breakdown["platform_markup_amount"]) + // 注意:发布快照的 platform_markup_amount 仍为主站口径提价(26.5,主站参考价→买价); + // 压价差不在此体现,而是结算层 profit = 净付款 − 号主快照价(204.1)自动进入 35/40/25 分成池。 + if readSummaryNumber(breakdown["platform_markup_amount"]) != 26.5 { + t.Fatalf("platform_markup_amount = %v, want 26.5 (main-site anchored markup)", breakdown["platform_markup_amount"]) } if readSummaryNumber(breakdown["site_receive_cost_delta"]) != 3 { t.Fatalf("site_receive_cost_delta = %v, want 3", breakdown["site_receive_cost_delta"]) diff --git a/backend/internal/modules/listing/service_test.go b/backend/internal/modules/listing/service_test.go index 514d504e..3aca142e 100644 --- a/backend/internal/modules/listing/service_test.go +++ b/backend/internal/modules/listing/service_test.go @@ -750,7 +750,7 @@ func TestExternalAccountToCreateRequestMapsUploadFields(t *testing.T) { if req.HafCoinAmount != 197100000 { t.Fatalf("expected haf coin amount 197100000, got %d", req.HafCoinAmount) } - if req.PriceCent != 59590 || req.DepositAmountCent != 40000 { + if req.PriceCent != 60040 || req.DepositAmountCent != 40000 { t.Fatalf("unexpected price/deposit cent %d/%d", req.PriceCent, req.DepositAmountCent) } if req.AssetSummary["season_insurance"] != "3*3" { @@ -790,10 +790,10 @@ func TestExternalAccountToCreateRequestMapsUploadFields(t *testing.T) { t.Fatalf("price_breakdown = %#v", req.AssetSummary["price_breakdown"]) } if breakdown["seller_coin_base_price"] != 458.0 || - breakdown["consumable_price"] != 90.5 || - breakdown["seller_total_price"] != 548.5 || + breakdown["consumable_price"] != 95.0 || + breakdown["seller_total_price"] != 553.0 || breakdown["buyer_coin_base_price"] != 505.4 || - breakdown["buyer_total_price"] != 595.9 || + breakdown["buyer_total_price"] != 600.4 || breakdown["buyer_ratio"] != 39.0 || breakdown["platform_markup_amount"] != 47.4 || breakdown["platform_rule_type"] != "ratio_subtract" { @@ -850,19 +850,19 @@ func TestExternalAccountToCreateRequestSeparatesPureCoinAndExtraItems(t *testing t.Fatalf("price_breakdown = %#v", req.AssetSummary["price_breakdown"]) } if breakdown["seller_coin_base_price"] != 659.0 || - breakdown["consumable_price"] != 11.0 || - breakdown["seller_total_price"] != 670.0 { + breakdown["consumable_price"] != 12.0 || + breakdown["seller_total_price"] != 671.0 { t.Fatalf("回收租金未按纯币价与额外物品拆分:%#v", breakdown) } if breakdown["buyer_coin_base_price"] != 717.6 || - breakdown["buyer_total_price"] != 728.6 || + breakdown["buyer_total_price"] != 729.6 || breakdown["buyer_ratio"] != 39.3 || breakdown["platform_markup_amount"] != 58.6 || breakdown["platform_rule_type"] != "ratio_subtract" { t.Fatalf("外部上传未按比例加价:%#v", breakdown) } - if req.PriceCent != 72860 { - t.Fatalf("PriceCent = %d, want 72860", req.PriceCent) + if req.PriceCent != 72960 { + t.Fatalf("PriceCent = %d, want 72960", req.PriceCent) } } @@ -1332,14 +1332,14 @@ func TestCreateDistributionListingUsesMainSiteReceiveRatio(t *testing.T) { } pricing := ReceivePricingFromAssetSummary(mustMarshalSummary(t, dto.AssetSummary)) - if pricing.SellerRatio != 43 { - t.Fatalf("distribution receive seller_ratio = %v, want 43 from main-site ratio_config", pricing.SellerRatio) + if pricing.SellerRatio != 46 { + t.Fatalf("distribution receive seller_ratio = %v, want 46 from main-site ratio_config", pricing.SellerRatio) } - if pricing.SellerTotalPriceCent != 23260 { - t.Fatalf("seller_total_price_cent = %d, want 23260", pricing.SellerTotalPriceCent) + if pricing.SellerTotalPriceCent != 21740 { + t.Fatalf("seller_total_price_cent = %d, want 21740", pricing.SellerTotalPriceCent) } - if dto.PriceCent != 26320 { - t.Fatalf("listing PriceCent = %d, want 26320 from main-site sale price", dto.PriceCent) + if dto.PriceCent != 24390 { + t.Fatalf("listing PriceCent = %d, want 24390 from main-site sale price", dto.PriceCent) } if dto.DistributionSiteCode != "dist_ratio_1" { t.Fatalf("DistributionSiteCode = %s, want dist_ratio_1", dto.DistributionSiteCode) @@ -1399,11 +1399,11 @@ func TestCreateDistributionListingAppliesSiteReceiveCostDelta(t *testing.T) { t.Fatalf("Create failed: %v", err) } pricing := ReceivePricingFromAssetSummary(mustMarshalSummary(t, dto.AssetSummary)) - if pricing.SellerRatio != 46 { - t.Fatalf("seller_ratio = %v, want 46 after site cost delta 3 (R=43+3) under decoupled model", pricing.SellerRatio) + if pricing.SellerRatio != 49 { + t.Fatalf("seller_ratio = %v, want 49 after site cost delta 3 (R=46+3) under decoupled model", pricing.SellerRatio) } - if dto.PriceCent != 26320 { - t.Fatalf("listing PriceCent = %d, want 26320 (buyer price stays anchored to main-site R)", dto.PriceCent) + if dto.PriceCent != 24390 { + t.Fatalf("listing PriceCent = %d, want 24390 (buyer price stays anchored to main-site R)", dto.PriceCent) } } diff --git a/backend/internal/modules/systemconfig/dto.go b/backend/internal/modules/systemconfig/dto.go index 23b36d9e..521f7d3a 100644 --- a/backend/internal/modules/systemconfig/dto.go +++ b/backend/internal/modules/systemconfig/dto.go @@ -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"` diff --git a/backend/internal/modules/systemconfig/normalize.go b/backend/internal/modules/systemconfig/normalize.go index acb65e7c..9a424045 100644 --- a/backend/internal/modules/systemconfig/normalize.go +++ b/backend/internal/modules/systemconfig/normalize.go @@ -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 diff --git a/backend/internal/modules/systemconfig/publish_options.go b/backend/internal/modules/systemconfig/publish_options.go index 316f7ca1..b50bc8b7 100644 --- a/backend/internal/modules/systemconfig/publish_options.go +++ b/backend/internal/modules/systemconfig/publish_options.go @@ -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}, diff --git a/backend/internal/modules/systemconfig/publish_options_test.go b/backend/internal/modules/systemconfig/publish_options_test.go index b237d5b3..0610b853 100644 --- a/backend/internal/modules/systemconfig/publish_options_test.go +++ b/backend/internal/modules/systemconfig/publish_options_test.go @@ -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, ) } diff --git a/docs/发布比例计算.md b/docs/发布比例计算.md index f7f1cc02..b0327794 100644 --- a/docs/发布比例计算.md +++ b/docs/发布比例计算.md @@ -8,6 +8,9 @@ --- +> 当前生产基础比例以后台「系统配置 → 发布表单选项 → 比例计算配置」为准。 +> 默认配置已同步为 `3*3=45、2*3=47、2*2=51、2*1=51`,不再使用下文的早期 `40/42/47/48` 示例值。 + ### 1. 核心大框架:基础比例(对标保险箱) 这是账号在配置全满(完美状态)下的初始比例: @@ -61,3 +64,31 @@ 4. **总计**:$40 + 3 + 2.5 = 45.5$ **最终该号的出租比例就是:$1:45.5$** + +--- + +### 4. 体力、负重与特殊皮肤分组修正 + +体力/负重支持按选中等级直接修正比例: + +- `7级`:`-1` +- `6级`:`-0.5` +- 命中上述等级规则时,不再叠加旧的“满体力/满负重”缺失加成 +- 未命中等级规则的低等级,继续使用后台“配置项缺失加成” + +每个皮肤分类还可以配置一个“特殊价格名单”和额外比例,例如近战皮肤默认: + +- 普通皮肤命中刀皮分组:抵消基础刀皮缺失加成 +- 包含 `赤霄` 或 `龙牙`:特殊刀皮分组再额外 `-1` +- 同一特殊分组内同时命中多件皮肤,只修正一次,不按件数叠加 + +最终参考比例: + +```text +R = 保险基础比例 + + 缺失项加成 + + 体力/负重等级修正 + + 特殊皮肤分组修正 + + 大额币修正 + + 日均损耗修正 +``` diff --git a/frontend/src/features/admin/components/PublishOptionsDialog.vue b/frontend/src/features/admin/components/PublishOptionsDialog.vue index aaff4578..555b0525 100644 --- a/frontend/src/features/admin/components/PublishOptionsDialog.vue +++ b/frontend/src/features/admin/components/PublishOptionsDialog.vue @@ -1,7 +1,8 @@