fix some bugs

This commit is contained in:
2026-07-29 19:57:32 +03:30
parent 67c31c9bce
commit 381d28aae5
2 changed files with 30 additions and 2 deletions
@@ -596,6 +596,12 @@ class SingleOrderController extends Controller
// سمت کسر کارمزد برای گزارش تفکیک‌شده در داشبورد
$data['fee_asset'] = $rialLocked ? 'gold' : 'rial';
if (!$rialLocked && (float) $data['total_price'] < 0) {
throw new UnprocessableEntityHttpException(
'مبلغ دریافتی فروش پس از کارمزد منفی شد. درصد کارمزد سفارش را بررسی کنید (باید اعشاری باشد؛ مثلاً ۰٫۰۱ برای ۱٪).'
);
}
$grossTotal = $data['amount'] * $data['price'];
$this->enforceProductOrderLimits($data, (float) $grossTotal);
@@ -675,6 +681,11 @@ class SingleOrderController extends Controller
$data['total_price'] = $data['amount'] * $data['price'] - $data['service_charge_price'];
$data['payment_amount'] = $data['total_price'];
$data['fee_asset'] = 'rial';
if ($data['total_price'] < 0) {
throw new UnprocessableEntityHttpException(
'مبلغ دریافتی فروش پس از کارمزد منفی شد. درصد کارمزد سفارش را بررسی کنید (باید اعشاری باشد؛ مثلاً ۰٫۰۱ برای ۱٪).'
);
}
$grossTotal = (float) ($data['amount'] * $data['price']);
$this->enforceProductOrderLimits($data, $grossTotal);
$wallet_interface_product = $this->productWalletInterface((int) $data["product_id"]);
+19 -2
View File
@@ -138,11 +138,28 @@ class ConfigService
foreach (['fee_service_charge_percentage', 'service_charge_percentage'] as $key) {
$raw = $this->getString($key, '');
if ($raw !== '') {
return (float) $raw;
return $this->normalizeServiceChargeRatio((float) $raw);
}
}
return (float) config('fee.service_charge_percentage', 0);
return $this->normalizeServiceChargeRatio((float) config('fee.service_charge_percentage', 0));
}
/**
* نسبت کارمزد (۰٫۰۱ = ۱٪). اگر ادمین «۱» به‌جای «۰٫۰۱» گذاشته باشد نرمال می‌شود.
*/
private function normalizeServiceChargeRatio(float $value): float
{
if ($value <= 0) {
return 0.0;
}
// مقدار ≥۱ یعنی درصد انسانی وارد شده (۱ → ۱٪)، نه نسبت
if ($value >= 1.0) {
return $value / 100.0;
}
return $value;
}
/**