1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
| CREATE DATABASE db_goodsapi;
USE db_goodsapi;
-- 1、商品类型 DROP TABLE IF EXISTS t_goodstype;
CREATE TABLE t_goodstype ( id INT PRIMARY KEY AUTO_INCREMENT, NAME VARCHAR (30), parentid INT, LEVEL INT, flag INT );
INSERT INTO t_goodstype (NAME, parentid, LEVEL, flag) VALUES ('家用电器', - 1, 1, 1), ('手机', - 1, 1, 2), ('运营商', - 1, 1, 2), ('数码', - 1, 1, 2), ('电脑', - 1, 1, 1), ('办公', - 1, 1, 1), ('电视', 1, 2, 101), ('冰箱', 1, 2, 101), ('空调', 1, 2, 101), ('洗衣机', 1, 2, 101), ('手机通讯', 2, 2, 1), ('手机配件', 2, 2, 201), ('摄影', 4, 2, 201), ('数码配件', 4, 2, 201);
UPDATE t_goodstype SET LEVEL = 2 WHERE id = 11;
SELECT * FROM t_goodstype;
-- 2、商品属性字段 DROP TABLE IF EXISTS t_attribute;
CREATE TABLE t_attribute ( id INT PRIMARY KEY AUTO_INCREMENT, NAME VARCHAR (30) );
INSERT INTO t_attribute (NAME) VALUES ('能效等级'), ('商品毛重'), ('商品产地'), ('电视类型'), ('电源功率(w)'), ('待机功率(w)'), ('工作电压(v)'), ('运行内存');
INSERT INTO t_attribute (NAME) VALUES ('color'), ('size');
-- 3、商品类型属性表 DROP TABLE IF EXISTS t_typeattribute;
CREATE TABLE t_typeattribute ( id INT PRIMARY KEY AUTO_INCREMENT, gtid INT, aid INT, flag INT COMMENT '标记位:值是否为类型 1否 2是' );
INSERT INTO t_typeattribute (gtid, aid) VALUES (7, 1), (7, 2), (7, 3), (7, 4), (7, 5), (7, 6), (7, 7), (7, 8);
-- 4、商品表 DROP TABLE IF EXISTS t_goods;
CREATE TABLE t_goods ( id INT PRIMARY KEY AUTO_INCREMENT, title VARCHAR (50), subtitle VARCHAR (100), gtid INT, flag INT COMMENT '1 下架 2上架 ', ctime DATETIME );
INSERT INTO t_goods (title, subtitle, gtid, flag, ctime) VALUES ( '长虹 55D4P 超薄无边全面屏 4K超高清 手机投屏 智能网络 教育电视 平板液晶电视', '【暑期欢乐购】热销TOP榜,数量有限,超薄无边全面屏,4K超清教育电视', 7, 2, NOW() );
-- 5、商品属性表 DROP TABLE IF EXISTS t_goodsattribute;
CREATE TABLE t_goodsattribute ( id INT PRIMARY KEY AUTO_INCREMENT, gid INT, aid INT, val VARCHAR (50), flag INT COMMENT '标记位 :1 SPU属性 2:SKU属性' );
ALTER TABLE t_goodsattribute ADD flag INT DEFAULT 1;
INSERT INTO t_goodsattribute (gid, aid, val) VALUES (1, 1, '二级能效'), (1, 2, '17.0kg'), (1, 3, '中国大陆'), ( 1, 4, '超薄电视;4K超清电视;LED电视' );
INSERT INTO t_goodsattribute (gid, aid, val, flag) VALUES (1, 9, '黑色', 2), (1, 9, '白色', 2), (1, 9, '银色', 2), (1, 9, '红色', 2), (1, 10, 55, 2), (1, 9, 45, 2), (1, 9, 60, 2), (1, 9, 65, 2);
SELECT * FROM t_goodsattribute;
-- 6、商品SKU属性 DROP TABLE IF EXISTS t_goodssku;
CREATE TABLE t_goodssku ( id INT PRIMARY KEY AUTO_INCREMENT, gid INT, skuid json COMMENT 'JSON数组:t_goodsattribute表的id [6,9]', sku json COMMENT '{"color":"黄色","size":2XL}', repertory INT, price INT COMMENT '单位 分', saleprice INT COMMENT '销售价格', minrepertory INT COMMENT '预警库存', flag INT );
INSERT INTO t_goodssku ( gid, skuid, sku, repertory, price, saleprice, minrepertory, flag ) VALUES ( 1, '[6,9]', '{"size":55,"color":"白色"}', 100, 130000, 99900, 10, 1 ), ( 1, '[5,9]', '{"size":55,"color":"黑色"}', 100, 130000, 94900, 10, 1 ), ( 1, '[5,12]', '{"size":65,"color":"黑色"}', 100, 230000, 194900, 10, 1 );
|