Files
boursecu_server/database/sql/garoosi_gold_settings_update.sql
T
2026-06-14 21:42:21 +03:30

353 lines
25 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- =============================================================================
-- گروسی گلد (garoosigold) — merge امن برای production
--
-- اصول:
-- • value کلیدهای فعال (montzar_*, fee, URL, توکن ته‌حساب) دست نخورده
-- • title_fa / type / is_active / can_edit + INSERT کلیدهای modular
-- • DELETE settings: کلید بدون استفاده در PHP + تست + legacy
-- • DELETE const: goldir, goldir_*, log (last_order_log نگه داشته می‌شود)
-- • قبل از اجرا: بکاپ کامل + USE دیتابیس_خودتان;
-- =============================================================================
START TRANSACTION;
-- ---------------------------------------------------------------------------
-- charset — روی بعضی سرورها description/title_fa هنوز latin1 است
-- ---------------------------------------------------------------------------
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;
-- ---------------------------------------------------------------------------
-- ۱) اصلاح باگ‌های شناخته‌شده
-- ---------------------------------------------------------------------------
UPDATE `settings`
SET `key` = 'logo_login', `value` = 'logo_login'
WHERE `key` LIKE 'logo_login%';
DELETE s1 FROM `settings` s1
INNER JOIN `settings` s2
ON s1.`key` = s2.`key` AND s1.`id` < s2.`id`
WHERE s1.`key` = 'montzar_closed';
UPDATE `settings`
SET `title_fa` = 'باز/بسته خودکار محصول در لیست'
WHERE `key` = 'product_auto_close_open_on_list';
-- legacy is_requaire_referral → referral_id (اگر قدیمی روشن بود)
UPDATE `settings` AS r
SET
r.`value` = 'required',
r.`is_active` = 1,
r.`updated_at` = NOW()
WHERE r.`key` = 'referral_id'
AND EXISTS (
SELECT 1 FROM (
SELECT `value`, `is_active` FROM `settings`
WHERE `key` = 'is_requaire_referral' LIMIT 1
) AS leg
WHERE leg.`is_active` = 1
AND LOWER(TRIM(COALESCE(leg.`value`, ''))) IN ('true', '1', 'yes')
)
AND TRIM(COALESCE(r.`value`, '')) <> 'required';
-- ---------------------------------------------------------------------------
-- ۲) title_fa و type (value دست نخورده)
-- ---------------------------------------------------------------------------
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` = 'توکن ته‌حساب', `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` = '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` = 'number', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'fee_service_charge_percentage';
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` = 'number', `is_active` = COALESCE(`is_active`, 1), `can_edit` = 0 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` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'send_to_tahesab';
UPDATE `settings` SET `title_fa` = 'تعداد سفارش اول بدون کارمزد', `type` = 'number', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'fee_free';
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` = '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` = 'tabanGohar_price';
UPDATE `settings` SET `title_fa` = 'دریافت قیمت از محصولات', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'main_product_price';
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` = 'select', `is_active` = COALESCE(`is_active`, 1), `description` = 'required = اجباری|required,' WHERE `key` = 'referral_id';
UPDATE `settings` SET `title_fa` = 'پیامک گروهی', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'group_sms';
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` = '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` = '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`, 0) WHERE `key` = 'referral_limit';
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` = 'آدرس 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_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` = 'نشان دادن آخرین قیمت', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'show_last_price';
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` = '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` = 'شماره همراه همکار', `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` = 'دریافت قیمت از همکار', `type` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'montzar_price';
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` = 'UUID نمودار Zaarbox',
`type` = 'text',
`is_active` = 1,
`can_edit` = 1,
`description` = 'خالی = ca3800a0-1f57-3528-b963-178f9168e04f',
`value` = CASE
WHEN TRIM(COALESCE(`value`, '')) = '' THEN '8c19e06a-446e-3d56-9cc0-750f7c6cd767'
ELSE `value`
END,
`updated_at` = NOW()
WHERE `key` = 'chart_id';
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` = 'شناسه ردیف تابلو (key یا UUID)', `type` = 'text', `is_active` = COALESCE(`is_active`, 1), `can_edit` = 1 WHERE `key` = 'zaarbox_price_key';
-- ---------------------------------------------------------------------------
-- ۳) INSERT کلیدهای modular که در گروسی نیست (value فقط اگر key نبود)
-- ---------------------------------------------------------------------------
INSERT INTO `settings` (`key`, `title_fa`, `value`, `can_edit`, `is_exist`, `is_active`, `type`, `description`)
SELECT 'price_provider', 'منبع قیمت', 'montzar', 1, 0, 1, 'select', 'منبع فعال قیمت|montzar,zaarbox,main_product,taban_gohar'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'price_provider' LIMIT 1);
INSERT INTO `settings` (`key`, `title_fa`, `value`, `can_edit`, `is_exist`, `is_active`, `type`)
SELECT 'register_jibit_verify', 'تایید کد ملی در ثبت‌نام', 'false', 1, 0, 1, 'switch'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'register_jibit_verify' LIMIT 1);
INSERT INTO `settings` (`key`, `title_fa`, `value`, `can_edit`, `is_exist`, `is_active`, `type`)
SELECT 'gift_for_referral', 'پاداش معرفی‌شده', '0', 1, 0, 1, 'number'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'gift_for_referral' LIMIT 1);
INSERT INTO `settings` (`key`, `title_fa`, `value`, `can_edit`, `is_exist`, `is_active`, `type`)
SELECT 'service_charge_percentage', 'کارمزد درصدی (alias)', COALESCE(
(SELECT `value` FROM `settings` WHERE `key` = 'fee_service_charge_percentage' LIMIT 1), '0.005'
), 0, 0, 1, 'number'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'service_charge_percentage' LIMIT 1);
INSERT INTO `settings` (`key`, `title_fa`, `value`, `can_edit`, `is_exist`, `is_active`, `type`)
SELECT 'profit_gold_api_enabled', 'API سود طلا', 'false', 1, 0, 0, 'switch'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'profit_gold_api_enabled' LIMIT 1);
INSERT INTO `settings` (`key`, `title_fa`, `value`, `can_edit`, `is_exist`, `is_active`, `type`)
SELECT 'title_pwa', 'عنوان PWA', 'گروسی گلد', 1, 0, 1, 'text'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'title_pwa' LIMIT 1);
INSERT INTO `settings` (`key`, `title_fa`, `value`, `can_edit`, `is_exist`, `is_active`, `type`)
SELECT 'title_fav', 'عنوان favicon', 'گروسی گلد', 1, 0, 1, 'text'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'title_fav' LIMIT 1);
INSERT INTO `settings` (`key`, `title_fa`, `value`, `can_edit`, `is_exist`, `is_active`, `type`)
SELECT 'text_rule', 'متن قوانین', '', 1, 0, 1, 'longtext'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'text_rule' LIMIT 1);
INSERT INTO `settings` (`key`, `title_fa`, `value`, `can_edit`, `is_exist`, `is_active`, `type`)
SELECT 'text_about', 'متن درباره ما', '', 1, 0, 1, 'longtext'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'text_about' LIMIT 1);
INSERT INTO `settings` (`key`, `title_fa`, `value`, `can_edit`, `is_exist`, `is_active`, `type`)
SELECT 'metal_type', 'نوع فلز', 'gold', 1, 0, 1, 'text'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'metal_type' LIMIT 1);
INSERT INTO `settings` (`key`, `title_fa`, `value`, `can_edit`, `is_exist`, `is_active`, `type`)
SELECT 'main_product', 'محصول آبشده', '13', 1, 0, 1, 'text'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'main_product' LIMIT 1);
INSERT INTO `settings` (`key`, `title_fa`, `value`, `can_edit`, `is_exist`, `is_active`, `type`)
SELECT 'zaarbox_api_url', 'آدرس API تابلو Zaarbox', '', 1, 0, 1, 'text'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'zaarbox_api_url' LIMIT 1);
INSERT INTO `settings` (`key`, `title_fa`, `value`, `can_edit`, `is_exist`, `is_active`, `type`)
SELECT 'zaarbox_price_key', 'شناسه ردیف تابلو (key یا UUID)', '', 1, 0, 1, 'text'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'zaarbox_price_key' LIMIT 1);
INSERT INTO `settings` (`key`, `title_fa`, `value`, `can_edit`, `is_exist`, `is_active`, `type`, `description`, `updated_at`)
SELECT
'chart_id',
'UUID نمودار Zaarbox',
'8c19e06a-446e-3d56-9cc0-750f7c6cd767',
1,
0,
1,
'text',
'خالی = ca3800a0-1f57-3528-b963-178f9168e04f',
NOW()
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'chart_id' LIMIT 1);
INSERT INTO `settings` (`key`, `title_fa`, `value`, `can_edit`, `is_exist`, `is_active`, `type`)
SELECT 'etehadie_api_url', 'Etehadie API URL', '', 1, 0, 0, 'text'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'etehadie_api_url' LIMIT 1);
-- ---------------------------------------------------------------------------
-- ۴) DELETE — کلید بدون استفاده در PHP + تست + legacy
-- ---------------------------------------------------------------------------
DELETE FROM `settings` WHERE `key` IN (
-- تست
'test', 'test2', 'test22', 'test3', 'test33', 'longtest', 'longtest2',
-- legacy / بدون استفاده در کد
'is_requaire_referral',
'send_to_goldir',
'goldir_price',
'liman_token',
'melted_product_id',
'display_montzar'
);
-- type پیش‌فرض
UPDATE `settings` SET `type` = 'text' WHERE (`type` IS NULL OR TRIM(`type`) = '') AND `key` NOT IN (
'montzar_order_response', 'montzar_last_product_log'
);
UPDATE `settings` SET `type` = 'switch' WHERE `key` IN (
'has_page_earn_money', 'has_page_fund', 'has_page_permission',
'has_page_price_trigger', 'has_page_physical_gold', 'has_chat', 'charge_notif',
'auto_active_customer', 'open_register', 'send_to_tahesab', 'tabanGohar_price',
'main_product_price', 'group_sms', 'jibit_verification', 'register_jibit_verify',
'close_price', 'montzar_price', 'show_last_price',
'product_update_price_on_list', 'product_auto_close_open_on_list',
'montzar_closed', 'montzar_open_buy', 'montzar_open_sell', 'profit_gold_api_enabled'
);
UPDATE `settings` SET `type` = 'number' WHERE `key` IN (
'fee_single', 'buy_fee', 'sell_fee', 'fee_cash', 'fee_service_charge_percentage',
'fee_free', 'montzar_product_id', 'service_charge_percentage',
'gift_for_referrer', 'gift_for_referral', 'referral_limit'
);
UPDATE `settings` SET `type` = 'longtext' WHERE `key` IN (
'montzar_order_response', 'montzar_last_product_log'
);
-- jibit_verification: is_active null → 1
UPDATE `settings` SET `is_active` = 1 WHERE `key` = 'jibit_verification' AND `is_active` IS NULL;
-- ---------------------------------------------------------------------------
-- ۴b) description — پاکسازی junk + metadata کاتالوگ
-- ---------------------------------------------------------------------------
UPDATE `settings` SET `description` = NULL
WHERE LOWER(TRIM(COALESCE(`description`, ''))) IN (
'true', 'false', '0', '1', 'yes', 'no', 'in server'
)
OR TRIM(COALESCE(`description`, '')) LIKE 'count of%';
UPDATE `settings` SET `description` = 'منبع فعال قیمت|montzar,zaarbox,main_product,taban_gohar'
WHERE `key` = 'price_provider';
UPDATE `settings` SET `description` = 'required = اجباری|required,', `title_fa` = 'کد معرف', `type` = 'select'
WHERE `key` = 'referral_id';
UPDATE `settings` SET `description` = 'جایگزین: price_provider=main_product' WHERE `key` = 'main_product_price';
UPDATE `settings` SET `description` = 'true یا price_provider=montzar' WHERE `key` = 'montzar_price';
UPDATE `settings` SET `description` = 'تعداد سفارش اول بدون کارمزد' WHERE `key` = 'fee_free';
UPDATE `settings` SET `description` = 'id یا reading_method محصول آبشده' WHERE `key` = 'main_product';
UPDATE `settings` SET `is_active` = 1 WHERE `key` IN ('zaarbox_api_url', 'zaarbox_price_key', 'chart_id');
-- ---------------------------------------------------------------------------
-- ۵) const — حذف legacy goldir + title + INSERT کلیدهای لازم
-- ---------------------------------------------------------------------------
DELETE FROM `const`
WHERE `key` = 'log'
OR `key` LIKE 'goldir%';
UPDATE `const` SET `title_fa` = 'قیمت صفحه اصلی' WHERE `key` = 'main_product' AND (`title_fa` IS NULL OR TRIM(`title_fa`) = '');
UPDATE `const` SET `title_fa` = 'بنر هدر' WHERE `key` = 'header_banner' 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` = 'jibit_counter' 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`) = '');
INSERT INTO `const` (`key`, `value`, `title_fa`)
SELECT 'gram', '1', 'ضریب گرم'
WHERE NOT EXISTS (SELECT 1 FROM `const` WHERE `key` = 'gram' 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_json`, `title_fa`)
SELECT 'price', '[]', 'لیست قیمت (JSON)'
WHERE NOT EXISTS (SELECT 1 FROM `const` WHERE `key` = 'price' LIMIT 1);
-- ---------------------------------------------------------------------------
-- ۶) products — ستون محدودیت مبلغ سفارش
-- ---------------------------------------------------------------------------
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 `key`, `title_fa`, `value`, `type`, `is_active` FROM `settings` ORDER BY `key`;
-- SELECT `key`, `value`, `title_fa` FROM `const` ORDER BY `key`;
--
-- حذف‌شده از settings: liman_token, goldir_price, melted_product_id,
-- send_to_goldir, is_requaire_referral, display_montzar, test*
-- حذف‌شده از const: log, goldir, goldir_*
-- نگه‌داشته: last_order_log (MontzarService), montzar_* runtime logs
--
-- تراکنش‌های ریالی قدیمی (جدا):
-- database/sql/fix_rial_transaction_types.sql
-- =============================================================================