feat(distribution): 分站可下调收号比例且不超过主站上限
让分销站能按自身能力下调收号比例扩大利润,同时把主站回收比例作为硬边界,避免分站把比例加得比主站更高。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
||||
hasAcceleratedSaleRatioInput as hasAcceleratedSaleRatioValue,
|
||||
isQuantityItemDisabledForInsurance,
|
||||
readFinalSaleRatio,
|
||||
applySiteReceiveRatioDelta,
|
||||
roundMoney,
|
||||
roundRatio,
|
||||
} from '@/shared/utils/pricing'
|
||||
@@ -31,6 +32,8 @@ export function usePricingCalculator(options: {
|
||||
quantityModes: Record<QuantityKey, ChargeMode>
|
||||
screenshotFiles: Record<ScreenshotKey, string[]>
|
||||
selectedSkins: Ref<string[]>
|
||||
isDistribution?: Ref<boolean>
|
||||
receiveRatioDelta?: Ref<number>
|
||||
}) {
|
||||
const serverOptions = computed(() => options.publishOptions.value.server_options)
|
||||
const faceOptions = computed(() => options.publishOptions.value.face_options)
|
||||
@@ -85,13 +88,20 @@ export function usePricingCalculator(options: {
|
||||
const maxAcceleratedSaleRatio = computed(() =>
|
||||
calculatedDefaultSaleRatio.value > 0 ? roundRatio(calculatedDefaultSaleRatio.value + 10) : 0
|
||||
)
|
||||
const calculatedRatio = computed(() =>
|
||||
readFinalSaleRatio(
|
||||
const siteReceiveRatioDelta = computed(() =>
|
||||
Math.max(0, Number(options.receiveRatioDelta?.value || 0))
|
||||
)
|
||||
const calculatedRatio = computed(() => {
|
||||
if (calculatedDefaultSaleRatio.value <= 0) return 0
|
||||
if (options.isDistribution?.value) {
|
||||
return applySiteReceiveRatioDelta(calculatedDefaultSaleRatio.value, siteReceiveRatioDelta.value)
|
||||
}
|
||||
return readFinalSaleRatio(
|
||||
calculatedDefaultSaleRatio.value,
|
||||
options.form.accelerated_sale_ratio,
|
||||
maxAcceleratedSaleRatio.value
|
||||
)
|
||||
)
|
||||
})
|
||||
const calculatedCoinBasePrice = computed(() => {
|
||||
if (calculatedRatio.value <= 0) return 0
|
||||
return roundMoney(coinWanAmount.value / calculatedRatio.value)
|
||||
@@ -131,6 +141,9 @@ export function usePricingCalculator(options: {
|
||||
)
|
||||
const saleRatioRangeText = computed(() => {
|
||||
if (calculatedDefaultSaleRatio.value <= 0) return '完成基础信息后自动计算参考比例'
|
||||
if (options.isDistribution?.value) {
|
||||
return `主站上限 1:${formatNumber(calculatedDefaultSaleRatio.value)},本站收号 1:${formatNumber(calculatedRatio.value)}`
|
||||
}
|
||||
return `可设置 1:${formatNumber(calculatedDefaultSaleRatio.value)} ~ 1:${formatNumber(maxAcceleratedSaleRatio.value)}`
|
||||
})
|
||||
const acceleratedSaleRatioPlaceholder = computed(() => {
|
||||
@@ -195,6 +208,7 @@ export function usePricingCalculator(options: {
|
||||
calculatedSellerReferenceRatio,
|
||||
calculatedDefaultSaleRatio,
|
||||
maxAcceleratedSaleRatio,
|
||||
siteReceiveRatioDelta,
|
||||
calculatedRatio,
|
||||
calculatedCoinBasePrice,
|
||||
calculatedConsumablePrice,
|
||||
|
||||
@@ -159,6 +159,12 @@ export function readFinalSaleRatio(
|
||||
return roundRatio(Math.min(Math.max(ratio, defaultRatio), maxAcceleratedSaleRatio))
|
||||
}
|
||||
|
||||
export function applySiteReceiveRatioDelta(referenceRatio: number, delta: number) {
|
||||
if (referenceRatio <= 0) return 0
|
||||
const safeDelta = Math.min(20, Math.max(0, Number(delta) || 0))
|
||||
return roundRatio(Math.max(referenceRatio - safeDelta, 0.01))
|
||||
}
|
||||
|
||||
export function hasAcceleratedSaleRatioInput(value: number | '' | null | undefined) {
|
||||
const ratio = Number(value)
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user