fix some bug
This commit is contained in:
+5
-13
@@ -9,26 +9,18 @@ export const price = ref<Price>()
|
||||
export const lastPrice = ref<Price>()
|
||||
export const olderPrice = ref<number | undefined>(0)
|
||||
|
||||
/** buy/sell معامله: اول up (مثل endpoint قدیمی /price/up) سپس fallback */
|
||||
/** buy/sell نمایش و معامله — همان buy/sell/price_last از /api/price/last */
|
||||
export function getTradeBuyPrice(p?: Price | null) {
|
||||
return p?.up?.buy ?? p?.buy ?? 0
|
||||
return p?.buy ?? p?.price_last ?? p?.up?.buy ?? 0
|
||||
}
|
||||
|
||||
export function getTradeSellPrice(p?: Price | null) {
|
||||
return p?.up?.sell ?? p?.sell ?? 0
|
||||
return p?.sell ?? p?.up?.sell ?? 0
|
||||
}
|
||||
|
||||
/** یکسانسازی پاسخ last با رفتار قدیمی price/up */
|
||||
/** up جدا نگه داشته میشود؛ buy/sell/price_last از lastPrice سرور دستنخورده میماند */
|
||||
export function normalizePriceResponse(data: Price): Price {
|
||||
if (!data?.up) {
|
||||
return data
|
||||
}
|
||||
|
||||
return {
|
||||
...data,
|
||||
buy: data.up.buy,
|
||||
sell: data.up.sell,
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
export async function setIntervalGetAllPrice() {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { Product } from '@/models/products'
|
||||
import { getTradeBuyPrice, lastPrice } from '@/utils/price'
|
||||
import { getTradeBuyPrice, getTradeSellPrice, lastPrice } from '@/utils/price'
|
||||
|
||||
/** قیمت خرید نمایشی محصول (همان مقداری که در لیست و اکشنشیت نشان داده میشود) */
|
||||
export function getProductBuyPrice(product: Product): number {
|
||||
if (product.group_type === 'آبشده') {
|
||||
return getTradeBuyPrice(lastPrice.value)
|
||||
return getTradeBuyPrice(lastPrice.value) + (product.cash_fee_buy ?? 0)
|
||||
}
|
||||
|
||||
if (['مس', 'نقره'].includes(product.group_type)) {
|
||||
@@ -18,6 +18,14 @@ export function getProductBuyPrice(product: Product): number {
|
||||
: basePrice
|
||||
}
|
||||
|
||||
/** قیمت فروش نمایشی آبشده — فقط cash_fee_sell محصول اختلاف ایجاد میکند */
|
||||
export function getProductSellPrice(product: Product): number {
|
||||
if (product.group_type === 'آبشده') {
|
||||
return getTradeSellPrice(lastPrice.value) - (product.cash_fee_sell ?? 0)
|
||||
}
|
||||
return getTradeSellPrice(lastPrice.value)
|
||||
}
|
||||
|
||||
export function isProductPriceInactive(product: Product): boolean {
|
||||
return getProductBuyPrice(product) <= 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user