added banning for when amount is under 0
This commit is contained in:
@@ -421,6 +421,7 @@ class CartController extends Controller
|
||||
}
|
||||
|
||||
app(ConfigService::class)->assertProductTradingOpen($product);
|
||||
app(ConfigService::class)->assertMainGoldZeroBeforeOtherProductBuy($wallet_interface->wallet, $product);
|
||||
|
||||
$qty = (int) $item->quantity;
|
||||
|
||||
|
||||
@@ -118,6 +118,8 @@ class SingleOrderController extends Controller
|
||||
// Check if the user wants to buy
|
||||
if ($data['direction'] == 1) {
|
||||
|
||||
$config->assertMainGoldZeroBeforeOtherProductBuy($wallet, $data['product']);
|
||||
|
||||
$data['service_charge_percentage'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : ($data['product']['percent_fee_buy']) * $data['number'];
|
||||
$data['price_original'] = $this->resolveProductUnitBasePrice($data['product']);
|
||||
$this->applyCashPriceDiff($config, $data['product'], 1, $data, (float) $data['price_original']);
|
||||
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user