widthdraw and deposit
This commit is contained in:
@@ -1,13 +1,28 @@
|
||||
import type { Product } from '@/models/products'
|
||||
import { getTradeBuyPrice, getTradeSellPrice, lastPrice } from '@/utils/price'
|
||||
import { isMetalCommodityGroup, isMeltedProductUsingAppPrice, isMeltedTradeGroup } from '@/utils/productCategories'
|
||||
|
||||
function applyPriceOffsetPercent(basePrice: number, offsetPercent?: number | null) {
|
||||
const offset = Number(offsetPercent ?? 0)
|
||||
if (!offset) {
|
||||
return basePrice
|
||||
}
|
||||
|
||||
return Math.round(basePrice * (1 + offset / 100))
|
||||
}
|
||||
|
||||
/** قیمت خرید نمایشی محصول (همان مقداری که در لیست و اکشنشیت نشان داده میشود) */
|
||||
export function getProductBuyPrice(product: Product): number {
|
||||
if (product.group_type === 'آبشده') {
|
||||
return getTradeBuyPrice(lastPrice.value) + (product.cash_fee_buy ?? 0)
|
||||
if (isMeltedProductUsingAppPrice(product)) {
|
||||
const base = applyPriceOffsetPercent(getTradeBuyPrice(lastPrice.value), product.price_offset_percent)
|
||||
return base + (product.cash_fee_buy ?? 0)
|
||||
}
|
||||
|
||||
if (['مس', 'نقره'].includes(product.group_type)) {
|
||||
if (isMeltedTradeGroup(product.group_type)) {
|
||||
return (product.price ?? 0) + (product.cash_fee_buy ?? 0)
|
||||
}
|
||||
|
||||
if (isMetalCommodityGroup(product.group_type)) {
|
||||
const base = (product.price_profit ?? 0) + (product.price ?? 0)
|
||||
return base + (product.cash_fee_buy ?? 0)
|
||||
}
|
||||
@@ -18,14 +33,23 @@ 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)
|
||||
if (isMeltedProductUsingAppPrice(product)) {
|
||||
const base = applyPriceOffsetPercent(getTradeSellPrice(lastPrice.value), product.price_offset_percent)
|
||||
return base - (product.cash_fee_sell ?? 0)
|
||||
}
|
||||
|
||||
if (isMeltedTradeGroup(product.group_type)) {
|
||||
const base = (product.price_profit ?? product.price ?? 0)
|
||||
return base - (product.cash_fee_sell ?? 0)
|
||||
}
|
||||
|
||||
return getTradeSellPrice(lastPrice.value)
|
||||
}
|
||||
|
||||
export function isProductPriceInactive(product: Product): boolean {
|
||||
return getProductBuyPrice(product) <= 0
|
||||
}
|
||||
|
||||
export { isMeltedTradeGroup, isMeltedProductUsingAppPrice } from '@/utils/productCategories'
|
||||
|
||||
Reference in New Issue
Block a user