增加前端格式检查配置
This commit is contained in:
@@ -10,7 +10,17 @@ import type {
|
||||
import type { DepositBreakdownItem, PublishForm, PublishPlatformPricing } from '@/types/publish'
|
||||
|
||||
export const dailyLossOptions = [10, 20, 30, 40, 50]
|
||||
export const commonOnlineTimes = ['00:00', '08:00', '10:00', '12:00', '14:00', '18:00', '20:00', '22:00', '23:59']
|
||||
export const commonOnlineTimes = [
|
||||
'00:00',
|
||||
'08:00',
|
||||
'10:00',
|
||||
'12:00',
|
||||
'14:00',
|
||||
'18:00',
|
||||
'20:00',
|
||||
'22:00',
|
||||
'23:59',
|
||||
]
|
||||
|
||||
/**
|
||||
* 将金额四舍五入到角精度(0.1元)
|
||||
@@ -58,7 +68,10 @@ export function isGridCardQuantityItem(item: { key: string; label: string }) {
|
||||
return item.key === 'gridCard9' || item.label.includes('9格体验卡')
|
||||
}
|
||||
|
||||
export function isQuantityItemDisabledForInsurance(item: { key: string; label: string }, seasonInsurance: string) {
|
||||
export function isQuantityItemDisabledForInsurance(
|
||||
item: { key: string; label: string },
|
||||
seasonInsurance: string
|
||||
) {
|
||||
return seasonInsurance === '3*3' && isGridCardQuantityItem(item)
|
||||
}
|
||||
|
||||
@@ -85,9 +98,9 @@ export function calculateRecommendedDeposit(options: {
|
||||
}) {
|
||||
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)
|
||||
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
|
||||
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)
|
||||
@@ -106,9 +119,9 @@ export function buildDepositBreakdownItems(options: {
|
||||
},
|
||||
]
|
||||
for (const rule of options.depositRecommendConfig.skin_group_rules) {
|
||||
const group = options.skinGroups.find((item) => item.key === rule.group_key)
|
||||
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 = group.options.filter(skin => options.selectedSkins.includes(skin)).length
|
||||
if (count <= 0) continue
|
||||
items.push({
|
||||
label: rule.label,
|
||||
@@ -129,7 +142,8 @@ export function calculateSellerReferenceRatio(options: {
|
||||
dailyLossRatioAdjustment: number
|
||||
}) {
|
||||
const { coinMAmount, form, ratioConfig } = options
|
||||
if (coinMAmount <= 0 || !form.season_insurance || !form.stamina_level || !form.load_level) return 0
|
||||
if (coinMAmount <= 0 || !form.season_insurance || !form.stamina_level || !form.load_level)
|
||||
return 0
|
||||
const baseRatio = getInsuranceBaseRatio(ratioConfig, form.season_insurance)
|
||||
if (baseRatio <= 0) return 0
|
||||
return (
|
||||
@@ -140,7 +154,11 @@ export function calculateSellerReferenceRatio(options: {
|
||||
)
|
||||
}
|
||||
|
||||
export function readFinalSaleRatio(defaultRatio: number, acceleratedSaleRatio: number | '', maxAcceleratedSaleRatio: number) {
|
||||
export function readFinalSaleRatio(
|
||||
defaultRatio: number,
|
||||
acceleratedSaleRatio: number | '',
|
||||
maxAcceleratedSaleRatio: number
|
||||
) {
|
||||
if (defaultRatio <= 0) return 0
|
||||
if (!hasAcceleratedSaleRatioInput(acceleratedSaleRatio)) return defaultRatio
|
||||
const ratio = Number(acceleratedSaleRatio)
|
||||
@@ -167,14 +185,18 @@ export function calculatePlatformPricing(options: {
|
||||
return buildPlatformPricing(
|
||||
roundMoney(options.sellerCoinBasePrice + Number(fixedRule.markup_amount || 0)),
|
||||
'fixed_markup',
|
||||
options,
|
||||
options
|
||||
)
|
||||
}
|
||||
const ratioRule = findSaleRatioAdjustmentRule(options.salePriceConfig, options.coinMAmount)
|
||||
const ratioSubtract = ratioRule ? Number(ratioRule.ratio_subtract || 0) : 0
|
||||
const buyerRatio = options.sellerRatio - ratioSubtract
|
||||
if (buyerRatio > 0 && ratioRule) {
|
||||
return buildPlatformPricing(roundMoney(options.coinWanAmount / buyerRatio), 'ratio_subtract', options)
|
||||
return buildPlatformPricing(
|
||||
roundMoney(options.coinWanAmount / buyerRatio),
|
||||
'ratio_subtract',
|
||||
options
|
||||
)
|
||||
}
|
||||
return buildPlatformPricing(options.sellerCoinBasePrice, 'none', options)
|
||||
}
|
||||
@@ -196,7 +218,7 @@ function buildPlatformPricing(
|
||||
coinWanAmount: number
|
||||
sellerTotalPrice: number
|
||||
consumablePrice: number
|
||||
},
|
||||
}
|
||||
): PublishPlatformPricing {
|
||||
const buyerTotalPrice = roundMoney(buyerCoinBasePrice + options.consumablePrice)
|
||||
return {
|
||||
@@ -211,13 +233,17 @@ function buildPlatformPricing(
|
||||
function findSaleFixedMarkupRule(config: PublishSalePriceConfig, coinMAmount: number) {
|
||||
return [...config.fixed_markup_rules]
|
||||
.sort((a, b) => a.min_m - b.min_m)
|
||||
.find((item, index, rules) => isCoinInSaleRange(item, index, rules, coinMAmount, { includeLastMax: true }))
|
||||
.find((item, index, rules) =>
|
||||
isCoinInSaleRange(item, index, rules, coinMAmount, { includeLastMax: true })
|
||||
)
|
||||
}
|
||||
|
||||
function findSaleRatioAdjustmentRule(config: PublishSalePriceConfig, coinMAmount: number) {
|
||||
return [...config.ratio_adjustment_rules]
|
||||
.sort((a, b) => a.min_m - b.min_m)
|
||||
.find((item, index, rules) => isCoinInSaleRange(item, index, rules, coinMAmount, { excludeFirstMin: true }))
|
||||
.find((item, index, rules) =>
|
||||
isCoinInSaleRange(item, index, rules, coinMAmount, { excludeFirstMin: true })
|
||||
)
|
||||
}
|
||||
|
||||
function isCoinInSaleRange(
|
||||
@@ -225,13 +251,15 @@ function isCoinInSaleRange(
|
||||
index: number,
|
||||
rules: Array<{ min_m: number; max_m: number }>,
|
||||
coinMAmount: number,
|
||||
options: { includeLastMax?: boolean; excludeFirstMin?: boolean } = {},
|
||||
options: { includeLastMax?: boolean; excludeFirstMin?: boolean } = {}
|
||||
) {
|
||||
const maxM = Number(item.max_m || 0)
|
||||
const minM = Number(item.min_m || 0)
|
||||
const minMatched = options.excludeFirstMin && index === 0 ? coinMAmount > minM : coinMAmount >= minM
|
||||
const minMatched =
|
||||
options.excludeFirstMin && index === 0 ? coinMAmount > minM : coinMAmount >= minM
|
||||
const isLastRule = index === rules.length - 1
|
||||
const maxMatched = maxM <= 0 || coinMAmount < maxM || (options.includeLastMax && isLastRule && coinMAmount <= maxM)
|
||||
const maxMatched =
|
||||
maxM <= 0 || coinMAmount < maxM || (options.includeLastMax && isLastRule && coinMAmount <= maxM)
|
||||
return minMatched && maxMatched
|
||||
}
|
||||
|
||||
@@ -240,8 +268,11 @@ function calculateEffectiveRatio(coinWanAmount: number, price: number) {
|
||||
return roundRatio(coinWanAmount / price)
|
||||
}
|
||||
|
||||
function getInsuranceBaseRatio(config: Pick<ListingPublishOptions['ratio_config'], 'insurance_base_ratios'>, insurance: string) {
|
||||
return config.insurance_base_ratios.find((item) => item.insurance === insurance)?.ratio || 0
|
||||
function getInsuranceBaseRatio(
|
||||
config: Pick<ListingPublishOptions['ratio_config'], 'insurance_base_ratios'>,
|
||||
insurance: string
|
||||
) {
|
||||
return config.insurance_base_ratios.find(item => item.insurance === insurance)?.ratio || 0
|
||||
}
|
||||
|
||||
function calculateConfigPenalty(
|
||||
@@ -251,7 +282,7 @@ function calculateConfigPenalty(
|
||||
skinGroups: PublishOptionGroup[]
|
||||
selectedSkins: string[]
|
||||
levelOptions: string[]
|
||||
},
|
||||
}
|
||||
) {
|
||||
return config.config_items.reduce((sum, item) => {
|
||||
return isRatioConfigItemMatched(item, options) ? sum : sum + Number(item.missing_penalty || 0)
|
||||
@@ -265,10 +296,11 @@ function isRatioConfigItemMatched(
|
||||
skinGroups: PublishOptionGroup[]
|
||||
selectedSkins: string[]
|
||||
levelOptions: string[]
|
||||
},
|
||||
}
|
||||
) {
|
||||
if (item.kind === 'skin_group') return hasSelectedSkinGroup(item.group_key || '', options)
|
||||
if (item.kind === 'max_stamina') return isMaxLevel(options.form.stamina_level, options.levelOptions)
|
||||
if (item.kind === 'max_stamina')
|
||||
return isMaxLevel(options.form.stamina_level, options.levelOptions)
|
||||
if (item.kind === 'max_load') return isMaxLevel(options.form.load_level, options.levelOptions)
|
||||
return false
|
||||
}
|
||||
@@ -278,11 +310,11 @@ function hasSelectedSkinGroup(
|
||||
options: {
|
||||
skinGroups: PublishOptionGroup[]
|
||||
selectedSkins: string[]
|
||||
},
|
||||
}
|
||||
) {
|
||||
const group = options.skinGroups.find((item) => item.key === groupKey)
|
||||
const group = options.skinGroups.find(item => item.key === groupKey)
|
||||
if (!group) return false
|
||||
return group.options.some((skin) => options.selectedSkins.includes(skin))
|
||||
return group.options.some(skin => options.selectedSkins.includes(skin))
|
||||
}
|
||||
|
||||
function isMaxLevel(value: string, levelOptions: string[]) {
|
||||
@@ -297,6 +329,13 @@ function readLevelNumber(value: string) {
|
||||
return match ? Number(match[0]) : 0
|
||||
}
|
||||
|
||||
function getCoinCorrection(config: Pick<ListingPublishOptions['ratio_config'], 'coin_corrections'>, coinM: number) {
|
||||
return [...config.coin_corrections].sort((a, b) => b.threshold_m - a.threshold_m).find((item) => coinM > item.threshold_m)?.correction || 0
|
||||
function getCoinCorrection(
|
||||
config: Pick<ListingPublishOptions['ratio_config'], 'coin_corrections'>,
|
||||
coinM: number
|
||||
) {
|
||||
return (
|
||||
[...config.coin_corrections]
|
||||
.sort((a, b) => b.threshold_m - a.threshold_m)
|
||||
.find(item => coinM > item.threshold_m)?.correction || 0
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user