fix bug ۲

This commit is contained in:
2026-07-10 00:19:30 +03:30
parent e0c4897111
commit abc58c4180
2 changed files with 27 additions and 5 deletions
@@ -265,7 +265,7 @@ class SingleOrderController extends Controller
$data['total_price'] = $data['amount'] * $data['price'];
$this->enforceProductOrderLimits($data, (float) $data['total_price']);
$this->enforceProductOrderLimits($data);
if (!empty($data['first_buy']) && ($minFirstBuy = Setting::where('is_active', 1)->where('key', 'min_first_buy')->value('value'))) {
if ($data['total_price'] < (int) $minFirstBuy) {
@@ -1278,7 +1278,7 @@ class SingleOrderController extends Controller
return false;
}
private function enforceProductOrderLimits(array &$data, float $totalPriceRial): void
private function enforceProductOrderLimits(array &$data, ?float $totalPriceRial = null): void
{
$product = $data['product'] ?? null;
@@ -1298,7 +1298,25 @@ class SingleOrderController extends Controller
}
if ($product instanceof Product) {
$product->validateOrderCashLimit($totalPriceRial);
$product->validateOrderCashLimit($this->resolveOrderLimitCashRial($data, $totalPriceRial));
}
}
/**
* مبلغ مؤثر برای min/max محصول — با target_cash همان مبلغی که کاربر وارد کرده
* (نه total_price موقت قبل از رُند گرم که ممکن است چند ریال کمتر شود).
*/
private function resolveOrderLimitCashRial(array $data, ?float $fallbackTotal = null): float
{
$targetCash = $this->resolveTargetCash($data);
if ($targetCash !== null) {
return (float) $targetCash;
}
if ($fallbackTotal !== null) {
return $fallbackTotal;
}
return (float) ($data['payment_amount'] ?? $data['total_price'] ?? 0);
}
}
+6 -2
View File
@@ -265,13 +265,17 @@ class Product extends Model
$min = $this->min_order_cash;
$max = $this->max_order_cash;
if ($min !== null && $totalPriceRial < (float) $min) {
// یک ریال تلرانس — وقتی target_cash به گرم تبدیل و دوباره ضرب می‌شود ممکن است
// total_price موقت چند ریال از حداقل کمتر شود (مثلاً دقیقاً ۲۰۰,۰۰۰,۰۰۰).
$toleranceRial = 1.0;
if ($min !== null && $totalPriceRial + $toleranceRial < (float) $min) {
throw new \Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException(
'حداقل مبلغ این محصول ' . number_format((float) $min) . ' ریال می‌باشد'
);
}
if ($max !== null && $totalPriceRial > (float) $max) {
if ($max !== null && $totalPriceRial > (float) $max + $toleranceRial) {
throw new \Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException(
'حداکثر مبلغ این محصول ' . number_format((float) $max) . ' ریال می‌باشد'
);