feat(publish): 推荐押金支持第二件折扣并放宽押金下限
- 推荐押金皮肤规则新增「第2件起计价」比例,组内首件按原价、后续件按比例计入 - 押金低于推荐押金允许发布,弹窗提示并禁用无忧租号保险 - 用户主动改低押金后不再被推荐值覆盖,点「使用推荐」恢复自动跟随
This commit is contained in:
@@ -196,6 +196,7 @@ function addDepositSkinGroupRule() {
|
||||
group_key: '',
|
||||
label: '',
|
||||
amount_per_item: 0,
|
||||
discount_percent: 0,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -634,7 +635,10 @@ async function handleSave() {
|
||||
<div class="section-heading">
|
||||
<div>
|
||||
<h3>推荐押金皮肤规则</h3>
|
||||
<p>按选中皮肤件数累加,与收号比例的特殊分组规则相互独立。</p>
|
||||
<p>
|
||||
按选中皮肤件数累加,与收号比例的特殊分组规则相互独立。开启「第2件起计价」后,
|
||||
该分组第 1 件按原价计入,第 2 件起按设置的比例计入。
|
||||
</p>
|
||||
</div>
|
||||
<el-button :icon="Plus" size="small" @click="addDepositSkinGroupRule"
|
||||
>添加押金规则</el-button
|
||||
@@ -657,6 +661,17 @@ async function handleSave() {
|
||||
<el-input-number v-model="row.amount_per_item" :min="0" :step="5" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="第2件起计价(%)" min-width="200">
|
||||
<template #default="{ row }">
|
||||
<el-input-number
|
||||
v-model="row.discount_percent"
|
||||
:min="0"
|
||||
:max="100"
|
||||
:step="5"
|
||||
/>
|
||||
<span class="field-hint">0 表示不开启折扣,每件都按原价计入。</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="76" align="center">
|
||||
<template #default="{ $index }">
|
||||
<el-tooltip content="删除押金规则" placement="top">
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -38,6 +38,7 @@ export function buildPublishDraft(options: {
|
||||
screenshotFiles: Record<ScreenshotKey, string[]>
|
||||
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)
|
||||
|
||||
@@ -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<Record<string, string[]>>({})
|
||||
const selectedSkins = ref<string[]>([])
|
||||
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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<string, string> = {
|
||||
type="number"
|
||||
inputmode="decimal"
|
||||
:placeholder="priceConfig.deposit_placeholder"
|
||||
@input="handleDepositInput"
|
||||
@blur="handleDepositBlur"
|
||||
/>
|
||||
<span>元</span>
|
||||
@@ -955,7 +965,7 @@ const screenshotGuides: Record<string, string> = {
|
||||
type="button"
|
||||
class="coverage-option"
|
||||
:class="{ active: form.compensation_plan === 'normal' }"
|
||||
@click="form.compensation_plan = 'normal'"
|
||||
@click="selectCompensationPlan('normal')"
|
||||
>
|
||||
<span class="coverage-option-top">
|
||||
<strong>普通赔付</strong>
|
||||
@@ -966,14 +976,21 @@ const screenshotGuides: Record<string, string> = {
|
||||
<button
|
||||
type="button"
|
||||
class="coverage-option"
|
||||
:class="{ active: form.compensation_plan === 'insurance' }"
|
||||
@click="form.compensation_plan = 'insurance'"
|
||||
:class="{
|
||||
active: form.compensation_plan === 'insurance',
|
||||
'is-disabled': depositBelowRecommended,
|
||||
}"
|
||||
:aria-disabled="depositBelowRecommended"
|
||||
@click="selectCompensationPlan('insurance')"
|
||||
>
|
||||
<span class="coverage-option-top">
|
||||
<strong>无忧租号保险</strong>
|
||||
<em class="coverage-rate is-insurance"> {{ insuranceFeePercent.toFixed(1) }}% </em>
|
||||
</span>
|
||||
<span>额外保障账号市场价值,按纯币结算金额计费</span>
|
||||
<em v-if="depositBelowRecommended" class="coverage-disabled-reason">
|
||||
押金低于推荐押金,无法购买无忧租号保险
|
||||
</em>
|
||||
<em v-if="isQualityOwner && form.is_premium" class="coverage-special-rate">
|
||||
已享极品专区专享费率
|
||||
</em>
|
||||
|
||||
@@ -1292,6 +1292,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;
|
||||
|
||||
@@ -105,7 +105,10 @@ const {
|
||||
handleFireLevelInput,
|
||||
handleAcceleratedSaleRatioInput,
|
||||
useRecommendedDeposit,
|
||||
handleDepositInput,
|
||||
handleDepositBlur,
|
||||
depositBelowRecommended,
|
||||
selectCompensationPlan,
|
||||
setQuantityMode,
|
||||
clampAcceleratedSaleRatioInput,
|
||||
useReferenceSaleRatio,
|
||||
@@ -128,6 +131,11 @@ const {
|
||||
notifySuccess: message => ElMessage.success(message),
|
||||
notifyWarning: message => ElMessage.warning(message),
|
||||
notifyError: message => ElMessage.error(message),
|
||||
alertDepositBelowRecommended: message =>
|
||||
void ElMessageBox.alert(message, '押金低于推荐押金', {
|
||||
confirmButtonText: '我知道了',
|
||||
type: 'warning',
|
||||
}),
|
||||
})
|
||||
|
||||
const agreementDialogVisible = ref(false)
|
||||
@@ -571,6 +579,7 @@ function selectDailyLoss(value: string | number) {
|
||||
:min="0"
|
||||
:controls="false"
|
||||
:placeholder="priceConfig.deposit_placeholder"
|
||||
@input="handleDepositInput"
|
||||
@blur="handleDepositBlur"
|
||||
/>
|
||||
<button class="recommend-button" type="button" @click="useRecommendedDeposit">
|
||||
@@ -581,7 +590,7 @@ function selectDailyLoss(value: string | number) {
|
||||
<span v-for="item in depositBreakdownItems" :key="`${item.label}-${item.count}`">
|
||||
{{ item.label }}<template v-if="item.count > 1"> x{{ item.count }}</template> ¥{{
|
||||
formatMoney(item.amount)
|
||||
}}
|
||||
}}<template v-if="item.detail">({{ item.detail }})</template>
|
||||
</span>
|
||||
</div>
|
||||
</label>
|
||||
@@ -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')"
|
||||
>
|
||||
<span class="coverage-option-top">
|
||||
<strong>普通赔付</strong>
|
||||
@@ -790,8 +799,12 @@ function selectDailyLoss(value: string | number) {
|
||||
<button
|
||||
type="button"
|
||||
class="coverage-option"
|
||||
:class="{ active: form.compensation_plan === 'insurance' }"
|
||||
@click="form.compensation_plan = 'insurance'"
|
||||
:class="{
|
||||
active: form.compensation_plan === 'insurance',
|
||||
'is-disabled': depositBelowRecommended,
|
||||
}"
|
||||
:aria-disabled="depositBelowRecommended"
|
||||
@click="selectCompensationPlan('insurance')"
|
||||
>
|
||||
<span class="coverage-option-top">
|
||||
<strong>无忧租号保险</strong>
|
||||
@@ -800,6 +813,9 @@ function selectDailyLoss(value: string | number) {
|
||||
</em>
|
||||
</span>
|
||||
<span>额外保障账号市场价值,费率按实际纯币结算金额扣除</span>
|
||||
<em v-if="depositBelowRecommended" class="coverage-disabled-reason">
|
||||
押金低于推荐押金,无法购买无忧租号保险
|
||||
</em>
|
||||
<em v-if="isQualityOwner && form.is_premium" class="coverage-special-rate">
|
||||
已享极品专区专享费率
|
||||
</em>
|
||||
|
||||
@@ -42,12 +42,16 @@ export interface PublishDraft {
|
||||
screenshotFiles: Record<ScreenshotKey, string[]>
|
||||
selectedSkins: string[]
|
||||
qualityOwnerRatioDefaultApplied?: boolean
|
||||
/** 用户是否主动把押金改到推荐值以下:为 true 时押金不再跟随推荐值上涨 */
|
||||
depositLoweredByUser?: boolean
|
||||
}
|
||||
|
||||
export interface DepositBreakdownItem {
|
||||
label: string
|
||||
amount: number
|
||||
count: number
|
||||
/** 折扣说明,例如「第2件起按50%计」;无折扣时为空 */
|
||||
detail?: string
|
||||
}
|
||||
|
||||
export interface PublishPlatformPricing {
|
||||
|
||||
@@ -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> = {}): PublishForm {
|
||||
return {
|
||||
server_region: 'QQ',
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user