fix bug
This commit is contained in:
+55
-21
@@ -11,50 +11,84 @@ function applyPriceOffsetPercent(basePrice: number, offsetPercent?: number | nul
|
||||
return Math.round(basePrice * (1 + offset / 100))
|
||||
}
|
||||
|
||||
/** قیمت خرید نمایشی محصول (همان مقداری که در لیست و اکشنشیت نشان داده میشود) */
|
||||
export function getProductBuyPrice(product: Product): number {
|
||||
/** قیمت پایه بدون کارمزد — اگر صفر باشد نباید فقط cash_fee بهعنوان قیمت نمایش داده شود */
|
||||
export function getProductBaseBuyPrice(product: Product): number {
|
||||
if (isMeltedProductUsingAppPrice(product)) {
|
||||
const tradeBuy = getTradeBuyPrice(lastPrice.value)
|
||||
const base = tradeBuy > 0
|
||||
? applyPriceOffsetPercent(tradeBuy, product.price_offset_percent)
|
||||
: (product.price ?? 0)
|
||||
return base + (product.cash_fee_buy ?? 0)
|
||||
if (tradeBuy > 0) {
|
||||
return applyPriceOffsetPercent(tradeBuy, product.price_offset_percent)
|
||||
}
|
||||
// provider صفر — آخرین قیمت ذخیرهشده از API (وقتی use_last_price_if_zero فعال است)
|
||||
return Number(product.price ?? 0)
|
||||
}
|
||||
|
||||
if (isMeltedTradeGroup(product.group_type)) {
|
||||
return (product.price ?? 0) + (product.cash_fee_buy ?? 0)
|
||||
return Number(product.price ?? 0)
|
||||
}
|
||||
|
||||
if (isMetalCommodityGroup(product.group_type)) {
|
||||
const base = (product.price_profit ?? 0) + (product.price ?? 0)
|
||||
return base + (product.cash_fee_buy ?? 0)
|
||||
return Number(product.price_profit ?? 0) + Number(product.price ?? 0)
|
||||
}
|
||||
|
||||
const basePrice = (product.price ?? 0) + (product.cash_fee_buy ?? 0)
|
||||
return product.direct_price === 0
|
||||
? basePrice * (product.amount ?? 0)
|
||||
: basePrice
|
||||
return Number(product.price ?? 0)
|
||||
}
|
||||
|
||||
/** قیمت فروش نمایشی محصول آبشدهای */
|
||||
export function getProductSellPrice(product: Product): number {
|
||||
/** قیمت خرید نمایشی محصول (همان مقداری که در لیست و اکشنشیت نشان داده میشود) */
|
||||
export function getProductBuyPrice(product: Product): number {
|
||||
const base = getProductBaseBuyPrice(product)
|
||||
if (base <= 0) {
|
||||
return 0
|
||||
}
|
||||
|
||||
const fee = Number(product.cash_fee_buy ?? 0)
|
||||
|
||||
if (
|
||||
isMeltedProductUsingAppPrice(product)
|
||||
|| isMeltedTradeGroup(product.group_type)
|
||||
|| isMetalCommodityGroup(product.group_type)
|
||||
) {
|
||||
return base + fee
|
||||
}
|
||||
|
||||
const withFee = base + fee
|
||||
return product.direct_price === 0
|
||||
? withFee * Number(product.amount ?? 0)
|
||||
: withFee
|
||||
}
|
||||
|
||||
function getProductBaseSellPrice(product: Product): number {
|
||||
if (isMeltedProductUsingAppPrice(product)) {
|
||||
const tradeSell = getTradeSellPrice(lastPrice.value)
|
||||
const base = tradeSell > 0
|
||||
? applyPriceOffsetPercent(tradeSell, product.price_offset_percent)
|
||||
: (product.price ?? 0)
|
||||
return base - (product.cash_fee_sell ?? 0)
|
||||
if (tradeSell > 0) {
|
||||
return applyPriceOffsetPercent(tradeSell, product.price_offset_percent)
|
||||
}
|
||||
// provider صفر — همان آخرین قیمت ذخیرهشده (فروش از همان مبنا)
|
||||
return Number(product.price ?? 0)
|
||||
}
|
||||
|
||||
if (isMeltedTradeGroup(product.group_type)) {
|
||||
return (product.price ?? 0) - (product.cash_fee_sell ?? 0)
|
||||
return Number(product.price ?? 0)
|
||||
}
|
||||
|
||||
return getTradeSellPrice(lastPrice.value)
|
||||
}
|
||||
|
||||
/** قیمت فروش نمایشی محصول آبشدهای */
|
||||
export function getProductSellPrice(product: Product): number {
|
||||
const base = getProductBaseSellPrice(product)
|
||||
if (base <= 0) {
|
||||
return 0
|
||||
}
|
||||
|
||||
if (isMeltedProductUsingAppPrice(product) || isMeltedTradeGroup(product.group_type)) {
|
||||
return base - Number(product.cash_fee_sell ?? 0)
|
||||
}
|
||||
|
||||
return base
|
||||
}
|
||||
|
||||
export function isProductPriceInactive(product: Product): boolean {
|
||||
return getProductBuyPrice(product) <= 0
|
||||
return getProductBaseBuyPrice(product) <= 0
|
||||
}
|
||||
|
||||
export { isMeltedTradeGroup, isMeltedProductUsingAppPrice } from '@/utils/productCategories'
|
||||
|
||||
Reference in New Issue
Block a user