widthdraw and deposit
This commit is contained in:
+121
-46
@@ -1,18 +1,22 @@
|
||||
import type { SelectItem } from '@/models/SelectItem'
|
||||
import { isBoursecuProject } from '@/utils/config'
|
||||
import { useSettingsStore } from '@/store/settingsStore'
|
||||
import {
|
||||
isLegacyMaftolGroup,
|
||||
isMeltedTradeGroup,
|
||||
LEGACY_GROUP_KATOD,
|
||||
LEGACY_GROUP_MAFTOL,
|
||||
normalizeProductGroupType,
|
||||
PRODUCT_CATEGORY_ABSHODE,
|
||||
} from '@/utils/productCategories'
|
||||
|
||||
/** شناسه group_type محصول در دیتابیس — نه برچسب نمایشی */
|
||||
export const BOURSECU_GROUP_MAFTOL = 'مفتول مس'
|
||||
export const BOURSECU_GROUP_KATOD = 'کاتد مس'
|
||||
export const BOURSECU_GROUP_ABSHODE = 'آبشده'
|
||||
/** @deprecated از isMeltedTradeGroup استفاده کنید */
|
||||
export const BOURSECU_GROUP_ABSHODE = PRODUCT_CATEGORY_ABSHODE
|
||||
export const BOURSECU_GROUP_KATOD = LEGACY_GROUP_KATOD
|
||||
export const BOURSECU_GROUP_MAFTOL = LEGACY_GROUP_MAFTOL
|
||||
|
||||
export const BOURSECU_WALLET_LABEL_GENERIC = 'موجودی کیف'
|
||||
|
||||
export function normalizeProductGroupType(groupType?: string | null) {
|
||||
return (groupType ?? '').trim()
|
||||
}
|
||||
|
||||
export function isBoursecuDealProductGroup(groupType?: string | null) {
|
||||
if (!isBoursecuProject()) {
|
||||
return false
|
||||
@@ -22,10 +26,12 @@ export function isBoursecuDealProductGroup(groupType?: string | null) {
|
||||
return group === BOURSECU_GROUP_MAFTOL
|
||||
|| group === BOURSECU_GROUP_KATOD
|
||||
|| group === BOURSECU_GROUP_ABSHODE
|
||||
|| group === 'مس'
|
||||
}
|
||||
|
||||
export function isMaftolMesGroup(groupType?: string | null) {
|
||||
return normalizeProductGroupType(groupType) === BOURSECU_GROUP_MAFTOL
|
||||
const group = normalizeProductGroupType(groupType)
|
||||
return group === BOURSECU_GROUP_MAFTOL || (isBoursecuProject() && group === 'مس')
|
||||
}
|
||||
|
||||
export function isKatodMesGroup(groupType?: string | null) {
|
||||
@@ -33,7 +39,7 @@ export function isKatodMesGroup(groupType?: string | null) {
|
||||
}
|
||||
|
||||
export function isGoldOnlyDealGroup(groupType?: string | null) {
|
||||
return normalizeProductGroupType(groupType) === BOURSECU_GROUP_ABSHODE
|
||||
return isMeltedTradeGroup(groupType)
|
||||
}
|
||||
|
||||
export interface ProductUnitSource {
|
||||
@@ -43,6 +49,11 @@ export interface ProductUnitSource {
|
||||
amount?: number | null
|
||||
}
|
||||
|
||||
export function isWeightBasedProductUnit(unit?: string | null) {
|
||||
const value = (unit ?? '').trim()
|
||||
return value === 'کیلوگرم' || value === 'گرم'
|
||||
}
|
||||
|
||||
const COUNT_BASED_GROUP_TYPES = ['سکه', 'گوی', 'مکعب', 'شمش', 'سکه پارسیان']
|
||||
|
||||
/** مطابق ادمین: وزن «دارد» یعنی amount مقدار واقعی است؛ «ندارد» یعنی amount = 1 */
|
||||
@@ -52,14 +63,19 @@ export function hasProductUnitWeight(product?: ProductUnitSource | null) {
|
||||
}
|
||||
|
||||
export function getProductWeightUnit(product?: ProductUnitSource | null) {
|
||||
const unit = product?.unit?.trim()
|
||||
if (unit && isWeightBasedProductUnit(unit)) {
|
||||
return unit
|
||||
}
|
||||
|
||||
if (isBoursecuProject()) {
|
||||
const group = normalizeProductGroupType(product?.group_type)
|
||||
if (group === BOURSECU_GROUP_MAFTOL || group === BOURSECU_GROUP_KATOD || group === BOURSECU_GROUP_ABSHODE) {
|
||||
if (group === BOURSECU_GROUP_MAFTOL || group === BOURSECU_GROUP_KATOD || group === BOURSECU_GROUP_ABSHODE || group === 'مس' || isMeltedTradeGroup(group)) {
|
||||
return getWeightUnit()
|
||||
}
|
||||
}
|
||||
|
||||
if (!isCountBasedProduct(product) || isGoldOnlyDealGroup(product?.group_type)) {
|
||||
if (!isCountBasedProduct(product) || isMeltedTradeGroup(product?.group_type)) {
|
||||
return getWeightUnit()
|
||||
}
|
||||
|
||||
@@ -124,12 +140,16 @@ export function isCountBasedProduct(product?: ProductUnitSource | null) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (isWeightBasedProductUnit(product.unit)) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (product.direct_price != null && product.direct_price !== 0) {
|
||||
return true
|
||||
}
|
||||
|
||||
const group = normalizeProductGroupType(product.group_type)
|
||||
if (group === BOURSECU_GROUP_MAFTOL || group === BOURSECU_GROUP_KATOD) {
|
||||
if (group === BOURSECU_GROUP_MAFTOL || isLegacyMaftolGroup(group) || (isBoursecuProject() && group === 'مس')) {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -137,15 +157,15 @@ export function isCountBasedProduct(product?: ProductUnitSource | null) {
|
||||
}
|
||||
|
||||
export function getProductQuantityUnit(product?: ProductUnitSource | null) {
|
||||
if (isCountBasedProduct(product)) {
|
||||
return 'عدد'
|
||||
}
|
||||
|
||||
const unit = product?.unit?.trim()
|
||||
if (unit) {
|
||||
return unit
|
||||
}
|
||||
|
||||
if (isCountBasedProduct(product)) {
|
||||
return 'عدد'
|
||||
}
|
||||
|
||||
return getWeightUnit()
|
||||
}
|
||||
|
||||
@@ -157,17 +177,34 @@ function getDefaultTypeDealOptions(): SelectItem[] {
|
||||
]
|
||||
}
|
||||
|
||||
export function getProductDealMethodOptions(groupType?: string | null): SelectItem[] {
|
||||
export function getProductDealMethodOptions(groupType?: string | null, isBuy = true): SelectItem[] {
|
||||
const settingsStore = useSettingsStore()
|
||||
|
||||
if (!isBoursecuProject()) {
|
||||
return getDefaultTypeDealOptions()
|
||||
if (isBuy) {
|
||||
return [
|
||||
{ value: 'نقدی', key: 'cash' },
|
||||
{ value: settingsStore.metalTypeLabel, key: 'gold' },
|
||||
]
|
||||
}
|
||||
|
||||
return [
|
||||
{ value: 'نقدی', key: 'cash' },
|
||||
{ value: `دریافت ${settingsStore.metalTypeLabel}`, key: 'gold' },
|
||||
]
|
||||
}
|
||||
|
||||
if (isMaftolMesGroup(groupType)) {
|
||||
if (isBuy) {
|
||||
return [
|
||||
{ value: `پرداخت با ${settingsStore.metalTypeLabel}`, key: 'katod' },
|
||||
{ value: 'نقدی', key: 'cash' },
|
||||
]
|
||||
}
|
||||
|
||||
return [
|
||||
{ value: settingsStore.metalTypeLabel, key: 'katod' },
|
||||
{ value: 'نقدی', key: 'cash' },
|
||||
{ value: `دریافت ${settingsStore.metalTypeLabel}`, key: 'katod' },
|
||||
]
|
||||
}
|
||||
|
||||
@@ -175,15 +212,38 @@ export function getProductDealMethodOptions(groupType?: string | null): SelectIt
|
||||
return [{ value: 'نقدی', key: 'cash' }]
|
||||
}
|
||||
|
||||
if (isGoldOnlyDealGroup(groupType)) {
|
||||
if (isMeltedTradeGroup(groupType)) {
|
||||
return [{ value: settingsStore.meltedGoldLabel, key: 'gold' }]
|
||||
}
|
||||
|
||||
return getDefaultTypeDealOptions()
|
||||
}
|
||||
|
||||
export function getDefaultProductDealMethod(groupType?: string | null) {
|
||||
return getProductDealMethodOptions(groupType)[0]?.key ?? 'cash'
|
||||
export function getDefaultProductDealMethod(groupType?: string | null, isBuy = true) {
|
||||
return getProductDealMethodOptions(groupType, isBuy)[0]?.key ?? 'cash'
|
||||
}
|
||||
|
||||
export function getProductDealMethodPlaceholder(isBuy = true) {
|
||||
return isBuy ? 'نحوه خرید را انتخاب کنید' : 'نحوه دریافت را انتخاب کنید'
|
||||
}
|
||||
|
||||
export function formatMainMetalReceiveText(weight?: number | null) {
|
||||
return `${useSettingsStore().metalTypeLabel}: ${weight ?? 0}${getWeightUnit()}`
|
||||
}
|
||||
|
||||
export function calcSellReceivedMetalWeight(
|
||||
count?: number | null,
|
||||
product?: ProductUnitSource & { percent_fee_sell?: number | null } | null,
|
||||
) {
|
||||
const quantity = Number(count ?? 0)
|
||||
const unitAmount = Number(product?.amount ?? 0)
|
||||
if (!quantity || !unitAmount) {
|
||||
return 0
|
||||
}
|
||||
|
||||
const grossAmount = quantity * unitAmount
|
||||
const feeRate = Number(product?.percent_fee_sell ?? 0)
|
||||
return grossAmount - feeRate * grossAmount
|
||||
}
|
||||
|
||||
export function isCashLikeDealMethod(method?: string | null) {
|
||||
@@ -204,36 +264,42 @@ export function getMeltedGoldWalletLabel() {
|
||||
return `موجودی کیف ${useSettingsStore().meltedGoldLabel}`
|
||||
}
|
||||
|
||||
export function getGoldWalletLabel(groupType?: string | null) {
|
||||
const settingsStore = useSettingsStore()
|
||||
export function getBoursecuMetalWalletLabel(groupType?: string | null) {
|
||||
const group = normalizeProductGroupType(groupType)
|
||||
if (group === BOURSECU_GROUP_MAFTOL) {
|
||||
return BOURSECU_GROUP_MAFTOL
|
||||
}
|
||||
if (group === BOURSECU_GROUP_KATOD) {
|
||||
return BOURSECU_GROUP_KATOD
|
||||
}
|
||||
if (group === BOURSECU_GROUP_ABSHODE) {
|
||||
return useSettingsStore().meltedGoldLabel
|
||||
}
|
||||
|
||||
return useSettingsStore().metalTypeLabel
|
||||
}
|
||||
|
||||
export function getGoldWalletLabel(groupType?: string | null) {
|
||||
if (!isBoursecuProject()) {
|
||||
return getMainMetalWalletLabel()
|
||||
}
|
||||
|
||||
const group = normalizeProductGroupType(groupType)
|
||||
if (group === BOURSECU_GROUP_MAFTOL) {
|
||||
return `موجودی کیف ${BOURSECU_GROUP_MAFTOL}`
|
||||
if (group === BOURSECU_GROUP_MAFTOL
|
||||
|| group === BOURSECU_GROUP_KATOD
|
||||
|| group === BOURSECU_GROUP_ABSHODE) {
|
||||
return `موجودی کیف ${getBoursecuMetalWalletLabel(groupType)}`
|
||||
}
|
||||
if (group === BOURSECU_GROUP_KATOD || group === BOURSECU_GROUP_ABSHODE || !group) {
|
||||
return group === BOURSECU_GROUP_ABSHODE
|
||||
? getMeltedGoldWalletLabel()
|
||||
: getMainMetalWalletLabel()
|
||||
|
||||
if (!group) {
|
||||
return getMainMetalWalletLabel()
|
||||
}
|
||||
|
||||
return BOURSECU_WALLET_LABEL_GENERIC
|
||||
}
|
||||
|
||||
export function getCashWalletLabel(groupType?: string | null) {
|
||||
if (!isBoursecuProject()) {
|
||||
return 'موجودی کیف پول'
|
||||
}
|
||||
|
||||
const group = normalizeProductGroupType(groupType)
|
||||
if (group === BOURSECU_GROUP_MAFTOL) {
|
||||
return `موجودی کیف ${BOURSECU_GROUP_MAFTOL}`
|
||||
}
|
||||
|
||||
/** پرداخت نقدی همیشه از کیف پول ریالی — مستقل از نوع محصول */
|
||||
export function getCashWalletLabel(_groupType?: string | null) {
|
||||
return 'موجودی کیف پول'
|
||||
}
|
||||
|
||||
@@ -250,7 +316,7 @@ export function getMaftolAssetLabel() {
|
||||
}
|
||||
|
||||
export function getWeightUnit() {
|
||||
return isBoursecuProject() ? 'کیلوگرم' : 'گرم'
|
||||
return useSettingsStore().tradeWeightUnit
|
||||
}
|
||||
|
||||
export function formatBoursecuAssetAmount(amount?: number | null) {
|
||||
@@ -269,12 +335,21 @@ export function formatCashWalletBalanceText(cashFormatted: string | number, grou
|
||||
return `${getCashWalletLabel(groupType)}: ${cashFormatted} ریال`
|
||||
}
|
||||
|
||||
export function getInsufficientGoldWalletMessage(groupType?: string | null) {
|
||||
return `${getGoldWalletLabel(groupType)} ناکافی است`
|
||||
/** برچسب کیف فلزی متناسب با نحوه پرداخت (مثلاً کاتد مس برای خرید مفتول با کیف کاتد) */
|
||||
export function getMetalWalletLabelForDealMethod(method?: string | null, groupType?: string | null) {
|
||||
if (!isBoursecuProject() || method === 'katod') {
|
||||
return getMainMetalWalletLabel()
|
||||
}
|
||||
|
||||
return getGoldWalletLabel(groupType)
|
||||
}
|
||||
|
||||
export function getInsufficientCashWalletMessage(groupType?: string | null) {
|
||||
return `${getCashWalletLabel(groupType)} ناکافی است`
|
||||
export function getInsufficientGoldWalletMessage(groupType?: string | null, method?: string | null) {
|
||||
return `${getMetalWalletLabelForDealMethod(method, groupType)} ناکافی است`
|
||||
}
|
||||
|
||||
export function getInsufficientCashWalletMessage(_groupType?: string | null) {
|
||||
return `${getCashWalletLabel()} ناکافی است`
|
||||
}
|
||||
|
||||
export function getInsufficientMainMetalWalletMessage() {
|
||||
|
||||
Reference in New Issue
Block a user