fix bug 3
This commit is contained in:
@@ -25,6 +25,7 @@ export interface Product {
|
|||||||
max_order_cash?: number | null
|
max_order_cash?: number | null
|
||||||
direct_price: number | undefined
|
direct_price: number | undefined
|
||||||
price_offset_percent?: number | null
|
price_offset_percent?: number | null
|
||||||
|
use_last_price_if_zero?: boolean
|
||||||
reading_method: any
|
reading_method: any
|
||||||
created_at: any
|
created_at: any
|
||||||
updated_at: any
|
updated_at: any
|
||||||
|
|||||||
+44
-10
@@ -2,6 +2,10 @@ import type { Product } from '@/models/products'
|
|||||||
import { getTradeBuyPrice, getTradeSellPrice, lastPrice } from '@/utils/price'
|
import { getTradeBuyPrice, getTradeSellPrice, lastPrice } from '@/utils/price'
|
||||||
import { isMetalCommodityGroup, isMeltedProductUsingAppPrice, isMeltedTradeGroup } from '@/utils/productCategories'
|
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) {
|
function applyPriceOffsetPercent(basePrice: number, offsetPercent?: number | null) {
|
||||||
const offset = Number(offsetPercent ?? 0)
|
const offset = Number(offsetPercent ?? 0)
|
||||||
if (!offset) {
|
if (!offset) {
|
||||||
@@ -14,12 +18,27 @@ function applyPriceOffsetPercent(basePrice: number, offsetPercent?: number | nul
|
|||||||
/** قیمت پایه بدون کارمزد — اگر صفر باشد نباید فقط cash_fee بهعنوان قیمت نمایش داده شود */
|
/** قیمت پایه بدون کارمزد — اگر صفر باشد نباید فقط cash_fee بهعنوان قیمت نمایش داده شود */
|
||||||
export function getProductBaseBuyPrice(product: Product): number {
|
export function getProductBaseBuyPrice(product: Product): number {
|
||||||
if (isMeltedProductUsingAppPrice(product)) {
|
if (isMeltedProductUsingAppPrice(product)) {
|
||||||
const tradeBuy = getTradeBuyPrice(lastPrice.value)
|
const apiPrice = Number(product.price ?? 0)
|
||||||
if (tradeBuy > 0) {
|
const useLast = productUsesLastPriceIfZero(product)
|
||||||
return applyPriceOffsetPercent(tradeBuy, product.price_offset_percent)
|
|
||||||
|
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)) {
|
if (isMeltedTradeGroup(product.group_type)) {
|
||||||
@@ -58,12 +77,27 @@ export function getProductBuyPrice(product: Product): number {
|
|||||||
|
|
||||||
function getProductBaseSellPrice(product: Product): number {
|
function getProductBaseSellPrice(product: Product): number {
|
||||||
if (isMeltedProductUsingAppPrice(product)) {
|
if (isMeltedProductUsingAppPrice(product)) {
|
||||||
const tradeSell = getTradeSellPrice(lastPrice.value)
|
const apiPrice = Number(product.price ?? 0)
|
||||||
if (tradeSell > 0) {
|
const useLast = productUsesLastPriceIfZero(product)
|
||||||
return applyPriceOffsetPercent(tradeSell, product.price_offset_percent)
|
|
||||||
|
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)) {
|
if (isMeltedTradeGroup(product.group_type)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user