feat(server): add show_on_tv product flag and public /tv products API

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-18 17:17:01 +03:30
co-authored by Cursor
parent da9f98b958
commit e158831fd3
6 changed files with 177 additions and 0 deletions
@@ -0,0 +1,43 @@
<?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_on_tv')) {
Schema::table('products', function (Blueprint $table) {
if (Schema::hasColumn('products', 'show_in_assets')) {
$table->boolean('show_on_tv')->default(false)->after('show_in_assets');
} elseif (Schema::hasColumn('products', 'show')) {
$table->boolean('show_on_tv')->default(false)->after('show');
} else {
$table->boolean('show_on_tv')->default(false);
}
});
} else {
DB::statement(
'ALTER TABLE `products` MODIFY COLUMN `show_on_tv` TINYINT(1) NOT NULL DEFAULT 0'
);
}
}
public function down(): void
{
if (!Schema::hasTable('products') || !Schema::hasColumn('products', 'show_on_tv')) {
return;
}
Schema::table('products', function (Blueprint $table) {
$table->dropColumn('show_on_tv');
});
}
};
+40
View File
@@ -0,0 +1,40 @@
-- نمایش محصول در مسیر /tv اپ مشتری
-- امن برای اجرای مجدد
-- 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 = 'show_on_tv') > 0,
'SELECT ''skip: show_on_tv 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 `show_on_tv` TINYINT(1) NOT NULL DEFAULT 0 COMMENT ''نمایش در تابلو /tv'' AFTER `show_in_assets`',
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_on_tv` TINYINT(1) NOT NULL DEFAULT 0 COMMENT ''نمایش در تابلو /tv'' AFTER `show`',
'ALTER TABLE `products` ADD COLUMN `show_on_tv` TINYINT(1) NOT NULL DEFAULT 0 COMMENT ''نمایش در تابلو /tv'''
)
)
)
);
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_on_tv') > 0,
'ALTER TABLE `products` MODIFY COLUMN `show_on_tv` TINYINT(1) NOT NULL DEFAULT 0 COMMENT ''نمایش در تابلو /tv''',
'SELECT ''skip: show_on_tv modify'' AS info'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
+25
View File
@@ -43,6 +43,31 @@ DEALLOCATE PREPARE stmt;
-- یک‌بار برای اصلاح سرورهایی که قبلاً DEFAULT 1 داشتند:
-- UPDATE `products` SET `show_in_assets` = 0;
-- ---------------------------------------------------------------------------
-- products.show_on_tv (تابلو قیمت /tv)
-- ---------------------------------------------------------------------------
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 = 'show_on_tv') = 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 `show_on_tv` TINYINT(1) NOT NULL DEFAULT 0 COMMENT ''نمایش در تابلو /tv'' AFTER `show_in_assets`',
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_on_tv` TINYINT(1) NOT NULL DEFAULT 0 COMMENT ''نمایش در تابلو /tv'' AFTER `show`',
'ALTER TABLE `products` ADD COLUMN `show_on_tv` TINYINT(1) NOT NULL DEFAULT 0 COMMENT ''نمایش در تابلو /tv'''
)
),
'SELECT ''skip products.show_on_tv'' AS info'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- ---------------------------------------------------------------------------
-- products.use_last_price_if_zero (fallback وقتی provider صفر است)
-- ---------------------------------------------------------------------------