price calulator changed 5
This commit is contained in:
@@ -54,7 +54,21 @@ type TransactionPriceSource = {
|
||||
price?: number | null
|
||||
total_price?: number | null
|
||||
amount?: number | null
|
||||
sts?: number | null
|
||||
sts_str?: string | number | null
|
||||
payment_sts?: number | null
|
||||
} | null
|
||||
withdraw?: {
|
||||
sts?: number | null
|
||||
sts_str?: string | number | null
|
||||
} | null
|
||||
order_id?: number | null
|
||||
}
|
||||
|
||||
const ORDER_STATUS_LABELS: Record<number, string> = {
|
||||
1: 'باز',
|
||||
2: 'موفق',
|
||||
3: 'ناموفق',
|
||||
}
|
||||
|
||||
export function getTransactionTradePrice(item: TransactionPriceSource): number {
|
||||
@@ -79,6 +93,34 @@ export function getTransactionTradePrice(item: TransactionPriceSource): number {
|
||||
return 0
|
||||
}
|
||||
|
||||
export function resolveTransactionStatusLabel(item?: TransactionPriceSource | null): string {
|
||||
if (!item) return ''
|
||||
|
||||
const raw = item.order?.sts_str ?? item.withdraw?.sts_str
|
||||
if (typeof raw === 'string') {
|
||||
const trimmed = raw.trim()
|
||||
if (trimmed && trimmed !== 'بدون مقدار') {
|
||||
return trimmed
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof raw === 'number' || (typeof raw === 'string' && /^\d+$/.test(String(raw).trim()))) {
|
||||
const mapped = ORDER_STATUS_LABELS[Number(raw)]
|
||||
if (mapped) return mapped
|
||||
}
|
||||
|
||||
const sts = item.order?.sts ?? item.withdraw?.sts
|
||||
if (sts != null && ORDER_STATUS_LABELS[Number(sts)]) {
|
||||
return ORDER_STATUS_LABELS[Number(sts)]
|
||||
}
|
||||
|
||||
if (item.order_id && Number(item.order?.payment_sts) === 4) {
|
||||
return 'موفق'
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
|
||||
export function getTransactionGoldAmount(item: TransactionPriceSource): number {
|
||||
const gold = Number(item.gold) || 0
|
||||
if (Math.abs(gold) > 0) {
|
||||
|
||||
Reference in New Issue
Block a user