diff --git a/src/utils/productDealMethod.ts b/src/utils/productDealMethod.ts index 4e10cbc..9e992a3 100644 --- a/src/utils/productDealMethod.ts +++ b/src/utils/productDealMethod.ts @@ -439,7 +439,7 @@ export function formatMainMetalReceiveText(weight?: number | null) { export function calcSellReceivedMetalWeight( count?: number | null, - product?: ProductUnitSource & { percent_fee_sell?: number | null } | null, + product?: ProductUnitSource | null, ) { const quantity = Number(count ?? 0) const unitAmount = Number(product?.amount ?? 0) @@ -447,9 +447,8 @@ export function calcSellReceivedMetalWeight( return 0 } - const grossAmount = quantity * unitAmount - const feeRate = Number(product?.percent_fee_sell ?? 0) - return grossAmount - feeRate * grossAmount + // کارمزد محصول تعدادی از ریال است — وزن دریافتی فلز کم نمی‌شود + return quantity * unitAmount } export function isCashLikeDealMethod(method?: string | null) { diff --git a/src/views/base/products/components/DealProduct.vue b/src/views/base/products/components/DealProduct.vue index c8f7fdb..9c42af0 100644 --- a/src/views/base/products/components/DealProduct.vue +++ b/src/views/base/products/components/DealProduct.vue @@ -332,6 +332,7 @@ import { useWalletAssets } from '@/composables/useWalletAssets' import { formatProductWalletBalanceText, formatInventoryCardValue, getCashWalletBalance, getProductInventoryQuantity } from '@/utils/productAssets' import { resolvePhysicalDeliveryState } from '@/utils/physicalDelivery' import { isStoreClosed, resolveStoreClosedNotice } from '@/utils/storeHours' +import { serviceFeePercentage } from '@/utils/serviceFee' const catalogProducts = getProductsCatalogRef() @@ -434,8 +435,24 @@ const isBuy = ref(true) const buyTotalPrice = computed(() => resolveProductTradeBuyUnitPrice(props?.ProductItem)) const sellTotalPrice = computed(() => resolveProductTradeSellUnitPrice(props?.ProductItem)) -const buyFee = computed(() => ((props?.ProductItem?.amount * (props?.ProductItem?.percent_fee_buy ?? 0) * (props?.ProductItem?.price ?? 0)).toFixed(0))) -const sellFee = computed(() => ((props?.ProductItem?.amount * (props?.ProductItem?.percent_fee_sell ?? 0) * (props?.ProductItem?.sellPrice ?? 0)).toFixed(0))) + +/** کارمزد از fee_service_charge_percentage — نه percent_fee_* / اختلاف قیمت */ +function countDealFeeGrams() { + const count = Number(form.value?.goldValue ?? 0) + const unitWeight = Number(props?.ProductItem?.amount ?? 0) + return count * unitWeight * Number(serviceFeePercentage.value) +} + +function countDealFeeRial(piecePrice?: number | null) { + const unitWeight = Number(props?.ProductItem?.amount ?? 0) + const perGram = unitWeight > 0 ? Number(piecePrice ?? 0) / unitWeight : 0 + return countDealFeeGrams() * perGram +} + +const buyFee = computed(() => countDealFeeRial(props?.ProductItem?.price).toFixed(0)) +const sellFee = computed(() => countDealFeeRial(props?.ProductItem?.sellPrice).toFixed(0)) +const buyFeeGeram = computed(() => countDealFeeGrams().toFixed(4)) +const sellFeeGeram = computed(() => countDealFeeGrams().toFixed(4)) const buyPagination = ref({ filters: [{ @@ -458,7 +475,10 @@ const sellPagination = ref({ }) const finalPrice = computed(() => (form.value?.goldValue * (isBuy.value ? props.ProductItem?.price ?? 0 : props.ProductItem?.sellPrice ?? 0))) -const payablePrice = computed(() => finalPrice.value) +const payablePrice = computed(() => { + const fee = countDealFeeRial(isBuy.value ? props.ProductItem?.price : props.ProductItem?.sellPrice) + return isBuy.value ? finalPrice.value + fee : Math.max(0, finalPrice.value - fee) +}) const minOrderCash = computed(() => productMinOrderCash(props.ProductItem, isBuy.value)) const maxOrderCash = computed(() => productMaxOrderCash(props.ProductItem))