added banning for when amount is under 0

This commit is contained in:
2026-07-20 21:29:30 +03:30
parent 5d98a6f041
commit 10a510529d
4 changed files with 48 additions and 0 deletions
+30
View File
@@ -695,6 +695,36 @@ class ConfigService
}
}
/**
* سوییچ require_zero_main_gold_before_other_buy (پیش‌فرض true).
* اگر مانده طلای کیف اصلی صفر یا زیر صفر باشد (منفی)، خرید محصول خارج از کیف اصلی
* تا صفر شدن بدهی مسدود است. معامله خودِ محصولات main_wallet_products همیشه مجاز است.
*
* @param object|null $mainWallet کیف اصلی (product_id=null) با فیلد gold
*/
public function assertMainGoldZeroBeforeOtherProductBuy(?object $mainWallet, Product $product): void
{
if (!$this->getBool('require_zero_main_gold_before_other_buy', true)) {
return;
}
$productId = (int) ($product->id ?? 0);
if ($productId <= 0 || $this->isMainWalletProduct($productId)) {
return;
}
$gold = (float) ($mainWallet->gold ?? 0);
// صفر = از قبل تسویه؛ فقط بدهی (زیر صفر) مسدود می‌کند
if ($gold >= 0) {
return;
}
$label = $this->mainWalletProductLabels() ?: 'آبشده / کیف اصلی';
throw new UnprocessableEntityHttpException(
"مانده طلای کیف اصلی منفی است. ابتدا مانده «{$label}» را صفر کنید، سپس می‌توانید محصول دیگر بخرید."
);
}
public const ACCOUNTING_NONE = 'none';
public const ACCOUNTING_TAHESAB = 'tahesab';
public const ACCOUNTING_PARGAR = 'pargar';