added percent in product price 3
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if (! Schema::hasTable('products')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Schema::hasColumn('products', 'cash_fee_buy')) {
|
||||
DB::statement('ALTER TABLE `products` MODIFY COLUMN `cash_fee_buy` DECIMAL(10,4) NULL DEFAULT NULL');
|
||||
}
|
||||
|
||||
if (Schema::hasColumn('products', 'cash_fee_sell')) {
|
||||
DB::statement('ALTER TABLE `products` MODIFY COLUMN `cash_fee_sell` DECIMAL(10,4) NULL DEFAULT NULL');
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if (! Schema::hasTable('products')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Schema::hasColumn('products', 'cash_fee_buy')) {
|
||||
DB::statement('ALTER TABLE `products` MODIFY COLUMN `cash_fee_buy` INT NULL DEFAULT NULL');
|
||||
}
|
||||
|
||||
if (Schema::hasColumn('products', 'cash_fee_sell')) {
|
||||
DB::statement('ALTER TABLE `products` MODIFY COLUMN `cash_fee_sell` INT NULL DEFAULT NULL');
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -367,6 +367,64 @@ PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
-- products — cash_fee_buy/sell: INT → DECIMAL برای درصدهای اعشاری (مثل 0.5%)
|
||||
-- ---------------------------------------------------------------------------
|
||||
SET @sql = IF(
|
||||
(SELECT COUNT(*) FROM information_schema.TABLES
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products') > 0
|
||||
AND (SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'cash_fee_buy') > 0,
|
||||
'ALTER TABLE `products` MODIFY COLUMN `cash_fee_buy` DECIMAL(10,4) NULL DEFAULT NULL',
|
||||
'SELECT ''skip products.cash_fee_buy decimal'' AS info'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @sql = IF(
|
||||
(SELECT COUNT(*) FROM information_schema.TABLES
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products') > 0
|
||||
AND (SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'cash_fee_sell') > 0,
|
||||
'ALTER TABLE `products` MODIFY COLUMN `cash_fee_sell` DECIMAL(10,4) NULL DEFAULT NULL',
|
||||
'SELECT ''skip products.cash_fee_sell decimal'' AS info'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
-- products — اعشار برای درصد (مثلاً 0.5%) و مبالغ دقیق
|
||||
-- ---------------------------------------------------------------------------
|
||||
SET @sql = IF(
|
||||
(SELECT COUNT(*) FROM information_schema.TABLES
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products') > 0
|
||||
AND (SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'cash_fee_buy') > 0
|
||||
AND (SELECT DATA_TYPE FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'cash_fee_buy' LIMIT 1) <> 'decimal',
|
||||
'ALTER TABLE `products` MODIFY COLUMN `cash_fee_buy` DECIMAL(10,4) NULL DEFAULT NULL',
|
||||
'SELECT ''skip products.cash_fee_buy decimal'' AS info'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @sql = IF(
|
||||
(SELECT COUNT(*) FROM information_schema.TABLES
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products') > 0
|
||||
AND (SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'cash_fee_sell') > 0
|
||||
AND (SELECT DATA_TYPE FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'cash_fee_sell' LIMIT 1) <> 'decimal',
|
||||
'ALTER TABLE `products` MODIFY COLUMN `cash_fee_sell` DECIMAL(10,4) NULL DEFAULT NULL',
|
||||
'SELECT ''skip products.cash_fee_sell decimal'' AS info'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
-- پایان — برای بورسمس (اختیاری، جدا اجرا کنید):
|
||||
-- UPDATE `settings` SET `value` = 'کیلوگرم' WHERE `key` = 'unit';
|
||||
|
||||
Reference in New Issue
Block a user