tahesab 2

This commit is contained in:
2026-06-07 18:27:04 +03:30
parent 20ed4ee3ad
commit 484f05a073
6 changed files with 398 additions and 88 deletions
@@ -0,0 +1,149 @@
-- =============================================================================
-- گروسی گلد — تکمیل merge (اگر garoosi_gold_settings_update.sql نصفه ماند)
-- امن برای اجرای مجدد. قبل: USE دیتابیس + بکاپ
-- =============================================================================
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;
-- legacy → 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';
DELETE FROM `settings` WHERE `key` IN (
'test', 'test2', 'test22', 'test3', 'test33', 'longtest', 'longtest2',
'is_requaire_referral', 'send_to_goldir', 'goldir_price', 'liman_token',
'melted_product_id', 'display_montzar'
);
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 '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);
-- پاکسازی description قدیمی / اشتباه
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%';
-- description کاتالوگ
UPDATE `settings` SET
`title_fa` = 'کد معرف',
`type` = 'select',
`description` = 'required = اجباری|required,'
WHERE `key` = 'referral_id';
UPDATE `settings` SET
`title_fa` = 'منبع قیمت',
`type` = 'select',
`is_active` = 1,
`description` = 'منبع فعال قیمت|montzar,zaarbox,main_product,taban_gohar'
WHERE `key` = 'price_provider';
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
WHERE `key` = 'chart_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 `type` = 'switch' WHERE `key` IN (
'group_sms', 'bale_bot_token', 'jibit_verification', 'register_jibit_verify',
'close_price', 'gift_for_referrer'
) AND (`type` IS NULL OR TRIM(`type`) = '');
UPDATE `settings` SET `type` = 'number' WHERE `key` IN (
'buy_fee', 'sell_fee', 'gift_for_referrer', 'montzar_product_id'
) AND (`type` IS NULL OR TRIM(`type`) = '' OR `type` = 'text');
UPDATE `settings` SET `type` = 'select', `description` = 'required = اجباری|required,'
WHERE `key` = 'referral_id' AND (`type` IS NULL OR TRIM(`type`) = '');
UPDATE `settings` SET `is_active` = 1 WHERE `key` IN ('zaarbox_api_url', 'zaarbox_price_key', 'chart_id');
COMMIT;
-- SELECT `key`, `title_fa`, `value`, `description`, `type`, `is_active` FROM `settings` ORDER BY `key`;
+191 -65
View File
@@ -1,36 +1,65 @@
-- =============================================================================
-- گروسی گلد (garoosigold) — به‌روزرسانی settings + const برای ماژول modular
-- گروسی گلد (garoosigold) — merge امن برای production
--
-- اصول:
-- • value توکن‌ها، URLها، feeها و montzar_* عمداً عوض نمی‌شود
-- • فقط title_fa / type / is_active / can_edit و INSERT کلیدهای جدید
-- • قبل از اجرا: بکاپ + USE دیتابیس_خودتان;
-- • 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;
-- ---------------------------------------------------------------------------
-- ۱) اصلاح باگ‌های شناخته‌شده
-- ---------------------------------------------------------------------------
-- کلید خراب logo_login\r\n
UPDATE `settings`
SET `key` = 'logo_login', `value` = 'logo_login'
WHERE `key` LIKE 'logo_login%';
-- montzar_closed تکراری (id قدیمی با value=true؛ ردیف switch جدیدتر را نگه می‌داریم)
DELETE s1 FROM `settings` s1
INNER JOIN `settings` s2
ON s1.`key` = s2.`key` AND s1.`id` < s2.`id`
WHERE s1.`key` = 'montzar_closed';
-- عنوان اشتباه product_auto_close_open_on_list
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 دست نخورده)
-- ۲) title_fa و type (value دست نخورده)
-- ---------------------------------------------------------------------------
UPDATE `settings` SET `title_fa` = 'نام فارسی', `type` = 'text', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'name_fa';
@@ -42,7 +71,6 @@ UPDATE `settings` SET `title_fa` = 'لوگوی ثبت‌نام', `type` =
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` = 'is_requaire_referral';
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';
@@ -54,7 +82,6 @@ UPDATE `settings` SET `title_fa` = 'کارمزد درصدی', `type` = '
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` = 'liman_token';
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) WHERE `key` = 'fee_cash';
UPDATE `settings` SET `title_fa` = 'اختلاف با قیمت واقعی', `type` = 'number', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'fee_single';
@@ -66,12 +93,14 @@ UPDATE `settings` SET `title_fa` = 'ثبت‌نام باز', `type` = '
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,' WHERE `key` = 'referral_id';
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` = 'switch', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'display_montzar';
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';
@@ -84,85 +113,185 @@ UPDATE `settings` SET `title_fa` = 'اختلاف قیمت همکار', `type`
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` = 'text', `is_active` = COALESCE(`is_active`, 1), `can_edit` = 0 WHERE `key` = 'montzar_order_response';
UPDATE `settings` SET `title_fa` = 'لاگ محصول همکار', `type` = 'text', `is_active` = COALESCE(`is_active`, 1), `can_edit` = 0 WHERE `key` = 'montzar_last_product_log';
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` = 'کد محصول آبشده', `type` = 'number', `is_active` = COALESCE(`is_active`, 1) WHERE `key` = 'melted_product_id';
-- alias کارمزد برای بکند قدیمی (value از fee_service_charge_percentage کپی می‌شود)
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);
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';
-- ---------------------------------------------------------------------------
-- ۳) فقط کلید ضروری modular
-- ۳) 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'
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',
'title_pwa', 'title_fav', 'text_rule', 'text_about',
'min_withdraw', 'min_first_buy', 'minimum_sell',
'gift_for_referral', 'referral_count_for_gift', 'referral_bonus_amount',
'profit_gold_api_enabled', 'register_jibit_verify', 'metal_type',
'support_messenger', 'support_messenger_id', 'support_messenger_text',
'payping_start_url', 'payping_verify_url', 'payping_gateway_name',
'payping_gateway_items', 'payping_round_toman', 'payping_strict_failed_withdraw',
'payping_fin_sync_enabled', 'external_order_api_enabled',
'balance_report_exclude_customer_id',
'zaarbox_api_url', 'zaarbox_price_key', 'chart_id', 'etehadie_api_url'
'goldir_price',
'liman_token',
'melted_product_id',
'display_montzar'
);
-- type پیش‌فرض برای ردیف‌های بدون type
UPDATE `settings` SET `type` = 'text' WHERE `type` IS NULL OR TRIM(`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'
);
UPDATE `settings` SET `type` = 'switch' WHERE `key` IN (
'is_requaire_referral', 'has_page_earn_money', 'has_page_fund', 'has_page_permission',
'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', 'display_montzar',
'close_price', 'montzar_price', 'show_last_price', 'product_update_price_on_list',
'product_auto_close_open_on_list', 'goldir_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', 'melted_product_id', '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;
-- ---------------------------------------------------------------------------
-- ۵) const — عنوان + کلیدهای لازم (value موجود حفظ می‌شود)
-- ۴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`) = '');
UPDATE `const` SET `title_fa` = 'لیست قیمت (JSON)' WHERE `key` = 'price' AND (`title_fa` IS NULL OR TRIM(`title_fa`) = '');
UPDATE `const` SET `title_fa` = 'ضریب گرم' WHERE `key` = 'gram' 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`) = '');
INSERT INTO `const` (`key`, `value`, `title_fa`)
SELECT 'gram', '1', 'ضریب گرم'
@@ -176,20 +305,8 @@ INSERT INTO `const` (`key`, `value_json`, `title_fa`)
SELECT 'price', '[]', 'لیست قیمت (JSON)'
WHERE NOT EXISTS (SELECT 1 FROM `const` WHERE `key` = 'price' LIMIT 1);
-- goldir_* در const قدیمی است؛ قیمت از montzar_* در settings می‌آید
DELETE FROM `const` WHERE `key` IN (
'goldir', 'goldir_password', 'goldir_mobile', 'goldir_order_response',
'goldir_price', 'goldir_diff', 'goldir_mazaneh',
'goldir_truly_buy_mazaneh', 'goldir_truly_sell_mazaneh',
'goldir_closed', 'goldir_open_buy', 'goldir_open_sell',
'log'
);
-- ⚠ app_closed الان true است — اگر اپ باید باز باشد بعد از اجرا دستی false کنید:
-- UPDATE `const` SET `value` = 'false' WHERE `key` = 'app_closed';
-- ---------------------------------------------------------------------------
-- ۶) products — ستون محدودیت مبلغ سفارش (بدون seed؛ مقدار از ادمین)
-- ۶) products — ستون محدودیت مبلغ سفارش
-- ---------------------------------------------------------------------------
SET @db = DATABASE();
@@ -220,7 +337,16 @@ 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`;
-- SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'products' AND COLUMN_NAME LIKE 'order_limit%' OR COLUMN_NAME LIKE '%order_cash%';
--
-- حذف‌شده از 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
-- =============================================================================