feat(publish): 推荐押金支持第二件折扣并放宽押金下限
- 推荐押金皮肤规则新增「第2件起计价」比例,组内首件按原价、后续件按比例计入 - 押金低于推荐押金允许发布,弹窗提示并禁用无忧租号保险 - 用户主动改低押金后不再被推荐值覆盖,点「使用推荐」恢复自动跟随
This commit is contained in:
@@ -184,6 +184,10 @@ type PublishDepositSkinGroupRule struct {
|
|||||||
GroupKey string `json:"group_key"`
|
GroupKey string `json:"group_key"`
|
||||||
Label string `json:"label"`
|
Label string `json:"label"`
|
||||||
AmountPerItem float64 `json:"amount_per_item"`
|
AmountPerItem float64 `json:"amount_per_item"`
|
||||||
|
// DiscountPercent 组内第 2 件起的计价百分比(0-100)。
|
||||||
|
// 0 表示不开启折扣,每件都按 AmountPerItem 计入;
|
||||||
|
// 50 表示第 1 件按原价计入,第 2 件起按原价的 50% 计入。
|
||||||
|
DiscountPercent float64 `json:"discount_percent"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PublishRatioConfig struct {
|
type PublishRatioConfig struct {
|
||||||
|
|||||||
@@ -271,6 +271,7 @@ func normalizePublishOptions(options *PublishOptionsDTO) {
|
|||||||
if len(options.DepositRecommend.SkinGroupRules) == 0 {
|
if len(options.DepositRecommend.SkinGroupRules) == 0 {
|
||||||
options.DepositRecommend.SkinGroupRules = defaults.DepositRecommend.SkinGroupRules
|
options.DepositRecommend.SkinGroupRules = defaults.DepositRecommend.SkinGroupRules
|
||||||
}
|
}
|
||||||
|
normalizeDepositSkinGroupRules(options.DepositRecommend.SkinGroupRules)
|
||||||
if len(options.RatioConfig.InsuranceBaseRatios) == 0 {
|
if len(options.RatioConfig.InsuranceBaseRatios) == 0 {
|
||||||
options.RatioConfig.InsuranceBaseRatios = defaults.RatioConfig.InsuranceBaseRatios
|
options.RatioConfig.InsuranceBaseRatios = defaults.RatioConfig.InsuranceBaseRatios
|
||||||
}
|
}
|
||||||
@@ -375,6 +376,27 @@ func normalizeSignedRatioAdjustment(value float64) float64 {
|
|||||||
return math.Round(value*10) / 10
|
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 {
|
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
|
||||||
|
|||||||
@@ -141,10 +141,10 @@ func DefaultPublishOptions() PublishOptionsDTO {
|
|||||||
DepositRecommend: PublishDepositRecommend{
|
DepositRecommend: PublishDepositRecommend{
|
||||||
BaseAmount: 200,
|
BaseAmount: 200,
|
||||||
SkinGroupRules: []PublishDepositSkinGroupRule{
|
SkinGroupRules: []PublishDepositSkinGroupRule{
|
||||||
{GroupKey: "melee", Label: "刀皮", AmountPerItem: 150},
|
{GroupKey: "melee", Label: "刀皮", AmountPerItem: 150, DiscountPercent: 0},
|
||||||
{GroupKey: "operatorGold", Label: "干员金皮", AmountPerItem: 0},
|
{GroupKey: "operatorGold", Label: "干员金皮", AmountPerItem: 0, DiscountPercent: 0},
|
||||||
{GroupKey: "operatorRed", Label: "干员红皮", AmountPerItem: 150},
|
{GroupKey: "operatorRed", Label: "干员红皮", AmountPerItem: 150, DiscountPercent: 0},
|
||||||
{GroupKey: "weapon", Label: "武器皮肤", AmountPerItem: 200},
|
{GroupKey: "weapon", Label: "武器皮肤", AmountPerItem: 200, DiscountPercent: 0},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RatioConfig: PublishRatioConfig{
|
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) {
|
func TestNormalizePublishOptionsValueDefaultsDepositTooltip(t *testing.T) {
|
||||||
normalized, err := normalizePublishOptionsValue(`{"schema_version":2}`)
|
normalized, err := normalizePublishOptionsValue(`{"schema_version":2}`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -196,6 +196,7 @@ function addDepositSkinGroupRule() {
|
|||||||
group_key: '',
|
group_key: '',
|
||||||
label: '',
|
label: '',
|
||||||
amount_per_item: 0,
|
amount_per_item: 0,
|
||||||
|
discount_percent: 0,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -634,7 +635,10 @@ async function handleSave() {
|
|||||||
<div class="section-heading">
|
<div class="section-heading">
|
||||||
<div>
|
<div>
|
||||||
<h3>推荐押金皮肤规则</h3>
|
<h3>推荐押金皮肤规则</h3>
|
||||||
<p>按选中皮肤件数累加,与收号比例的特殊分组规则相互独立。</p>
|
<p>
|
||||||
|
按选中皮肤件数累加,与收号比例的特殊分组规则相互独立。开启「第2件起计价」后,
|
||||||
|
该分组第 1 件按原价计入,第 2 件起按设置的比例计入。
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<el-button :icon="Plus" size="small" @click="addDepositSkinGroupRule"
|
<el-button :icon="Plus" size="small" @click="addDepositSkinGroupRule"
|
||||||
>添加押金规则</el-button
|
>添加押金规则</el-button
|
||||||
@@ -657,6 +661,17 @@ async function handleSave() {
|
|||||||
<el-input-number v-model="row.amount_per_item" :min="0" :step="5" />
|
<el-input-number v-model="row.amount_per_item" :min="0" :step="5" />
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</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">
|
<el-table-column label="操作" width="76" align="center">
|
||||||
<template #default="{ $index }">
|
<template #default="{ $index }">
|
||||||
<el-tooltip content="删除押金规则" placement="top">
|
<el-tooltip content="删除押金规则" placement="top">
|
||||||
|
|||||||
@@ -108,4 +108,43 @@ describe('mergeListingPublishOptions', () => {
|
|||||||
{ key: 'load6', field: 'load', level: '6级', ratio_adjustment: -0.5 },
|
{ 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
|
group_key: string
|
||||||
label: string
|
label: string
|
||||||
amount_per_item: number
|
amount_per_item: number
|
||||||
|
/** 组内第 2 件起的计价百分比;0 表示不开启折扣 */
|
||||||
|
discount_percent: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PublishDepositRecommendConfig {
|
export interface PublishDepositRecommendConfig {
|
||||||
@@ -209,10 +211,10 @@ export const emptyListingPublishOptions: ListingPublishOptions = {
|
|||||||
deposit_recommend_config: {
|
deposit_recommend_config: {
|
||||||
base_amount: 200,
|
base_amount: 200,
|
||||||
skin_group_rules: [
|
skin_group_rules: [
|
||||||
{ group_key: 'melee', label: '刀皮', amount_per_item: 150 },
|
{ group_key: 'melee', label: '刀皮', amount_per_item: 150, discount_percent: 0 },
|
||||||
{ group_key: 'operatorGold', label: '干员金皮', amount_per_item: 0 },
|
{ group_key: 'operatorGold', label: '干员金皮', amount_per_item: 0, discount_percent: 0 },
|
||||||
{ group_key: 'operatorRed', label: '干员红皮', amount_per_item: 150 },
|
{ group_key: 'operatorRed', label: '干员红皮', amount_per_item: 150, discount_percent: 0 },
|
||||||
{ group_key: 'weapon', label: '武器皮肤', amount_per_item: 200 },
|
{ group_key: 'weapon', label: '武器皮肤', amount_per_item: 200, discount_percent: 0 },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
ratio_config: {
|
ratio_config: {
|
||||||
@@ -451,6 +453,7 @@ function normalizeDepositSkinGroupRules(values: unknown[]): PublishDepositSkinGr
|
|||||||
group_key: typeof row.group_key === 'string' ? row.group_key.trim() : '',
|
group_key: typeof row.group_key === 'string' ? row.group_key.trim() : '',
|
||||||
label: typeof row.label === 'string' ? row.label.trim() : '',
|
label: typeof row.label === 'string' ? row.label.trim() : '',
|
||||||
amount_per_item: readNumber(row.amount_per_item),
|
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)
|
.filter(item => item.group_key && item.label && item.amount_per_item >= 0)
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ export function buildPublishDraft(options: {
|
|||||||
screenshotFiles: Record<ScreenshotKey, string[]>
|
screenshotFiles: Record<ScreenshotKey, string[]>
|
||||||
selectedSkins: string[]
|
selectedSkins: string[]
|
||||||
qualityOwnerRatioDefaultApplied: boolean
|
qualityOwnerRatioDefaultApplied: boolean
|
||||||
|
depositLoweredByUser: boolean
|
||||||
}): PublishDraft {
|
}): PublishDraft {
|
||||||
return {
|
return {
|
||||||
form: {
|
form: {
|
||||||
@@ -49,6 +50,7 @@ export function buildPublishDraft(options: {
|
|||||||
screenshotFiles: cloneScreenshotFiles(options.screenshotFiles),
|
screenshotFiles: cloneScreenshotFiles(options.screenshotFiles),
|
||||||
selectedSkins: [...options.selectedSkins],
|
selectedSkins: [...options.selectedSkins],
|
||||||
qualityOwnerRatioDefaultApplied: options.qualityOwnerRatioDefaultApplied,
|
qualityOwnerRatioDefaultApplied: options.qualityOwnerRatioDefaultApplied,
|
||||||
|
depositLoweredByUser: options.depositLoweredByUser,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,6 +71,8 @@ export function readPublishDraft(draftKey: string) {
|
|||||||
typeof draft.qualityOwnerRatioDefaultApplied === 'boolean'
|
typeof draft.qualityOwnerRatioDefaultApplied === 'boolean'
|
||||||
? draft.qualityOwnerRatioDefaultApplied
|
? draft.qualityOwnerRatioDefaultApplied
|
||||||
: undefined,
|
: undefined,
|
||||||
|
depositLoweredByUser:
|
||||||
|
typeof draft.depositLoweredByUser === 'boolean' ? draft.depositLoweredByUser : undefined,
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
localStorage.removeItem(draftKey)
|
localStorage.removeItem(draftKey)
|
||||||
|
|||||||
@@ -39,8 +39,10 @@ import type { PublishForm } from '@/shared/types/publish'
|
|||||||
import { yuanToCent } from '@/shared/utils/money'
|
import { yuanToCent } from '@/shared/utils/money'
|
||||||
import {
|
import {
|
||||||
calculateInsuranceFeeAmount,
|
calculateInsuranceFeeAmount,
|
||||||
|
canPurchaseInsurance,
|
||||||
dailyLossOptions,
|
dailyLossOptions,
|
||||||
formatNumber,
|
formatNumber,
|
||||||
|
isDepositBelowRecommended,
|
||||||
roundRatio,
|
roundRatio,
|
||||||
} from '@/shared/utils/pricing'
|
} from '@/shared/utils/pricing'
|
||||||
import { useDistributionSiteStore } from '@/stores/distributionSite'
|
import { useDistributionSiteStore } from '@/stores/distributionSite'
|
||||||
@@ -59,6 +61,8 @@ interface UsePublishFormOptions {
|
|||||||
notifySuccess: (message: string) => void
|
notifySuccess: (message: string) => void
|
||||||
notifyWarning: (message: string) => void
|
notifyWarning: (message: string) => void
|
||||||
notifyError: (message: string) => void
|
notifyError: (message: string) => void
|
||||||
|
/** 押金低于推荐押金时的弹窗提示(桌面用 ElMessageBox,移动端用 vant showDialog) */
|
||||||
|
alertDepositBelowRecommended?: (message: string) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export function usePublishForm(options: UsePublishFormOptions) {
|
export function usePublishForm(options: UsePublishFormOptions) {
|
||||||
@@ -88,6 +92,8 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
|||||||
const screenshotPreviews = reactive<Record<string, string[]>>({})
|
const screenshotPreviews = reactive<Record<string, string[]>>({})
|
||||||
const selectedSkins = ref<string[]>([])
|
const selectedSkins = ref<string[]>([])
|
||||||
let draftSaveTimer: number | undefined
|
let draftSaveTimer: number | undefined
|
||||||
|
// 最近一次已提示过的「低于推荐押金」金额,避免同一次输入反复弹窗。
|
||||||
|
let lastAlertedDepositValue: number | null = null
|
||||||
const editListingID = computed(() => Number(route.params.id || 0))
|
const editListingID = computed(() => Number(route.params.id || 0))
|
||||||
const isEditMode = computed(() => Number.isFinite(editListingID.value) && editListingID.value > 0)
|
const isEditMode = computed(() => Number.isFinite(editListingID.value) && editListingID.value > 0)
|
||||||
const pageTitle = computed(() => (isEditMode.value ? '编辑账号' : '发布账号'))
|
const pageTitle = computed(() => (isEditMode.value ? '编辑账号' : '发布账号'))
|
||||||
@@ -98,6 +104,10 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
|||||||
const nextSeasonPassEnabled = computed(() => publishOptions.value.next_season_pass_enabled)
|
const nextSeasonPassEnabled = computed(() => publishOptions.value.next_season_pass_enabled)
|
||||||
const isQualityOwner = computed(() => qualityOwnerStatus.value?.active === true)
|
const isQualityOwner = computed(() => qualityOwnerStatus.value?.active === true)
|
||||||
const qualityOwnerRatioDefaultApplied = ref(true)
|
const qualityOwnerRatioDefaultApplied = ref(true)
|
||||||
|
// 用户是否主动把押金改到推荐值以下:为 true 时押金不再跟随推荐值上涨。
|
||||||
|
const depositLoweredByUser = ref(false)
|
||||||
|
// 押金是否由用户在本次会话里亲自输入:这种情况下由失焦弹窗统一提示。
|
||||||
|
const depositEditedByUser = ref(false)
|
||||||
const insuranceFeeBps = computed(() =>
|
const insuranceFeeBps = computed(() =>
|
||||||
form.is_premium && isQualityOwner.value
|
form.is_premium && isQualityOwner.value
|
||||||
? Number(qualityOwnerStatus.value?.premium_insurance_fee_bps || 400)
|
? Number(qualityOwnerStatus.value?.premium_insurance_fee_bps || 400)
|
||||||
@@ -126,6 +136,10 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
|||||||
const calculatedTakeHomePrice = computed(() =>
|
const calculatedTakeHomePrice = computed(() =>
|
||||||
Math.max(pricing.calculatedSellerPrice.value - calculatedInsuranceFee.value, 0)
|
Math.max(pricing.calculatedSellerPrice.value - calculatedInsuranceFee.value, 0)
|
||||||
)
|
)
|
||||||
|
// 押金是否低于推荐押金:低于推荐押金允许发布,但不能选购无忧租号保险。
|
||||||
|
const depositBelowRecommended = computed(() =>
|
||||||
|
isDepositBelowRecommended(form.depositAmountYuan, pricing.recommendedDepositAmount.value)
|
||||||
|
)
|
||||||
const qualityOwnerSaleRatioSelected = computed(
|
const qualityOwnerSaleRatioSelected = computed(
|
||||||
() =>
|
() =>
|
||||||
isQualityOwner.value &&
|
isQualityOwner.value &&
|
||||||
@@ -221,11 +235,23 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
|||||||
watch(
|
watch(
|
||||||
pricing.recommendedDepositAmount,
|
pricing.recommendedDepositAmount,
|
||||||
() => {
|
() => {
|
||||||
|
// 推荐值变化不是用户手动改押金,后续提示按「推荐值上涨」处理。
|
||||||
|
depositEditedByUser.value = false
|
||||||
syncRecommendedDeposit()
|
syncRecommendedDeposit()
|
||||||
},
|
},
|
||||||
{ immediate: true }
|
{ 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(
|
watch(
|
||||||
[() => form.season_insurance, pricing.quantityItems],
|
[() => form.season_insurance, pricing.quantityItems],
|
||||||
() => {
|
() => {
|
||||||
@@ -330,6 +356,7 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
|||||||
screenshotFiles,
|
screenshotFiles,
|
||||||
selectedSkins: selectedSkins.value,
|
selectedSkins: selectedSkins.value,
|
||||||
qualityOwnerRatioDefaultApplied: qualityOwnerRatioDefaultApplied.value,
|
qualityOwnerRatioDefaultApplied: qualityOwnerRatioDefaultApplied.value,
|
||||||
|
depositLoweredByUser: depositLoweredByUser.value,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -347,6 +374,9 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
|||||||
const draft = readPublishDraft(options.draftKey)
|
const draft = readPublishDraft(options.draftKey)
|
||||||
if (!draft) return
|
if (!draft) return
|
||||||
Object.assign(form, draft.form)
|
Object.assign(form, draft.form)
|
||||||
|
// 草稿里标记为用户主动改低的押金,不再被推荐值自动覆盖。
|
||||||
|
depositLoweredByUser.value = draft.depositLoweredByUser === true
|
||||||
|
depositEditedByUser.value = false
|
||||||
normalizeOnlineTime()
|
normalizeOnlineTime()
|
||||||
clearRecord(quantityValues)
|
clearRecord(quantityValues)
|
||||||
clearRecord(quantityModes)
|
clearRecord(quantityModes)
|
||||||
@@ -440,6 +470,8 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
|||||||
passwordAndDeviceConfirmed.value = false
|
passwordAndDeviceConfirmed.value = false
|
||||||
activeUploadKey.value = 'coin'
|
activeUploadKey.value = 'coin'
|
||||||
qualityOwnerRatioDefaultApplied.value = true
|
qualityOwnerRatioDefaultApplied.value = true
|
||||||
|
depositLoweredByUser.value = false
|
||||||
|
depositEditedByUser.value = false
|
||||||
|
|
||||||
// Also re-initialize quantityValues to 0
|
// Also re-initialize quantityValues to 0
|
||||||
for (const item of publishOptions.value.quantity_items) {
|
for (const item of publishOptions.value.quantity_items) {
|
||||||
@@ -655,8 +687,10 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
|||||||
function syncRecommendedDeposit() {
|
function syncRecommendedDeposit() {
|
||||||
const recommended = pricing.recommendedDepositAmount.value
|
const recommended = pricing.recommendedDepositAmount.value
|
||||||
if (recommended <= 0) return
|
if (recommended <= 0) return
|
||||||
|
// 用户已经把押金改到推荐值以下,保留其输入(点「使用推荐」可恢复自动跟随)。
|
||||||
|
if (depositLoweredByUser.value) return
|
||||||
const current = Number(form.depositAmountYuan)
|
const current = Number(form.depositAmountYuan)
|
||||||
if (form.depositAmountYuan === '' || !Number.isFinite(current) || current < recommended) {
|
if (!hasValidDeposit() || current < recommended) {
|
||||||
form.depositAmountYuan = recommended
|
form.depositAmountYuan = recommended
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -664,18 +698,74 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
|||||||
function useRecommendedDeposit() {
|
function useRecommendedDeposit() {
|
||||||
if (pricing.recommendedDepositAmount.value > 0) {
|
if (pricing.recommendedDepositAmount.value > 0) {
|
||||||
form.depositAmountYuan = pricing.recommendedDepositAmount.value
|
form.depositAmountYuan = pricing.recommendedDepositAmount.value
|
||||||
|
depositLoweredByUser.value = false
|
||||||
|
depositEditedByUser.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 失焦时实时校正:押金低于(或低于等于无效/为空)智能推荐时自动补到推荐值并提示。
|
// 押金输入:标记用户正在手动编辑,用于区分提示方式。
|
||||||
|
function handleDepositInput() {
|
||||||
|
depositEditedByUser.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// 失焦时:低于推荐押金允许继续发布,但弹出提示并禁购无忧租号保险。
|
||||||
function handleDepositBlur() {
|
function handleDepositBlur() {
|
||||||
const recommended = pricing.recommendedDepositAmount.value
|
const recommended = pricing.recommendedDepositAmount.value
|
||||||
if (recommended <= 0) return
|
if (recommended <= 0) return
|
||||||
const current = Number(form.depositAmountYuan)
|
if (!hasValidDeposit()) {
|
||||||
if (form.depositAmountYuan === '' || !Number.isFinite(current) || current < recommended) {
|
|
||||||
form.depositAmountYuan = recommended
|
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() {
|
function clearForbiddenQuantityItems() {
|
||||||
@@ -834,20 +924,17 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
|||||||
if (nextSeasonPassEnabled.value && !form.next_season_pass) {
|
if (nextSeasonPassEnabled.value && !form.next_season_pass) {
|
||||||
return '请选择下赛季是否购买通行证'
|
return '请选择下赛季是否购买通行证'
|
||||||
}
|
}
|
||||||
if (form.depositAmountYuan === '' || Number(form.depositAmountYuan) < 0) return '请填写押金'
|
if (!hasValidDeposit()) return '请填写押金'
|
||||||
if (!Number.isFinite(Number(form.depositAmountYuan))) return '押金格式不正确'
|
if (Number(form.depositAmountYuan) < 0) return '押金格式不正确'
|
||||||
if (
|
|
||||||
pricing.recommendedDepositAmount.value > 0 &&
|
|
||||||
Number(form.depositAmountYuan) < pricing.recommendedDepositAmount.value
|
|
||||||
) {
|
|
||||||
return `押金不能低于智能推荐 ¥${pricing.recommendedDepositAmount.value}`
|
|
||||||
}
|
|
||||||
if (
|
if (
|
||||||
pricing.calculatedConsumablePrice.value > 0 &&
|
pricing.calculatedConsumablePrice.value > 0 &&
|
||||||
Number(form.depositAmountYuan) <= pricing.calculatedConsumablePrice.value
|
Number(form.depositAmountYuan) <= pricing.calculatedConsumablePrice.value
|
||||||
) {
|
) {
|
||||||
return `押金必须大于额外消耗品总价值 ¥${pricing.calculatedConsumablePrice.value}`
|
return `押金必须大于额外消耗品总价值 ¥${pricing.calculatedConsumablePrice.value}`
|
||||||
}
|
}
|
||||||
|
if (form.compensation_plan === 'insurance' && depositBelowRecommended.value) {
|
||||||
|
return '押金低于推荐押金,无法购买无忧租号保险,请提高押金或改选普通赔付'
|
||||||
|
}
|
||||||
if (!pricing.calculatedFinalPrice.value) return '请完善币数、保险、体力和负重后再发布'
|
if (!pricing.calculatedFinalPrice.value) return '请完善币数、保险、体力和负重后再发布'
|
||||||
if (!Number.isFinite(pricing.calculatedFinalPrice.value))
|
if (!Number.isFinite(pricing.calculatedFinalPrice.value))
|
||||||
return '发布价格计算异常,请检查填写内容'
|
return '发布价格计算异常,请检查填写内容'
|
||||||
@@ -1098,7 +1185,10 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
|||||||
handleAcceleratedSaleRatioInput,
|
handleAcceleratedSaleRatioInput,
|
||||||
syncRecommendedDeposit,
|
syncRecommendedDeposit,
|
||||||
useRecommendedDeposit,
|
useRecommendedDeposit,
|
||||||
|
handleDepositInput,
|
||||||
handleDepositBlur,
|
handleDepositBlur,
|
||||||
|
depositBelowRecommended,
|
||||||
|
selectCompensationPlan,
|
||||||
clearForbiddenQuantityItems,
|
clearForbiddenQuantityItems,
|
||||||
setQuantityMode,
|
setQuantityMode,
|
||||||
clampAcceleratedSaleRatioInput,
|
clampAcceleratedSaleRatioInput,
|
||||||
|
|||||||
@@ -1120,6 +1120,27 @@
|
|||||||
background: #f3ebff;
|
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 {
|
.coverage-option.active {
|
||||||
border-color: #7c3aed;
|
border-color: #7c3aed;
|
||||||
background: #faf5ff;
|
background: #faf5ff;
|
||||||
|
|||||||
@@ -93,7 +93,10 @@ const {
|
|||||||
handleFireLevelInput,
|
handleFireLevelInput,
|
||||||
handleAcceleratedSaleRatioInput,
|
handleAcceleratedSaleRatioInput,
|
||||||
useRecommendedDeposit,
|
useRecommendedDeposit,
|
||||||
|
handleDepositInput,
|
||||||
handleDepositBlur,
|
handleDepositBlur,
|
||||||
|
depositBelowRecommended,
|
||||||
|
selectCompensationPlan,
|
||||||
setQuantityMode,
|
setQuantityMode,
|
||||||
clampAcceleratedSaleRatioInput,
|
clampAcceleratedSaleRatioInput,
|
||||||
useReferenceSaleRatio,
|
useReferenceSaleRatio,
|
||||||
@@ -117,6 +120,12 @@ const {
|
|||||||
notifySuccess: message => showToast({ message, icon: 'passed' }),
|
notifySuccess: message => showToast({ message, icon: 'passed' }),
|
||||||
notifyWarning: message => showToast({ message, icon: 'warning-o' }),
|
notifyWarning: message => showToast({ message, icon: 'warning-o' }),
|
||||||
notifyError: message => showToast({ message, icon: 'cross' }),
|
notifyError: message => showToast({ message, icon: 'cross' }),
|
||||||
|
alertDepositBelowRecommended: message =>
|
||||||
|
void showDialog({
|
||||||
|
title: '押金低于推荐押金',
|
||||||
|
message,
|
||||||
|
confirmButtonText: '我知道了',
|
||||||
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
const agreementPopupVisible = ref(false)
|
const agreementPopupVisible = ref(false)
|
||||||
@@ -729,6 +738,7 @@ const screenshotGuides: Record<string, string> = {
|
|||||||
type="number"
|
type="number"
|
||||||
inputmode="decimal"
|
inputmode="decimal"
|
||||||
:placeholder="priceConfig.deposit_placeholder"
|
:placeholder="priceConfig.deposit_placeholder"
|
||||||
|
@input="handleDepositInput"
|
||||||
@blur="handleDepositBlur"
|
@blur="handleDepositBlur"
|
||||||
/>
|
/>
|
||||||
<span>元</span>
|
<span>元</span>
|
||||||
@@ -955,7 +965,7 @@ const screenshotGuides: Record<string, string> = {
|
|||||||
type="button"
|
type="button"
|
||||||
class="coverage-option"
|
class="coverage-option"
|
||||||
:class="{ active: form.compensation_plan === 'normal' }"
|
:class="{ active: form.compensation_plan === 'normal' }"
|
||||||
@click="form.compensation_plan = 'normal'"
|
@click="selectCompensationPlan('normal')"
|
||||||
>
|
>
|
||||||
<span class="coverage-option-top">
|
<span class="coverage-option-top">
|
||||||
<strong>普通赔付</strong>
|
<strong>普通赔付</strong>
|
||||||
@@ -966,14 +976,21 @@ const screenshotGuides: Record<string, string> = {
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="coverage-option"
|
class="coverage-option"
|
||||||
:class="{ active: form.compensation_plan === 'insurance' }"
|
:class="{
|
||||||
@click="form.compensation_plan = 'insurance'"
|
active: form.compensation_plan === 'insurance',
|
||||||
|
'is-disabled': depositBelowRecommended,
|
||||||
|
}"
|
||||||
|
:aria-disabled="depositBelowRecommended"
|
||||||
|
@click="selectCompensationPlan('insurance')"
|
||||||
>
|
>
|
||||||
<span class="coverage-option-top">
|
<span class="coverage-option-top">
|
||||||
<strong>无忧租号保险</strong>
|
<strong>无忧租号保险</strong>
|
||||||
<em class="coverage-rate is-insurance"> {{ insuranceFeePercent.toFixed(1) }}% </em>
|
<em class="coverage-rate is-insurance"> {{ insuranceFeePercent.toFixed(1) }}% </em>
|
||||||
</span>
|
</span>
|
||||||
<span>额外保障账号市场价值,按纯币结算金额计费</span>
|
<span>额外保障账号市场价值,按纯币结算金额计费</span>
|
||||||
|
<em v-if="depositBelowRecommended" class="coverage-disabled-reason">
|
||||||
|
押金低于推荐押金,无法购买无忧租号保险
|
||||||
|
</em>
|
||||||
<em v-if="isQualityOwner && form.is_premium" class="coverage-special-rate">
|
<em v-if="isQualityOwner && form.is_premium" class="coverage-special-rate">
|
||||||
已享极品专区专享费率
|
已享极品专区专享费率
|
||||||
</em>
|
</em>
|
||||||
|
|||||||
@@ -1292,6 +1292,27 @@
|
|||||||
background: #f3ebff;
|
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 {
|
.coverage-option.active {
|
||||||
border-color: #7c3aed;
|
border-color: #7c3aed;
|
||||||
background: #faf5ff;
|
background: #faf5ff;
|
||||||
|
|||||||
@@ -105,7 +105,10 @@ const {
|
|||||||
handleFireLevelInput,
|
handleFireLevelInput,
|
||||||
handleAcceleratedSaleRatioInput,
|
handleAcceleratedSaleRatioInput,
|
||||||
useRecommendedDeposit,
|
useRecommendedDeposit,
|
||||||
|
handleDepositInput,
|
||||||
handleDepositBlur,
|
handleDepositBlur,
|
||||||
|
depositBelowRecommended,
|
||||||
|
selectCompensationPlan,
|
||||||
setQuantityMode,
|
setQuantityMode,
|
||||||
clampAcceleratedSaleRatioInput,
|
clampAcceleratedSaleRatioInput,
|
||||||
useReferenceSaleRatio,
|
useReferenceSaleRatio,
|
||||||
@@ -128,6 +131,11 @@ const {
|
|||||||
notifySuccess: message => ElMessage.success(message),
|
notifySuccess: message => ElMessage.success(message),
|
||||||
notifyWarning: message => ElMessage.warning(message),
|
notifyWarning: message => ElMessage.warning(message),
|
||||||
notifyError: message => ElMessage.error(message),
|
notifyError: message => ElMessage.error(message),
|
||||||
|
alertDepositBelowRecommended: message =>
|
||||||
|
void ElMessageBox.alert(message, '押金低于推荐押金', {
|
||||||
|
confirmButtonText: '我知道了',
|
||||||
|
type: 'warning',
|
||||||
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
const agreementDialogVisible = ref(false)
|
const agreementDialogVisible = ref(false)
|
||||||
@@ -571,6 +579,7 @@ function selectDailyLoss(value: string | number) {
|
|||||||
:min="0"
|
:min="0"
|
||||||
:controls="false"
|
:controls="false"
|
||||||
:placeholder="priceConfig.deposit_placeholder"
|
:placeholder="priceConfig.deposit_placeholder"
|
||||||
|
@input="handleDepositInput"
|
||||||
@blur="handleDepositBlur"
|
@blur="handleDepositBlur"
|
||||||
/>
|
/>
|
||||||
<button class="recommend-button" type="button" @click="useRecommendedDeposit">
|
<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}`">
|
<span v-for="item in depositBreakdownItems" :key="`${item.label}-${item.count}`">
|
||||||
{{ item.label }}<template v-if="item.count > 1"> x{{ item.count }}</template> ¥{{
|
{{ item.label }}<template v-if="item.count > 1"> x{{ item.count }}</template> ¥{{
|
||||||
formatMoney(item.amount)
|
formatMoney(item.amount)
|
||||||
}}
|
}}<template v-if="item.detail">({{ item.detail }})</template>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
@@ -779,7 +788,7 @@ function selectDailyLoss(value: string | number) {
|
|||||||
type="button"
|
type="button"
|
||||||
class="coverage-option"
|
class="coverage-option"
|
||||||
:class="{ active: form.compensation_plan === 'normal' }"
|
:class="{ active: form.compensation_plan === 'normal' }"
|
||||||
@click="form.compensation_plan = 'normal'"
|
@click="selectCompensationPlan('normal')"
|
||||||
>
|
>
|
||||||
<span class="coverage-option-top">
|
<span class="coverage-option-top">
|
||||||
<strong>普通赔付</strong>
|
<strong>普通赔付</strong>
|
||||||
@@ -790,8 +799,12 @@ function selectDailyLoss(value: string | number) {
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="coverage-option"
|
class="coverage-option"
|
||||||
:class="{ active: form.compensation_plan === 'insurance' }"
|
:class="{
|
||||||
@click="form.compensation_plan = 'insurance'"
|
active: form.compensation_plan === 'insurance',
|
||||||
|
'is-disabled': depositBelowRecommended,
|
||||||
|
}"
|
||||||
|
:aria-disabled="depositBelowRecommended"
|
||||||
|
@click="selectCompensationPlan('insurance')"
|
||||||
>
|
>
|
||||||
<span class="coverage-option-top">
|
<span class="coverage-option-top">
|
||||||
<strong>无忧租号保险</strong>
|
<strong>无忧租号保险</strong>
|
||||||
@@ -800,6 +813,9 @@ function selectDailyLoss(value: string | number) {
|
|||||||
</em>
|
</em>
|
||||||
</span>
|
</span>
|
||||||
<span>额外保障账号市场价值,费率按实际纯币结算金额扣除</span>
|
<span>额外保障账号市场价值,费率按实际纯币结算金额扣除</span>
|
||||||
|
<em v-if="depositBelowRecommended" class="coverage-disabled-reason">
|
||||||
|
押金低于推荐押金,无法购买无忧租号保险
|
||||||
|
</em>
|
||||||
<em v-if="isQualityOwner && form.is_premium" class="coverage-special-rate">
|
<em v-if="isQualityOwner && form.is_premium" class="coverage-special-rate">
|
||||||
已享极品专区专享费率
|
已享极品专区专享费率
|
||||||
</em>
|
</em>
|
||||||
|
|||||||
@@ -42,12 +42,16 @@ export interface PublishDraft {
|
|||||||
screenshotFiles: Record<ScreenshotKey, string[]>
|
screenshotFiles: Record<ScreenshotKey, string[]>
|
||||||
selectedSkins: string[]
|
selectedSkins: string[]
|
||||||
qualityOwnerRatioDefaultApplied?: boolean
|
qualityOwnerRatioDefaultApplied?: boolean
|
||||||
|
/** 用户是否主动把押金改到推荐值以下:为 true 时押金不再跟随推荐值上涨 */
|
||||||
|
depositLoweredByUser?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DepositBreakdownItem {
|
export interface DepositBreakdownItem {
|
||||||
label: string
|
label: string
|
||||||
amount: number
|
amount: number
|
||||||
count: number
|
count: number
|
||||||
|
/** 折扣说明,例如「第2件起按50%计」;无折扣时为空 */
|
||||||
|
detail?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PublishPlatformPricing {
|
export interface PublishPlatformPricing {
|
||||||
|
|||||||
@@ -1,9 +1,21 @@
|
|||||||
import { describe, expect, it } from 'vitest'
|
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 type { PublishForm } from '@/shared/types/publish'
|
||||||
|
|
||||||
import { calculateInsuranceFeeAmount, calculateSellerReferenceRatio } from '../pricing'
|
import {
|
||||||
|
buildDepositBreakdownItems,
|
||||||
|
calculateDepositGroupAmount,
|
||||||
|
calculateInsuranceFeeAmount,
|
||||||
|
calculateRecommendedDeposit,
|
||||||
|
calculateSellerReferenceRatio,
|
||||||
|
canPurchaseInsurance,
|
||||||
|
isDepositBelowRecommended,
|
||||||
|
} from '../pricing'
|
||||||
|
|
||||||
describe('calculateInsuranceFeeAmount', () => {
|
describe('calculateInsuranceFeeAmount', () => {
|
||||||
it('普通赔付不收取保险服务费', () => {
|
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 {
|
function basePublishForm(overrides: Partial<PublishForm> = {}): PublishForm {
|
||||||
return {
|
return {
|
||||||
server_region: 'QQ',
|
server_region: 'QQ',
|
||||||
|
|||||||
@@ -40,6 +40,28 @@ export function roundRatio(value: number) {
|
|||||||
return Math.round(value * 10) / 10
|
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位小数)
|
* 格式化数字为字符串(保留1位小数)
|
||||||
*/
|
*/
|
||||||
@@ -97,15 +119,41 @@ export function calculateRecommendedDeposit(options: {
|
|||||||
selectedSkins: string[]
|
selectedSkins: string[]
|
||||||
}) {
|
}) {
|
||||||
const baseAmount = Number(options.depositRecommendConfig.base_amount || 0)
|
const baseAmount = Number(options.depositRecommendConfig.base_amount || 0)
|
||||||
const skinAmount = options.depositRecommendConfig.skin_group_rules.reduce((sum, rule) => {
|
const skinAmount = options.depositRecommendConfig.skin_group_rules.reduce(
|
||||||
const group = options.skinGroups.find(item => item.key === rule.group_key)
|
(sum, rule) => sum + calculateDepositGroupAmount(rule, countSelectedSkins(rule, options)),
|
||||||
if (!group) return sum
|
0
|
||||||
const selectedCount = group.options.filter(skin => options.selectedSkins.includes(skin)).length
|
)
|
||||||
return sum + selectedCount * Number(rule.amount_per_item || 0)
|
|
||||||
}, 0)
|
|
||||||
return roundMoney(baseAmount + skinAmount)
|
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: {
|
export function buildDepositBreakdownItems(options: {
|
||||||
depositRecommendConfig: PublishDepositRecommendConfig
|
depositRecommendConfig: PublishDepositRecommendConfig
|
||||||
skinGroups: PublishOptionGroup[]
|
skinGroups: PublishOptionGroup[]
|
||||||
@@ -119,19 +167,34 @@ export function buildDepositBreakdownItems(options: {
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
for (const rule of options.depositRecommendConfig.skin_group_rules) {
|
for (const rule of options.depositRecommendConfig.skin_group_rules) {
|
||||||
const group = options.skinGroups.find(item => item.key === rule.group_key)
|
const count = countSelectedSkins(rule, options)
|
||||||
if (!group) continue
|
|
||||||
const count = group.options.filter(skin => options.selectedSkins.includes(skin)).length
|
|
||||||
if (count <= 0) continue
|
if (count <= 0) continue
|
||||||
items.push({
|
items.push({
|
||||||
label: rule.label,
|
label: rule.label,
|
||||||
amount: Number(rule.amount_per_item || 0) * count,
|
amount: calculateDepositGroupAmount(rule, count),
|
||||||
count,
|
count,
|
||||||
|
detail: describeDepositGroupDiscount(rule, count),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return items
|
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: {
|
export function calculateSellerReferenceRatio(options: {
|
||||||
coinMAmount: number
|
coinMAmount: number
|
||||||
form: PublishForm
|
form: PublishForm
|
||||||
|
|||||||
Reference in New Issue
Block a user