Files
lgp-admin-plus-api/database/sql/2026-08-18/02_cc_package.sql

59 lines
2.8 KiB
MySQL
Raw Normal View History

2026-08-19 08:16:49 +08:00
-- ============================================================
-- 家具套餐:主表 + 搭配明细(幂等)
-- 金额一律整数分original_amount 由明细自动算package_amount 是独立报价
-- ============================================================
SET @db := DATABASE();
SET @exists := (
SELECT COUNT(*) FROM information_schema.TABLES
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'cc_package'
);
SET @sql := IF(@exists = 0,
'CREATE TABLE `cc_package` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL DEFAULT '''' COMMENT '''',
`cover` varchar(500) NOT NULL DEFAULT '''' COMMENT '''',
`subtitle` varchar(200) NOT NULL DEFAULT '''' COMMENT '''',
`remark` varchar(255) NOT NULL DEFAULT '''' COMMENT '''',
`original_amount` int NOT NULL DEFAULT 0 COMMENT ''=1'',
`package_amount` int NOT NULL DEFAULT 0 COMMENT ''=1'',
`is_hot` tinyint NOT NULL DEFAULT 0 COMMENT ''1='',
`sort` int NOT NULL DEFAULT 0,
`status` tinyint NOT NULL DEFAULT 0 COMMENT ''0= 1='',
`created_at` int NOT NULL DEFAULT 0,
`updated_at` int NOT NULL DEFAULT 0,
`deleted_at` int NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
KEY `idx_package_hot` (`is_hot`, `sort`, `status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=''''',
'SELECT ''skip cc_package'' AS msg'
);
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @exists := (
SELECT COUNT(*) FROM information_schema.TABLES
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'cc_package_item'
);
SET @sql := IF(@exists = 0,
'CREATE TABLE `cc_package_item` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`package_id` int NOT NULL DEFAULT 0 COMMENT '''',
`catalogue_id` int NOT NULL DEFAULT 0 COMMENT '''',
`price_sheet_id` int NOT NULL DEFAULT 0 COMMENT '''',
`material_key` varchar(50) NOT NULL DEFAULT ''routine'' COMMENT '''',
`quantity` int NOT NULL DEFAULT 1 COMMENT '''',
`unit_price` int NOT NULL DEFAULT 0 COMMENT '''',
`sort` int NOT NULL DEFAULT 0,
`remark` varchar(255) NOT NULL DEFAULT '''',
`created_at` int NOT NULL DEFAULT 0,
`updated_at` int NOT NULL DEFAULT 0,
`deleted_at` int NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
KEY `idx_package_item_pkg` (`package_id`),
KEY `idx_package_item_cat` (`catalogue_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=''''',
'SELECT ''skip cc_package_item'' AS msg'
);
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;