diff --git a/src/models/products.ts b/src/models/products.ts index 4963c1e..20db82f 100644 --- a/src/models/products.ts +++ b/src/models/products.ts @@ -41,6 +41,7 @@ export interface Product { similar?:Product[] inventory:number app_price?: boolean | number | null + colleague_price?: boolean | number | null tv_price?: number | null tv_sell_price?: number | null direct_price?: number | null diff --git a/src/utils/productCategories.ts b/src/utils/productCategories.ts index 7493860..2d931a1 100644 --- a/src/utils/productCategories.ts +++ b/src/utils/productCategories.ts @@ -51,12 +51,23 @@ export function resolveMeltedPriceSource(product?: { return 'app' } +/** قیمت از همکار: قیمت هر عدد، نه هر گرم */ +export function isColleaguePriceProduct(product?: { + colleague_price?: boolean | number | null +} | null) { + if (!product) { + return false + } + return product.colleague_price === true || Number(product.colleague_price) === 1 +} + /** محصول با پرچم صریح «قیمت اپ» */ export function isAppPriceProduct(product?: { app_price?: boolean | number | null reading_method?: string | null + colleague_price?: boolean | number | null } | null) { - if (!product || product.reading_method) { + if (!product || product.reading_method || isColleaguePriceProduct(product)) { return false } return product.app_price === true || Number(product.app_price) === 1 diff --git a/src/utils/productPrice.ts b/src/utils/productPrice.ts index be8b348..210ab2b 100644 --- a/src/utils/productPrice.ts +++ b/src/utils/productPrice.ts @@ -3,6 +3,7 @@ import { getTradeBuyPrice, getTradeSellPrice, lastPrice } from '@/utils/price' import { resolveProductCashFeeBuyRial, resolveProductCashFeeSellRial } from '@/utils/productCashFee' import { isAppPriceProduct, + isColleaguePriceProduct, isMeltedProductUsingAppPrice, isMeltedTradeGroup, isMetalCommodityGroup, @@ -31,7 +32,7 @@ function hasProductUnitWeight(product?: Product | null) { } function productPriceAmountFactor(product?: Product | null) { - if (!product || product.reading_method) { + if (!product || product.reading_method || isColleaguePriceProduct(product)) { return 1 } if (isAppPriceProduct(product)) { @@ -137,6 +138,10 @@ export function getProductBuyPrice(product?: Product | null): number { const fee = resolveProductCashFeeBuyRial(product, base) const withFee = base + fee + if (isColleaguePriceProduct(product)) { + return withFee + } + if (isAppPriceProduct(product)) { return withFee * productPriceAmountFactor(product) } @@ -194,6 +199,10 @@ export function getProductBaseSellPrice(product?: Product | null): number { return Number(product.sellPrice ?? product.price ?? 0) } + if (isColleaguePriceProduct(product)) { + return Number(product.sellPrice ?? product.price ?? 0) + } + const serverSell = Number(product.sellPrice ?? 0) if (serverSell > 0) { return serverSell @@ -213,6 +222,10 @@ export function getProductSellPrice(product?: Product | null): number { return 0 } + if (isColleaguePriceProduct(product)) { + return base - resolveProductCashFeeSellRial(product, base) + } + if (isAppPriceProduct(product)) { const withFee = base - resolveProductCashFeeSellRial(product, base) return withFee * productPriceAmountFactor(product) diff --git a/src/views/base/products/components/DealProduct.vue b/src/views/base/products/components/DealProduct.vue index 03f53b8..a66c7ff 100644 --- a/src/views/base/products/components/DealProduct.vue +++ b/src/views/base/products/components/DealProduct.vue @@ -276,6 +276,7 @@ import { useWalletAssets } from '@/composables/useWalletAssets' import { useCartStore } from '@/store/cartStore' import { getStoreClosedMessage, isStoreClosed } from '@/utils/storeHours' import { isProductTradingHoursOpen, productHoursClosedMessage } from '@/utils/productTradeOpen' +import { loadServiceFeeFromSettings, serviceFeePercentage } from '@/utils/serviceFee' const typeDeal: SelectItem[] = [ { @@ -313,8 +314,14 @@ interface Prop { const props = withDefaults(defineProps(), {}) const isBuy = ref(true) -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 نسبت به قیمت واحد × تعداد — نه وزن گرم */ +function countDealFeeRial(unitPrice?: number | null, count = Number(form.value?.goldValue ?? 0)) { + return count * Number(unitPrice ?? 0) * Number(serviceFeePercentage.value) +} + +const buyFee = computed(() => countDealFeeRial(props?.ProductItem?.price).toFixed(0)) +const sellFee = computed(() => countDealFeeRial(props?.ProductItem?.sellPrice).toFixed(0)) const sellFeeGeram = computed(() => { if (form.value.goldVazn) return (form.value.goldVazn * props.ProductItem?.percent_fee_sell).toFixed(3) @@ -344,8 +351,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 + finalPrice.value * 0.007) -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 disableTransaction = computed(() => { if (isStoreClosed() || !isProductTradingHoursOpen(props.ProductItem)) { @@ -466,6 +475,7 @@ async function initSellTable() { // } onMounted(async () => { + await loadServiceFeeFromSettings() switch (router.currentRoute.value.query.state) { case 'sell': isBuy.value = false @@ -570,7 +580,10 @@ function calculateCash(val: number) { console.log(val,props?.ProductItem?.price,props?.ProductItem?.cash_fee_buy,lastPrice.value?.buy) if (isBuy.value) { if (val){ - form.value.goldCash = parseFloat(val * (( props?.ProductItem?.price) + (props?.ProductItem?.cash_fee_buy))).toFixed(0) + const base = Number(props?.ProductItem?.price ?? 0) + const goods = val * (base + Number(props?.ProductItem?.cash_fee_buy ?? 0)) + const fee = countDealFeeRial(base, val) + form.value.goldCash = parseFloat(String(goods + fee)).toFixed(0) } else { form.value.goldCash = 0 @@ -578,8 +591,12 @@ console.log(val,props?.ProductItem?.price,props?.ProductItem?.cash_fee_buy,lastP } } else { - if (val) - form.value.goldCash = parseFloat((val * props?.ProductItem?.price) + (props?.ProductItem?.cash_fee_sell)).toFixed(0) + if (val) { + const base = Number(props?.ProductItem?.price ?? 0) + const goods = val * base + Number(props?.ProductItem?.cash_fee_sell ?? 0) + const fee = countDealFeeRial(base, val) + form.value.goldCash = parseFloat(String(Math.max(0, goods - fee))).toFixed(0) + } else{ form.value.goldCash = 0 form.value.goldVazn = 0