Stop multiplying colleague prices by weight and fee from unit price.
Colleague quotes are per piece, and the settings service charge is a percent of that price times count. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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<Prop>(), {})
|
||||
const isBuy = ref<boolean>(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<TableEngineInput>({
|
||||
})
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user