This commit is contained in:
2026-06-11 21:21:15 +03:30
parent 366157e026
commit 298f9a6055
13 changed files with 135 additions and 78 deletions
+4 -2
View File
@@ -32,6 +32,7 @@ import {computed, ref} from 'vue'
import type {Rule} from 'ant-design-vue/es/form'
import {useWalletStore} from "@/store/walletStore";
import { isCashLikeDealMethod, isMainMetalWalletDealMethod, getInsufficientCashWalletMessage, getInsufficientGoldWalletMessage } from '@/utils/productDealMethod'
import { getCashWalletBalance } from '@/utils/productAssets'
export const mobileValidation = (title?: string): Rule => {
const label = title ?? 'شماره تلفن'
@@ -160,13 +161,14 @@ const checkNumber = async (_rule: Rule, value: number) => {
return Promise.reject('استفاده از اعداد اعشاری مجاز نمی باشد')
}
if (isBuyP){
if (!walletCash?.walletInfo?.cash && isCashLikeDealMethod(methodP)){
const availableCash = getCashWalletBalance(walletCash?.walletInfo)
if (!availableCash && isCashLikeDealMethod(methodP)){
return Promise.reject(getInsufficientCashWalletMessage(groupTypeP))
}
if (!walletCash?.walletInfo?.gold && isMainMetalWalletDealMethod(methodP)){
return Promise.reject(getInsufficientGoldWalletMessage(groupTypeP, methodP))
}
if (priceP * value > walletCash?.walletInfo?.cash && isCashLikeDealMethod(methodP))
if (priceP * value > availableCash && isCashLikeDealMethod(methodP))
return Promise.reject(getInsufficientCashWalletMessage(groupTypeP))
if (amountP * value > walletCash?.walletInfo?.gold && isMainMetalWalletDealMethod(methodP))
return Promise.reject(getInsufficientGoldWalletMessage(groupTypeP, methodP))
+17 -2
View File
@@ -334,17 +334,32 @@ export function getTotalMetalWeight(
return Number(walletInfo?.treasure ?? walletInfo?.gold_sum ?? walletInfo?.count_gold ?? 0)
}
/** فقط موجودی نقدی کیف اصلی — فیلد gold (مثل 0.3 کیلوگرم) جزو دارایی ریالی نیست */
/** موجودی ریالی کیف اصلی — با main_wallet_products فیلد cash ممکن است کیف محصول باشد */
export function getRialCashAmount(
walletInfo?: Record<string, unknown> | null,
wallets?: UserWalletLine[] | null
): number {
const aggregated = walletInfo?.count_cash_wallet ?? walletInfo?.count_cash
if (aggregated != null && aggregated !== '') {
const parsed = Number(aggregated)
if (!Number.isNaN(parsed)) {
return parsed
}
}
const mainCash = getMainWalletCash(wallets)
if (mainCash > 0) {
return mainCash
}
return Number(walletInfo?.count_cash ?? walletInfo?.cash ?? 0)
return Number(walletInfo?.cash ?? 0)
}
export function getCashWalletBalance(
walletInfo?: Record<string, unknown> | null,
wallets?: UserWalletLine[] | null
): number {
return getRialCashAmount(walletInfo, wallets)
}
export function getTotalRialEquivalent(walletInfo?: Record<string, unknown> | null): number {
+55 -21
View File
@@ -11,50 +11,84 @@ function applyPriceOffsetPercent(basePrice: number, offsetPercent?: number | nul
return Math.round(basePrice * (1 + offset / 100))
}
/** قیمت خرید نمایشی محصول (همان مقداری که در لیست و اکشن‌شیت نشان داده می‌شود) */
export function getProductBuyPrice(product: Product): number {
/** قیمت پایه بدون کارمزد — اگر صفر باشد نباید فقط cash_fee به‌عنوان قیمت نمایش داده شود */
export function getProductBaseBuyPrice(product: Product): number {
if (isMeltedProductUsingAppPrice(product)) {
const tradeBuy = getTradeBuyPrice(lastPrice.value)
const base = tradeBuy > 0
? applyPriceOffsetPercent(tradeBuy, product.price_offset_percent)
: (product.price ?? 0)
return base + (product.cash_fee_buy ?? 0)
if (tradeBuy > 0) {
return applyPriceOffsetPercent(tradeBuy, product.price_offset_percent)
}
// provider صفر — آخرین قیمت ذخیره‌شده از API (وقتی use_last_price_if_zero فعال است)
return Number(product.price ?? 0)
}
if (isMeltedTradeGroup(product.group_type)) {
return (product.price ?? 0) + (product.cash_fee_buy ?? 0)
return Number(product.price ?? 0)
}
if (isMetalCommodityGroup(product.group_type)) {
const base = (product.price_profit ?? 0) + (product.price ?? 0)
return base + (product.cash_fee_buy ?? 0)
return Number(product.price_profit ?? 0) + Number(product.price ?? 0)
}
const basePrice = (product.price ?? 0) + (product.cash_fee_buy ?? 0)
return product.direct_price === 0
? basePrice * (product.amount ?? 0)
: basePrice
return Number(product.price ?? 0)
}
/** قیمت فروش نمایشی محصول آبشده‌ای */
export function getProductSellPrice(product: Product): number {
/** قیمت خرید نمایشی محصول (همان مقداری که در لیست و اکشن‌شیت نشان داده می‌شود) */
export function getProductBuyPrice(product: Product): number {
const base = getProductBaseBuyPrice(product)
if (base <= 0) {
return 0
}
const fee = Number(product.cash_fee_buy ?? 0)
if (
isMeltedProductUsingAppPrice(product)
|| isMeltedTradeGroup(product.group_type)
|| isMetalCommodityGroup(product.group_type)
) {
return base + fee
}
const withFee = base + fee
return product.direct_price === 0
? withFee * Number(product.amount ?? 0)
: withFee
}
function getProductBaseSellPrice(product: Product): number {
if (isMeltedProductUsingAppPrice(product)) {
const tradeSell = getTradeSellPrice(lastPrice.value)
const base = tradeSell > 0
? applyPriceOffsetPercent(tradeSell, product.price_offset_percent)
: (product.price ?? 0)
return base - (product.cash_fee_sell ?? 0)
if (tradeSell > 0) {
return applyPriceOffsetPercent(tradeSell, product.price_offset_percent)
}
// provider صفر — همان آخرین قیمت ذخیره‌شده (فروش از همان مبنا)
return Number(product.price ?? 0)
}
if (isMeltedTradeGroup(product.group_type)) {
return (product.price ?? 0) - (product.cash_fee_sell ?? 0)
return Number(product.price ?? 0)
}
return getTradeSellPrice(lastPrice.value)
}
/** قیمت فروش نمایشی محصول آبشده‌ای */
export function getProductSellPrice(product: Product): number {
const base = getProductBaseSellPrice(product)
if (base <= 0) {
return 0
}
if (isMeltedProductUsingAppPrice(product) || isMeltedTradeGroup(product.group_type)) {
return base - Number(product.cash_fee_sell ?? 0)
}
return base
}
export function isProductPriceInactive(product: Product): boolean {
return getProductBuyPrice(product) <= 0
return getProductBaseBuyPrice(product) <= 0
}
export { isMeltedTradeGroup, isMeltedProductUsingAppPrice } from '@/utils/productCategories'