fix wallet

This commit is contained in:
2026-06-10 13:11:51 +03:30
parent fe4d85325e
commit 539e38d034
14 changed files with 957 additions and 293 deletions
@@ -392,6 +392,12 @@ class ProductController extends SuperController
$data['show_in_assets'] = !empty($data['show_in_assets']);
}
if (!Product::hasUseLastPriceIfZeroColumn()) {
unset($data['use_last_price_if_zero']);
} elseif (array_key_exists('use_last_price_if_zero', $data)) {
$data['use_last_price_if_zero'] = !empty($data['use_last_price_if_zero']);
}
return $data;
}
}
@@ -47,9 +47,13 @@ class ReportController extends Controller
public function updatePrise()
{
// $difference = config('fee.single');
$difference = Setting::where('key', 'fee_single')->first()->value;
$difference = (float) (Setting::where('key', 'fee_single')->value('value') ?? config('fee.single', 0));
$lastPrice = Price::latest()->first();
if (!$lastPrice) {
return response()->json();
}
$PriceTriggers = PriceTrigger::where("is_active", true)->get();
foreach ($PriceTriggers as $PriceTrigger) {
$priseGold = $PriceTrigger->dirction == 1
@@ -58,6 +62,9 @@ class ReportController extends Controller
if (eval('return $priseGold ' . $PriceTrigger->price_condition . ' $PriceTrigger->target_price;')) {
$customer = Customer::find($PriceTrigger->customer_id);
if (!$customer) {
continue;
}
$message = "قیمت طلا به " . number_format($priseGold, -1) . " در هر گرم رسید\n" .$this->Config('name_fa');
if ($PriceTrigger->action == 'email') {
Mail::to("$customer->email")->send(new YourMailableClass($message, '', '', '', ''));
+29
View File
@@ -19,6 +19,7 @@ class Product extends Model
private static ?bool $priceColumnExists = null;
private static ?bool $orderLimitColumnsExist = null;
private static ?bool $showInAssetsColumnExists = null;
private static ?bool $useLastPriceIfZeroColumnExists = null;
protected static function booted(): void
{
@@ -36,6 +37,9 @@ class Product extends Model
if (!static::hasShowInAssetsColumn()) {
unset($product->attributes['show_in_assets']);
}
if (!static::hasUseLastPriceIfZeroColumn()) {
unset($product->attributes['use_last_price_if_zero']);
}
});
}
@@ -109,6 +113,24 @@ class Product extends Model
return static::$showInAssetsColumnExists;
}
public static function hasUseLastPriceIfZeroColumn(): bool
{
if (static::$useLastPriceIfZeroColumnExists !== null) {
return static::$useLastPriceIfZeroColumnExists;
}
try {
static::$useLastPriceIfZeroColumnExists = Schema::hasColumn(
(new static)->getTable(),
'use_last_price_if_zero'
);
} catch (\Throwable) {
static::$useLastPriceIfZeroColumnExists = false;
}
return static::$useLastPriceIfZeroColumnExists;
}
public function orderLimitsEnabled(): bool
{
if (!static::hasOrderLimitColumns() || !($this->order_limit_enabled ?? false)) {
@@ -160,6 +182,7 @@ class Product extends Model
'for_barayand', // Whether it is for Barayand (boolean).
'show', // Whether to show the record (boolean).
'show_in_assets', // Show balance on customer assets page cards
'use_last_price_if_zero', // Keep last DB price when automatic provider returns zero
'open_sell', // Whether selling is open (boolean).
'auto_open_at', // Whether selling is open (boolean).
'auto_close_at', // Whether selling is open (boolean).
@@ -180,11 +203,17 @@ class Product extends Model
'bubble',
];
protected $attributes = [
'show_in_assets' => false,
'use_last_price_if_zero' => false,
];
protected $casts = [
'can_canceled' => 'boolean', // Cast to boolean.
'active' => 'boolean', // Cast to boolean.
'show' => 'boolean', // Cast to boolean.
'show_in_assets' => 'boolean',
'use_last_price_if_zero' => 'boolean',
'for_barayand' => 'boolean', // Cast to boolean.
'open_sell' => 'boolean', // Cast to boolean.
'auto_sell' => 'boolean', // Cast to boolean (you mentioned this in your casts but it's missing in `$fillable`).
+149 -7
View File
@@ -16,6 +16,11 @@ class AssetSummaryService
3 => 'مس',
];
public function __construct(
private readonly ConfigService $configService
) {
}
public function buildForCustomer(int $customerId, int $ownerType): array
{
$catalog = Product::query()
@@ -35,8 +40,11 @@ class AssetSummaryService
$hasCountBased = $this->catalogHasCountBased($catalog);
$hasWeightBased = $this->catalogHasWeightBased($catalog);
$inventoryCards = $this->buildInventoryCards($userWallets);
$metalTotals = $this->buildMetalTotals($userWallets, $mainWallet, $metalIds, $weightUnit);
$inventoryCards = array_merge(
$this->buildMeltedInventoryCards($catalog, $mainWallet, $metalIds, $weightUnit, $userWallets),
$this->buildInventoryCards($userWallets)
);
$metalTotals = $this->buildMetalTotals($userWallets, $mainWallet, $metalIds, $weightUnit, $catalog);
$cashWallet = (float) ($mainWallet->cash ?? 0);
$assetsRialValue = $this->sumAssetsRialValue($userWallets);
$totalRialValue = $cashWallet + $assetsRialValue;
@@ -83,6 +91,131 @@ class AssetSummaryService
return $catalog->contains(fn (Product $product) => !$this->isCountBasedProduct($product));
}
private function buildMeltedInventoryCards(
Collection $catalog,
?Wallet $mainWallet,
array $metalIds,
string $weightUnit,
Collection $userWallets
): array {
$cards = [];
$mainWalletGrams = Controller::weightToGrams((float) ($mainWallet->gold ?? 0));
$assignedMetalIds = [];
$metalsWithProductWallets = $this->metalIdsWithVisibleProductWallet($userWallets);
foreach ($this->resolveMeltedProducts($catalog) as $product) {
if (!$this->shouldShowInAssets($product)) {
continue;
}
$metalId = (int) ($product->metal_id ?? 0);
if (
$metalId <= 0
|| in_array($metalId, $assignedMetalIds, true)
|| in_array($metalId, $metalsWithProductWallets, true)
) {
continue;
}
$meltedGrams = $this->meltedGramsForMetal($mainWalletGrams, $metalId, $metalIds, $catalog);
if ($meltedGrams <= 0) {
continue;
}
$assignedMetalIds[] = $metalId;
$productPayload = $this->productPayload($product);
$cards[] = [
'product_id' => (int) $product->id,
'title' => (string) $product->title,
'group_type' => $this->meltedGroupTypeLabel($product),
'metal_id' => $metalId,
'quantity' => round(Controller::gramsToTradeUnit($meltedGrams), 3),
'unit' => Controller::productQuantityUnit($productPayload),
'display_type' => 'weight',
'unit_weight' => $this->productUnitWeightLabel($product),
'show_in_assets' => true,
'is_melted' => true,
'file' => $this->filePayload($product),
];
}
return $cards;
}
/**
* محصولات آبشده: دسته «آبشده»/«کاتد مس» + محصول اصلی تنظیمات (main_product).
*/
private function resolveMeltedProducts(Collection $catalog): Collection
{
$mainProductId = $this->configService->mainProductId();
return $catalog
->filter(fn (Product $product) => $this->isMeltedCatalogProduct($product, $mainProductId))
->sortBy(fn (Product $product) => $this->isMainMeltedProduct($product, $mainProductId) ? 0 : 1)
->values();
}
private function isMeltedCatalogProduct(Product $product, ?int $mainProductId): bool
{
if ($mainProductId && (int) $product->id === (int) $mainProductId) {
return true;
}
return $this->isMeltedTradeProduct($product);
}
private function isMainMeltedProduct(Product $product, ?int $mainProductId): bool
{
return $mainProductId !== null && (int) $product->id === (int) $mainProductId;
}
private function isMeltedTradeProduct(Product $product): bool
{
$group = trim((string) ($product->group_type ?? ''));
return in_array($group, ['آبشده', 'کاتد مس'], true);
}
private function meltedGroupTypeLabel(Product $product): string
{
$group = trim((string) ($product->group_type ?? ''));
return $group !== '' ? $group : 'آبشده';
}
private function hasVisibleMeltedProductForMetal(Collection $catalog, int $metalId): bool
{
return $this->resolveMeltedProducts($catalog)->contains(
fn (Product $product) => (int) ($product->metal_id ?? 0) === (int) $metalId
&& $this->shouldShowInAssets($product)
);
}
/** فلزهایی که کاربر موجودی روی کیف محصول دارد — کارت آبشده جدا لازم نیست. */
private function metalIdsWithVisibleProductWallet(Collection $userWallets): array
{
$metalIds = [];
foreach ($userWallets as $walletLine) {
if ($walletLine->product_id === null || (float) $walletLine->gold <= 0) {
continue;
}
$product = $walletLine->product;
if (!$product || !$this->shouldShowInAssets($product)) {
continue;
}
$metalId = (int) ($product->metal_id ?? 0);
if ($metalId > 0) {
$metalIds[] = $metalId;
}
}
return array_values(array_unique($metalIds));
}
private function buildInventoryCards(Collection $userWallets): array
{
$cards = [];
@@ -121,7 +254,8 @@ class AssetSummaryService
Collection $userWallets,
?Wallet $mainWallet,
array $metalIds,
string $weightUnit
string $weightUnit,
Collection $catalog
): array {
if ($metalIds === []) {
return [];
@@ -152,7 +286,7 @@ class AssetSummaryService
);
}
$meltedGrams = $this->meltedGramsForMetal($mainWalletGrams, $metalId, $metalIds);
$meltedGrams = $this->meltedGramsForMetal($mainWalletGrams, $metalId, $metalIds, $catalog);
$productWeight = round(Controller::gramsToTradeUnit($productGrams), 3);
$meltedWeight = round(Controller::gramsToTradeUnit($meltedGrams), 3);
@@ -170,12 +304,20 @@ class AssetSummaryService
return $totals;
}
private function meltedGramsForMetal(float $mainWalletGrams, int $metalId, array $catalogMetalIds): float
{
private function meltedGramsForMetal(
float $mainWalletGrams,
int $metalId,
array $catalogMetalIds,
Collection $catalog
): float {
if ($mainWalletGrams <= 0) {
return 0.0;
}
if (!$this->hasVisibleMeltedProductForMetal($catalog, $metalId)) {
return 0.0;
}
if (count($catalogMetalIds) === 1) {
return (int) $catalogMetalIds[0] === (int) $metalId ? $mainWalletGrams : 0.0;
}
@@ -209,7 +351,7 @@ class AssetSummaryService
private function shouldShowInAssets(Product $product): bool
{
if (Product::hasShowInAssetsColumn()) {
return (bool) ($product->show_in_assets ?? true);
return (bool) ($product->show_in_assets ?? false);
}
return true;
+11 -1
View File
@@ -33,7 +33,17 @@ class ProductPriceService
}
$offsetPercent = self::offsetPercent($product);
$data = ['price' => self::adjustedTotal($basePrice, $baseProfit, $offsetPercent)];
$adjustedPrice = self::adjustedTotal($basePrice, $baseProfit, $offsetPercent);
if (
$adjustedPrice <= 0
&& Product::hasUseLastPriceIfZeroColumn()
&& ($product->use_last_price_if_zero ?? false)
) {
return;
}
$data = ['price' => $adjustedPrice];
if (\Illuminate\Support\Facades\Schema::hasColumn($product->getTable(), 'price_profit')) {
$data['price_profit'] = 0;
@@ -0,0 +1,42 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
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', 'show_in_assets')) {
Schema::table('products', function (Blueprint $table) {
if (Schema::hasColumn('products', 'show')) {
$table->boolean('show_in_assets')->default(false)->after('show');
} else {
$table->boolean('show_in_assets')->default(false);
}
});
} else {
DB::statement(
'ALTER TABLE `products` MODIFY COLUMN `show_in_assets` TINYINT(1) NOT NULL DEFAULT 0'
);
DB::table('products')->update(['show_in_assets' => 0]);
}
}
public function down(): void
{
if (!Schema::hasTable('products') || !Schema::hasColumn('products', 'show_in_assets')) {
return;
}
Schema::table('products', function (Blueprint $table) {
$table->dropColumn('show_in_assets');
});
}
};
@@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
if (!Schema::hasTable('products')) {
return;
}
if (!Schema::hasColumn('products', 'use_last_price_if_zero')) {
Schema::table('products', function (Blueprint $table) {
if (Schema::hasColumn('products', 'show_in_assets')) {
$table->boolean('use_last_price_if_zero')->default(false)->after('show_in_assets');
} else {
$table->boolean('use_last_price_if_zero')->default(false);
}
});
}
}
public function down(): void
{
if (!Schema::hasTable('products') || !Schema::hasColumn('products', 'use_last_price_if_zero')) {
return;
}
Schema::table('products', function (Blueprint $table) {
$table->dropColumn('use_last_price_if_zero');
});
}
};
+1 -1
View File
@@ -10,7 +10,7 @@ SET @db = DATABASE();
SET @table_name = 'products';
SET @column_name = 'show_in_assets';
SET @after_column = 'show';
SET @column_def = 'TINYINT(1) NOT NULL DEFAULT 1 COMMENT ''نمایش در صفحه دارایی‌ها''';
SET @column_def = 'TINYINT(1) NOT NULL DEFAULT 0 COMMENT ''نمایش در صفحه دارایی‌ها''';
SET @sql = IF(
(SELECT COUNT(*) FROM information_schema.TABLES
+20 -2
View File
@@ -15,11 +15,29 @@ SET @sql = IF(
IF(
(SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'show') > 0,
'ALTER TABLE `products` ADD COLUMN `show_in_assets` TINYINT(1) NOT NULL DEFAULT 1 COMMENT ''نمایش در صفحه دارایی‌ها'' AFTER `show`',
'ALTER TABLE `products` ADD COLUMN `show_in_assets` TINYINT(1) NOT NULL DEFAULT 1 COMMENT ''نمایش در صفحه دارایی‌ها'''
'ALTER TABLE `products` ADD COLUMN `show_in_assets` TINYINT(1) NOT NULL DEFAULT 0 COMMENT ''نمایش در صفحه دارایی‌ها'' AFTER `show`',
'ALTER TABLE `products` ADD COLUMN `show_in_assets` TINYINT(1) NOT NULL DEFAULT 0 COMMENT ''نمایش در صفحه دارایی‌ها'''
)
)
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- اگر ستون از قبل با DEFAULT 1 ساخته شده: پیش‌فرض جدول + رکوردهای فعلی
SET @sql = IF(
(SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'show_in_assets') > 0,
'ALTER TABLE `products` MODIFY COLUMN `show_in_assets` TINYINT(1) NOT NULL DEFAULT 0 COMMENT ''نمایش در صفحه دارایی‌ها''',
'SELECT ''skip: show_in_assets modify'' AS info'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
UPDATE `products`
SET `show_in_assets` = 0
WHERE EXISTS (
SELECT 1 FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'show_in_assets'
);
@@ -0,0 +1,34 @@
-- اگر provider در حالت اتوماتیک قیمت صفر بدهد: استفاده از آخرین قیمت DB (per product)
-- USE دیتابیس_خودتان;
SET @db = DATABASE();
SET @sql = IF(
(SELECT COUNT(*) FROM information_schema.TABLES
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products') = 0,
'SELECT ''skip: products table not found'' AS info',
IF(
(SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'use_last_price_if_zero') > 0,
'SELECT ''skip: use_last_price_if_zero exists'' AS info',
IF(
(SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'show_in_assets') > 0,
'ALTER TABLE `products` ADD COLUMN `use_last_price_if_zero` TINYINT(1) NOT NULL DEFAULT 0 COMMENT ''استفاده از آخرین قیمت وقتی provider صفر است'' AFTER `show_in_assets`',
'ALTER TABLE `products` ADD COLUMN `use_last_price_if_zero` TINYINT(1) NOT NULL DEFAULT 0 COMMENT ''استفاده از آخرین قیمت وقتی provider صفر است'''
)
)
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @sql = IF(
(SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'use_last_price_if_zero') > 0,
'ALTER TABLE `products` MODIFY COLUMN `use_last_price_if_zero` TINYINT(1) NOT NULL DEFAULT 0 COMMENT ''استفاده از آخرین قیمت وقتی provider صفر است''',
'SELECT ''skip: use_last_price_if_zero modify'' AS info'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
+549
View File
@@ -0,0 +1,549 @@
-- =============================================================================
-- بذر طلا (bazretala) — merge ماژولار settings + const
--
-- USE `ak`; -- یا نام دیتابیس بذر طلا
-- SOURCE bazre_tala_settings_update.sql;
--
-- اصول:
-- • value ردیف موجود overwrite نمی‌شود
-- • title_fa / type / can_edit / is_active به‌روز می‌شود
-- • INSERT کلیدهای modular + کلیدهای legacy (liman_* / const)
-- • اگر const از قبل پر است → فقط خالی‌های settings پر می‌شود
-- • DELETE ندارد — legacy می‌ماند تا خودتان پاک کنید
--
-- قبل از اجرا: بکاپ کامل
-- =============================================================================
START TRANSACTION;
SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE `settings`
MODIFY COLUMN `description` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL,
MODIFY COLUMN `title_fa` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL,
MODIFY COLUMN `type` VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL;
ALTER TABLE `const`
MODIFY COLUMN `title_fa` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL;
-- -----------------------------------------------------------------------------
-- قیمت — منبع و zaarbox / main_product
-- -----------------------------------------------------------------------------
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'price_provider', 'montzar', 'منبع قیمت', 1, 1, 'montzar | zaarbox | main_product | taban_gohar | etehadie'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'price_provider' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'main_product', '13', 'محصول آبشده (id یا reading_method)', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'main_product' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'zaarbox_api_url', 'https://price.zaarbox.ir/api/free', 'آدرس API تابلو Zaarbox', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'zaarbox_api_url' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'zaarbox_price_key', '', 'شناسه ردیف تابلو (key یا UUID)', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'zaarbox_price_key' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'chart_id', '', 'UUID نمودار Zaarbox', 1, 1, 'خالی = ca3800a0-1f57-3528-b963-178f9168e04f'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'chart_id' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'etehadie_api_url', 'http://109.122.246.48:4949/api/free', 'آدرس API اتحادیه', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'etehadie_api_url' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'main_product_price', 'false', 'دریافت قیمت از محصولات (legacy)', 1, 1, 'جایگزین: price_provider=main_product'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'main_product_price' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'tabanGohar_price', 'false', 'دریافت قیمت تابان گوهر', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'tabanGohar_price' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'show_last_price', 'true', 'نمایش آخرین قیمت DB وقتی API قطع است', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'show_last_price' LIMIT 1);
-- -----------------------------------------------------------------------------
-- Montzar / همکار (لیمان)
-- -----------------------------------------------------------------------------
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'montzar_price', 'false', 'دریافت قیمت از همکار', 1, 1, 'true یا price_provider=montzar'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_price' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'montzar_mobile', '', 'موبایل ورود API همکار', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_mobile' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'montzar_password', '', 'رمز ورود API همکار', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_password' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'montzar_product_id', '25', 'کد محصول همکار', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_product_id' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'montzar_base_url', 'https://limangold.ir', 'آدرس سرور همکار', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_base_url' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'montzar_token', '', 'توکن همکار (سیستم)', 0, 1, 'خودکار پر می‌شود'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_token' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'montzar_closed', 'false', 'بسته بودن سرویس همکار', 0, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_closed' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'montzar_open_buy', 'true', 'باز بودن خرید همکار', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_open_buy' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'montzar_open_sell', 'true', 'باز بودن فروش همکار', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_open_sell' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'montzar_diff', '0', 'اختلاف قیمت همکار (سیستم)', 0, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_diff' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'montzar_live_price', '0', 'قیمت لحظه‌ای همکار', 0, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_live_price' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'montzar_mazaneh', '0', 'مظنه همکار', 0, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_mazaneh' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'montzar_truly_buy_mazaneh', '0', 'مظنه خرید واقعی همکار', 0, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_truly_buy_mazaneh' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'montzar_truly_sell_mazaneh', '0', 'مظنه فروش واقعی همکار', 0, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_truly_sell_mazaneh' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'display_montzar', 'true', 'نمایش بلوک همکار در UI', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'display_montzar' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'liman_token', '', 'توکن لیمان (legacy)', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'liman_token' LIMIT 1);
-- -----------------------------------------------------------------------------
-- کارمزد نمایش و سفارش
-- -----------------------------------------------------------------------------
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'fee_single', '500000', 'اختلاف پایه نمایش (ریال)', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'fee_single' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'buy_fee', '500000', 'سود خرید نمایش', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'buy_fee' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'sell_fee', '500000', 'سود فروش نمایش', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'sell_fee' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'fee_cash', '500000', 'اختلاف ریالی سفارش (legacy)', 1, 1, 'zaarbox/main از buy_fee هم استفاده می‌شود'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'fee_cash' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'fee_service_charge_percentage', '0.005', 'درصد کارمزد سفارش', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'fee_service_charge_percentage' LIMIT 1);
-- -----------------------------------------------------------------------------
-- Jibit — settings
-- -----------------------------------------------------------------------------
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'jibit_verification', 'false', 'تأیید کارت بانکی با جیبیت', 1, 1, 'true/false'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'jibit_verification' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'register_jibit_verify', 'false', 'تأیید کدملی/موبایل در ثبت‌نام', 1, 1, 'true/false'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'register_jibit_verify' LIMIT 1);
-- -----------------------------------------------------------------------------
-- ساعات بسته بودن قیمت
-- -----------------------------------------------------------------------------
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'close_price', 'false', 'بستن قیمت در بازه زمانی', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'close_price' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'startDay', '10:00', 'شروع بازه معامله', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'startDay' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'endDay', '20:30', 'پایان بازه معامله', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'endDay' LIMIT 1);
-- -----------------------------------------------------------------------------
-- const — شمارنده و موارد پرکاربرد (جدول const یا cnt)
-- -----------------------------------------------------------------------------
INSERT INTO `const` (`key`, `value`, `title_fa`)
SELECT 'jibit_counter', '0', 'شمارنده درخواست جیبیت'
WHERE NOT EXISTS (SELECT 1 FROM `const` WHERE `key` = 'jibit_counter' LIMIT 1);
INSERT INTO `const` (`key`, `value`, `title_fa`)
SELECT 'main_product', '13', 'محصول آبشده (پشتیبان settings)'
WHERE NOT EXISTS (SELECT 1 FROM `const` WHERE `key` = 'main_product' LIMIT 1);
INSERT INTO `const` (`key`, `value`, `title_fa`)
SELECT 'limited_price', '0', 'سقف واریز اولیه'
WHERE NOT EXISTS (SELECT 1 FROM `const` WHERE `key` = 'limited_price' LIMIT 1);
INSERT INTO `const` (`key`, `value`, `title_fa`)
SELECT 'liman', '', 'توکن لیمان (legacy const)'
WHERE NOT EXISTS (SELECT 1 FROM `const` WHERE `key` = 'liman' LIMIT 1);
INSERT INTO `const` (`key`, `value`, `title_fa`)
SELECT 'liman_diff', '0', 'اختلاف لیمان'
WHERE NOT EXISTS (SELECT 1 FROM `const` WHERE `key` = 'liman_diff' LIMIT 1);
INSERT INTO `const` (`key`, `value`, `title_fa`)
SELECT 'liman_price', '0', 'قیمت گرم لیمان'
WHERE NOT EXISTS (SELECT 1 FROM `const` WHERE `key` = 'liman_price' LIMIT 1);
INSERT INTO `const` (`key`, `value`, `title_fa`)
SELECT 'liman_mazaneh', '0', 'مظنه لیمان'
WHERE NOT EXISTS (SELECT 1 FROM `const` WHERE `key` = 'liman_mazaneh' LIMIT 1);
INSERT INTO `const` (`key`, `value`, `title_fa`)
SELECT 'liman_truly_buy_mazaneh', '0', 'مظنه خرید واقعی لیمان'
WHERE NOT EXISTS (SELECT 1 FROM `const` WHERE `key` = 'liman_truly_buy_mazaneh' LIMIT 1);
INSERT INTO `const` (`key`, `value`, `title_fa`)
SELECT 'liman_truly_sell_mazaneh', '0', 'مظنه فروش واقعی لیمان'
WHERE NOT EXISTS (SELECT 1 FROM `const` WHERE `key` = 'liman_truly_sell_mazaneh' LIMIT 1);
INSERT INTO `const` (`key`, `value`, `title_fa`)
SELECT 'log', '{}', 'لاگ محصول لیمان'
WHERE NOT EXISTS (SELECT 1 FROM `const` WHERE `key` = 'log' LIMIT 1);
INSERT INTO `const` (`key`, `value`, `title_fa`)
SELECT 'liman_closed', 'false', 'بسته بودن لیمان'
WHERE NOT EXISTS (SELECT 1 FROM `const` WHERE `key` = 'liman_closed' LIMIT 1);
INSERT INTO `const` (`key`, `value`, `title_fa`)
SELECT 'liman_order_response', 'null', 'پاسخ سفارش لیمان'
WHERE NOT EXISTS (SELECT 1 FROM `const` WHERE `key` = 'liman_order_response' LIMIT 1);
INSERT INTO `const` (`key`, `value`, `title_fa`)
SELECT 'liman_password', '', 'رمز لیمان'
WHERE NOT EXISTS (SELECT 1 FROM `const` WHERE `key` = 'liman_password' LIMIT 1);
INSERT INTO `const` (`key`, `value`, `title_fa`)
SELECT 'liman_mobile', '', 'موبایل لیمان'
WHERE NOT EXISTS (SELECT 1 FROM `const` WHERE `key` = 'liman_mobile' LIMIT 1);
INSERT INTO `const` (`key`, `value`, `title_fa`)
SELECT 'liman_open_buy', 'true', 'باز بودن خرید لیمان'
WHERE NOT EXISTS (SELECT 1 FROM `const` WHERE `key` = 'liman_open_buy' LIMIT 1);
INSERT INTO `const` (`key`, `value`, `title_fa`)
SELECT 'liman_open_sell', 'true', 'باز بودن فروش لیمان'
WHERE NOT EXISTS (SELECT 1 FROM `const` WHERE `key` = 'liman_open_sell' LIMIT 1);
INSERT INTO `const` (`key`, `value`, `title_fa`)
SELECT 'app_closed', 'false', 'بسته بودن اپ'
WHERE NOT EXISTS (SELECT 1 FROM `const` WHERE `key` = 'app_closed' LIMIT 1);
INSERT INTO `const` (`key`, `value`, `title_fa`)
SELECT 'last_order_log', '', 'آخرین پاسخ سفارش (legacy)'
WHERE NOT EXISTS (SELECT 1 FROM `const` WHERE `key` = 'last_order_log' LIMIT 1);
-- -----------------------------------------------------------------------------
-- settings — کلیدهای legacy (کنار montzar_*)
-- -----------------------------------------------------------------------------
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`, `type`)
SELECT 'liman_password', '', 'رمز لیمان (legacy)', 1, 1, NULL, 'text'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'liman_password' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`, `type`)
SELECT 'liman_mobile', '', 'موبایل لیمان (legacy)', 1, 1, NULL, 'text'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'liman_mobile' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`, `type`)
SELECT 'do_send_liman', 'false', 'ارسال سفارش به لیمان (legacy)', 1, 1, NULL, 'switch'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'do_send_liman' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`, `type`)
SELECT 'price_liman', 'false', 'دریافت قیمت از لیمان (legacy)', 1, 1, NULL, 'switch'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'price_liman' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`, `type`)
SELECT 'montzar_order_response', '[]', 'پاسخ سفارش همکار', 0, 1, NULL, 'longtext'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_order_response' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`, `type`)
SELECT 'montzar_last_product_log', '{}', 'لاگ محصول همکار', 0, 1, NULL, 'longtext'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_last_product_log' LIMIT 1);
-- -----------------------------------------------------------------------------
-- const پر شده → settings خالی (مهاجرت؛ value پر overwrite نمی‌شود)
-- -----------------------------------------------------------------------------
UPDATE `settings` s
INNER JOIN `const` c ON c.`key` = 'liman'
SET s.`value` = c.`value`, s.`updated_at` = NOW()
WHERE s.`key` IN ('montzar_token', 'liman_token')
AND (s.`value` IS NULL OR TRIM(s.`value`) = '');
UPDATE `settings` s
INNER JOIN `const` c ON c.`key` = 'liman_diff'
SET s.`value` = c.`value`, s.`updated_at` = NOW()
WHERE s.`key` = 'montzar_diff'
AND (s.`value` IS NULL OR TRIM(s.`value`) = '' OR s.`value` = '0');
UPDATE `settings` s
INNER JOIN `const` c ON c.`key` = 'liman_price'
SET s.`value` = c.`value`, s.`updated_at` = NOW()
WHERE s.`key` = 'montzar_live_price'
AND (s.`value` IS NULL OR TRIM(s.`value`) = '' OR s.`value` = '0');
UPDATE `settings` s
INNER JOIN `const` c ON c.`key` = 'liman_mazaneh'
SET s.`value` = c.`value`, s.`updated_at` = NOW()
WHERE s.`key` = 'montzar_mazaneh'
AND (s.`value` IS NULL OR TRIM(s.`value`) = '' OR s.`value` = '0');
UPDATE `settings` s
INNER JOIN `const` c ON c.`key` = 'liman_truly_buy_mazaneh'
SET s.`value` = c.`value`, s.`updated_at` = NOW()
WHERE s.`key` = 'montzar_truly_buy_mazaneh'
AND (s.`value` IS NULL OR TRIM(s.`value`) = '' OR s.`value` = '0');
UPDATE `settings` s
INNER JOIN `const` c ON c.`key` = 'liman_truly_sell_mazaneh'
SET s.`value` = c.`value`, s.`updated_at` = NOW()
WHERE s.`key` = 'montzar_truly_sell_mazaneh'
AND (s.`value` IS NULL OR TRIM(s.`value`) = '' OR s.`value` = '0');
UPDATE `settings` s
INNER JOIN `const` c ON c.`key` = 'log'
SET s.`value` = c.`value`, s.`updated_at` = NOW()
WHERE s.`key` = 'montzar_last_product_log'
AND (s.`value` IS NULL OR TRIM(s.`value`) = '' OR s.`value` = '{}');
UPDATE `settings` s
INNER JOIN `const` c ON c.`key` = 'liman_closed'
SET s.`value` = c.`value`, s.`updated_at` = NOW()
WHERE s.`key` = 'montzar_closed'
AND (s.`value` IS NULL OR TRIM(s.`value`) = '');
UPDATE `settings` s
INNER JOIN `const` c ON c.`key` = 'liman_order_response'
SET s.`value` = c.`value`, s.`updated_at` = NOW()
WHERE s.`key` = 'montzar_order_response'
AND (s.`value` IS NULL OR TRIM(s.`value`) = '' OR s.`value` = '[]');
UPDATE `settings` s
INNER JOIN `const` c ON c.`key` = 'liman_password'
SET s.`value` = c.`value`, s.`updated_at` = NOW()
WHERE s.`key` IN ('montzar_password', 'liman_password')
AND (s.`value` IS NULL OR TRIM(s.`value`) = '');
UPDATE `settings` s
INNER JOIN `const` c ON c.`key` = 'liman_mobile'
SET s.`value` = c.`value`, s.`updated_at` = NOW()
WHERE s.`key` IN ('montzar_mobile', 'liman_mobile')
AND (s.`value` IS NULL OR TRIM(s.`value`) = '');
UPDATE `settings` s
INNER JOIN `const` c ON c.`key` = 'liman_open_buy'
SET s.`value` = c.`value`, s.`updated_at` = NOW()
WHERE s.`key` = 'montzar_open_buy'
AND (s.`value` IS NULL OR TRIM(s.`value`) = '');
UPDATE `settings` s
INNER JOIN `const` c ON c.`key` = 'liman_open_sell'
SET s.`value` = c.`value`, s.`updated_at` = NOW()
WHERE s.`key` = 'montzar_open_sell'
AND (s.`value` IS NULL OR TRIM(s.`value`) = '');
UPDATE `settings` s
INNER JOIN `const` c ON c.`key` = 'main_product'
SET s.`value` = c.`value`, s.`updated_at` = NOW()
WHERE s.`key` = 'main_product'
AND (s.`value` IS NULL OR TRIM(s.`value`) = '');
-- -----------------------------------------------------------------------------
-- API خارجی Node (HMAC) — NODE_CLIENT_ID / NODE_SHARED_SECRET
-- -----------------------------------------------------------------------------
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'node_client_id', '', 'شناسه کلاینت API خارجی (X-Client-Id)', 1, 1, 'fallback: .env NODE_CLIENT_ID'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'node_client_id' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'node_shared_secret', '', 'کلید امضای HMAC API خارجی', 1, 1, 'fallback: .env NODE_SHARED_SECRET'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'node_shared_secret' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'external_order_api_enabled', 'false', 'API سفارش خارجی (get_wallet / order)', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'external_order_api_enabled' LIMIT 1);
-- -----------------------------------------------------------------------------
-- title_fa + type (value دست نخورده) — همه کلیدهای modular + legacy
-- -----------------------------------------------------------------------------
UPDATE `settings` SET `title_fa` = 'نام فارسی', `type` = 'text', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'name_fa';
UPDATE `settings` SET `title_fa` = 'نام انگلیسی', `type` = 'text', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'name_en';
UPDATE `settings` SET `title_fa` = 'آدرس اپ (کاربر)', `type` = 'text', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'app_url';
UPDATE `settings` SET `title_fa` = 'آدرس پایه سرور', `type` = 'text', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'bace_url';
UPDATE `settings` SET `title_fa` = 'لوگوی ورود', `type` = 'text', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'logo_login';
UPDATE `settings` SET `title_fa` = 'لوگوی ثبت‌نام', `type` = 'text', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'logo_register';
UPDATE `settings` SET `title_fa` = 'آدرس پنل ادمین', `type` = 'text', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'admin_url';
UPDATE `settings` SET `title_fa` = 'عنوان PWA', `type` = 'text', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'title_pwa';
UPDATE `settings` SET `title_fa` = 'عنوان favicon', `type` = 'text', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'title_fav';
UPDATE `settings` SET `title_fa` = 'متن قوانین', `type` = 'longtext', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'text_rule';
UPDATE `settings` SET `title_fa` = 'متن درباره ما', `type` = 'longtext', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'text_about';
UPDATE `settings` SET `title_fa` = 'نوع فلز', `type` = 'text', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'metal_type';
UPDATE `settings` SET `title_fa` = 'توکن ته‌حساب', `type` = 'text', `is_active` = COALESCE(`is_active`, 1), `can_edit` = 0 WHERE `key` = 'tahesab_token';
UPDATE `settings` SET `title_fa` = 'دیتابیس ته‌حساب', `type` = 'text', `is_active` = COALESCE(`is_active`, 1), `can_edit` = 0 WHERE `key` = 'tahesab_db';
UPDATE `settings` SET `title_fa` = 'حساب بانکی ته‌حساب', `type` = 'text', `is_active` = COALESCE(`is_active`, 1), `can_edit` = 0 WHERE `key` = 'tahesab_bank_account';
UPDATE `settings` SET `title_fa` = 'صفحه کسب درآمد', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'has_page_earn_money';
UPDATE `settings` SET `title_fa` = 'صفحه صندوق', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'has_page_fund';
UPDATE `settings` SET `title_fa` = 'صفحه مجوزها', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'has_page_permission';
UPDATE `settings` SET `title_fa` = 'صفحه هشدار قیمت', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'has_page_price_trigger';
UPDATE `settings` SET `title_fa` = 'صفحه طلای فیزیکی', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'has_page_physical_gold';
UPDATE `settings` SET `title_fa` = 'رنگ اصلی', `type` = 'text', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'color_primary';
UPDATE `settings` SET `title_fa` = 'رنگ ثانویه', `type` = 'text', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'color_secondary';
UPDATE `settings` SET `title_fa` = 'چت', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'has_chat';
UPDATE `settings` SET `title_fa` = 'آدرس API سرور', `type` = 'text', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'server_url';
UPDATE `settings` SET `title_fa` = 'کلید اپ', `type` = 'text', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'key';
UPDATE `settings` SET `title_fa` = 'توکن بات تلگرام', `type` = 'text', `is_active` = COALESCE(`is_active`, 1), `can_edit` = 0 WHERE `key` = 'telegram_bot_token';
UPDATE `settings` SET `title_fa` = 'توکن بات بله', `type` = 'text', `is_active` = COALESCE(`is_active`, 1), `can_edit` = 0 WHERE `key` = 'bale_bot_token';
UPDATE `settings` SET `title_fa` = 'پیامک شارژ ادمین', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'charge_notif';
UPDATE `settings` SET `title_fa` = 'پیامک گروهی', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'group_sms';
UPDATE `settings` SET `title_fa` = 'فعال‌سازی خودکار کاربر', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'auto_active_customer';
UPDATE `settings` SET `title_fa` = 'ثبت‌نام باز', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'open_register';
UPDATE `settings` SET `title_fa` = 'ارسال اسناد به ته‌حساب', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'send_to_tahesab';
UPDATE `settings` SET `title_fa` = 'کد معرف اجباری (legacy)', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'is_requaire_referral';
UPDATE `settings` SET `title_fa` = 'کد معرف', `type` = 'select', `is_active` = COALESCE(`is_active`, 1), `description` = 'required = اجباری|required,' WHERE `key` = 'referral_id';
UPDATE `settings` SET `title_fa` = 'محدودیت دعوت', `type` = 'number', `is_active` = COALESCE(`is_active`, 0) WHERE `key` = 'referral_limit';
UPDATE `settings` SET `title_fa` = 'پاداش معرف', `type` = 'number', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'gift_for_referrer';
UPDATE `settings` SET `title_fa` = 'پاداش معرفی‌شده', `type` = 'number', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'gift_for_referral';
UPDATE `settings` SET `title_fa` = 'حداقل برداشت', `type` = 'number', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'min_withdraw';
UPDATE `settings` SET `title_fa` = 'حداقل اولین خرید', `type` = 'number', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'min_first_buy';
UPDATE `settings` SET `title_fa` = 'حداقل فروش', `type` = 'number', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'minimum_sell';
UPDATE `settings` SET `title_fa` = 'کارمزد رایگان (تعداد)', `type` = 'number', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'fee_free';
UPDATE `settings` SET `title_fa` = 'کارمزد درصدی (legacy)', `type` = 'number', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'fee';
UPDATE `settings` SET `title_fa` = 'کارمزد درصدی', `type` = 'number', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'fee_service_charge_percentage';
UPDATE `settings` SET `title_fa` = 'کارمزد درصدی (alias)', `type` = 'number', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'service_charge_percentage';
UPDATE `settings` SET `title_fa` = 'کارمزد ریالی', `type` = 'number', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'fee_cash';
UPDATE `settings` SET `title_fa` = 'اختلاف با قیمت واقعی', `type` = 'number', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'fee_single';
UPDATE `settings` SET `title_fa` = 'سود خرید', `type` = 'number', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'buy_fee';
UPDATE `settings` SET `title_fa` = 'سود فروش', `type` = 'number', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'sell_fee';
UPDATE `settings` SET `title_fa` = 'منبع قیمت', `type` = 'select', `is_active` = COALESCE(`is_active`, 1), `can_edit` = 1, `description` = 'montzar,zaarbox,main_product,etehadie,taban_gohar' WHERE `key` = 'price_provider';
UPDATE `settings` SET `title_fa` = 'منبع قیمت (legacy)', `type` = 'text', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'price_primary_source';
UPDATE `settings` SET `title_fa` = 'محصول آبشده', `type` = 'text', `is_active` = COALESCE(`is_active`, 1), `can_edit` = 1 WHERE `key` = 'main_product';
UPDATE `settings` SET `title_fa` = 'آدرس API Zaarbox', `type` = 'text', `is_active` = COALESCE(`is_active`, 1), `can_edit` = 1 WHERE `key` = 'zaarbox_api_url';
UPDATE `settings` SET `title_fa` = 'شناسه ردیف Zaarbox', `type` = 'text', `is_active` = COALESCE(`is_active`, 1), `can_edit` = 1 WHERE `key` = 'zaarbox_price_key';
UPDATE `settings` SET `title_fa` = 'UUID نمودار Zaarbox', `type` = 'text', `is_active` = COALESCE(`is_active`, 1), `can_edit` = 1 WHERE `key` = 'chart_id';
UPDATE `settings` SET `title_fa` = 'آدرس API اتحادیه', `type` = 'text', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'etehadie_api_url';
UPDATE `settings` SET `title_fa` = 'دریافت قیمت از محصولات', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'main_product_price';
UPDATE `settings` SET `title_fa` = 'دریافت قیمت تابان‌گوهر', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'tabanGohar_price';
UPDATE `settings` SET `title_fa` = 'نشان دادن آخرین قیمت', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'show_last_price';
UPDATE `settings` SET `title_fa` = 'بستن قیمت در ساعات مشخص', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'close_price';
UPDATE `settings` SET `title_fa` = 'ساعت شروع', `type` = 'text', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'startDay';
UPDATE `settings` SET `title_fa` = 'ساعت پایان', `type` = 'text', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'endDay';
UPDATE `settings` SET `title_fa` = 'بیشترین قیمت امروز', `type` = 'number', `is_active` = COALESCE(`is_active`, 1), `can_edit` = 0 WHERE `key` = 'up_price';
UPDATE `settings` SET `title_fa` = 'کمترین قیمت امروز', `type` = 'number', `is_active` = COALESCE(`is_active`, 1), `can_edit` = 0 WHERE `key` = 'down_price';
UPDATE `settings` SET `title_fa` = 'تاریخ min/max روز', `type` = 'text', `is_active` = COALESCE(`is_active`, 1), `can_edit` = 0 WHERE `key` = 'price_extreme_date';
UPDATE `settings` SET `title_fa` = 'دریافت قیمت از همکار', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'montzar_price';
UPDATE `settings` SET `title_fa` = 'نمایش بلوک همکار', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'display_montzar';
UPDATE `settings` SET `title_fa` = 'شماره همراه همکار', `type` = 'text', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'montzar_mobile';
UPDATE `settings` SET `title_fa` = 'کلمه عبور همکار', `type` = 'text', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'montzar_password';
UPDATE `settings` SET `title_fa` = 'کد محصول همکار', `type` = 'number', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'montzar_product_id';
UPDATE `settings` SET `title_fa` = 'آدرس API همکار', `type` = 'text', `is_active` = COALESCE(`is_active`, 1), `can_edit` = 0 WHERE `key` = 'montzar_base_url';
UPDATE `settings` SET `title_fa` = 'توکن همکار', `type` = 'text', `is_active` = COALESCE(`is_active`, 1), `can_edit` = 0 WHERE `key` = 'montzar_token';
UPDATE `settings` SET `title_fa` = 'بسته بودن سرویس همکار', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1), `can_edit` = 0 WHERE `key` = 'montzar_closed';
UPDATE `settings` SET `title_fa` = 'باز بودن خرید همکار', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1), `can_edit` = 0 WHERE `key` = 'montzar_open_buy';
UPDATE `settings` SET `title_fa` = 'باز بودن فروش همکار', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1), `can_edit` = 0 WHERE `key` = 'montzar_open_sell';
UPDATE `settings` SET `title_fa` = 'اختلاف قیمت همکار', `type` = 'text', `is_active` = COALESCE(`is_active`, 1), `can_edit` = 0 WHERE `key` = 'montzar_diff';
UPDATE `settings` SET `title_fa` = 'قیمت لحظه‌ای همکار', `type` = 'text', `is_active` = COALESCE(`is_active`, 1), `can_edit` = 0 WHERE `key` = 'montzar_live_price';
UPDATE `settings` SET `title_fa` = 'مظنه همکار', `type` = 'text', `is_active` = COALESCE(`is_active`, 1), `can_edit` = 0 WHERE `key` = 'montzar_mazaneh';
UPDATE `settings` SET `title_fa` = 'مظنه خرید واقعی همکار', `type` = 'text', `is_active` = COALESCE(`is_active`, 1), `can_edit` = 0 WHERE `key` = 'montzar_truly_buy_mazaneh';
UPDATE `settings` SET `title_fa` = 'مظنه فروش واقعی همکار', `type` = 'text', `is_active` = COALESCE(`is_active`, 1), `can_edit` = 0 WHERE `key` = 'montzar_truly_sell_mazaneh';
UPDATE `settings` SET `title_fa` = 'پاسخ سفارش همکار', `type` = 'longtext', `is_active` = COALESCE(`is_active`, 1), `can_edit` = 0 WHERE `key` = 'montzar_order_response';
UPDATE `settings` SET `title_fa` = 'لاگ محصول همکار', `type` = 'longtext', `is_active` = COALESCE(`is_active`, 1), `can_edit` = 0 WHERE `key` = 'montzar_last_product_log';
UPDATE `settings` SET `title_fa` = 'توکن لیمان (legacy)', `type` = 'text', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'liman_token';
UPDATE `settings` SET `title_fa` = 'رمز لیمان (legacy)', `type` = 'text', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'liman_password';
UPDATE `settings` SET `title_fa` = 'موبایل لیمان (legacy)', `type` = 'text', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'liman_mobile';
UPDATE `settings` SET `title_fa` = 'ارسال سفارش به لیمان', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'do_send_liman';
UPDATE `settings` SET `title_fa` = 'دریافت قیمت از لیمان', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'price_liman';
UPDATE `settings` SET `title_fa` = 'تأیید کارت با جیبیت', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'jibit_verification';
UPDATE `settings` SET `title_fa` = 'تأیید کد ملی در ثبت‌نام', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'register_jibit_verify';
UPDATE `settings` SET `title_fa` = 'بروزرسانی قیمت در لیست', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'product_update_price_on_list';
UPDATE `settings` SET `title_fa` = 'باز/بسته خودکار محصول در لیست', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'product_auto_close_open_on_list';
UPDATE `settings` SET `title_fa` = 'شناسه کلاینت API خارجی', `type` = 'text', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'node_client_id';
UPDATE `settings` SET `title_fa` = 'کلید HMAC API خارجی', `type` = 'text', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'node_shared_secret';
UPDATE `settings` SET `title_fa` = 'API سفارش خارجی', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'external_order_api_enabled';
UPDATE `settings` SET `title_fa` = 'پیام‌رسان پشتیبانی', `type` = 'select', `is_active` = COALESCE(`is_active`, 1), `description` = 'bale,telegram,whatsapp,rubika,eitaa,soroush' WHERE `key` = 'support_messenger';
UPDATE `settings` SET `title_fa` = 'شناسه پشتیبانی', `type` = 'text', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'support_messenger_id';
UPDATE `settings` SET `title_fa` = 'متن پشتیبانی', `type` = 'text', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'support_messenger_text';
UPDATE `settings` SET `title_fa` = 'نام Montify', `type` = 'text', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'montify_name';
UPDATE `settings` SET `title_fa` = 'API سود طلا', `type` = 'switch', `is_active` = COALESCE(`is_active`, 0) WHERE `key` = 'profit_gold_api_enabled';
-- const — عنوان فارسی
UPDATE `const` SET `title_fa` = 'شمارنده جیبیت' WHERE `key` = 'jibit_counter' AND (`title_fa` IS NULL OR TRIM(`title_fa`) = '');
UPDATE `const` SET `title_fa` = 'محصول آبشده (fallback)' WHERE `key` = 'main_product' AND (`title_fa` IS NULL OR TRIM(`title_fa`) = '');
UPDATE `const` SET `title_fa` = 'سقف واریز اولیه' WHERE `key` = 'limited_price' AND (`title_fa` IS NULL OR TRIM(`title_fa`) = '');
UPDATE `const` SET `title_fa` = 'توکن لیمان (legacy)' WHERE `key` = 'liman' AND (`title_fa` IS NULL OR TRIM(`title_fa`) = '');
UPDATE `const` SET `title_fa` = 'اختلاف لیمان' WHERE `key` = 'liman_diff' AND (`title_fa` IS NULL OR TRIM(`title_fa`) = '');
UPDATE `const` SET `title_fa` = 'قیمت گرم لیمان' WHERE `key` = 'liman_price' AND (`title_fa` IS NULL OR TRIM(`title_fa`) = '');
UPDATE `const` SET `title_fa` = 'مظنه لیمان' WHERE `key` = 'liman_mazaneh' AND (`title_fa` IS NULL OR TRIM(`title_fa`) = '');
UPDATE `const` SET `title_fa` = 'بسته بودن لیمان' WHERE `key` = 'liman_closed' AND (`title_fa` IS NULL OR TRIM(`title_fa`) = '');
UPDATE `const` SET `title_fa` = 'لاگ محصول لیمان' WHERE `key` = 'log' AND (`title_fa` IS NULL OR TRIM(`title_fa`) = '');
UPDATE `const` SET `title_fa` = 'بسته بودن اپ' WHERE `key` = 'app_closed' AND (`title_fa` IS NULL OR TRIM(`title_fa`) = '');
UPDATE `const` SET `title_fa` = 'لاگ آخرین سفارش' WHERE `key` = 'last_order_log' AND (`title_fa` IS NULL OR TRIM(`title_fa`) = '');
-- type پیش‌فرض برای ردیف‌های بدون type
UPDATE `settings` SET `type` = 'text' WHERE (`type` IS NULL OR TRIM(`type`) = '') AND `key` NOT IN (
'montzar_order_response', 'montzar_last_product_log', 'text_rule', 'text_about'
);
-- =============================================================================
-- products — محدودیت مبلغ سفارش (ستون‌های جدول products؛ مقدار از پنل ادمین)
-- patch: database/sql/add_product_order_limit_columns.sql
-- =============================================================================
SET @db = DATABASE();
SET @sql = IF(
(SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'order_limit_enabled') = 0,
'ALTER TABLE `products` ADD COLUMN `order_limit_enabled` TINYINT(1) NOT NULL DEFAULT 0 AFTER `percent_fee_buy`',
'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @sql = IF(
(SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'min_order_cash') = 0,
'ALTER TABLE `products` ADD COLUMN `min_order_cash` BIGINT UNSIGNED NULL DEFAULT NULL AFTER `order_limit_enabled`',
'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @sql = IF(
(SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'max_order_cash') = 0,
'ALTER TABLE `products` ADD COLUMN `max_order_cash` BIGINT UNSIGNED NULL DEFAULT NULL AFTER `min_order_cash`',
'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
COMMIT;
SELECT 'bazre_tala_settings_update.sql finished' AS status;
-- بذر طلا: valueهای اختصاصی (name_fa، price_provider، montzar_* و ...) از پنل تنظیم می‌شود.
-- حذف legacy (وقتی بک‌اند قدیمی خاموش شد): goldali_cleanup_legacy_keys.sql
+48 -2
View File
@@ -21,8 +21,8 @@ SET @sql = IF(
IF(
(SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'show') > 0,
'ALTER TABLE `products` ADD COLUMN `show_in_assets` TINYINT(1) NOT NULL DEFAULT 1 COMMENT ''نمایش در صفحه دارایی‌ها'' AFTER `show`',
'ALTER TABLE `products` ADD COLUMN `show_in_assets` TINYINT(1) NOT NULL DEFAULT 1 COMMENT ''نمایش در صفحه دارایی‌ها'''
'ALTER TABLE `products` ADD COLUMN `show_in_assets` TINYINT(1) NOT NULL DEFAULT 0 COMMENT ''نمایش در صفحه دارایی‌ها'' AFTER `show`',
'ALTER TABLE `products` ADD COLUMN `show_in_assets` TINYINT(1) NOT NULL DEFAULT 0 COMMENT ''نمایش در صفحه دارایی‌ها'''
),
'SELECT ''skip products.show_in_assets'' AS info'
);
@@ -30,6 +30,49 @@ PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @sql = IF(
(SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'show_in_assets') > 0,
'ALTER TABLE `products` MODIFY COLUMN `show_in_assets` TINYINT(1) NOT NULL DEFAULT 0 COMMENT ''نمایش در صفحه دارایی‌ها''',
'SELECT ''skip products.show_in_assets modify'' AS info'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- یک‌بار برای اصلاح سرورهایی که قبلاً DEFAULT 1 داشتند:
-- UPDATE `products` SET `show_in_assets` = 0;
-- ---------------------------------------------------------------------------
-- products.use_last_price_if_zero (fallback وقتی provider صفر است)
-- ---------------------------------------------------------------------------
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 = 'use_last_price_if_zero') = 0,
IF(
(SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'show_in_assets') > 0,
'ALTER TABLE `products` ADD COLUMN `use_last_price_if_zero` TINYINT(1) NOT NULL DEFAULT 0 COMMENT ''استفاده از آخرین قیمت وقتی provider صفر است'' AFTER `show_in_assets`',
'ALTER TABLE `products` ADD COLUMN `use_last_price_if_zero` TINYINT(1) NOT NULL DEFAULT 0 COMMENT ''استفاده از آخرین قیمت وقتی provider صفر است'''
),
'SELECT ''skip products.use_last_price_if_zero'' AS info'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @sql = IF(
(SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'use_last_price_if_zero') > 0,
'ALTER TABLE `products` MODIFY COLUMN `use_last_price_if_zero` TINYINT(1) NOT NULL DEFAULT 0 COMMENT ''استفاده از آخرین قیمت وقتی provider صفر است''',
'SELECT ''skip products.use_last_price_if_zero modify'' AS info'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- ---------------------------------------------------------------------------
-- products — محدودیت مبلغ سفارش
-- ---------------------------------------------------------------------------
@@ -254,5 +297,8 @@ AND NOT EXISTS (
-- ---------------------------------------------------------------------------
-- پایان — برای بورس‌مس (اختیاری، جدا اجرا کنید):
-- UPDATE `settings` SET `value` = 'کیلوگرم' WHERE `key` = 'unit';
--
-- بذر طلا — merge settings + const (modular + legacy):
-- SOURCE bazre_tala_settings_update.sql;
-- ---------------------------------------------------------------------------
SELECT 'deploy_safe_schema.sql finished' AS status;
@@ -0,0 +1,23 @@
-- فعال‌سازی «نمایش در صفحه دارایی‌ها» برای محصول آبشده اصلی
-- بعد از migration که همه را 0 کرده — فقط محصول main_product و دسته آبشده
-- USE دیتابیس_خودتان;
SET @db = DATABASE();
UPDATE `products`
SET `show_in_assets` = 1
WHERE EXISTS (
SELECT 1 FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'show_in_assets'
)
AND TRIM(`group_type`) = 'آبشده';
UPDATE `products` p
INNER JOIN `settings` s ON s.`key` = 'main_product'
AND s.`value` REGEXP '^[0-9]+$'
AND p.`id` = CAST(s.`value` AS UNSIGNED)
SET p.`show_in_assets` = 1
WHERE EXISTS (
SELECT 1 FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'show_in_assets'
);
-278
View File
@@ -1,278 +0,0 @@
-- =============================================================================
-- کاتالوگ واحد تنظیمات — ابشده‌خانگی / گلد علی / montzar / zaarbox
--
-- • ردیف موجود: value عوض نمی‌شود؛ title_fa و can_edit به‌روز می‌شود
-- • ردیف جدید: INSERT با مقدار پیش‌فرض خالی/false
-- • jibit_counter در جدول const است (نه settings)
--
-- قبل از اجرا: USE دیتابیس پروژه + بکاپ
-- =============================================================================
START TRANSACTION;
-- helper: فقط عنوان و can_edit را برای کلیدهای موجود هماهنگ کن
-- (value دست نخورده)
-- -----------------------------------------------------------------------------
-- قیمت — منبع و zaarbox / main_product
-- -----------------------------------------------------------------------------
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'price_provider', 'montzar', 'منبع قیمت', 1, 1, 'montzar | zaarbox | main_product | taban_gohar | etehadie'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'price_provider' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'main_product', '13', 'محصول آبشده (id یا reading_method)', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'main_product' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'zaarbox_api_url', 'https://price.zaarbox.ir/api/free', 'آدرس API تابلو Zaarbox', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'zaarbox_api_url' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'zaarbox_price_key', '', 'شناسه ردیف تابلو (key یا UUID)', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'zaarbox_price_key' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'chart_id', '', 'UUID نمودار Zaarbox', 1, 1, 'خالی = ca3800a0-1f57-3528-b963-178f9168e04f'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'chart_id' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'etehadie_api_url', 'http://109.122.246.48:4949/api/free', 'آدرس API اتحادیه', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'etehadie_api_url' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'main_product_price', 'false', 'دریافت قیمت از محصولات (legacy)', 1, 1, 'جایگزین: price_provider=main_product'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'main_product_price' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'tabanGohar_price', 'false', 'دریافت قیمت تابان گوهر', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'tabanGohar_price' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'show_last_price', 'true', 'نمایش آخرین قیمت DB وقتی API قطع است', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'show_last_price' LIMIT 1);
-- -----------------------------------------------------------------------------
-- Montzar / همکار (لیمان)
-- -----------------------------------------------------------------------------
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'montzar_price', 'false', 'دریافت قیمت از همکار', 1, 1, 'true یا price_provider=montzar'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_price' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'montzar_mobile', '', 'موبایل ورود API همکار', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_mobile' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'montzar_password', '', 'رمز ورود API همکار', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_password' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'montzar_product_id', '25', 'کد محصول همکار', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_product_id' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'montzar_base_url', 'https://limangold.ir', 'آدرس سرور همکار', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_base_url' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'montzar_token', '', 'توکن همکار (سیستم)', 0, 1, 'خودکار پر می‌شود'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_token' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'montzar_closed', 'false', 'بسته بودن سرویس همکار', 0, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_closed' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'montzar_open_buy', 'true', 'باز بودن خرید همکار', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_open_buy' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'montzar_open_sell', 'true', 'باز بودن فروش همکار', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_open_sell' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'montzar_diff', '0', 'اختلاف قیمت همکار (سیستم)', 0, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_diff' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'montzar_live_price', '0', 'قیمت لحظه‌ای همکار', 0, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_live_price' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'montzar_mazaneh', '0', 'مظنه همکار', 0, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_mazaneh' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'montzar_truly_buy_mazaneh', '0', 'مظنه خرید واقعی همکار', 0, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_truly_buy_mazaneh' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'montzar_truly_sell_mazaneh', '0', 'مظنه فروش واقعی همکار', 0, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_truly_sell_mazaneh' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'display_montzar', 'true', 'نمایش بلوک همکار در UI', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'display_montzar' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'liman_token', '', 'توکن لیمان (legacy)', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'liman_token' LIMIT 1);
-- -----------------------------------------------------------------------------
-- کارمزد نمایش و سفارش
-- -----------------------------------------------------------------------------
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'fee_single', '500000', 'اختلاف پایه نمایش (ریال)', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'fee_single' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'buy_fee', '500000', 'سود خرید نمایش', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'buy_fee' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'sell_fee', '500000', 'سود فروش نمایش', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'sell_fee' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'fee_cash', '500000', 'اختلاف ریالی سفارش (legacy)', 1, 1, 'zaarbox/main از buy_fee هم استفاده می‌شود'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'fee_cash' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'fee_service_charge_percentage', '0.005', 'درصد کارمزد سفارش', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'fee_service_charge_percentage' LIMIT 1);
-- -----------------------------------------------------------------------------
-- Jibit — settings
-- -----------------------------------------------------------------------------
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'jibit_verification', 'false', 'تأیید کارت بانکی با جیبیت', 1, 1, 'true/false'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'jibit_verification' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'register_jibit_verify', 'false', 'تأیید کدملی/موبایل در ثبت‌نام', 1, 1, 'true/false'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'register_jibit_verify' LIMIT 1);
-- -----------------------------------------------------------------------------
-- ساعات بسته بودن قیمت
-- -----------------------------------------------------------------------------
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'close_price', 'false', 'بستن قیمت در بازه زمانی', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'close_price' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'startDay', '10:00', 'شروع بازه معامله', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'startDay' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'endDay', '20:30', 'پایان بازه معامله', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'endDay' LIMIT 1);
-- -----------------------------------------------------------------------------
-- const — شمارنده و موارد پرکاربرد (جدول const یا cnt)
-- -----------------------------------------------------------------------------
INSERT INTO `const` (`key`, `value`, `title_fa`)
SELECT 'jibit_counter', '0', 'شمارنده درخواست جیبیت'
WHERE NOT EXISTS (SELECT 1 FROM `const` WHERE `key` = 'jibit_counter' LIMIT 1);
INSERT INTO `const` (`key`, `value`, `title_fa`)
SELECT 'main_product', '13', 'محصول آبشده (پشتیبان settings)'
WHERE NOT EXISTS (SELECT 1 FROM `const` WHERE `key` = 'main_product' LIMIT 1);
INSERT INTO `const` (`key`, `value`, `title_fa`)
SELECT 'limited_price', '0', 'سقف واریز اولیه'
WHERE NOT EXISTS (SELECT 1 FROM `const` WHERE `key` = 'limited_price' LIMIT 1);
-- -----------------------------------------------------------------------------
-- API خارجی Node (HMAC) — NODE_CLIENT_ID / NODE_SHARED_SECRET
-- -----------------------------------------------------------------------------
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'node_client_id', '', 'شناسه کلاینت API خارجی (X-Client-Id)', 1, 1, 'fallback: .env NODE_CLIENT_ID'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'node_client_id' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'node_shared_secret', '', 'کلید امضای HMAC API خارجی', 1, 1, 'fallback: .env NODE_SHARED_SECRET'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'node_shared_secret' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'external_order_api_enabled', 'false', 'API سفارش خارجی (get_wallet / order)', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'external_order_api_enabled' LIMIT 1);
-- -----------------------------------------------------------------------------
-- عنوان فارسی + can_edit برای کلیدهای موجود
-- -----------------------------------------------------------------------------
UPDATE `settings` SET `title_fa` = COALESCE(NULLIF(TRIM(`title_fa`), ''), 'منبع قیمت'), `can_edit` = 1 WHERE `key` = 'price_provider';
UPDATE `settings` SET `title_fa` = COALESCE(NULLIF(TRIM(`title_fa`), ''), 'محصول آبشده'), `can_edit` = 1 WHERE `key` = 'main_product';
UPDATE `settings` SET `title_fa` = COALESCE(NULLIF(TRIM(`title_fa`), ''), 'آدرس API Zaarbox'), `can_edit` = 1 WHERE `key` = 'zaarbox_api_url';
UPDATE `settings` SET `title_fa` = COALESCE(NULLIF(TRIM(`title_fa`), ''), 'شناسه ردیف Zaarbox'), `can_edit` = 1 WHERE `key` = 'zaarbox_price_key';
UPDATE `settings` SET `title_fa` = COALESCE(NULLIF(TRIM(`title_fa`), ''), 'UUID نمودار'), `can_edit` = 1 WHERE `key` = 'chart_id';
UPDATE `settings` SET `title_fa` = COALESCE(NULLIF(TRIM(`title_fa`), ''), 'دریافت قیمت همکار'), `can_edit` = 1 WHERE `key` = 'montzar_price';
UPDATE `settings` SET `title_fa` = COALESCE(NULLIF(TRIM(`title_fa`), ''), 'موبایل همکار'), `can_edit` = 1 WHERE `key` = 'montzar_mobile';
UPDATE `settings` SET `title_fa` = COALESCE(NULLIF(TRIM(`title_fa`), ''), 'رمز همکار'), `can_edit` = 1 WHERE `key` = 'montzar_password';
UPDATE `settings` SET `title_fa` = COALESCE(NULLIF(TRIM(`title_fa`), ''), 'کد محصول همکار'), `can_edit` = 1 WHERE `key` = 'montzar_product_id';
UPDATE `settings` SET `title_fa` = COALESCE(NULLIF(TRIM(`title_fa`), ''), 'آدرس همکار'), `can_edit` = 1 WHERE `key` = 'montzar_base_url';
UPDATE `settings` SET `title_fa` = COALESCE(NULLIF(TRIM(`title_fa`), ''), 'توکن همکار'), `can_edit` = 0 WHERE `key` = 'montzar_token';
UPDATE `settings` SET `title_fa` = COALESCE(NULLIF(TRIM(`title_fa`), ''), 'اختلاف همکار'), `can_edit` = 0 WHERE `key` = 'montzar_diff';
UPDATE `settings` SET `title_fa` = COALESCE(NULLIF(TRIM(`title_fa`), ''), 'قیمت لحظه‌ای همکار'), `can_edit` = 0 WHERE `key` = 'montzar_live_price';
UPDATE `settings` SET `title_fa` = COALESCE(NULLIF(TRIM(`title_fa`), ''), 'تأیید کارت جیبیت'), `can_edit` = 1 WHERE `key` = 'jibit_verification';
UPDATE `settings` SET `title_fa` = COALESCE(NULLIF(TRIM(`title_fa`), ''), 'تأیید ثبت‌نام جیبیت'), `can_edit` = 1 WHERE `key` = 'register_jibit_verify';
UPDATE `settings` SET `title_fa` = COALESCE(NULLIF(TRIM(`title_fa`), ''), 'سود خرید'), `can_edit` = 1 WHERE `key` = 'buy_fee';
UPDATE `settings` SET `title_fa` = COALESCE(NULLIF(TRIM(`title_fa`), ''), 'سود فروش'), `can_edit` = 1 WHERE `key` = 'sell_fee';
UPDATE `settings` SET `title_fa` = COALESCE(NULLIF(TRIM(`title_fa`), ''), 'اختلاف پایه'), `can_edit` = 1 WHERE `key` = 'fee_single';
-- نوع فیلد پنل ادمین
UPDATE `settings` SET `type` = 'longtext' WHERE `key` IN ('text_rule', 'text_about');
UPDATE `settings` SET `type` = 'select', `description` = 'montzar,zaarbox,main_product,etehadie,taban_gohar' WHERE `key` = 'price_provider';
UPDATE `settings` SET `type` = 'switch' WHERE `key` IN (
'jibit_verification', 'register_jibit_verify', 'montzar_price', 'main_product_price',
'tabanGohar_price', 'show_last_price', 'close_price', 'montzar_closed', 'montzar_open_buy', 'montzar_open_sell', 'display_montzar',
'external_order_api_enabled'
);
UPDATE `settings` SET `type` = 'number' WHERE `key` IN ('fee_single', 'buy_fee', 'sell_fee', 'fee_cash', 'fee_service_charge_percentage', 'montzar_product_id');
UPDATE `settings` SET `type` = 'text' WHERE `type` IS NULL OR TRIM(`type`) = '';
-- =============================================================================
-- products — محدودیت مبلغ سفارش (ستون‌های جدول products؛ مقدار از پنل ادمین)
-- patch: database/sql/add_product_order_limit_columns.sql
-- =============================================================================
SET @db = DATABASE();
SET @sql = IF(
(SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'order_limit_enabled') = 0,
'ALTER TABLE `products` ADD COLUMN `order_limit_enabled` TINYINT(1) NOT NULL DEFAULT 0 AFTER `percent_fee_buy`',
'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @sql = IF(
(SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'min_order_cash') = 0,
'ALTER TABLE `products` ADD COLUMN `min_order_cash` BIGINT UNSIGNED NULL DEFAULT NULL AFTER `order_limit_enabled`',
'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @sql = IF(
(SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'products' AND COLUMN_NAME = 'max_order_cash') = 0,
'ALTER TABLE `products` ADD COLUMN `max_order_cash` BIGINT UNSIGNED NULL DEFAULT NULL AFTER `min_order_cash`',
'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
COMMIT;
-- پروژه گلد علی: بعد از این فایل فقط goldali_database_settings.sql یا goldali_zaarbox_price.sql
-- برای valueهای اختصاصی (price_provider=zaarbox و ...) بزنید.
--
-- jibit_counter در پنل «تنظیمات» نیست مگر const را جدا مدیریت کنید — در const/cnt است.