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:
@@ -0,0 +1,34 @@
|
||||
<?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('price_triggers')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::table('price_triggers', function (Blueprint $table) {
|
||||
if (! Schema::hasColumn('price_triggers', 'product_id')) {
|
||||
$table->unsignedBigInteger('product_id')->nullable()->after('customer_id');
|
||||
$table->index('product_id');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if (! Schema::hasTable('price_triggers') || ! Schema::hasColumn('price_triggers', 'product_id')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::table('price_triggers', function (Blueprint $table) {
|
||||
$table->dropIndex(['product_id']);
|
||||
$table->dropColumn('product_id');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -593,6 +593,7 @@ DROP TABLE IF EXISTS `price_triggers`;
|
||||
CREATE TABLE `price_triggers` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
|
||||
`customer_id` bigint unsigned NOT NULL,
|
||||
`product_id` bigint unsigned DEFAULT NULL,
|
||||
`target_price` bigint NOT NULL,
|
||||
`price_condition` varchar(50) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
|
||||
`action` varchar(50) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
|
||||
|
||||
@@ -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;
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user