import type { Shop } from "@/lib/types" type ShopCommission = Pick export interface IncomeCalculation { income: number commissionLabel: string } function roundCurrency(amount: number) { return Number(amount.toFixed(2)) } export function calculateOrderIncome(totalPrice: number, shop?: ShopCommission): IncomeCalculation { if (!shop) { return { income: roundCurrency(totalPrice), commissionLabel: "独立接单无抽成", } } const commission = Number(shop.commissionValue) if (shop.commissionType === "percentage") { return { income: roundCurrency(totalPrice * (1 - commission / 100)), commissionLabel: `扣除${shop.commissionValue}%抽成`, } } return { income: roundCurrency(Math.max(0, totalPrice - commission)), commissionLabel: `扣除¥${shop.commissionValue}固定抽成`, } }