feat(server): evaluate price alerts per product and fix gold discharge rounding

Alerts now bind to a product_id and share one evaluator; displayed gold within a rounding step discharges the full wallet.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-18 22:23:20 +03:30
co-authored by Cursor
parent 341b2da2c9
commit b0296c6e94
10 changed files with 454 additions and 55 deletions
@@ -0,0 +1,25 @@
-- محصول هشدار قیمت (price_triggers.product_id)
-- امن برای اجرای مجدد
-- USE دیتابیس_خودتان;
SET @db = DATABASE();
SET @sql = IF(
(SELECT COUNT(*) FROM information_schema.TABLES
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'price_triggers') = 0,
'SELECT ''skip: price_triggers table not found'' AS info',
IF(
(SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'price_triggers' AND COLUMN_NAME = 'product_id') > 0,
'SELECT ''skip: product_id exists'' AS info',
IF(
(SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'price_triggers' AND COLUMN_NAME = 'customer_id') > 0,
'ALTER TABLE `price_triggers` ADD COLUMN `product_id` BIGINT UNSIGNED NULL DEFAULT NULL COMMENT ''محصول هشدار'' AFTER `customer_id`, ADD INDEX `price_triggers_product_id_index` (`product_id`)',
'ALTER TABLE `price_triggers` ADD COLUMN `product_id` BIGINT UNSIGNED NULL DEFAULT NULL COMMENT ''محصول هشدار'', ADD INDEX `price_triggers_product_id_index` (`product_id`)'
)
)
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
+32
View File
@@ -523,6 +523,38 @@ PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- ---------------------------------------------------------------------------
-- price_triggers.product_id (هشدار قیمت روی محصول)
-- ---------------------------------------------------------------------------
SET @sql = IF(
(SELECT COUNT(*) FROM information_schema.TABLES
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'price_triggers') > 0
AND (SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'price_triggers' AND COLUMN_NAME = 'product_id') = 0,
IF(
(SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'price_triggers' AND COLUMN_NAME = 'customer_id') > 0,
'ALTER TABLE `price_triggers` ADD COLUMN `product_id` BIGINT UNSIGNED NULL DEFAULT NULL COMMENT ''محصول هشدار'' AFTER `customer_id`',
'ALTER TABLE `price_triggers` ADD COLUMN `product_id` BIGINT UNSIGNED NULL DEFAULT NULL COMMENT ''محصول هشدار'''
),
'SELECT ''skip price_triggers.product_id'' AS info'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @sql = IF(
(SELECT COUNT(*) FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'price_triggers' AND INDEX_NAME = 'price_triggers_product_id_index') = 0
AND (SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'price_triggers' AND COLUMN_NAME = 'product_id') > 0,
'ALTER TABLE `price_triggers` ADD INDEX `price_triggers_product_id_index` (`product_id`)',
'SELECT ''skip price_triggers.product_id index'' AS info'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- ---------------------------------------------------------------------------
-- پایان — برای بورس‌مس (اختیاری، جدا اجرا کنید):
-- UPDATE `settings` SET `value` = 'کیلوگرم' WHERE `key` = 'unit';