added percent in product price 2

This commit is contained in:
2026-07-04 22:06:20 +03:30
parent 4ef0dfb2c0
commit ed5bd74986
3 changed files with 68 additions and 2 deletions
@@ -667,6 +667,35 @@ class ProductController extends SuperController
$data['override_trading_hours'] = !empty($data['override_trading_hours']);
}
$data['cash_fee_buy'] = $this->normalizeCashFeeValue($data['cash_fee_buy'] ?? 0);
$data['cash_fee_sell'] = $this->normalizeCashFeeValue($data['cash_fee_sell'] ?? 0);
if (Product::hasCashFeePercentModeColumns()) {
$data['cash_fee_buy_is_percent'] = filter_var(
$data['cash_fee_buy_is_percent'] ?? false,
FILTER_VALIDATE_BOOLEAN
);
$data['cash_fee_sell_is_percent'] = filter_var(
$data['cash_fee_sell_is_percent'] ?? false,
FILTER_VALIDATE_BOOLEAN
);
} else {
unset($data['cash_fee_buy_is_percent'], $data['cash_fee_sell_is_percent']);
}
return $data;
}
private function normalizeCashFeeValue(mixed $value): float
{
if ($value === null || $value === '') {
return 0.0;
}
if (is_string($value)) {
$value = str_replace([',', ' ', '٬'], '', $value);
}
return (float) $value;
}
}
+2 -2
View File
@@ -353,8 +353,8 @@ class Product extends Model
'order_limit_enabled' => 'boolean',
'min_order_cash' => 'int',
'max_order_cash' => 'int',
'cash_fee_buy' => 'int', // Cast to int or decimal if needed
'cash_fee_sell' => 'int', // Cast to int or decimal if needed
'cash_fee_buy' => 'float',
'cash_fee_sell' => 'float',
'cash_fee_buy_is_percent' => 'boolean',
'cash_fee_sell_is_percent' => 'boolean',
'price_offset_percent' => 'float',
+37
View File
@@ -330,6 +330,43 @@ AND NOT EXISTS (
UPDATE `settings` SET `can_edit` = 0 WHERE `key` = 'main_wallet_products';
-- ---------------------------------------------------------------------------
-- products — نوع هزینه خرید/فروش: نقدی (ریال) یا درصدی
-- ---------------------------------------------------------------------------
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_is_percent') = 0,
IF(
(SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'cash_fee_buy') > 0,
'ALTER TABLE `products` ADD COLUMN `cash_fee_buy_is_percent` TINYINT(1) NOT NULL DEFAULT 0 AFTER `cash_fee_buy`',
'ALTER TABLE `products` ADD COLUMN `cash_fee_buy_is_percent` TINYINT(1) NOT NULL DEFAULT 0'
),
'SELECT ''skip products.cash_fee_buy_is_percent'' 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_is_percent') = 0,
IF(
(SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'cash_fee_sell') > 0,
'ALTER TABLE `products` ADD COLUMN `cash_fee_sell_is_percent` TINYINT(1) NOT NULL DEFAULT 0 AFTER `cash_fee_sell`',
'ALTER TABLE `products` ADD COLUMN `cash_fee_sell_is_percent` TINYINT(1) NOT NULL DEFAULT 0'
),
'SELECT ''skip products.cash_fee_sell_is_percent'' AS info'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- ---------------------------------------------------------------------------
-- پایان — برای بورس‌مس (اختیاری، جدا اجرا کنید):
-- UPDATE `settings` SET `value` = 'کیلوگرم' WHERE `key` = 'unit';