feat(publish): 增加等级与特殊皮肤价格修正
This commit is contained in:
@@ -37,8 +37,8 @@ func TestCalculateExternalListingAdjustmentByDiscountAmount(t *testing.T) {
|
|||||||
assertExternalAdjustmentNumber(t, "发布比例", result.SaleRatio, 44.4)
|
assertExternalAdjustmentNumber(t, "发布比例", result.SaleRatio, 44.4)
|
||||||
assertExternalAdjustmentNumber(t, "号主纯币价", result.SellerCoinPrice, 225.2)
|
assertExternalAdjustmentNumber(t, "号主纯币价", result.SellerCoinPrice, 225.2)
|
||||||
assertExternalAdjustmentNumber(t, "实际让利", result.ActualDiscountAmount, 24.8)
|
assertExternalAdjustmentNumber(t, "实际让利", result.ActualDiscountAmount, 24.8)
|
||||||
assertExternalAdjustmentNumber(t, "额外物品", result.ConsumablePrice, 11.5)
|
assertExternalAdjustmentNumber(t, "额外物品", result.ConsumablePrice, 12.5)
|
||||||
assertExternalAdjustmentNumber(t, "号主合计", result.SellerTotalPrice, 236.7)
|
assertExternalAdjustmentNumber(t, "号主合计", result.SellerTotalPrice, 237.7)
|
||||||
if result.SaleRatio <= result.ReferenceRatio {
|
if result.SaleRatio <= result.ReferenceRatio {
|
||||||
t.Fatalf("降价后应进入特惠状态,参考比例 %.1f,调整比例 %.1f", result.ReferenceRatio, result.SaleRatio)
|
t.Fatalf("降价后应进入特惠状态,参考比例 %.1f,调整比例 %.1f", result.ReferenceRatio, result.SaleRatio)
|
||||||
}
|
}
|
||||||
@@ -91,8 +91,8 @@ func TestAdjustExternalListingSynchronizesAssetsPricesAndAudit(t *testing.T) {
|
|||||||
if updated.SourceChannel != "淘宝" {
|
if updated.SourceChannel != "淘宝" {
|
||||||
t.Fatalf("来源渠道 = %q,期望 淘宝", updated.SourceChannel)
|
t.Fatalf("来源渠道 = %q,期望 淘宝", updated.SourceChannel)
|
||||||
}
|
}
|
||||||
if updated.PriceCent != 33310 || updated.DepositAmountCent != 50000 {
|
if updated.PriceCent != 33410 || updated.DepositAmountCent != 50000 {
|
||||||
t.Fatalf("商品价格/押金 = %d/%d,期望 33310/50000", updated.PriceCent, updated.DepositAmountCent)
|
t.Fatalf("商品价格/押金 = %d/%d,期望 33410/50000", updated.PriceCent, updated.DepositAmountCent)
|
||||||
}
|
}
|
||||||
|
|
||||||
var storedAccount model.GameAccount
|
var storedAccount model.GameAccount
|
||||||
@@ -117,10 +117,10 @@ func TestAdjustExternalListingSynchronizesAssetsPricesAndAudit(t *testing.T) {
|
|||||||
breakdown := ensurePriceBreakdown(summary)
|
breakdown := ensurePriceBreakdown(summary)
|
||||||
assertExternalAdjustmentNumber(t, "账号发布比例", readSummaryNumber(breakdown["seller_ratio"]), 42.9)
|
assertExternalAdjustmentNumber(t, "账号发布比例", readSummaryNumber(breakdown["seller_ratio"]), 42.9)
|
||||||
assertExternalAdjustmentNumber(t, "号主纯币价", readSummaryNumber(breakdown["seller_coin_base_price"]), 279.7)
|
assertExternalAdjustmentNumber(t, "号主纯币价", readSummaryNumber(breakdown["seller_coin_base_price"]), 279.7)
|
||||||
assertExternalAdjustmentNumber(t, "额外物品价格", readSummaryNumber(breakdown["consumable_price"]), 16.5)
|
assertExternalAdjustmentNumber(t, "额外物品价格", readSummaryNumber(breakdown["consumable_price"]), 17.5)
|
||||||
assertExternalAdjustmentNumber(t, "号主合计", readSummaryNumber(breakdown["seller_total_price"]), 296.2)
|
assertExternalAdjustmentNumber(t, "号主合计", readSummaryNumber(breakdown["seller_total_price"]), 297.2)
|
||||||
assertExternalAdjustmentNumber(t, "租客比例", readSummaryNumber(breakdown["buyer_ratio"]), 37.9)
|
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"] != "用户申请加入特惠" {
|
if breakdown["external_admin_adjust_reason"] != "用户申请加入特惠" {
|
||||||
t.Fatalf("调整原因未写入价格快照: %#v", 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(before["haf_coin_amount"]), 100000000)
|
||||||
assertExternalAdjustmentNumber(t, "审计调整后纯币", readSummaryNumber(after["haf_coin_amount"]), 120000000)
|
assertExternalAdjustmentNumber(t, "审计调整后纯币", readSummaryNumber(after["haf_coin_amount"]), 120000000)
|
||||||
assertExternalAdjustmentNumber(t, "审计调整后比例", readSummaryNumber(after["sale_ratio"]), 42.9)
|
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" {
|
if detail["request_id"] != "request-1" {
|
||||||
t.Fatalf("审计 request_id = %#v,期望 request-1", detail["request_id"])
|
t.Fatalf("审计 request_id = %#v,期望 request-1", detail["request_id"])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -268,6 +268,7 @@ func (s *Service) publishRatioOptions(ctx context.Context) (systemconfig.Publish
|
|||||||
if len(parsed.SkinGroups) == 0 {
|
if len(parsed.SkinGroups) == 0 {
|
||||||
parsed.SkinGroups = options.SkinGroups
|
parsed.SkinGroups = options.SkinGroups
|
||||||
}
|
}
|
||||||
|
systemconfig.NormalizePublishOptions(&parsed)
|
||||||
return parsed, nil
|
return parsed, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,10 +287,14 @@ func calculateSellerReferenceRatio(coinM float64, summary map[string]any, option
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
dailyLoss := readSummaryNumber(summary["daily_loss_m"])
|
dailyLoss := readSummaryNumber(summary["daily_loss_m"])
|
||||||
return baseRatio +
|
ratio := baseRatio +
|
||||||
calculateRatioConfigPenalty(options, summary, stamina, load) +
|
calculateRatioConfigPenalty(options, summary, stamina, load) +
|
||||||
coinCorrection(options.RatioConfig.CoinCorrections, coinM) +
|
coinCorrection(options.RatioConfig.CoinCorrections, coinM) +
|
||||||
calculateDailyLossRatioAdjustment(dailyLoss)
|
calculateDailyLossRatioAdjustment(dailyLoss)
|
||||||
|
if ratio <= 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return roundRatio(ratio)
|
||||||
}
|
}
|
||||||
|
|
||||||
func clampSaleRatio(referenceRatio, requestedRatio, minRatio float64) float64 {
|
func clampSaleRatio(referenceRatio, requestedRatio, minRatio float64) float64 {
|
||||||
@@ -322,9 +327,82 @@ func calculateRatioConfigPenalty(options systemconfig.PublishOptionsDTO, summary
|
|||||||
if ratioConfigItemMatched(item, options, selectedSkins, stamina, load) {
|
if ratioConfigItemMatched(item, options, selectedSkins, stamina, load) {
|
||||||
continue
|
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
|
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(
|
func ratioConfigItemMatched(
|
||||||
|
|||||||
@@ -34,8 +34,40 @@ func TestCalculateSellerReferenceRatioUsesMainSiteConfig(t *testing.T) {
|
|||||||
"daily_loss_m": 10,
|
"daily_loss_m": 10,
|
||||||
}
|
}
|
||||||
got := calculateSellerReferenceRatio(100, summary, options)
|
got := calculateSellerReferenceRatio(100, summary, options)
|
||||||
if got != 43 {
|
if got != 46 {
|
||||||
t.Fatalf("reference ratio = %v, want 43 (base 40 + missing skin penalties 3)", got)
|
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)
|
req := fullReceivePricingRequest(10)
|
||||||
applyMainSiteReceivePricing(&req, systemconfig.DefaultPublishOptions(), defaultSalePriceConfig(), 0, 0, false)
|
applyMainSiteReceivePricing(&req, systemconfig.DefaultPublishOptions(), defaultSalePriceConfig(), 0, 0, false)
|
||||||
breakdown := ensurePriceBreakdown(req.AssetSummary)
|
breakdown := ensurePriceBreakdown(req.AssetSummary)
|
||||||
if readSummaryNumber(breakdown["seller_ratio"]) != 43 {
|
if readSummaryNumber(breakdown["seller_ratio"]) != 46 {
|
||||||
t.Fatalf("seller_ratio = %v, want 43", breakdown["seller_ratio"])
|
t.Fatalf("seller_ratio = %v, want 46", breakdown["seller_ratio"])
|
||||||
}
|
}
|
||||||
if readSummaryNumber(breakdown["seller_reference_ratio"]) != 43 {
|
if readSummaryNumber(breakdown["seller_reference_ratio"]) != 46 {
|
||||||
t.Fatalf("seller_reference_ratio = %v, want 43", breakdown["seller_reference_ratio"])
|
t.Fatalf("seller_reference_ratio = %v, want 46", breakdown["seller_reference_ratio"])
|
||||||
}
|
}
|
||||||
if readSummaryNumber(breakdown["seller_coin_base_price"]) != 232.6 {
|
if readSummaryNumber(breakdown["seller_coin_base_price"]) != 217.4 {
|
||||||
t.Fatalf("seller_coin_base_price = %v, want 232.6", breakdown["seller_coin_base_price"])
|
t.Fatalf("seller_coin_base_price = %v, want 217.4", breakdown["seller_coin_base_price"])
|
||||||
}
|
}
|
||||||
if readSummaryNumber(breakdown["buyer_ratio"]) != 38 {
|
if readSummaryNumber(breakdown["buyer_ratio"]) != 41 {
|
||||||
t.Fatalf("buyer_ratio = %v, want 38", breakdown["buyer_ratio"])
|
t.Fatalf("buyer_ratio = %v, want 41", breakdown["buyer_ratio"])
|
||||||
}
|
}
|
||||||
if req.PriceCent != 26320 {
|
if req.PriceCent != 24390 {
|
||||||
t.Fatalf("PriceCent = %d, want 26320", req.PriceCent)
|
t.Fatalf("PriceCent = %d, want 24390", req.PriceCent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,8 +99,8 @@ func TestApplyMainSiteReceivePricingKeepsAcceleratedRatioWithinMainSiteRange(t *
|
|||||||
if readSummaryNumber(breakdown["seller_ratio"]) != 50 {
|
if readSummaryNumber(breakdown["seller_ratio"]) != 50 {
|
||||||
t.Fatalf("accelerated seller_ratio = %v, want 50", breakdown["seller_ratio"])
|
t.Fatalf("accelerated seller_ratio = %v, want 50", breakdown["seller_ratio"])
|
||||||
}
|
}
|
||||||
if readSummaryNumber(breakdown["seller_reference_ratio"]) != 43 {
|
if readSummaryNumber(breakdown["seller_reference_ratio"]) != 46 {
|
||||||
t.Fatalf("seller_reference_ratio = %v, want 43", breakdown["seller_reference_ratio"])
|
t.Fatalf("seller_reference_ratio = %v, want 46", breakdown["seller_reference_ratio"])
|
||||||
}
|
}
|
||||||
if got := readSummaryNumber(breakdown["seller_coin_base_price"]); got != 200 {
|
if got := readSummaryNumber(breakdown["seller_coin_base_price"]); got != 200 {
|
||||||
t.Fatalf("accelerated seller_coin_base_price = %v, want 200", got)
|
t.Fatalf("accelerated seller_coin_base_price = %v, want 200", got)
|
||||||
@@ -85,7 +117,9 @@ func TestApplyMainSiteReceivePricingKeepsAcceleratedRatioWithinMainSiteRange(t *
|
|||||||
func TestApplyMainSiteReceivePricingIncludesPremiumReviewMarkup(t *testing.T) {
|
func TestApplyMainSiteReceivePricingIncludesPremiumReviewMarkup(t *testing.T) {
|
||||||
req := fullReceivePricingRequest(50)
|
req := fullReceivePricingRequest(50)
|
||||||
req.IsPremium = true
|
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)
|
breakdown := ensurePriceBreakdown(req.AssetSummary)
|
||||||
if got := readSummaryNumber(breakdown["premium_review_ratio_markup"]); got != 1 {
|
if got := readSummaryNumber(breakdown["premium_review_ratio_markup"]); got != 1 {
|
||||||
t.Fatalf("premium review markup = %v, want 1", got)
|
t.Fatalf("premium review markup = %v, want 1", got)
|
||||||
@@ -105,13 +139,13 @@ func TestApplyMainSiteReceivePricingIncludesPremiumReviewMarkup(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestApplyMainSiteReceivePricingAllowsQualityOwnerExclusiveRatio(t *testing.T) {
|
func TestApplyMainSiteReceivePricingAllowsQualityOwnerExclusiveRatio(t *testing.T) {
|
||||||
req := fullReceivePricingRequest(42)
|
req := fullReceivePricingRequest(45)
|
||||||
req.OwnerIsQualityOwner = true
|
req.OwnerIsQualityOwner = true
|
||||||
options := systemconfig.DefaultPublishOptions()
|
options := systemconfig.DefaultPublishOptions()
|
||||||
applyMainSiteReceivePricing(&req, options, defaultSalePriceConfig(), 0, 0, false)
|
applyMainSiteReceivePricing(&req, options, defaultSalePriceConfig(), 0, 0, false)
|
||||||
breakdown := ensurePriceBreakdown(req.AssetSummary)
|
breakdown := ensurePriceBreakdown(req.AssetSummary)
|
||||||
if readSummaryNumber(breakdown["seller_ratio"]) != 42 {
|
if readSummaryNumber(breakdown["seller_ratio"]) != 45 {
|
||||||
t.Fatalf("quality owner seller_ratio = %v, want 42", breakdown["seller_ratio"])
|
t.Fatalf("quality owner seller_ratio = %v, want 45", breakdown["seller_ratio"])
|
||||||
}
|
}
|
||||||
if readSummaryNumber(breakdown["quality_owner_ratio_discount"]) != 1 {
|
if readSummaryNumber(breakdown["quality_owner_ratio_discount"]) != 1 {
|
||||||
t.Fatalf(
|
t.Fatalf(
|
||||||
@@ -120,11 +154,11 @@ func TestApplyMainSiteReceivePricingAllowsQualityOwnerExclusiveRatio(t *testing.
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
ordinary := fullReceivePricingRequest(42)
|
ordinary := fullReceivePricingRequest(45)
|
||||||
applyMainSiteReceivePricing(&ordinary, options, defaultSalePriceConfig(), 0, 0, false)
|
applyMainSiteReceivePricing(&ordinary, options, defaultSalePriceConfig(), 0, 0, false)
|
||||||
ordinaryBreakdown := ensurePriceBreakdown(ordinary.AssetSummary)
|
ordinaryBreakdown := ensurePriceBreakdown(ordinary.AssetSummary)
|
||||||
if readSummaryNumber(ordinaryBreakdown["seller_ratio"]) != 43 {
|
if readSummaryNumber(ordinaryBreakdown["seller_ratio"]) != 46 {
|
||||||
t.Fatalf("ordinary seller_ratio = %v, want reference 43", ordinaryBreakdown["seller_ratio"])
|
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
|
options.RatioConfig.QualityOwnerRatioDiscount = 3
|
||||||
applyMainSiteReceivePricing(&req, options, defaultSalePriceConfig(), 0, 0, false)
|
applyMainSiteReceivePricing(&req, options, defaultSalePriceConfig(), 0, 0, false)
|
||||||
breakdown := ensurePriceBreakdown(req.AssetSummary)
|
breakdown := ensurePriceBreakdown(req.AssetSummary)
|
||||||
if readSummaryNumber(breakdown["seller_ratio"]) != 40 {
|
if readSummaryNumber(breakdown["seller_ratio"]) != 43 {
|
||||||
t.Fatalf("configured quality owner seller_ratio = %v, want 40", breakdown["seller_ratio"])
|
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)
|
req := fullReceivePricingRequest(50)
|
||||||
applyMainSiteReceivePricing(&req, systemconfig.DefaultPublishOptions(), defaultSalePriceConfig(), 0, 0, true)
|
applyMainSiteReceivePricing(&req, systemconfig.DefaultPublishOptions(), defaultSalePriceConfig(), 0, 0, true)
|
||||||
breakdown := ensurePriceBreakdown(req.AssetSummary)
|
breakdown := ensurePriceBreakdown(req.AssetSummary)
|
||||||
if readSummaryNumber(breakdown["seller_ratio"]) != 43 {
|
if readSummaryNumber(breakdown["seller_ratio"]) != 46 {
|
||||||
t.Fatalf("distribution seller_ratio = %v, want main-site reference 43 when cost delta is 0", breakdown["seller_ratio"])
|
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 {
|
if readSummaryNumber(breakdown["buyer_total_price"]) != 243.9 {
|
||||||
t.Fatalf("distribution buyer_total_price = %v, want 263.2 anchored to main site", breakdown["buyer_total_price"])
|
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)
|
req := fullReceivePricingRequest(50)
|
||||||
applyMainSiteReceivePricing(&req, systemconfig.DefaultPublishOptions(), defaultSalePriceConfig(), 0, 3, true)
|
applyMainSiteReceivePricing(&req, systemconfig.DefaultPublishOptions(), defaultSalePriceConfig(), 0, 3, true)
|
||||||
breakdown := ensurePriceBreakdown(req.AssetSummary)
|
breakdown := ensurePriceBreakdown(req.AssetSummary)
|
||||||
// 压价 3 点:收号比例 = R+3 = 46,号主收 217.4(低于主站 232.6)。
|
// 压价 3 点:收号比例 = R+3 = 49,号主收 204.1(低于主站 217.4)。
|
||||||
if readSummaryNumber(breakdown["seller_ratio"]) != 46 {
|
if readSummaryNumber(breakdown["seller_ratio"]) != 49 {
|
||||||
t.Fatalf("distribution seller_ratio = %v, want 46 (R+3) under cost-decoupled model", breakdown["seller_ratio"])
|
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 {
|
if got := readSummaryNumber(breakdown["seller_coin_base_price"]); got != 204.1 {
|
||||||
t.Fatalf("seller_coin_base_price = %v, want 217.4 (lower than main site 232.6)", got)
|
t.Fatalf("seller_coin_base_price = %v, want 204.1 (lower than main site 217.4)", got)
|
||||||
}
|
}
|
||||||
// 卖价锚定主站:买家比例仍为 38、买家价仍为 263.2,不随收号价下降。
|
// 卖价锚定主站:买家比例仍为 41、买家价仍为 243.9,不随收号价下降。
|
||||||
if readSummaryNumber(breakdown["buyer_ratio"]) != 38 {
|
if readSummaryNumber(breakdown["buyer_ratio"]) != 41 {
|
||||||
t.Fatalf("buyer_ratio = %v, want 38 (decoupled from receive ratio)", breakdown["buyer_ratio"])
|
t.Fatalf("buyer_ratio = %v, want 41 (decoupled from receive ratio)", breakdown["buyer_ratio"])
|
||||||
}
|
}
|
||||||
if readSummaryNumber(breakdown["buyer_total_price"]) != 263.2 {
|
if readSummaryNumber(breakdown["buyer_total_price"]) != 243.9 {
|
||||||
t.Fatalf("buyer_total_price = %v, want 263.2 unchanged by cost delta", breakdown["buyer_total_price"])
|
t.Fatalf("buyer_total_price = %v, want 243.9 unchanged by cost delta", breakdown["buyer_total_price"])
|
||||||
}
|
}
|
||||||
// 注意:发布快照的 platform_markup_amount 仍为主站口径提价(30.6,锚定价→买价);
|
// 注意:发布快照的 platform_markup_amount 仍为主站口径提价(26.5,主站参考价→买价);
|
||||||
// 压价差不在此体现,而是结算层 profit = 净付款 − 号主快照价(217.4)自动进入 35/40/25 分成池。
|
// 压价差不在此体现,而是结算层 profit = 净付款 − 号主快照价(204.1)自动进入 35/40/25 分成池。
|
||||||
if readSummaryNumber(breakdown["platform_markup_amount"]) != 30.6 {
|
if readSummaryNumber(breakdown["platform_markup_amount"]) != 26.5 {
|
||||||
t.Fatalf("platform_markup_amount = %v, want 30.6 (main-site anchored markup)", breakdown["platform_markup_amount"])
|
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 {
|
if readSummaryNumber(breakdown["site_receive_cost_delta"]) != 3 {
|
||||||
t.Fatalf("site_receive_cost_delta = %v, want 3", breakdown["site_receive_cost_delta"])
|
t.Fatalf("site_receive_cost_delta = %v, want 3", breakdown["site_receive_cost_delta"])
|
||||||
|
|||||||
@@ -750,7 +750,7 @@ func TestExternalAccountToCreateRequestMapsUploadFields(t *testing.T) {
|
|||||||
if req.HafCoinAmount != 197100000 {
|
if req.HafCoinAmount != 197100000 {
|
||||||
t.Fatalf("expected haf coin amount 197100000, got %d", req.HafCoinAmount)
|
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)
|
t.Fatalf("unexpected price/deposit cent %d/%d", req.PriceCent, req.DepositAmountCent)
|
||||||
}
|
}
|
||||||
if req.AssetSummary["season_insurance"] != "3*3" {
|
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"])
|
t.Fatalf("price_breakdown = %#v", req.AssetSummary["price_breakdown"])
|
||||||
}
|
}
|
||||||
if breakdown["seller_coin_base_price"] != 458.0 ||
|
if breakdown["seller_coin_base_price"] != 458.0 ||
|
||||||
breakdown["consumable_price"] != 90.5 ||
|
breakdown["consumable_price"] != 95.0 ||
|
||||||
breakdown["seller_total_price"] != 548.5 ||
|
breakdown["seller_total_price"] != 553.0 ||
|
||||||
breakdown["buyer_coin_base_price"] != 505.4 ||
|
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["buyer_ratio"] != 39.0 ||
|
||||||
breakdown["platform_markup_amount"] != 47.4 ||
|
breakdown["platform_markup_amount"] != 47.4 ||
|
||||||
breakdown["platform_rule_type"] != "ratio_subtract" {
|
breakdown["platform_rule_type"] != "ratio_subtract" {
|
||||||
@@ -850,19 +850,19 @@ func TestExternalAccountToCreateRequestSeparatesPureCoinAndExtraItems(t *testing
|
|||||||
t.Fatalf("price_breakdown = %#v", req.AssetSummary["price_breakdown"])
|
t.Fatalf("price_breakdown = %#v", req.AssetSummary["price_breakdown"])
|
||||||
}
|
}
|
||||||
if breakdown["seller_coin_base_price"] != 659.0 ||
|
if breakdown["seller_coin_base_price"] != 659.0 ||
|
||||||
breakdown["consumable_price"] != 11.0 ||
|
breakdown["consumable_price"] != 12.0 ||
|
||||||
breakdown["seller_total_price"] != 670.0 {
|
breakdown["seller_total_price"] != 671.0 {
|
||||||
t.Fatalf("回收租金未按纯币价与额外物品拆分:%#v", breakdown)
|
t.Fatalf("回收租金未按纯币价与额外物品拆分:%#v", breakdown)
|
||||||
}
|
}
|
||||||
if breakdown["buyer_coin_base_price"] != 717.6 ||
|
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["buyer_ratio"] != 39.3 ||
|
||||||
breakdown["platform_markup_amount"] != 58.6 ||
|
breakdown["platform_markup_amount"] != 58.6 ||
|
||||||
breakdown["platform_rule_type"] != "ratio_subtract" {
|
breakdown["platform_rule_type"] != "ratio_subtract" {
|
||||||
t.Fatalf("外部上传未按比例加价:%#v", breakdown)
|
t.Fatalf("外部上传未按比例加价:%#v", breakdown)
|
||||||
}
|
}
|
||||||
if req.PriceCent != 72860 {
|
if req.PriceCent != 72960 {
|
||||||
t.Fatalf("PriceCent = %d, want 72860", req.PriceCent)
|
t.Fatalf("PriceCent = %d, want 72960", req.PriceCent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1332,14 +1332,14 @@ func TestCreateDistributionListingUsesMainSiteReceiveRatio(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pricing := ReceivePricingFromAssetSummary(mustMarshalSummary(t, dto.AssetSummary))
|
pricing := ReceivePricingFromAssetSummary(mustMarshalSummary(t, dto.AssetSummary))
|
||||||
if pricing.SellerRatio != 43 {
|
if pricing.SellerRatio != 46 {
|
||||||
t.Fatalf("distribution receive seller_ratio = %v, want 43 from main-site ratio_config", pricing.SellerRatio)
|
t.Fatalf("distribution receive seller_ratio = %v, want 46 from main-site ratio_config", pricing.SellerRatio)
|
||||||
}
|
}
|
||||||
if pricing.SellerTotalPriceCent != 23260 {
|
if pricing.SellerTotalPriceCent != 21740 {
|
||||||
t.Fatalf("seller_total_price_cent = %d, want 23260", pricing.SellerTotalPriceCent)
|
t.Fatalf("seller_total_price_cent = %d, want 21740", pricing.SellerTotalPriceCent)
|
||||||
}
|
}
|
||||||
if dto.PriceCent != 26320 {
|
if dto.PriceCent != 24390 {
|
||||||
t.Fatalf("listing PriceCent = %d, want 26320 from main-site sale price", dto.PriceCent)
|
t.Fatalf("listing PriceCent = %d, want 24390 from main-site sale price", dto.PriceCent)
|
||||||
}
|
}
|
||||||
if dto.DistributionSiteCode != "dist_ratio_1" {
|
if dto.DistributionSiteCode != "dist_ratio_1" {
|
||||||
t.Fatalf("DistributionSiteCode = %s, want dist_ratio_1", dto.DistributionSiteCode)
|
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)
|
t.Fatalf("Create failed: %v", err)
|
||||||
}
|
}
|
||||||
pricing := ReceivePricingFromAssetSummary(mustMarshalSummary(t, dto.AssetSummary))
|
pricing := ReceivePricingFromAssetSummary(mustMarshalSummary(t, dto.AssetSummary))
|
||||||
if pricing.SellerRatio != 46 {
|
if pricing.SellerRatio != 49 {
|
||||||
t.Fatalf("seller_ratio = %v, want 46 after site cost delta 3 (R=43+3) under decoupled model", pricing.SellerRatio)
|
t.Fatalf("seller_ratio = %v, want 49 after site cost delta 3 (R=46+3) under decoupled model", pricing.SellerRatio)
|
||||||
}
|
}
|
||||||
if dto.PriceCent != 26320 {
|
if dto.PriceCent != 24390 {
|
||||||
t.Fatalf("listing PriceCent = %d, want 26320 (buyer price stays anchored to main-site R)", dto.PriceCent)
|
t.Fatalf("listing PriceCent = %d, want 24390 (buyer price stays anchored to main-site R)", dto.PriceCent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -144,9 +144,11 @@ type PublishOptionsDTO struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PublishOptionGroup struct {
|
type PublishOptionGroup struct {
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Options []string `json:"options"`
|
Options []string `json:"options"`
|
||||||
|
SpecialPriceOptions []string `json:"special_price_options"`
|
||||||
|
SpecialRatioAdjustment float64 `json:"special_ratio_adjustment"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PublishQuantityItem struct {
|
type PublishQuantityItem struct {
|
||||||
@@ -188,6 +190,7 @@ type PublishRatioConfig struct {
|
|||||||
QualityOwnerRatioDiscount float64 `json:"quality_owner_ratio_discount"`
|
QualityOwnerRatioDiscount float64 `json:"quality_owner_ratio_discount"`
|
||||||
PremiumReviewRatioMarkup float64 `json:"premium_review_ratio_markup"`
|
PremiumReviewRatioMarkup float64 `json:"premium_review_ratio_markup"`
|
||||||
InsuranceBaseRatios []PublishInsuranceBaseRatio `json:"insurance_base_ratios"`
|
InsuranceBaseRatios []PublishInsuranceBaseRatio `json:"insurance_base_ratios"`
|
||||||
|
LevelRatioRules []PublishLevelRatioRule `json:"level_ratio_rules"`
|
||||||
ConfigItems []PublishRatioConfigItem `json:"config_items"`
|
ConfigItems []PublishRatioConfigItem `json:"config_items"`
|
||||||
CoinCorrections []PublishCoinCorrection `json:"coin_corrections"`
|
CoinCorrections []PublishCoinCorrection `json:"coin_corrections"`
|
||||||
}
|
}
|
||||||
@@ -205,6 +208,13 @@ type PublishRatioConfigItem struct {
|
|||||||
MissingPenalty float64 `json:"missing_penalty"`
|
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 {
|
type PublishCoinCorrection struct {
|
||||||
ThresholdM float64 `json:"threshold_m"`
|
ThresholdM float64 `json:"threshold_m"`
|
||||||
Correction float64 `json:"correction"`
|
Correction float64 `json:"correction"`
|
||||||
|
|||||||
@@ -222,9 +222,7 @@ func normalizePublishOptions(options *PublishOptionsDTO) {
|
|||||||
if len(options.RegionOptions) == 0 {
|
if len(options.RegionOptions) == 0 {
|
||||||
options.RegionOptions = defaults.RegionOptions
|
options.RegionOptions = defaults.RegionOptions
|
||||||
}
|
}
|
||||||
if len(options.SkinGroups) == 0 {
|
normalizePublishOptionGroups(options, defaults.SkinGroups)
|
||||||
options.SkinGroups = defaults.SkinGroups
|
|
||||||
}
|
|
||||||
if len(options.QuantityItems) == 0 {
|
if len(options.QuantityItems) == 0 {
|
||||||
options.QuantityItems = defaults.QuantityItems
|
options.QuantityItems = defaults.QuantityItems
|
||||||
}
|
}
|
||||||
@@ -276,6 +274,10 @@ func normalizePublishOptions(options *PublishOptionsDTO) {
|
|||||||
if len(options.RatioConfig.InsuranceBaseRatios) == 0 {
|
if len(options.RatioConfig.InsuranceBaseRatios) == 0 {
|
||||||
options.RatioConfig.InsuranceBaseRatios = defaults.RatioConfig.InsuranceBaseRatios
|
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 {
|
if len(options.RatioConfig.ConfigItems) == 0 {
|
||||||
options.RatioConfig.ConfigItems = defaults.RatioConfig.ConfigItems
|
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 {
|
func normalizePremiumReviewRatioMarkup(value float64) float64 {
|
||||||
if value < 0 || math.IsNaN(value) || math.IsInf(value, 0) {
|
if value < 0 || math.IsNaN(value) || math.IsInf(value, 0) {
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package systemconfig
|
|||||||
import "encoding/json"
|
import "encoding/json"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// publishOptionsSchemaVersion 发布选项结构版本;v2 新增「是否解锁德穆兰」开关(默认关闭),
|
// publishOptionsSchemaVersion 发布选项结构版本;v3 新增体力/负重命中比例修正
|
||||||
// 并把「下赛季是否购买通行证」默认打开。
|
// 与皮肤分类特殊价格子集。
|
||||||
publishOptionsSchemaVersion = 2
|
publishOptionsSchemaVersion = 3
|
||||||
publishOptionsConfigKey = "listing.publish_options"
|
publishOptionsConfigKey = "listing.publish_options"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,13 +20,13 @@ func defaultPublishOptionsConfigValue() string {
|
|||||||
func DefaultPublishOptions() PublishOptionsDTO {
|
func DefaultPublishOptions() PublishOptionsDTO {
|
||||||
return PublishOptionsDTO{
|
return PublishOptionsDTO{
|
||||||
SchemaVersion: publishOptionsSchemaVersion,
|
SchemaVersion: publishOptionsSchemaVersion,
|
||||||
UnlockDemulanEnabled: false,
|
UnlockDemulanEnabled: true,
|
||||||
NextSeasonPassEnabled: true,
|
NextSeasonPassEnabled: false,
|
||||||
ServerOptions: []string{"QQ", "微信", "Steam"},
|
ServerOptions: []string{"QQ", "微信"},
|
||||||
FaceOptions: []string{"是", "否"},
|
FaceOptions: []string{"是", "否"},
|
||||||
RankOptions: []string{"青铜", "白银", "黄金", "铂金", "钻石", "黑鹰", "三角洲巅峰"},
|
RankOptions: []string{"青铜", "白银", "黄金", "铂金", "钻石", "黑鹰", "三角洲巅峰"},
|
||||||
InsuranceOptions: []string{"2*1", "2*2", "2*3", "3*3"},
|
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{"扫码", "账号密码"},
|
LoginMethodOptions: []string{"扫码", "账号密码"},
|
||||||
RegionOptions: []string{
|
RegionOptions: []string{
|
||||||
"北京", "天津", "河北", "山西", "内蒙古", "辽宁", "吉林", "黑龙江",
|
"北京", "天津", "河北", "山西", "内蒙古", "辽宁", "吉林", "黑龙江",
|
||||||
@@ -40,38 +40,50 @@ func DefaultPublishOptions() PublishOptionsDTO {
|
|||||||
Key: "melee",
|
Key: "melee",
|
||||||
Title: "近战皮肤",
|
Title: "近战皮肤",
|
||||||
Options: []string{
|
Options: []string{
|
||||||
"坠星者", "暗星", "龙牙", "信条", "怜悯", "赤枭", "影锋", "黑海", "北极星", "电锯惊魂", "处刑者",
|
"坠星者", "暗星", "龙牙", "信条", "怜悯", "赤霄", "影锋", "黑海", "北极星", "电锯惊魂", "处刑者",
|
||||||
|
"挽歌", "重塑", "黑伤",
|
||||||
},
|
},
|
||||||
|
SpecialPriceOptions: []string{"龙牙", "赤霄"},
|
||||||
|
SpecialRatioAdjustment: -1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Key: "operatorGold",
|
Key: "operatorGold",
|
||||||
Title: "干员金皮",
|
Title: "干员金皮",
|
||||||
|
SpecialPriceOptions: []string{},
|
||||||
|
SpecialRatioAdjustment: -1,
|
||||||
Options: []string{
|
Options: []string{
|
||||||
"露娜-古墓丽影联动", "蛊-不羁人生", "红狼-电锯惊魂", "露娜-金牌射手",
|
"露娜-古墓丽影联动", "蛊-不羁人生", "红狼-电锯惊魂", "露娜-金牌射手",
|
||||||
"牧羊人-街头之星", "蜂医-危险物质", "蜂医-送葬人", "无名-夜鹰",
|
"牧羊人-街头之星", "蜂医-危险物质", "蜂医-送葬人", "无名-夜鹰",
|
||||||
"威龙-壮志凌云", "威龙-蛟龙特战队", "威龙-铁面判官", "威龙-吴彦祖",
|
"威龙-壮志凌云", "威龙-蛟龙特战队", "威龙-铁面判官", "威龙-吴彦祖",
|
||||||
|
"疾风-西部往事", "骇爪-骇客少女", "比特-沙漠孤星",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Key: "operatorRed",
|
Key: "operatorRed",
|
||||||
Title: "干员红皮",
|
Title: "干员红皮",
|
||||||
|
SpecialPriceOptions: []string{},
|
||||||
|
SpecialRatioAdjustment: -1,
|
||||||
Options: []string{
|
Options: []string{
|
||||||
"凌霄成卫", "蚀金玫瑰", "水墨云图", "午夜邮差", "天际线", "维什戴尔",
|
"凌霄成卫", "蚀金玫瑰", "水墨云图", "午夜邮差", "天际线", "维什戴尔",
|
||||||
|
"狂怒", "安魂牧羊人", "雷霆之息",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Key: "weapon",
|
Key: "weapon",
|
||||||
Title: "武器皮肤",
|
Title: "武器皮肤",
|
||||||
|
SpecialPriceOptions: []string{},
|
||||||
|
SpecialRatioAdjustment: -1,
|
||||||
Options: []string{
|
Options: []string{
|
||||||
"M7棱镜攻势S2", "腾龙气象感应", "MP7电玩高手S2", "M250电玩高手S2",
|
"M7棱镜攻势S2", "腾龙气象感应", "MP7电玩高手S2", "M250电玩高手S2",
|
||||||
"AS Val悬赏令", "K416命运", "M4A1棱镜攻势", "SCAR-H电玩高手",
|
"AS Val悬赏令", "K416命运", "M4A1棱镜攻势", "SCAR-H电玩高手",
|
||||||
"QBZ95王牌之剑", "AUG气象感应", "Vector美杜莎", "KC17-造物纪元",
|
"QBZ95王牌之剑", "AUG气象感应", "Vector美杜莎", "KC17-造物纪元",
|
||||||
|
"AKM-群星", "MK4冲锋枪-疾光魅影", "K437突击步枪-王者之剑", "禁卫14",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
QuantityItems: []PublishQuantityItem{
|
QuantityItems: []PublishQuantityItem{
|
||||||
{Key: "level6Ammo", Label: "6级弹", Price: "0.1元/发", Placeholder: "按单发数量填写,60发=6元"},
|
{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: "barrettAmmo", Label: "巴雷特子弹", Price: "0.3元/发"},
|
||||||
{Key: "armor6", Label: "6甲", Price: "2.5元/个"},
|
{Key: "armor6", Label: "6甲", Price: "2.5元/个"},
|
||||||
{Key: "helmet6", Label: "6头", Price: "1.5元/个"},
|
{Key: "helmet6", Label: "6头", Price: "1.5元/个"},
|
||||||
@@ -84,7 +96,7 @@ func DefaultPublishOptions() PublishOptionsDTO {
|
|||||||
{Key: "coin", Label: "纯币截图", Required: true, Hint: "请上传纯币截图(必传)"},
|
{Key: "coin", Label: "纯币截图", Required: true, Hint: "请上传纯币截图(必传)"},
|
||||||
{Key: "gameId", Label: "游戏ID截图", Required: true, Hint: "请上传游戏ID截图(必传)"},
|
{Key: "gameId", Label: "游戏ID截图", Required: true, Hint: "请上传游戏ID截图(必传)"},
|
||||||
{Key: "totalAsset", Label: "总资产截图", Required: true, Hint: "请上传总资产截图(必传)"},
|
{Key: "totalAsset", Label: "总资产截图", Required: true, Hint: "请上传总资产截图(必传)"},
|
||||||
{Key: "tencentSecurity", Label: "腾讯安全中心截图", Required: false, Hint: "有封禁记录时必传"},
|
{Key: "tencentSecurity", Label: "腾讯安全中心截图", Required: true, Hint: "腾讯安全中心截图"},
|
||||||
{Key: "skin", Label: "皮肤截图", Required: false, Hint: "请上传皮肤截图(选传)"},
|
{Key: "skin", Label: "皮肤截图", Required: false, Hint: "请上传皮肤截图(选传)"},
|
||||||
},
|
},
|
||||||
BanRecordOptions: []string{"无封禁记录", "有封禁记录"},
|
BanRecordOptions: []string{"无封禁记录", "有封禁记录"},
|
||||||
@@ -99,22 +111,22 @@ func DefaultPublishOptions() PublishOptionsDTO {
|
|||||||
|
|
||||||
2. 系统推荐押金未覆盖项目(需自行评估)
|
2. 系统推荐押金未覆盖项目(需自行评估)
|
||||||
|
|
||||||
请注意,系统推荐押金暂不包含以下资产类型,您需要根据实际情况额外评估其价值:
|
请注意,系统推荐押金只包含了皮肤评估的价值!暂不包含以下资产类型,您需要根据实际情况额外评估其价值:
|
||||||
|
|
||||||
- 收藏室内的稀有物品
|
- 收藏室内的稀有物品
|
||||||
- 其他具有个人纪念意义或情怀价值的虚拟资产(如限定称号、绝版道具等)
|
- 其他具有个人纪念意义或情怀价值的虚拟资产(如限定称号、绝版道具等)
|
||||||
|
|
||||||
3. 未出租价值折算规则(重点)
|
3. 未出租价值折算规则(重点)
|
||||||
|
|
||||||
请在「收藏室及不出租部分哈弗币价值」中填写收藏室等不出租资产折合的哈弗币。系统按 1元=50万 计算参考值,并自动更新推荐押金:低于参考值时覆盖为参考值,否则追加参考值的 50%。
|
请在「收藏室及不出租部分哈弗币价值,如150m纯币只出50m纯币」中填写收藏室等不出租资产折合的哈弗币。系统按 1元=50万 计算参考值,并自动更新推荐押金:低于参考值时覆盖为参考值,否则追加参考值的 50%。
|
||||||
|
|
||||||
示例:基础推荐押金 200 元、收藏室价值 200M → 参考值 400 元,200<400,推荐押金更新为 400 元。
|
示例:基础推荐押金 200 元、收藏室价值 200M → 参考值 400 元,200<400,推荐押金更新为 400 元。
|
||||||
|
|
||||||
目的:该举能够有效覆盖租客可能出现的洗号、违规操作导致账号封禁等风险带来的损失,为您提供充分的风险缓冲。
|
目的:该举能够有效覆盖租客可能出现的洗号、违规操作导致账号封禁等风险带来的损失,为您提供充分的风险缓冲。也不用担心押金高账号出不去,只要其账号配置是符合押金的,一样的可以正常租出。
|
||||||
|
|
||||||
4. 额外保障选项
|
4. 额外保障选项
|
||||||
|
|
||||||
若您在设置足额押金后仍感不放心,可选择购买平台提供的《全额包赔服务》。一旦发生封号损失,将获得账号市场价值的全额赔付,让您的出租过程后顾无忧。`,
|
若您在设置足额押金后仍感不放心,可选择购买平台提供的《无忧租号保险》。一旦发生封号损失,将获得账号市场价值的全额赔付,让您的出租过程后顾无忧。但选择《无忧租号保险》,在结算是会产生额外保险服务费,具体可阅读《无忧租号保险》条例。`,
|
||||||
PremiumZoneTooltip: `极品专区是面向优质号主和高价值账号的专属展示区。
|
PremiumZoneTooltip: `极品专区是面向优质号主和高价值账号的专属展示区。
|
||||||
|
|
||||||
1. 发布条件:仅已认证且有效的优质号主可以开启;未开通时需先缴纳平台要求的信用保证金并完成优质号主认证。
|
1. 发布条件:仅已认证且有效的优质号主可以开启;未开通时需先缴纳平台要求的信用保证金并完成优质号主认证。
|
||||||
@@ -122,26 +134,33 @@ func DefaultPublishOptions() PublishOptionsDTO {
|
|||||||
3. 价格规则:系统会按后台配置在基础比例上计算极品专区专享比例,审核页展示的最终价格通过后不再改价。
|
3. 价格规则:系统会按后台配置在基础比例上计算极品专区专享比例,审核页展示的最终价格通过后不再改价。
|
||||||
4. 保险服务:可选择无忧租号保险,服务费率按优质号主及极品专区的当前配置执行,并按实际纯币结算金额计算,额外物品不计入保险基数。
|
4. 保险服务:可选择无忧租号保险,服务费率按优质号主及极品专区的当前配置执行,并按实际纯币结算金额计算,额外物品不计入保险基数。
|
||||||
5. 责任说明:开启专区不会免除商品审核、资料真实性及发布协议中的责任,请如实填写账号资产与出租条件。`,
|
5. 责任说明:开启专区不会免除商品审核、资料真实性及发布协议中的责任,请如实填写账号资产与出租条件。`,
|
||||||
CompensationNote: "普通赔付方案如下:账号在租期内或祖期外出现封禁,追回、洗号等情况,最高可获赔全款相金+押金\n\n无忧保险赔付方案:按账号市场价值进行赔付(可参照螃蟹,盼之等主流交易平台)。无忧保险服务费按实际纯币结算金额计算,额外物品不计入计费基数;具体费率以当前配置为准。押金须达到推荐押金方可购买。",
|
CompensationNote: "普通赔付方案如下:账号在租期内或祖期外出现封禁30天和十年等情况,最高可获赔全款相金+押金\n\n无忧保险赔付方案:按账号市场价值进行赔付(可参照螃蟹,盼之等主流交易平台)。无忧保险服务费按实际纯币结算金额计算,额外物品不计入计费基数;具体费率以当前配置为准。押金须达到推荐押金以上方可购买。",
|
||||||
PricePlaceholder: "填写币数、保险、体力和负重后自动计算;发布总价=纯币基础价+额外消耗品",
|
PricePlaceholder: "填写币数、保险、体力和负重后自动计算;发布总价=纯币基础价+额外消耗品",
|
||||||
RatioDescription: "1:xx 表示 1 元人民币(RMB)等价兑换 xx 万哈夫币",
|
RatioDescription: "1:xx 表示 1 元人民币(RMB)等价兑换 xx 万哈夫币",
|
||||||
},
|
},
|
||||||
DepositRecommend: PublishDepositRecommend{
|
DepositRecommend: PublishDepositRecommend{
|
||||||
BaseAmount: 50,
|
BaseAmount: 200,
|
||||||
SkinGroupRules: []PublishDepositSkinGroupRule{
|
SkinGroupRules: []PublishDepositSkinGroupRule{
|
||||||
{GroupKey: "melee", Label: "刀皮", AmountPerItem: 5},
|
{GroupKey: "melee", Label: "刀皮", AmountPerItem: 150},
|
||||||
{GroupKey: "operatorGold", Label: "干员金皮", AmountPerItem: 10},
|
{GroupKey: "operatorGold", Label: "干员金皮", AmountPerItem: 0},
|
||||||
{GroupKey: "operatorRed", Label: "干员红皮", AmountPerItem: 30},
|
{GroupKey: "operatorRed", Label: "干员红皮", AmountPerItem: 150},
|
||||||
|
{GroupKey: "weapon", Label: "武器皮肤", AmountPerItem: 200},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RatioConfig: PublishRatioConfig{
|
RatioConfig: PublishRatioConfig{
|
||||||
QualityOwnerRatioDiscount: 1,
|
QualityOwnerRatioDiscount: 1,
|
||||||
PremiumReviewRatioMarkup: 1,
|
PremiumReviewRatioMarkup: 0,
|
||||||
InsuranceBaseRatios: []PublishInsuranceBaseRatio{
|
InsuranceBaseRatios: []PublishInsuranceBaseRatio{
|
||||||
{Insurance: "3*3", Ratio: 40},
|
{Insurance: "3*3", Ratio: 45},
|
||||||
{Insurance: "2*3", Ratio: 42},
|
{Insurance: "2*3", Ratio: 47},
|
||||||
{Insurance: "2*2", Ratio: 47},
|
{Insurance: "2*2", Ratio: 51},
|
||||||
{Insurance: "2*1", Ratio: 48},
|
{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{
|
ConfigItems: []PublishRatioConfigItem{
|
||||||
{Key: "operatorRed", Label: "干员红皮", Kind: "skin_group", GroupKey: "operatorRed", MissingPenalty: 1},
|
{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) {
|
func TestNormalizePublishOptionsValueDefaultsQualityOwnerRatioDiscount(t *testing.T) {
|
||||||
legacy := `{
|
legacy := `{
|
||||||
"schema_version": 2,
|
"schema_version": 2,
|
||||||
@@ -128,9 +301,9 @@ func TestNormalizePublishOptionsValueDefaultsQualityOwnerRatioDiscount(t *testin
|
|||||||
got.RatioConfig.QualityOwnerRatioDiscount,
|
got.RatioConfig.QualityOwnerRatioDiscount,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if got.RatioConfig.PremiumReviewRatioMarkup != 1 {
|
if got.RatioConfig.PremiumReviewRatioMarkup != 0 {
|
||||||
t.Fatalf(
|
t.Fatalf(
|
||||||
"premium_review_ratio_markup = %v, want 1",
|
"premium_review_ratio_markup = %v, want 0",
|
||||||
got.RatioConfig.PremiumReviewRatioMarkup,
|
got.RatioConfig.PremiumReviewRatioMarkup,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,9 @@
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
> 当前生产基础比例以后台「系统配置 → 发布表单选项 → 比例计算配置」为准。
|
||||||
|
> 默认配置已同步为 `3*3=45、2*3=47、2*2=51、2*1=51`,不再使用下文的早期 `40/42/47/48` 示例值。
|
||||||
|
|
||||||
### 1. 核心大框架:基础比例(对标保险箱)
|
### 1. 核心大框架:基础比例(对标保险箱)
|
||||||
|
|
||||||
这是账号在配置全满(完美状态)下的初始比例:
|
这是账号在配置全满(完美状态)下的初始比例:
|
||||||
@@ -61,3 +64,31 @@
|
|||||||
4. **总计**:$40 + 3 + 2.5 = 45.5$
|
4. **总计**:$40 + 3 + 2.5 = 45.5$
|
||||||
|
|
||||||
**最终该号的出租比例就是:$1:45.5$**
|
**最终该号的出租比例就是:$1:45.5$**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 4. 体力、负重与特殊皮肤分组修正
|
||||||
|
|
||||||
|
体力/负重支持按选中等级直接修正比例:
|
||||||
|
|
||||||
|
- `7级`:`-1`
|
||||||
|
- `6级`:`-0.5`
|
||||||
|
- 命中上述等级规则时,不再叠加旧的“满体力/满负重”缺失加成
|
||||||
|
- 未命中等级规则的低等级,继续使用后台“配置项缺失加成”
|
||||||
|
|
||||||
|
每个皮肤分类还可以配置一个“特殊价格名单”和额外比例,例如近战皮肤默认:
|
||||||
|
|
||||||
|
- 普通皮肤命中刀皮分组:抵消基础刀皮缺失加成
|
||||||
|
- 包含 `赤霄` 或 `龙牙`:特殊刀皮分组再额外 `-1`
|
||||||
|
- 同一特殊分组内同时命中多件皮肤,只修正一次,不按件数叠加
|
||||||
|
|
||||||
|
最终参考比例:
|
||||||
|
|
||||||
|
```text
|
||||||
|
R = 保险基础比例
|
||||||
|
+ 缺失项加成
|
||||||
|
+ 体力/负重等级修正
|
||||||
|
+ 特殊皮肤分组修正
|
||||||
|
+ 大额币修正
|
||||||
|
+ 日均损耗修正
|
||||||
|
```
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -57,4 +57,55 @@ describe('mergeListingPublishOptions', () => {
|
|||||||
|
|
||||||
expect(options.price_config.premium_zone_tooltip).toBe('自定义极品专区说明')
|
expect(options.price_config.premium_zone_tooltip).toBe('自定义极品专区说明')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('旧皮肤分组缺少特殊价格字段时补默认特殊刀皮', () => {
|
||||||
|
const options = mergeListingPublishOptions({
|
||||||
|
skin_groups: [
|
||||||
|
{
|
||||||
|
key: 'melee',
|
||||||
|
title: '近战皮肤',
|
||||||
|
options: ['北极星', '龙牙', '赤霄'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(options.skin_groups[0].special_price_options).toEqual(['龙牙', '赤霄'])
|
||||||
|
expect(options.skin_groups[0].special_ratio_adjustment).toBe(-1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('后台显式清空特殊皮肤时不重新补默认值', () => {
|
||||||
|
const options = mergeListingPublishOptions({
|
||||||
|
skin_groups: [
|
||||||
|
{
|
||||||
|
key: 'melee',
|
||||||
|
title: '近战皮肤',
|
||||||
|
options: ['北极星'],
|
||||||
|
special_price_options: [],
|
||||||
|
special_ratio_adjustment: 0,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(options.skin_groups[0].special_price_options).toEqual([])
|
||||||
|
expect(options.skin_groups[0].special_ratio_adjustment).toBe(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('旧配置缺少等级比例规则时补默认 7/6 级规则', () => {
|
||||||
|
const options = mergeListingPublishOptions({
|
||||||
|
ratio_config: {
|
||||||
|
quality_owner_ratio_discount: 1,
|
||||||
|
premium_review_ratio_markup: 0,
|
||||||
|
insurance_base_ratios: [],
|
||||||
|
config_items: [],
|
||||||
|
coin_corrections: [],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(options.ratio_config.level_ratio_rules).toEqual([
|
||||||
|
{ key: 'stamina7', field: 'stamina', level: '7级', ratio_adjustment: -1 },
|
||||||
|
{ key: 'stamina6', field: 'stamina', level: '6级', ratio_adjustment: -0.5 },
|
||||||
|
{ key: 'load7', field: 'load', level: '7级', ratio_adjustment: -1 },
|
||||||
|
{ key: 'load6', field: 'load', level: '6级', ratio_adjustment: -0.5 },
|
||||||
|
])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ export interface PublishOptionGroup {
|
|||||||
key: SkinCategoryKey | string
|
key: SkinCategoryKey | string
|
||||||
title: string
|
title: string
|
||||||
options: string[]
|
options: string[]
|
||||||
|
special_price_options: string[]
|
||||||
|
special_ratio_adjustment: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PublishQuantityItem {
|
export interface PublishQuantityItem {
|
||||||
@@ -63,6 +65,13 @@ export interface PublishRatioConfigItem {
|
|||||||
missing_penalty: number
|
missing_penalty: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface PublishLevelRatioRule {
|
||||||
|
key: string
|
||||||
|
field: 'stamina' | 'load' | string
|
||||||
|
level: string
|
||||||
|
ratio_adjustment: number
|
||||||
|
}
|
||||||
|
|
||||||
export interface PublishCoinCorrection {
|
export interface PublishCoinCorrection {
|
||||||
threshold_m: number
|
threshold_m: number
|
||||||
correction: number
|
correction: number
|
||||||
@@ -84,6 +93,7 @@ export interface PublishRatioConfig {
|
|||||||
quality_owner_ratio_discount: number
|
quality_owner_ratio_discount: number
|
||||||
premium_review_ratio_markup: number
|
premium_review_ratio_markup: number
|
||||||
insurance_base_ratios: PublishInsuranceBaseRatio[]
|
insurance_base_ratios: PublishInsuranceBaseRatio[]
|
||||||
|
level_ratio_rules: PublishLevelRatioRule[]
|
||||||
config_items: PublishRatioConfigItem[]
|
config_items: PublishRatioConfigItem[]
|
||||||
coin_corrections: PublishCoinCorrection[]
|
coin_corrections: PublishCoinCorrection[]
|
||||||
}
|
}
|
||||||
@@ -132,22 +142,22 @@ const defaultDepositTooltip = `1. 系统推荐押金(基础覆盖)
|
|||||||
|
|
||||||
2. 系统推荐押金未覆盖项目(需自行评估)
|
2. 系统推荐押金未覆盖项目(需自行评估)
|
||||||
|
|
||||||
请注意,系统推荐押金暂不包含以下资产类型,您需要根据实际情况额外评估其价值:
|
请注意,系统推荐押金只包含了皮肤评估的价值!暂不包含以下资产类型,您需要根据实际情况额外评估其价值:
|
||||||
|
|
||||||
- 收藏室内的稀有物品
|
- 收藏室内的稀有物品
|
||||||
- 其他具有个人纪念意义或情怀价值的虚拟资产(如限定称号、绝版道具等)
|
- 其他具有个人纪念意义或情怀价值的虚拟资产(如限定称号、绝版道具等)
|
||||||
|
|
||||||
3. 未出租价值折算规则(重点)
|
3. 未出租价值折算规则(重点)
|
||||||
|
|
||||||
请在「收藏室及不出租部分哈弗币价值」中填写收藏室等不出租资产折合的哈弗币。系统按 1元=50万 计算参考值,并自动更新推荐押金:低于参考值时覆盖为参考值,否则追加参考值的 50%。
|
请在「收藏室及不出租部分哈弗币价值,如150m纯币只出50m纯币」中填写收藏室等不出租资产折合的哈弗币。系统按 1元=50万 计算参考值,并自动更新推荐押金:低于参考值时覆盖为参考值,否则追加参考值的 50%。
|
||||||
|
|
||||||
示例:基础推荐押金 200 元、收藏室价值 200M → 参考值 400 元,200<400,推荐押金更新为 400 元。
|
示例:基础推荐押金 200 元、收藏室价值 200M → 参考值 400 元,200<400,推荐押金更新为 400 元。
|
||||||
|
|
||||||
目的:该举能够有效覆盖租客可能出现的洗号、违规操作导致账号封禁等风险带来的损失,为您提供充分的风险缓冲。
|
目的:该举能够有效覆盖租客可能出现的洗号、违规操作导致账号封禁等风险带来的损失,为您提供充分的风险缓冲。也不用担心押金高账号出不去,只要其账号配置是符合押金的,一样的可以正常租出。
|
||||||
|
|
||||||
4. 额外保障选项
|
4. 额外保障选项
|
||||||
|
|
||||||
若您在设置足额押金后仍感不放心,可选择购买平台提供的《全额包赔服务》。一旦发生封号损失,将获得账号市场价值的全额赔付,让您的出租过程后顾无忧。`
|
若您在设置足额押金后仍感不放心,可选择购买平台提供的《无忧租号保险》。一旦发生封号损失,将获得账号市场价值的全额赔付,让您的出租过程后顾无忧。但选择《无忧租号保险》,在结算是会产生额外保险服务费,具体可阅读《无忧租号保险》条例。`
|
||||||
|
|
||||||
const defaultPremiumZoneTooltip = `极品专区是面向优质号主和高价值账号的专属展示区。
|
const defaultPremiumZoneTooltip = `极品专区是面向优质号主和高价值账号的专属展示区。
|
||||||
|
|
||||||
@@ -157,9 +167,20 @@ const defaultPremiumZoneTooltip = `极品专区是面向优质号主和高价值
|
|||||||
4. 保险服务:可选择无忧租号保险,服务费率按优质号主及极品专区的当前配置执行,并按实际纯币结算金额计算,额外物品不计入保险基数。
|
4. 保险服务:可选择无忧租号保险,服务费率按优质号主及极品专区的当前配置执行,并按实际纯币结算金额计算,额外物品不计入保险基数。
|
||||||
5. 责任说明:开启专区不会免除商品审核、资料真实性及发布协议中的责任,请如实填写账号资产与出租条件。`
|
5. 责任说明:开启专区不会免除商品审核、资料真实性及发布协议中的责任,请如实填写账号资产与出租条件。`
|
||||||
|
|
||||||
|
const defaultLevelRatioRules: PublishLevelRatioRule[] = [
|
||||||
|
{ key: 'stamina7', field: 'stamina', level: '7级', ratio_adjustment: -1 },
|
||||||
|
{ key: 'stamina6', field: 'stamina', level: '6级', ratio_adjustment: -0.5 },
|
||||||
|
{ key: 'load7', field: 'load', level: '7级', ratio_adjustment: -1 },
|
||||||
|
{ key: 'load6', field: 'load', level: '6级', ratio_adjustment: -0.5 },
|
||||||
|
]
|
||||||
|
|
||||||
|
const defaultSpecialPriceOptionsByGroup: Record<string, string[]> = {
|
||||||
|
melee: ['龙牙', '赤霄'],
|
||||||
|
}
|
||||||
|
|
||||||
export const emptyListingPublishOptions: ListingPublishOptions = {
|
export const emptyListingPublishOptions: ListingPublishOptions = {
|
||||||
schema_version: 2,
|
schema_version: 3,
|
||||||
unlock_demulan_enabled: false,
|
unlock_demulan_enabled: true,
|
||||||
next_season_pass_enabled: false,
|
next_season_pass_enabled: false,
|
||||||
server_options: [],
|
server_options: [],
|
||||||
face_options: [],
|
face_options: [],
|
||||||
@@ -175,27 +196,35 @@ export const emptyListingPublishOptions: ListingPublishOptions = {
|
|||||||
ban_evidence_options: [],
|
ban_evidence_options: [],
|
||||||
fire_level_min: 38,
|
fire_level_min: 38,
|
||||||
price_config: {
|
price_config: {
|
||||||
deposit_placeholder: '',
|
deposit_placeholder:
|
||||||
|
'温馨提示:本押金用于保障账号安全。若买家在租用期间,使用非纯币类道具/资源(如消耗品、材料等)或导致账号被封禁,相关损失将直接从押金中扣除进行赔付。押金过高会延长出租等待时间(请自行衡量)感谢理解。',
|
||||||
deposit_hint: '租客缴纳,封号必赔付',
|
deposit_hint: '租客缴纳,封号必赔付',
|
||||||
deposit_tooltip: defaultDepositTooltip,
|
deposit_tooltip: defaultDepositTooltip,
|
||||||
premium_zone_tooltip: defaultPremiumZoneTooltip,
|
premium_zone_tooltip: defaultPremiumZoneTooltip,
|
||||||
compensation_note:
|
compensation_note:
|
||||||
'普通赔付方案如下:账号在租期内或祖期外出现封禁,追回、洗号等情况,最高可获赔全款相金+押金\n\n无忧保险赔付方案:按账号市场价值进行赔付(可参照螃蟹,盼之等主流交易平台)。无忧保险服务费按实际纯币结算金额计算,额外物品不计入计费基数;具体费率以当前配置为准。押金须达到推荐押金方可购买。',
|
'普通赔付方案如下:账号在租期内或祖期外出现封禁30天和十年等情况,最高可获赔全款相金+押金\n\n无忧保险赔付方案:按账号市场价值进行赔付(可参照螃蟹,盼之等主流交易平台)。无忧保险服务费按实际纯币结算金额计算,额外物品不计入计费基数;具体费率以当前配置为准。押金须达到推荐押金以上方可购买。',
|
||||||
price_placeholder: '',
|
price_placeholder: '填写币数、保险、体力和负重后自动计算;发布总价=纯币基础价+额外消耗品',
|
||||||
ratio_description: '',
|
ratio_description: '1:xx 表示 1 元人民币(RMB)等价兑换 xx 万哈夫币',
|
||||||
},
|
},
|
||||||
deposit_recommend_config: {
|
deposit_recommend_config: {
|
||||||
base_amount: 50,
|
base_amount: 200,
|
||||||
skin_group_rules: [
|
skin_group_rules: [
|
||||||
{ group_key: 'melee', label: '刀皮', amount_per_item: 5 },
|
{ group_key: 'melee', label: '刀皮', amount_per_item: 150 },
|
||||||
{ group_key: 'operatorGold', label: '干员金皮', amount_per_item: 10 },
|
{ group_key: 'operatorGold', label: '干员金皮', amount_per_item: 0 },
|
||||||
{ group_key: 'operatorRed', label: '干员红皮', amount_per_item: 30 },
|
{ group_key: 'operatorRed', label: '干员红皮', amount_per_item: 150 },
|
||||||
|
{ group_key: 'weapon', label: '武器皮肤', amount_per_item: 200 },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
ratio_config: {
|
ratio_config: {
|
||||||
quality_owner_ratio_discount: 1,
|
quality_owner_ratio_discount: 1,
|
||||||
premium_review_ratio_markup: 1,
|
premium_review_ratio_markup: 0,
|
||||||
insurance_base_ratios: [],
|
insurance_base_ratios: [
|
||||||
|
{ insurance: '3*3', ratio: 45 },
|
||||||
|
{ insurance: '2*3', ratio: 47 },
|
||||||
|
{ insurance: '2*2', ratio: 51 },
|
||||||
|
{ insurance: '2*1', ratio: 51 },
|
||||||
|
],
|
||||||
|
level_ratio_rules: defaultLevelRatioRules,
|
||||||
config_items: [],
|
config_items: [],
|
||||||
coin_corrections: [],
|
coin_corrections: [],
|
||||||
},
|
},
|
||||||
@@ -255,7 +284,7 @@ export function mergeListingPublishOptions(
|
|||||||
options?: Partial<ListingPublishOptions>
|
options?: Partial<ListingPublishOptions>
|
||||||
): ListingPublishOptions {
|
): ListingPublishOptions {
|
||||||
return {
|
return {
|
||||||
schema_version: readPositiveInteger(options?.schema_version, 2),
|
schema_version: readPositiveInteger(options?.schema_version, 3),
|
||||||
unlock_demulan_enabled: options?.unlock_demulan_enabled === true,
|
unlock_demulan_enabled: options?.unlock_demulan_enabled === true,
|
||||||
next_season_pass_enabled: options?.next_season_pass_enabled === true,
|
next_season_pass_enabled: options?.next_season_pass_enabled === true,
|
||||||
server_options: normalizeStringList(options?.server_options),
|
server_options: normalizeStringList(options?.server_options),
|
||||||
@@ -318,10 +347,20 @@ function normalizeOptionGroups(values?: unknown[]): PublishOptionGroup[] {
|
|||||||
return values
|
return values
|
||||||
.map(item => {
|
.map(item => {
|
||||||
const group = isRecord(item) ? item : {}
|
const group = isRecord(item) ? item : {}
|
||||||
|
const key = typeof group.key === 'string' ? group.key.trim() : ''
|
||||||
|
const rawSpecialOptions = group.special_price_options
|
||||||
|
const hasSpecialOptions = Array.isArray(rawSpecialOptions)
|
||||||
|
const specialPriceOptions = hasSpecialOptions
|
||||||
|
? normalizeStringList(rawSpecialOptions)
|
||||||
|
: [...(defaultSpecialPriceOptionsByGroup[key] || [])]
|
||||||
return {
|
return {
|
||||||
key: typeof group.key === 'string' ? group.key.trim() : '',
|
key,
|
||||||
title: typeof group.title === 'string' ? group.title.trim() : '',
|
title: typeof group.title === 'string' ? group.title.trim() : '',
|
||||||
options: normalizeStringList(Array.isArray(group.options) ? group.options : []),
|
options: normalizeStringList(Array.isArray(group.options) ? group.options : []),
|
||||||
|
special_price_options: specialPriceOptions,
|
||||||
|
special_ratio_adjustment: readSignedRatioAdjustment(
|
||||||
|
hasSpecialOptions ? group.special_ratio_adjustment : -1
|
||||||
|
),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.filter(item => item.key && item.title)
|
.filter(item => item.key && item.title)
|
||||||
@@ -431,6 +470,9 @@ function normalizeRatioConfig(value?: unknown): PublishRatioConfig {
|
|||||||
insurance_base_ratios: normalizeInsuranceBaseRatios(
|
insurance_base_ratios: normalizeInsuranceBaseRatios(
|
||||||
Array.isArray(row.insurance_base_ratios) ? row.insurance_base_ratios : []
|
Array.isArray(row.insurance_base_ratios) ? row.insurance_base_ratios : []
|
||||||
),
|
),
|
||||||
|
level_ratio_rules: Array.isArray(row.level_ratio_rules)
|
||||||
|
? normalizeLevelRatioRules(row.level_ratio_rules)
|
||||||
|
: defaultLevelRatioRules.map(item => ({ ...item })),
|
||||||
config_items: normalizeRatioConfigItems(
|
config_items: normalizeRatioConfigItems(
|
||||||
Array.isArray(row.config_items) ? row.config_items : []
|
Array.isArray(row.config_items) ? row.config_items : []
|
||||||
),
|
),
|
||||||
@@ -440,6 +482,20 @@ function normalizeRatioConfig(value?: unknown): PublishRatioConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function normalizeLevelRatioRules(values: unknown[]): PublishLevelRatioRule[] {
|
||||||
|
return values
|
||||||
|
.map(item => {
|
||||||
|
const row = isRecord(item) ? item : {}
|
||||||
|
return {
|
||||||
|
key: typeof row.key === 'string' ? row.key.trim() : '',
|
||||||
|
field: typeof row.field === 'string' ? row.field.trim() : '',
|
||||||
|
level: typeof row.level === 'string' ? row.level.trim() : '',
|
||||||
|
ratio_adjustment: readSignedRatioAdjustment(row.ratio_adjustment),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.filter(item => item.key && item.field && item.level)
|
||||||
|
}
|
||||||
|
|
||||||
function normalizeSalePriceConfig(value?: unknown): PublishSalePriceConfig {
|
function normalizeSalePriceConfig(value?: unknown): PublishSalePriceConfig {
|
||||||
const row = isRecord(value) ? value : {}
|
const row = isRecord(value) ? value : {}
|
||||||
const config = {
|
const config = {
|
||||||
@@ -456,6 +512,10 @@ function normalizeSalePriceConfig(value?: unknown): PublishSalePriceConfig {
|
|||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function readSignedRatioAdjustment(value: unknown) {
|
||||||
|
return Math.min(10, Math.max(-10, readNumber(value)))
|
||||||
|
}
|
||||||
|
|
||||||
function normalizeInsuranceBaseRatios(values: unknown[]): PublishInsuranceBaseRatio[] {
|
function normalizeInsuranceBaseRatios(values: unknown[]): PublishInsuranceBaseRatio[] {
|
||||||
return values
|
return values
|
||||||
.map(item => {
|
.map(item => {
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { describe, expect, it } from 'vitest'
|
import { describe, expect, it } from 'vitest'
|
||||||
|
|
||||||
import { calculateInsuranceFeeAmount } from '../pricing'
|
import type { PublishOptionGroup, PublishRatioConfig } from '@/features/listings/api/listingOptions'
|
||||||
|
import type { PublishForm } from '@/shared/types/publish'
|
||||||
|
|
||||||
|
import { calculateInsuranceFeeAmount, calculateSellerReferenceRatio } from '../pricing'
|
||||||
|
|
||||||
describe('calculateInsuranceFeeAmount', () => {
|
describe('calculateInsuranceFeeAmount', () => {
|
||||||
it('普通赔付不收取保险服务费', () => {
|
it('普通赔付不收取保险服务费', () => {
|
||||||
@@ -23,3 +26,97 @@ describe('calculateInsuranceFeeAmount', () => {
|
|||||||
expect(calculateInsuranceFeeAmount(1, 10_000)).toBe(1)
|
expect(calculateInsuranceFeeAmount(1, 10_000)).toBe(1)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function basePublishForm(overrides: Partial<PublishForm> = {}): PublishForm {
|
||||||
|
return {
|
||||||
|
server_region: 'QQ',
|
||||||
|
face_owner: '',
|
||||||
|
haf_coin_amount: 100,
|
||||||
|
rank_level: '',
|
||||||
|
secret_kd: '',
|
||||||
|
fire_level: '',
|
||||||
|
daily_loss_m: 10,
|
||||||
|
accelerated_sale_ratio: '',
|
||||||
|
season_insurance: '3*3',
|
||||||
|
stamina_level: '7级',
|
||||||
|
load_level: '7级',
|
||||||
|
login_method: '',
|
||||||
|
online_start: '',
|
||||||
|
online_end: '',
|
||||||
|
early_morning_response: '否',
|
||||||
|
can_change_game_name: '',
|
||||||
|
all_hero: '',
|
||||||
|
unlock_demulan: '',
|
||||||
|
next_season_pass: '',
|
||||||
|
ban_record: '',
|
||||||
|
common_regions: [],
|
||||||
|
depositAmountYuan: '',
|
||||||
|
is_premium: false,
|
||||||
|
compensation_plan: 'normal',
|
||||||
|
remark: '',
|
||||||
|
...overrides,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const ratioConfig: PublishRatioConfig = {
|
||||||
|
quality_owner_ratio_discount: 1,
|
||||||
|
premium_review_ratio_markup: 0,
|
||||||
|
insurance_base_ratios: [{ insurance: '3*3', ratio: 45 }],
|
||||||
|
level_ratio_rules: [
|
||||||
|
{ key: 'stamina7', field: 'stamina', level: '7级', ratio_adjustment: -1 },
|
||||||
|
{ key: 'stamina6', field: 'stamina', level: '6级', ratio_adjustment: -0.5 },
|
||||||
|
{ key: 'load7', field: 'load', level: '7级', ratio_adjustment: -1 },
|
||||||
|
{ key: 'load6', field: 'load', level: '6级', ratio_adjustment: -0.5 },
|
||||||
|
],
|
||||||
|
config_items: [
|
||||||
|
{ key: 'melee', label: '刀皮', kind: 'skin_group', group_key: 'melee', missing_penalty: 1 },
|
||||||
|
{ key: 'staminaMax', label: '满体力', kind: 'max_stamina', missing_penalty: 1 },
|
||||||
|
{ key: 'loadMax', label: '满负重', kind: 'max_load', missing_penalty: 1 },
|
||||||
|
],
|
||||||
|
coin_corrections: [],
|
||||||
|
}
|
||||||
|
|
||||||
|
const skinGroups: PublishOptionGroup[] = [
|
||||||
|
{
|
||||||
|
key: 'melee',
|
||||||
|
title: '近战皮肤',
|
||||||
|
options: ['北极星', '龙牙', '赤霄'],
|
||||||
|
special_price_options: ['龙牙', '赤霄'],
|
||||||
|
special_ratio_adjustment: -1,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
function referenceRatio(form: PublishForm, selectedSkins: string[]) {
|
||||||
|
return calculateSellerReferenceRatio({
|
||||||
|
coinMAmount: 100,
|
||||||
|
form,
|
||||||
|
ratioConfig,
|
||||||
|
skinGroups,
|
||||||
|
selectedSkins,
|
||||||
|
levelOptions: ['4级', '5级', '6级', '7级'],
|
||||||
|
dailyLossRatioAdjustment: 0,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('calculateSellerReferenceRatio', () => {
|
||||||
|
it('7级体力和负重各减 1 点', () => {
|
||||||
|
expect(referenceRatio(basePublishForm(), ['北极星'])).toBe(43)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('6级体力和负重各减 0.5 点且不叠加旧缺失加成', () => {
|
||||||
|
expect(
|
||||||
|
referenceRatio(basePublishForm({ stamina_level: '6级', load_level: '6级' }), ['北极星'])
|
||||||
|
).toBe(44)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('没有等级命中规则时继续使用旧满级缺失加成', () => {
|
||||||
|
expect(
|
||||||
|
referenceRatio(basePublishForm({ stamina_level: '5级', load_level: '7级' }), ['北极星'])
|
||||||
|
).toBe(45)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('特殊刀皮分组命中后额外减 1,且同组多件只减一次', () => {
|
||||||
|
expect(referenceRatio(basePublishForm(), ['北极星', '龙牙'])).toBe(42)
|
||||||
|
expect(referenceRatio(basePublishForm(), ['北极星', '龙牙', '赤霄'])).toBe(42)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|||||||
@@ -146,12 +146,12 @@ export function calculateSellerReferenceRatio(options: {
|
|||||||
return 0
|
return 0
|
||||||
const baseRatio = getInsuranceBaseRatio(ratioConfig, form.season_insurance)
|
const baseRatio = getInsuranceBaseRatio(ratioConfig, form.season_insurance)
|
||||||
if (baseRatio <= 0) return 0
|
if (baseRatio <= 0) return 0
|
||||||
return (
|
const ratio =
|
||||||
baseRatio +
|
baseRatio +
|
||||||
calculateConfigPenalty(ratioConfig, options) +
|
calculateConfigPenalty(ratioConfig, options) +
|
||||||
getCoinCorrection(ratioConfig, coinMAmount) +
|
getCoinCorrection(ratioConfig, coinMAmount) +
|
||||||
options.dailyLossRatioAdjustment
|
options.dailyLossRatioAdjustment
|
||||||
)
|
return ratio > 0 ? roundRatio(ratio) : 0
|
||||||
}
|
}
|
||||||
|
|
||||||
export function readFinalSaleRatio(
|
export function readFinalSaleRatio(
|
||||||
@@ -296,7 +296,7 @@ function getInsuranceBaseRatio(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function calculateConfigPenalty(
|
function calculateConfigPenalty(
|
||||||
config: Pick<ListingPublishOptions['ratio_config'], 'config_items'>,
|
config: Pick<ListingPublishOptions['ratio_config'], 'config_items' | 'level_ratio_rules'>,
|
||||||
options: {
|
options: {
|
||||||
form: PublishForm
|
form: PublishForm
|
||||||
skinGroups: PublishOptionGroup[]
|
skinGroups: PublishOptionGroup[]
|
||||||
@@ -304,8 +304,68 @@ function calculateConfigPenalty(
|
|||||||
levelOptions: string[]
|
levelOptions: string[]
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
return config.config_items.reduce((sum, item) => {
|
let penalty = config.config_items.reduce((sum, item) => {
|
||||||
return isRatioConfigItemMatched(item, options) ? sum : sum + Number(item.missing_penalty || 0)
|
if (isRatioConfigItemMatched(item, options)) return sum
|
||||||
|
if (
|
||||||
|
item.kind === 'max_stamina' &&
|
||||||
|
hasMatchingLevelRatioRule(config.level_ratio_rules, 'stamina', options.form.stamina_level)
|
||||||
|
) {
|
||||||
|
return sum
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
item.kind === 'max_load' &&
|
||||||
|
hasMatchingLevelRatioRule(config.level_ratio_rules, 'load', options.form.load_level)
|
||||||
|
) {
|
||||||
|
return sum
|
||||||
|
}
|
||||||
|
return sum + Number(item.missing_penalty || 0)
|
||||||
|
}, 0)
|
||||||
|
penalty += calculateLevelRatioAdjustment(
|
||||||
|
config.level_ratio_rules,
|
||||||
|
options.form.stamina_level,
|
||||||
|
options.form.load_level
|
||||||
|
)
|
||||||
|
penalty += calculateSpecialSkinRatioAdjustment(options.skinGroups, options.selectedSkins)
|
||||||
|
return roundRatio(penalty)
|
||||||
|
}
|
||||||
|
|
||||||
|
function hasMatchingLevelRatioRule(
|
||||||
|
rules: ListingPublishOptions['ratio_config']['level_ratio_rules'],
|
||||||
|
field: 'stamina' | 'load',
|
||||||
|
level: string
|
||||||
|
) {
|
||||||
|
return rules.some(rule => rule.field === field && rule.level === level)
|
||||||
|
}
|
||||||
|
|
||||||
|
function calculateLevelRatioAdjustment(
|
||||||
|
rules: ListingPublishOptions['ratio_config']['level_ratio_rules'],
|
||||||
|
stamina: string,
|
||||||
|
load: string
|
||||||
|
) {
|
||||||
|
return rules.reduce((sum, rule) => {
|
||||||
|
if (rule.field === 'stamina' && rule.level === stamina) {
|
||||||
|
return sum + Number(rule.ratio_adjustment || 0)
|
||||||
|
}
|
||||||
|
if (rule.field === 'load' && rule.level === load) {
|
||||||
|
return sum + Number(rule.ratio_adjustment || 0)
|
||||||
|
}
|
||||||
|
return sum
|
||||||
|
}, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
function calculateSpecialSkinRatioAdjustment(
|
||||||
|
skinGroups: PublishOptionGroup[],
|
||||||
|
selectedSkins: string[]
|
||||||
|
) {
|
||||||
|
if (!selectedSkins.length) return 0
|
||||||
|
const selected = new Set(selectedSkins)
|
||||||
|
return skinGroups.reduce((sum, group) => {
|
||||||
|
if (Number(group.special_ratio_adjustment || 0) === 0 || !group.special_price_options.length) {
|
||||||
|
return sum
|
||||||
|
}
|
||||||
|
return group.special_price_options.some(skin => selected.has(skin))
|
||||||
|
? sum + Number(group.special_ratio_adjustment || 0)
|
||||||
|
: sum
|
||||||
}, 0)
|
}, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user