diff --git a/src/utils/promotionPricing.js b/src/utils/promotionPricing.js index 523ada8..979a8bd 100644 --- a/src/utils/promotionPricing.js +++ b/src/utils/promotionPricing.js @@ -7,6 +7,16 @@ export function safeTruncate(num, decimals = 2) { return (scaled / factor).toFixed(decimals) } +function toTruncatedCents(num) { + if (Number.isNaN(num) || !Number.isFinite(num)) + return 0 + return Math.trunc((num + Number.EPSILON) * 100) +} + +function centsToFixed(cents) { + return (cents / 100).toFixed(2) +} + function calculatePlatformOverpricingCost(price, config) { if (price <= config.p_pricing_standard) return 0 @@ -37,10 +47,12 @@ export function calculatePromotionPricing(priceInput, config) { const platformOverpricingCost = calculatePlatformOverpricingCost(price, config) const superiorOverpricingCost = calculateSuperiorOverpricingCost(price, config) const totalCost = baseCost + platformOverpricingCost + superiorOverpricingCost - const revenue = price - totalCost + const priceCents = toTruncatedCents(price) + const costCents = toTruncatedCents(totalCost) + const revenueCents = priceCents - costCents return { - costPrice: safeTruncate(totalCost), - promotionRevenue: safeTruncate(revenue), + costPrice: centsToFixed(costCents), + promotionRevenue: centsToFixed(revenueCents), } } diff --git a/src/views/Agent.vue b/src/views/Agent.vue index 7b629a4..4503f96 100644 --- a/src/views/Agent.vue +++ b/src/views/Agent.vue @@ -17,7 +17,8 @@ 待结账金额:¥ {{ (data?.frozen_balance || 0).toFixed(2) }}
待结账金额将在订单创建24小时后自动结账。 @@ -105,17 +106,95 @@
- +
-
- -