diff --git a/backend/internal/modules/systemconfig/dto.go b/backend/internal/modules/systemconfig/dto.go
index 521f7d3a..74a88aae 100644
--- a/backend/internal/modules/systemconfig/dto.go
+++ b/backend/internal/modules/systemconfig/dto.go
@@ -184,6 +184,10 @@ type PublishDepositSkinGroupRule struct {
GroupKey string `json:"group_key"`
Label string `json:"label"`
AmountPerItem float64 `json:"amount_per_item"`
+ // DiscountPercent 组内第 2 件起的计价百分比(0-100)。
+ // 0 表示不开启折扣,每件都按 AmountPerItem 计入;
+ // 50 表示第 1 件按原价计入,第 2 件起按原价的 50% 计入。
+ DiscountPercent float64 `json:"discount_percent"`
}
type PublishRatioConfig struct {
diff --git a/backend/internal/modules/systemconfig/normalize.go b/backend/internal/modules/systemconfig/normalize.go
index 9a424045..06b230db 100644
--- a/backend/internal/modules/systemconfig/normalize.go
+++ b/backend/internal/modules/systemconfig/normalize.go
@@ -271,6 +271,7 @@ func normalizePublishOptions(options *PublishOptionsDTO) {
if len(options.DepositRecommend.SkinGroupRules) == 0 {
options.DepositRecommend.SkinGroupRules = defaults.DepositRecommend.SkinGroupRules
}
+ normalizeDepositSkinGroupRules(options.DepositRecommend.SkinGroupRules)
if len(options.RatioConfig.InsuranceBaseRatios) == 0 {
options.RatioConfig.InsuranceBaseRatios = defaults.RatioConfig.InsuranceBaseRatios
}
@@ -375,6 +376,27 @@ func normalizeSignedRatioAdjustment(value float64) float64 {
return math.Round(value*10) / 10
}
+// normalizeDepositSkinGroupRules 收敛押金皮肤规则的折扣比例。
+// 0 表示不开启折扣(每件按原价计入),上限 100 表示第 2 件起不再加价。
+func normalizeDepositSkinGroupRules(rules []PublishDepositSkinGroupRule) {
+ for index := range rules {
+ rules[index].DiscountPercent = normalizeDepositDiscountPercent(rules[index].DiscountPercent)
+ }
+}
+
+func normalizeDepositDiscountPercent(value float64) float64 {
+ if math.IsNaN(value) || math.IsInf(value, 0) {
+ return 0
+ }
+ if value <= 0 {
+ return 0
+ }
+ if value >= 100 {
+ return 100
+ }
+ return math.Round(value*10) / 10
+}
+
func normalizePremiumReviewRatioMarkup(value float64) float64 {
if value < 0 || math.IsNaN(value) || math.IsInf(value, 0) {
return 0
diff --git a/backend/internal/modules/systemconfig/publish_options.go b/backend/internal/modules/systemconfig/publish_options.go
index b50bc8b7..a73078d5 100644
--- a/backend/internal/modules/systemconfig/publish_options.go
+++ b/backend/internal/modules/systemconfig/publish_options.go
@@ -141,10 +141,10 @@ func DefaultPublishOptions() PublishOptionsDTO {
DepositRecommend: PublishDepositRecommend{
BaseAmount: 200,
SkinGroupRules: []PublishDepositSkinGroupRule{
- {GroupKey: "melee", Label: "刀皮", AmountPerItem: 150},
- {GroupKey: "operatorGold", Label: "干员金皮", AmountPerItem: 0},
- {GroupKey: "operatorRed", Label: "干员红皮", AmountPerItem: 150},
- {GroupKey: "weapon", Label: "武器皮肤", AmountPerItem: 200},
+ {GroupKey: "melee", Label: "刀皮", AmountPerItem: 150, DiscountPercent: 0},
+ {GroupKey: "operatorGold", Label: "干员金皮", AmountPerItem: 0, DiscountPercent: 0},
+ {GroupKey: "operatorRed", Label: "干员红皮", AmountPerItem: 150, DiscountPercent: 0},
+ {GroupKey: "weapon", Label: "武器皮肤", AmountPerItem: 200, DiscountPercent: 0},
},
},
RatioConfig: PublishRatioConfig{
diff --git a/backend/internal/modules/systemconfig/publish_options_test.go b/backend/internal/modules/systemconfig/publish_options_test.go
index 0610b853..bc0a96d3 100644
--- a/backend/internal/modules/systemconfig/publish_options_test.go
+++ b/backend/internal/modules/systemconfig/publish_options_test.go
@@ -309,6 +309,54 @@ func TestNormalizePublishOptionsValueDefaultsQualityOwnerRatioDiscount(t *testin
}
}
+func TestNormalizePublishOptionsValueKeepsDepositSkinGroupDiscount(t *testing.T) {
+ raw := `{
+ "schema_version": 3,
+ "deposit_recommend_config": {
+ "base_amount": 200,
+ "skin_group_rules": [
+ {"group_key": "melee", "label": "刀皮", "amount_per_item": 100, "discount_percent": 50},
+ {"group_key": "weapon", "label": "武器皮肤", "amount_per_item": 200, "discount_percent": 120},
+ {"group_key": "operatorRed", "label": "干员红皮", "amount_per_item": 150, "discount_percent": -10}
+ ]
+ }
+ }`
+
+ normalized, err := normalizePublishOptionsValue(raw)
+ if err != nil {
+ t.Fatalf("规范化失败: %v", err)
+ }
+ var got PublishOptionsDTO
+ if err := json.Unmarshal([]byte(normalized), &got); err != nil {
+ t.Fatalf("解析规范化结果失败: %v", err)
+ }
+ rules := got.DepositRecommend.SkinGroupRules
+ if len(rules) != 3 {
+ t.Fatalf("skin_group_rules = %#v, want 3 rules", rules)
+ }
+ if rules[0].DiscountPercent != 50 {
+ t.Fatalf("折扣比例被覆盖: %#v", rules[0])
+ }
+ if rules[1].DiscountPercent != 100 {
+ t.Fatalf("超范围折扣比例未收敛: %#v", rules[1])
+ }
+ if rules[2].DiscountPercent != 0 {
+ t.Fatalf("负数折扣比例未收敛: %#v", rules[2])
+ }
+}
+
+func TestDefaultPublishOptionsKeepsDepositSkinGroupDiscountDisabled(t *testing.T) {
+ options := DefaultPublishOptions()
+ if len(options.DepositRecommend.SkinGroupRules) != 4 {
+ t.Fatalf("skin_group_rules = %#v, want 4 rules", options.DepositRecommend.SkinGroupRules)
+ }
+ for _, rule := range options.DepositRecommend.SkinGroupRules {
+ if rule.DiscountPercent != 0 {
+ t.Fatalf("默认不应开启第二件折扣: %#v", rule)
+ }
+ }
+}
+
func TestNormalizePublishOptionsValueDefaultsDepositTooltip(t *testing.T) {
normalized, err := normalizePublishOptionsValue(`{"schema_version":2}`)
if err != nil {
diff --git a/frontend/src/features/admin/components/PublishOptionsDialog.vue b/frontend/src/features/admin/components/PublishOptionsDialog.vue
index 555b0525..f1d07e1b 100644
--- a/frontend/src/features/admin/components/PublishOptionsDialog.vue
+++ b/frontend/src/features/admin/components/PublishOptionsDialog.vue
@@ -196,6 +196,7 @@ function addDepositSkinGroupRule() {
group_key: '',
label: '',
amount_per_item: 0,
+ discount_percent: 0,
})
}
@@ -634,7 +635,10 @@ async function handleSave() {
推荐押金皮肤规则
-
按选中皮肤件数累加,与收号比例的特殊分组规则相互独立。
+
+ 按选中皮肤件数累加,与收号比例的特殊分组规则相互独立。开启「第2件起计价」后,
+ 该分组第 1 件按原价计入,第 2 件起按设置的比例计入。
+
添加押金规则
+
+
+
+ 0 表示不开启折扣,每件都按原价计入。
+
+
diff --git a/frontend/src/features/listings/api/listingOptions.spec.ts b/frontend/src/features/listings/api/listingOptions.spec.ts
index f3ff4370..4874f1d4 100644
--- a/frontend/src/features/listings/api/listingOptions.spec.ts
+++ b/frontend/src/features/listings/api/listingOptions.spec.ts
@@ -108,4 +108,43 @@ describe('mergeListingPublishOptions', () => {
{ key: 'load6', field: 'load', level: '6级', ratio_adjustment: -0.5 },
])
})
+
+ it('读取押金皮肤规则的第二件折扣比例', () => {
+ const options = mergeListingPublishOptions({
+ deposit_recommend_config: {
+ base_amount: 200,
+ skin_group_rules: [
+ { group_key: 'melee', label: '刀皮', amount_per_item: 100, discount_percent: 50 },
+ ],
+ },
+ })
+
+ expect(options.deposit_recommend_config.skin_group_rules[0].discount_percent).toBe(50)
+ })
+
+ it('旧配置缺少折扣比例时按不开启折扣处理', () => {
+ const options = mergeListingPublishOptions({
+ deposit_recommend_config: {
+ base_amount: 200,
+ skin_group_rules: [{ group_key: 'melee', label: '刀皮', amount_per_item: 100 }],
+ },
+ })
+
+ expect(options.deposit_recommend_config.skin_group_rules[0].discount_percent).toBe(0)
+ })
+
+ it('折扣比例收敛到 0-100 区间', () => {
+ const options = mergeListingPublishOptions({
+ deposit_recommend_config: {
+ base_amount: 200,
+ skin_group_rules: [
+ { group_key: 'melee', label: '刀皮', amount_per_item: 100, discount_percent: 120 },
+ { group_key: 'weapon', label: '武器皮肤', amount_per_item: 200, discount_percent: -10 },
+ ],
+ },
+ })
+
+ expect(options.deposit_recommend_config.skin_group_rules[0].discount_percent).toBe(100)
+ expect(options.deposit_recommend_config.skin_group_rules[1].discount_percent).toBe(0)
+ })
})
diff --git a/frontend/src/features/listings/api/listingOptions.ts b/frontend/src/features/listings/api/listingOptions.ts
index bad59acc..a1b2ea09 100644
--- a/frontend/src/features/listings/api/listingOptions.ts
+++ b/frontend/src/features/listings/api/listingOptions.ts
@@ -45,6 +45,8 @@ export interface PublishDepositSkinGroupRule {
group_key: string
label: string
amount_per_item: number
+ /** 组内第 2 件起的计价百分比;0 表示不开启折扣 */
+ discount_percent: number
}
export interface PublishDepositRecommendConfig {
@@ -209,10 +211,10 @@ export const emptyListingPublishOptions: ListingPublishOptions = {
deposit_recommend_config: {
base_amount: 200,
skin_group_rules: [
- { group_key: 'melee', label: '刀皮', amount_per_item: 150 },
- { group_key: 'operatorGold', label: '干员金皮', amount_per_item: 0 },
- { group_key: 'operatorRed', label: '干员红皮', amount_per_item: 150 },
- { group_key: 'weapon', label: '武器皮肤', amount_per_item: 200 },
+ { group_key: 'melee', label: '刀皮', amount_per_item: 150, discount_percent: 0 },
+ { group_key: 'operatorGold', label: '干员金皮', amount_per_item: 0, discount_percent: 0 },
+ { group_key: 'operatorRed', label: '干员红皮', amount_per_item: 150, discount_percent: 0 },
+ { group_key: 'weapon', label: '武器皮肤', amount_per_item: 200, discount_percent: 0 },
],
},
ratio_config: {
@@ -451,6 +453,7 @@ function normalizeDepositSkinGroupRules(values: unknown[]): PublishDepositSkinGr
group_key: typeof row.group_key === 'string' ? row.group_key.trim() : '',
label: typeof row.label === 'string' ? row.label.trim() : '',
amount_per_item: readNumber(row.amount_per_item),
+ discount_percent: Math.min(100, Math.max(0, readNumber(row.discount_percent))),
}
})
.filter(item => item.group_key && item.label && item.amount_per_item >= 0)
diff --git a/frontend/src/features/seller/composables/usePublishDraft.ts b/frontend/src/features/seller/composables/usePublishDraft.ts
index efc3d156..8f5af1d0 100644
--- a/frontend/src/features/seller/composables/usePublishDraft.ts
+++ b/frontend/src/features/seller/composables/usePublishDraft.ts
@@ -38,6 +38,7 @@ export function buildPublishDraft(options: {
screenshotFiles: Record
selectedSkins: string[]
qualityOwnerRatioDefaultApplied: boolean
+ depositLoweredByUser: boolean
}): PublishDraft {
return {
form: {
@@ -49,6 +50,7 @@ export function buildPublishDraft(options: {
screenshotFiles: cloneScreenshotFiles(options.screenshotFiles),
selectedSkins: [...options.selectedSkins],
qualityOwnerRatioDefaultApplied: options.qualityOwnerRatioDefaultApplied,
+ depositLoweredByUser: options.depositLoweredByUser,
}
}
@@ -69,6 +71,8 @@ export function readPublishDraft(draftKey: string) {
typeof draft.qualityOwnerRatioDefaultApplied === 'boolean'
? draft.qualityOwnerRatioDefaultApplied
: undefined,
+ depositLoweredByUser:
+ typeof draft.depositLoweredByUser === 'boolean' ? draft.depositLoweredByUser : undefined,
}
} catch {
localStorage.removeItem(draftKey)
diff --git a/frontend/src/features/seller/composables/usePublishForm.ts b/frontend/src/features/seller/composables/usePublishForm.ts
index 3b8feb2c..adb94b0b 100644
--- a/frontend/src/features/seller/composables/usePublishForm.ts
+++ b/frontend/src/features/seller/composables/usePublishForm.ts
@@ -39,8 +39,10 @@ import type { PublishForm } from '@/shared/types/publish'
import { yuanToCent } from '@/shared/utils/money'
import {
calculateInsuranceFeeAmount,
+ canPurchaseInsurance,
dailyLossOptions,
formatNumber,
+ isDepositBelowRecommended,
roundRatio,
} from '@/shared/utils/pricing'
import { useDistributionSiteStore } from '@/stores/distributionSite'
@@ -59,6 +61,8 @@ interface UsePublishFormOptions {
notifySuccess: (message: string) => void
notifyWarning: (message: string) => void
notifyError: (message: string) => void
+ /** 押金低于推荐押金时的弹窗提示(桌面用 ElMessageBox,移动端用 vant showDialog) */
+ alertDepositBelowRecommended?: (message: string) => void
}
export function usePublishForm(options: UsePublishFormOptions) {
@@ -88,6 +92,8 @@ export function usePublishForm(options: UsePublishFormOptions) {
const screenshotPreviews = reactive>({})
const selectedSkins = ref([])
let draftSaveTimer: number | undefined
+ // 最近一次已提示过的「低于推荐押金」金额,避免同一次输入反复弹窗。
+ let lastAlertedDepositValue: number | null = null
const editListingID = computed(() => Number(route.params.id || 0))
const isEditMode = computed(() => Number.isFinite(editListingID.value) && editListingID.value > 0)
const pageTitle = computed(() => (isEditMode.value ? '编辑账号' : '发布账号'))
@@ -98,6 +104,10 @@ export function usePublishForm(options: UsePublishFormOptions) {
const nextSeasonPassEnabled = computed(() => publishOptions.value.next_season_pass_enabled)
const isQualityOwner = computed(() => qualityOwnerStatus.value?.active === true)
const qualityOwnerRatioDefaultApplied = ref(true)
+ // 用户是否主动把押金改到推荐值以下:为 true 时押金不再跟随推荐值上涨。
+ const depositLoweredByUser = ref(false)
+ // 押金是否由用户在本次会话里亲自输入:这种情况下由失焦弹窗统一提示。
+ const depositEditedByUser = ref(false)
const insuranceFeeBps = computed(() =>
form.is_premium && isQualityOwner.value
? Number(qualityOwnerStatus.value?.premium_insurance_fee_bps || 400)
@@ -126,6 +136,10 @@ export function usePublishForm(options: UsePublishFormOptions) {
const calculatedTakeHomePrice = computed(() =>
Math.max(pricing.calculatedSellerPrice.value - calculatedInsuranceFee.value, 0)
)
+ // 押金是否低于推荐押金:低于推荐押金允许发布,但不能选购无忧租号保险。
+ const depositBelowRecommended = computed(() =>
+ isDepositBelowRecommended(form.depositAmountYuan, pricing.recommendedDepositAmount.value)
+ )
const qualityOwnerSaleRatioSelected = computed(
() =>
isQualityOwner.value &&
@@ -221,11 +235,23 @@ export function usePublishForm(options: UsePublishFormOptions) {
watch(
pricing.recommendedDepositAmount,
() => {
+ // 推荐值变化不是用户手动改押金,后续提示按「推荐值上涨」处理。
+ depositEditedByUser.value = false
syncRecommendedDeposit()
},
{ immediate: true }
)
+ // 押金低于推荐押金时禁购无忧租号保险:已选购的自动退回普通赔付。
+ watch(depositBelowRecommended, below => {
+ if (!below) return
+ if (form.compensation_plan !== 'insurance') return
+ form.compensation_plan = 'normal'
+ // 用户主动改低押金时由失焦弹窗统一提示,这里不重复提示。
+ if (depositEditedByUser.value) return
+ options.notifyWarning('押金低于推荐押金,已取消无忧租号保险')
+ })
+
watch(
[() => form.season_insurance, pricing.quantityItems],
() => {
@@ -330,6 +356,7 @@ export function usePublishForm(options: UsePublishFormOptions) {
screenshotFiles,
selectedSkins: selectedSkins.value,
qualityOwnerRatioDefaultApplied: qualityOwnerRatioDefaultApplied.value,
+ depositLoweredByUser: depositLoweredByUser.value,
})
)
}
@@ -347,6 +374,9 @@ export function usePublishForm(options: UsePublishFormOptions) {
const draft = readPublishDraft(options.draftKey)
if (!draft) return
Object.assign(form, draft.form)
+ // 草稿里标记为用户主动改低的押金,不再被推荐值自动覆盖。
+ depositLoweredByUser.value = draft.depositLoweredByUser === true
+ depositEditedByUser.value = false
normalizeOnlineTime()
clearRecord(quantityValues)
clearRecord(quantityModes)
@@ -440,6 +470,8 @@ export function usePublishForm(options: UsePublishFormOptions) {
passwordAndDeviceConfirmed.value = false
activeUploadKey.value = 'coin'
qualityOwnerRatioDefaultApplied.value = true
+ depositLoweredByUser.value = false
+ depositEditedByUser.value = false
// Also re-initialize quantityValues to 0
for (const item of publishOptions.value.quantity_items) {
@@ -655,8 +687,10 @@ export function usePublishForm(options: UsePublishFormOptions) {
function syncRecommendedDeposit() {
const recommended = pricing.recommendedDepositAmount.value
if (recommended <= 0) return
+ // 用户已经把押金改到推荐值以下,保留其输入(点「使用推荐」可恢复自动跟随)。
+ if (depositLoweredByUser.value) return
const current = Number(form.depositAmountYuan)
- if (form.depositAmountYuan === '' || !Number.isFinite(current) || current < recommended) {
+ if (!hasValidDeposit() || current < recommended) {
form.depositAmountYuan = recommended
}
}
@@ -664,18 +698,74 @@ export function usePublishForm(options: UsePublishFormOptions) {
function useRecommendedDeposit() {
if (pricing.recommendedDepositAmount.value > 0) {
form.depositAmountYuan = pricing.recommendedDepositAmount.value
+ depositLoweredByUser.value = false
+ depositEditedByUser.value = false
}
}
- // 失焦时实时校正:押金低于(或低于等于无效/为空)智能推荐时自动补到推荐值并提示。
+ // 押金输入:标记用户正在手动编辑,用于区分提示方式。
+ function handleDepositInput() {
+ depositEditedByUser.value = true
+ }
+
+ // 失焦时:低于推荐押金允许继续发布,但弹出提示并禁购无忧租号保险。
function handleDepositBlur() {
const recommended = pricing.recommendedDepositAmount.value
if (recommended <= 0) return
- const current = Number(form.depositAmountYuan)
- if (form.depositAmountYuan === '' || !Number.isFinite(current) || current < recommended) {
+ if (!hasValidDeposit()) {
form.depositAmountYuan = recommended
- options.notifyWarning(`押金不能低于智能推荐 ¥${recommended},已自动调整`)
+ depositLoweredByUser.value = false
+ depositEditedByUser.value = false
+ lastAlertedDepositValue = null
+ return
}
+ const current = Number(form.depositAmountYuan)
+ depositLoweredByUser.value = current < recommended
+ if (current < recommended) {
+ notifyDepositBelowRecommended()
+ } else {
+ lastAlertedDepositValue = null
+ }
+ // 结束本次输入,后续推荐值变化再用轻提示说明。
+ depositEditedByUser.value = false
+ }
+
+ function hasValidDeposit() {
+ const raw = form.depositAmountYuan
+ if (raw === '' || raw === null || raw === undefined) return false
+ return Number.isFinite(Number(raw))
+ }
+
+ function showDepositBelowRecommendedAlert(recommended: number) {
+ const message = `押金低于推荐押金 ¥${recommended},无法购买无忧租号保险`
+ if (options.alertDepositBelowRecommended) {
+ options.alertDepositBelowRecommended(message)
+ } else {
+ options.notifyWarning(message)
+ }
+ }
+
+ // 同一次输入只提示一次,避免反复失焦反复弹窗。
+ function notifyDepositBelowRecommended() {
+ const recommended = pricing.recommendedDepositAmount.value
+ if (recommended <= 0) return
+ const current = Number(form.depositAmountYuan)
+ if (!Number.isFinite(current)) return
+ if (lastAlertedDepositValue === current) return
+ lastAlertedDepositValue = current
+ showDepositBelowRecommendedAlert(recommended)
+ }
+
+ // 选择赔付方案:押金低于推荐押金时禁购无忧租号保险,并给出弹窗提示。
+ function selectCompensationPlan(plan: 'normal' | 'insurance') {
+ const recommended = pricing.recommendedDepositAmount.value
+ if (plan === 'insurance' && !canPurchaseInsurance(form.depositAmountYuan, recommended)) {
+ // 复用失焦提示的去重逻辑,避免连续操作弹出多个对话框。
+ notifyDepositBelowRecommended()
+ form.compensation_plan = 'normal'
+ return
+ }
+ form.compensation_plan = plan
}
function clearForbiddenQuantityItems() {
@@ -834,20 +924,17 @@ export function usePublishForm(options: UsePublishFormOptions) {
if (nextSeasonPassEnabled.value && !form.next_season_pass) {
return '请选择下赛季是否购买通行证'
}
- if (form.depositAmountYuan === '' || Number(form.depositAmountYuan) < 0) return '请填写押金'
- if (!Number.isFinite(Number(form.depositAmountYuan))) return '押金格式不正确'
- if (
- pricing.recommendedDepositAmount.value > 0 &&
- Number(form.depositAmountYuan) < pricing.recommendedDepositAmount.value
- ) {
- return `押金不能低于智能推荐 ¥${pricing.recommendedDepositAmount.value}`
- }
+ if (!hasValidDeposit()) return '请填写押金'
+ if (Number(form.depositAmountYuan) < 0) return '押金格式不正确'
if (
pricing.calculatedConsumablePrice.value > 0 &&
Number(form.depositAmountYuan) <= pricing.calculatedConsumablePrice.value
) {
return `押金必须大于额外消耗品总价值 ¥${pricing.calculatedConsumablePrice.value}`
}
+ if (form.compensation_plan === 'insurance' && depositBelowRecommended.value) {
+ return '押金低于推荐押金,无法购买无忧租号保险,请提高押金或改选普通赔付'
+ }
if (!pricing.calculatedFinalPrice.value) return '请完善币数、保险、体力和负重后再发布'
if (!Number.isFinite(pricing.calculatedFinalPrice.value))
return '发布价格计算异常,请检查填写内容'
@@ -1098,7 +1185,10 @@ export function usePublishForm(options: UsePublishFormOptions) {
handleAcceleratedSaleRatioInput,
syncRecommendedDeposit,
useRecommendedDeposit,
+ handleDepositInput,
handleDepositBlur,
+ depositBelowRecommended,
+ selectCompensationPlan,
clearForbiddenQuantityItems,
setQuantityMode,
clampAcceleratedSaleRatioInput,
diff --git a/frontend/src/features/seller/views/MobileSellerListingCreateView.css b/frontend/src/features/seller/views/MobileSellerListingCreateView.css
index d9d79cfc..0c7386e0 100644
--- a/frontend/src/features/seller/views/MobileSellerListingCreateView.css
+++ b/frontend/src/features/seller/views/MobileSellerListingCreateView.css
@@ -1120,6 +1120,27 @@
background: #f3ebff;
}
+.coverage-option .coverage-disabled-reason {
+ color: #d97706;
+ font-weight: 700;
+}
+
+.coverage-option.is-disabled {
+ border-color: #e5e7eb;
+ background: #f9fafb;
+ color: #9ca3af;
+ cursor: not-allowed;
+}
+
+.coverage-option.is-disabled .coverage-rate.is-insurance {
+ background: #f3f4f6;
+ color: #9ca3af;
+}
+
+.coverage-option.is-disabled span {
+ color: #9ca3af;
+}
+
.coverage-option.active {
border-color: #7c3aed;
background: #faf5ff;
diff --git a/frontend/src/features/seller/views/MobileSellerListingCreateView.vue b/frontend/src/features/seller/views/MobileSellerListingCreateView.vue
index b43d9b28..e63b46a7 100644
--- a/frontend/src/features/seller/views/MobileSellerListingCreateView.vue
+++ b/frontend/src/features/seller/views/MobileSellerListingCreateView.vue
@@ -93,7 +93,10 @@ const {
handleFireLevelInput,
handleAcceleratedSaleRatioInput,
useRecommendedDeposit,
+ handleDepositInput,
handleDepositBlur,
+ depositBelowRecommended,
+ selectCompensationPlan,
setQuantityMode,
clampAcceleratedSaleRatioInput,
useReferenceSaleRatio,
@@ -117,6 +120,12 @@ const {
notifySuccess: message => showToast({ message, icon: 'passed' }),
notifyWarning: message => showToast({ message, icon: 'warning-o' }),
notifyError: message => showToast({ message, icon: 'cross' }),
+ alertDepositBelowRecommended: message =>
+ void showDialog({
+ title: '押金低于推荐押金',
+ message,
+ confirmButtonText: '我知道了',
+ }),
})
const agreementPopupVisible = ref(false)
@@ -729,6 +738,7 @@ const screenshotGuides: Record = {
type="number"
inputmode="decimal"
:placeholder="priceConfig.deposit_placeholder"
+ @input="handleDepositInput"
@blur="handleDepositBlur"
/>
元
@@ -955,7 +965,7 @@ const screenshotGuides: Record = {
type="button"
class="coverage-option"
:class="{ active: form.compensation_plan === 'normal' }"
- @click="form.compensation_plan = 'normal'"
+ @click="selectCompensationPlan('normal')"
>
普通赔付
@@ -966,14 +976,21 @@ const screenshotGuides: Record = {
@@ -779,7 +788,7 @@ function selectDailyLoss(value: string | number) {
type="button"
class="coverage-option"
:class="{ active: form.compensation_plan === 'normal' }"
- @click="form.compensation_plan = 'normal'"
+ @click="selectCompensationPlan('normal')"
>
普通赔付
@@ -790,8 +799,12 @@ function selectDailyLoss(value: string | number) {
无忧租号保险
@@ -800,6 +813,9 @@ function selectDailyLoss(value: string | number) {
额外保障账号市场价值,费率按实际纯币结算金额扣除
+
+ 押金低于推荐押金,无法购买无忧租号保险
+
已享极品专区专享费率
diff --git a/frontend/src/shared/types/publish.ts b/frontend/src/shared/types/publish.ts
index 7f25fba6..57e4e7d3 100644
--- a/frontend/src/shared/types/publish.ts
+++ b/frontend/src/shared/types/publish.ts
@@ -42,12 +42,16 @@ export interface PublishDraft {
screenshotFiles: Record
selectedSkins: string[]
qualityOwnerRatioDefaultApplied?: boolean
+ /** 用户是否主动把押金改到推荐值以下:为 true 时押金不再跟随推荐值上涨 */
+ depositLoweredByUser?: boolean
}
export interface DepositBreakdownItem {
label: string
amount: number
count: number
+ /** 折扣说明,例如「第2件起按50%计」;无折扣时为空 */
+ detail?: string
}
export interface PublishPlatformPricing {
diff --git a/frontend/src/shared/utils/__tests__/pricing.spec.ts b/frontend/src/shared/utils/__tests__/pricing.spec.ts
index fcba96d8..c8f0542c 100644
--- a/frontend/src/shared/utils/__tests__/pricing.spec.ts
+++ b/frontend/src/shared/utils/__tests__/pricing.spec.ts
@@ -1,9 +1,21 @@
import { describe, expect, it } from 'vitest'
-import type { PublishOptionGroup, PublishRatioConfig } from '@/features/listings/api/listingOptions'
+import type {
+ PublishDepositRecommendConfig,
+ PublishOptionGroup,
+ PublishRatioConfig,
+} from '@/features/listings/api/listingOptions'
import type { PublishForm } from '@/shared/types/publish'
-import { calculateInsuranceFeeAmount, calculateSellerReferenceRatio } from '../pricing'
+import {
+ buildDepositBreakdownItems,
+ calculateDepositGroupAmount,
+ calculateInsuranceFeeAmount,
+ calculateRecommendedDeposit,
+ calculateSellerReferenceRatio,
+ canPurchaseInsurance,
+ isDepositBelowRecommended,
+} from '../pricing'
describe('calculateInsuranceFeeAmount', () => {
it('普通赔付不收取保险服务费', () => {
@@ -27,6 +39,118 @@ describe('calculateInsuranceFeeAmount', () => {
})
})
+const depositSkinGroups: PublishOptionGroup[] = [
+ {
+ key: 'melee',
+ title: '近战皮肤',
+ options: ['北极星', '龙牙', '赤霄'],
+ special_price_options: ['龙牙', '赤霄'],
+ special_ratio_adjustment: -1,
+ },
+]
+
+function depositConfig(
+ rules: PublishDepositRecommendConfig['skin_group_rules']
+): PublishDepositRecommendConfig {
+ return {
+ base_amount: 200,
+ skin_group_rules: rules,
+ }
+}
+
+describe('calculateDepositGroupAmount', () => {
+ it('未开启折扣时每件按原价累加', () => {
+ const rule = { group_key: 'melee', label: '刀皮', amount_per_item: 100, discount_percent: 0 }
+ expect(calculateDepositGroupAmount(rule, 3)).toBe(300)
+ })
+
+ it('开启第二件折扣时第 1 件按原价、后续按比例计入', () => {
+ const rule = { group_key: 'melee', label: '刀皮', amount_per_item: 100, discount_percent: 50 }
+ expect(calculateDepositGroupAmount(rule, 1)).toBe(100)
+ expect(calculateDepositGroupAmount(rule, 2)).toBe(150)
+ expect(calculateDepositGroupAmount(rule, 3)).toBe(200)
+ })
+
+ it('折扣金额按角取整后再累加', () => {
+ const rule = { group_key: 'melee', label: '刀皮', amount_per_item: 100, discount_percent: 33 }
+ expect(calculateDepositGroupAmount(rule, 3)).toBe(166)
+ })
+})
+
+describe('calculateRecommendedDeposit', () => {
+ it('基础押金叠加皮肤金额', () => {
+ const deposit = calculateRecommendedDeposit({
+ depositRecommendConfig: depositConfig([
+ { group_key: 'melee', label: '刀皮', amount_per_item: 100, discount_percent: 0 },
+ ]),
+ skinGroups: depositSkinGroups,
+ selectedSkins: ['北极星', '龙牙'],
+ })
+ expect(deposit).toBe(400)
+ })
+
+ it('开启第二件折扣后推荐押金按折扣后的金额累计', () => {
+ const deposit = calculateRecommendedDeposit({
+ depositRecommendConfig: depositConfig([
+ { group_key: 'melee', label: '刀皮', amount_per_item: 100, discount_percent: 50 },
+ ]),
+ skinGroups: depositSkinGroups,
+ selectedSkins: ['北极星', '龙牙', '赤霄'],
+ })
+ expect(deposit).toBe(400)
+ })
+})
+
+describe('buildDepositBreakdownItems', () => {
+ it('明细按折扣后的实际金额展示并附带折扣说明', () => {
+ const items = buildDepositBreakdownItems({
+ depositRecommendConfig: depositConfig([
+ { group_key: 'melee', label: '刀皮', amount_per_item: 100, discount_percent: 50 },
+ ]),
+ skinGroups: depositSkinGroups,
+ selectedSkins: ['北极星', '龙牙'],
+ })
+ expect(items[0]).toEqual({ label: '基础押金', amount: 200, count: 1 })
+ expect(items[1]).toEqual({
+ label: '刀皮',
+ amount: 150,
+ count: 2,
+ detail: '第2件起按50%计',
+ })
+ })
+})
+
+describe('isDepositBelowRecommended', () => {
+ it('押金等于推荐押金时不低于推荐', () => {
+ expect(isDepositBelowRecommended(200, 200)).toBe(false)
+ })
+
+ it('押金低于推荐押金时返回 true', () => {
+ expect(isDepositBelowRecommended(150, 200)).toBe(true)
+ })
+
+ it('押金为空或非法时不判定为低于推荐', () => {
+ expect(isDepositBelowRecommended('', 200)).toBe(false)
+ expect(isDepositBelowRecommended(null, 200)).toBe(false)
+ expect(isDepositBelowRecommended(Number.NaN, 200)).toBe(false)
+ })
+
+ it('没有推荐押金时不做限制', () => {
+ expect(isDepositBelowRecommended(10, 0)).toBe(false)
+ })
+})
+
+describe('canPurchaseInsurance', () => {
+ it('押金达到推荐押金时可以购买无忧租号保险', () => {
+ expect(canPurchaseInsurance(200, 200)).toBe(true)
+ expect(canPurchaseInsurance(300, 200)).toBe(true)
+ })
+
+ it('押金低于推荐押金时禁止购买无忧租号保险', () => {
+ expect(canPurchaseInsurance(150, 200)).toBe(false)
+ })
+})
+
function basePublishForm(overrides: Partial = {}): PublishForm {
return {
server_region: 'QQ',
diff --git a/frontend/src/shared/utils/pricing.ts b/frontend/src/shared/utils/pricing.ts
index 61705a19..16bcddc7 100644
--- a/frontend/src/shared/utils/pricing.ts
+++ b/frontend/src/shared/utils/pricing.ts
@@ -40,6 +40,28 @@ export function roundRatio(value: number) {
return Math.round(value * 10) / 10
}
+/**
+ * 押金是否低于推荐押金。
+ * 低于推荐押金允许发布,但不能选购无忧租号保险。
+ */
+export function isDepositBelowRecommended(
+ deposit: number | '' | null | undefined,
+ recommended: number
+) {
+ if (recommended <= 0) return false
+ if (deposit === '' || deposit === null || deposit === undefined) return false
+ const value = Number(deposit)
+ if (!Number.isFinite(value)) return false
+ return value < recommended
+}
+
+/**
+ * 押金低于推荐押金时不可选购无忧租号保险。
+ */
+export function canPurchaseInsurance(deposit: number | '' | null | undefined, recommended: number) {
+ return !isDepositBelowRecommended(deposit, recommended)
+}
+
/**
* 格式化数字为字符串(保留1位小数)
*/
@@ -97,15 +119,41 @@ export function calculateRecommendedDeposit(options: {
selectedSkins: string[]
}) {
const baseAmount = Number(options.depositRecommendConfig.base_amount || 0)
- const skinAmount = options.depositRecommendConfig.skin_group_rules.reduce((sum, rule) => {
- const group = options.skinGroups.find(item => item.key === rule.group_key)
- if (!group) return sum
- const selectedCount = group.options.filter(skin => options.selectedSkins.includes(skin)).length
- return sum + selectedCount * Number(rule.amount_per_item || 0)
- }, 0)
+ const skinAmount = options.depositRecommendConfig.skin_group_rules.reduce(
+ (sum, rule) => sum + calculateDepositGroupAmount(rule, countSelectedSkins(rule, options)),
+ 0
+ )
return roundMoney(baseAmount + skinAmount)
}
+/**
+ * 统计规则命中的皮肤件数
+ */
+function countSelectedSkins(
+ rule: PublishDepositRecommendConfig['skin_group_rules'][number],
+ options: { skinGroups: PublishOptionGroup[]; selectedSkins: string[] }
+) {
+ const group = options.skinGroups.find(item => item.key === rule.group_key)
+ if (!group) return 0
+ return group.options.filter(skin => options.selectedSkins.includes(skin)).length
+}
+
+/**
+ * 计算单个皮肤分组计入推荐押金的金额。
+ * 分组内累计:第 1 件按原价计入,第 2 件起按折扣比例计入(discount_percent=0 表示不开启折扣)。
+ */
+export function calculateDepositGroupAmount(
+ rule: PublishDepositRecommendConfig['skin_group_rules'][number],
+ count: number
+) {
+ const amountPerItem = Number(rule.amount_per_item || 0)
+ if (count <= 0 || amountPerItem <= 0) return 0
+ const discountPercent = Math.min(100, Math.max(0, Number(rule.discount_percent || 0)))
+ if (discountPercent <= 0 || count === 1) return roundMoney(amountPerItem * count)
+ const discountAmount = roundMoney((amountPerItem * discountPercent) / 100)
+ return roundMoney(amountPerItem + discountAmount * (count - 1))
+}
+
export function buildDepositBreakdownItems(options: {
depositRecommendConfig: PublishDepositRecommendConfig
skinGroups: PublishOptionGroup[]
@@ -119,19 +167,34 @@ export function buildDepositBreakdownItems(options: {
},
]
for (const rule of options.depositRecommendConfig.skin_group_rules) {
- const group = options.skinGroups.find(item => item.key === rule.group_key)
- if (!group) continue
- const count = group.options.filter(skin => options.selectedSkins.includes(skin)).length
+ const count = countSelectedSkins(rule, options)
if (count <= 0) continue
items.push({
label: rule.label,
- amount: Number(rule.amount_per_item || 0) * count,
+ amount: calculateDepositGroupAmount(rule, count),
count,
+ detail: describeDepositGroupDiscount(rule, count),
})
}
return items
}
+/**
+ * 生成押金明细的折扣说明,例如「第2件起按50%计」
+ */
+function describeDepositGroupDiscount(
+ rule: PublishDepositRecommendConfig['skin_group_rules'][number],
+ count: number
+) {
+ const discountPercent = Math.min(100, Math.max(0, Number(rule.discount_percent || 0)))
+ if (discountPercent <= 0 || count <= 1) return ''
+ return `第2件起按${trimTrailingZero(discountPercent)}%计`
+}
+
+function trimTrailingZero(value: number) {
+ return String(Math.round(value * 10) / 10)
+}
+
export function calculateSellerReferenceRatio(options: {
coinMAmount: number
form: PublishForm