From abc58c41807bcfe388942a4a329d335b2e8e3fd5 Mon Sep 17 00:00:00 2001 From: mohammad sedighi Date: Fri, 10 Jul 2026 00:19:30 +0330 Subject: [PATCH] =?UTF-8?q?fix=20bug=20=DB=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Single/SingleOrderController.php | 24 ++++++++++++++++--- app/Models/Product.php | 8 +++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/Single/SingleOrderController.php b/app/Http/Controllers/Single/SingleOrderController.php index cdd7320..72fa3c5 100644 --- a/app/Http/Controllers/Single/SingleOrderController.php +++ b/app/Http/Controllers/Single/SingleOrderController.php @@ -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); + } } diff --git a/app/Models/Product.php b/app/Models/Product.php index f729df7..38b2f67 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -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) . ' ریال می‌باشد' );