fix bug 3

This commit is contained in:
2026-06-11 21:49:46 +03:30
parent 298f9a6055
commit 13d2ce8805
2 changed files with 45 additions and 10 deletions
+1
View File
@@ -25,6 +25,7 @@ export interface Product {
max_order_cash?: number | null
direct_price: number | undefined
price_offset_percent?: number | null
use_last_price_if_zero?: boolean
reading_method: any
created_at: any
updated_at: any
+44 -10
View File
@@ -2,6 +2,10 @@ import type { Product } from '@/models/products'
import { getTradeBuyPrice, getTradeSellPrice, lastPrice } from '@/utils/price'
import { isMetalCommodityGroup, isMeltedProductUsingAppPrice, isMeltedTradeGroup } from '@/utils/productCategories'
function productUsesLastPriceIfZero(product: Product): boolean {
return Boolean(product.use_last_price_if_zero)
}
function applyPriceOffsetPercent(basePrice: number, offsetPercent?: number | null) {
const offset = Number(offsetPercent ?? 0)
if (!offset) {
@@ -14,12 +18,27 @@ function applyPriceOffsetPercent(basePrice: number, offsetPercent?: number | nul
/** قیمت پایه بدون کارمزد — اگر صفر باشد نباید فقط cash_fee به‌عنوان قیمت نمایش داده شود */
export function getProductBaseBuyPrice(product: Product): number {
if (isMeltedProductUsingAppPrice(product)) {
const tradeBuy = getTradeBuyPrice(lastPrice.value)
if (tradeBuy > 0) {
return applyPriceOffsetPercent(tradeBuy, product.price_offset_percent)
const apiPrice = Number(product.price ?? 0)
const useLast = productUsesLastPriceIfZero(product)
if (!useLast) {
const liveBuy = getTradeBuyPrice(lastPrice.value)
if (liveBuy > 0) {
return applyPriceOffsetPercent(liveBuy, product.price_offset_percent)
}
return 0
}
// provider صفر — آخرین قیمت ذخیره‌شده از API (وقتی use_last_price_if_zero فعال است)
return Number(product.price ?? 0)
if (apiPrice > 0) {
return apiPrice
}
const liveBuy = getTradeBuyPrice(lastPrice.value)
if (liveBuy > 0) {
return applyPriceOffsetPercent(liveBuy, product.price_offset_percent)
}
return 0
}
if (isMeltedTradeGroup(product.group_type)) {
@@ -58,12 +77,27 @@ export function getProductBuyPrice(product: Product): number {
function getProductBaseSellPrice(product: Product): number {
if (isMeltedProductUsingAppPrice(product)) {
const tradeSell = getTradeSellPrice(lastPrice.value)
if (tradeSell > 0) {
return applyPriceOffsetPercent(tradeSell, product.price_offset_percent)
const apiPrice = Number(product.price ?? 0)
const useLast = productUsesLastPriceIfZero(product)
if (!useLast) {
const liveSell = getTradeSellPrice(lastPrice.value)
if (liveSell > 0) {
return applyPriceOffsetPercent(liveSell, product.price_offset_percent)
}
return 0
}
// provider صفر — همان آخرین قیمت ذخیره‌شده (فروش از همان مبنا)
return Number(product.price ?? 0)
if (apiPrice > 0) {
return apiPrice
}
const liveSell = getTradeSellPrice(lastPrice.value)
if (liveSell > 0) {
return applyPriceOffsetPercent(liveSell, product.price_offset_percent)
}
return 0
}
if (isMeltedTradeGroup(product.group_type)) {