added percent in product price 3

This commit is contained in:
2026-07-04 22:14:18 +03:30
parent ed5bd74986
commit 3373bc82ca
4 changed files with 111 additions and 8 deletions
@@ -693,7 +693,12 @@ class ProductController extends SuperController
}
if (is_string($value)) {
$value = str_replace([',', ' ', '٬'], '', $value);
$value = trim(str_replace([' ', '٬'], '', $value));
if (str_contains($value, ',') && ! str_contains($value, '.')) {
$value = str_replace(',', '.', $value);
} else {
$value = str_replace(',', '', $value);
}
}
return (float) $value;
+9 -7
View File
@@ -6,20 +6,22 @@ use App\Models\Product;
class ProductPriceService
{
/** 5 => 5% ، 0.05 => 5% (اعشاری) */
public static function feePercentRatio(float $percentValue): float
/** 0.5 => 0.5% ، 5 => 5% — همیشه عدد درصد، نه اعشار (۰.۵ ≠ ۵۰٪) */
public static function cashFeePercentRatio(float $percentValue): float
{
if ($percentValue == 0.0) {
return 0.0;
}
if (abs($percentValue) > 0 && abs($percentValue) < 1) {
return $percentValue;
}
return $percentValue / 100;
}
/** @deprecated از cashFeePercentRatio استفاده کنید */
public static function feePercentRatio(float $percentValue): float
{
return self::cashFeePercentRatio($percentValue);
}
public static function resolveCashFeeRial(Product $product, int $direction, float $basePriceRial): float
{
$isBuy = $direction === 1;
@@ -41,7 +43,7 @@ class ProductPriceService
return 0.0;
}
return round(abs($basePriceRial * self::feePercentRatio($rawFee)));
return round(abs($basePriceRial * self::cashFeePercentRatio($rawFee)));
}
public static function productBasePriceRial(Product $product): float