feat(publish): 推荐押金支持第二件折扣并放宽押金下限
- 推荐押金皮肤规则新增「第2件起计价」比例,组内首件按原价、后续件按比例计入 - 押金低于推荐押金允许发布,弹窗提示并禁用无忧租号保险 - 用户主动改低押金后不再被推荐值覆盖,点「使用推荐」恢复自动跟随
This commit is contained in:
@@ -184,6 +184,10 @@ type PublishDepositSkinGroupRule struct {
|
||||
GroupKey string `json:"group_key"`
|
||||
Label string `json:"label"`
|
||||
AmountPerItem float64 `json:"amount_per_item"`
|
||||
// DiscountPercent 组内第 2 件起的计价百分比(0-100)。
|
||||
// 0 表示不开启折扣,每件都按 AmountPerItem 计入;
|
||||
// 50 表示第 1 件按原价计入,第 2 件起按原价的 50% 计入。
|
||||
DiscountPercent float64 `json:"discount_percent"`
|
||||
}
|
||||
|
||||
type PublishRatioConfig struct {
|
||||
|
||||
@@ -271,6 +271,7 @@ func normalizePublishOptions(options *PublishOptionsDTO) {
|
||||
if len(options.DepositRecommend.SkinGroupRules) == 0 {
|
||||
options.DepositRecommend.SkinGroupRules = defaults.DepositRecommend.SkinGroupRules
|
||||
}
|
||||
normalizeDepositSkinGroupRules(options.DepositRecommend.SkinGroupRules)
|
||||
if len(options.RatioConfig.InsuranceBaseRatios) == 0 {
|
||||
options.RatioConfig.InsuranceBaseRatios = defaults.RatioConfig.InsuranceBaseRatios
|
||||
}
|
||||
@@ -375,6 +376,27 @@ func normalizeSignedRatioAdjustment(value float64) float64 {
|
||||
return math.Round(value*10) / 10
|
||||
}
|
||||
|
||||
// normalizeDepositSkinGroupRules 收敛押金皮肤规则的折扣比例。
|
||||
// 0 表示不开启折扣(每件按原价计入),上限 100 表示第 2 件起不再加价。
|
||||
func normalizeDepositSkinGroupRules(rules []PublishDepositSkinGroupRule) {
|
||||
for index := range rules {
|
||||
rules[index].DiscountPercent = normalizeDepositDiscountPercent(rules[index].DiscountPercent)
|
||||
}
|
||||
}
|
||||
|
||||
func normalizeDepositDiscountPercent(value float64) float64 {
|
||||
if math.IsNaN(value) || math.IsInf(value, 0) {
|
||||
return 0
|
||||
}
|
||||
if value <= 0 {
|
||||
return 0
|
||||
}
|
||||
if value >= 100 {
|
||||
return 100
|
||||
}
|
||||
return math.Round(value*10) / 10
|
||||
}
|
||||
|
||||
func normalizePremiumReviewRatioMarkup(value float64) float64 {
|
||||
if value < 0 || math.IsNaN(value) || math.IsInf(value, 0) {
|
||||
return 0
|
||||
|
||||
@@ -141,10 +141,10 @@ func DefaultPublishOptions() PublishOptionsDTO {
|
||||
DepositRecommend: PublishDepositRecommend{
|
||||
BaseAmount: 200,
|
||||
SkinGroupRules: []PublishDepositSkinGroupRule{
|
||||
{GroupKey: "melee", Label: "刀皮", AmountPerItem: 150},
|
||||
{GroupKey: "operatorGold", Label: "干员金皮", AmountPerItem: 0},
|
||||
{GroupKey: "operatorRed", Label: "干员红皮", AmountPerItem: 150},
|
||||
{GroupKey: "weapon", Label: "武器皮肤", AmountPerItem: 200},
|
||||
{GroupKey: "melee", Label: "刀皮", AmountPerItem: 150, DiscountPercent: 0},
|
||||
{GroupKey: "operatorGold", Label: "干员金皮", AmountPerItem: 0, DiscountPercent: 0},
|
||||
{GroupKey: "operatorRed", Label: "干员红皮", AmountPerItem: 150, DiscountPercent: 0},
|
||||
{GroupKey: "weapon", Label: "武器皮肤", AmountPerItem: 200, DiscountPercent: 0},
|
||||
},
|
||||
},
|
||||
RatioConfig: PublishRatioConfig{
|
||||
|
||||
@@ -309,6 +309,54 @@ func TestNormalizePublishOptionsValueDefaultsQualityOwnerRatioDiscount(t *testin
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizePublishOptionsValueKeepsDepositSkinGroupDiscount(t *testing.T) {
|
||||
raw := `{
|
||||
"schema_version": 3,
|
||||
"deposit_recommend_config": {
|
||||
"base_amount": 200,
|
||||
"skin_group_rules": [
|
||||
{"group_key": "melee", "label": "刀皮", "amount_per_item": 100, "discount_percent": 50},
|
||||
{"group_key": "weapon", "label": "武器皮肤", "amount_per_item": 200, "discount_percent": 120},
|
||||
{"group_key": "operatorRed", "label": "干员红皮", "amount_per_item": 150, "discount_percent": -10}
|
||||
]
|
||||
}
|
||||
}`
|
||||
|
||||
normalized, err := normalizePublishOptionsValue(raw)
|
||||
if err != nil {
|
||||
t.Fatalf("规范化失败: %v", err)
|
||||
}
|
||||
var got PublishOptionsDTO
|
||||
if err := json.Unmarshal([]byte(normalized), &got); err != nil {
|
||||
t.Fatalf("解析规范化结果失败: %v", err)
|
||||
}
|
||||
rules := got.DepositRecommend.SkinGroupRules
|
||||
if len(rules) != 3 {
|
||||
t.Fatalf("skin_group_rules = %#v, want 3 rules", rules)
|
||||
}
|
||||
if rules[0].DiscountPercent != 50 {
|
||||
t.Fatalf("折扣比例被覆盖: %#v", rules[0])
|
||||
}
|
||||
if rules[1].DiscountPercent != 100 {
|
||||
t.Fatalf("超范围折扣比例未收敛: %#v", rules[1])
|
||||
}
|
||||
if rules[2].DiscountPercent != 0 {
|
||||
t.Fatalf("负数折扣比例未收敛: %#v", rules[2])
|
||||
}
|
||||
}
|
||||
|
||||
func TestDefaultPublishOptionsKeepsDepositSkinGroupDiscountDisabled(t *testing.T) {
|
||||
options := DefaultPublishOptions()
|
||||
if len(options.DepositRecommend.SkinGroupRules) != 4 {
|
||||
t.Fatalf("skin_group_rules = %#v, want 4 rules", options.DepositRecommend.SkinGroupRules)
|
||||
}
|
||||
for _, rule := range options.DepositRecommend.SkinGroupRules {
|
||||
if rule.DiscountPercent != 0 {
|
||||
t.Fatalf("默认不应开启第二件折扣: %#v", rule)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizePublishOptionsValueDefaultsDepositTooltip(t *testing.T) {
|
||||
normalized, err := normalizePublishOptionsValue(`{"schema_version":2}`)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user