Mysql 商品模块设计

DB规划

  • 为以后的数据库迁移提供方便
  • 避免跨库的操作,把经常一起关联查询的表放到一个DB中
  • 建议为了方便识别表所在的db,在表名的前增加库名前缀
  • 用户数据库(mc_customerdb)
    • customer_inf
    • customer_login
    • customer_logo_log
    • customer_level_inf
    • customer_point_log
    • customer_balance_log
  • 商品数据库 (mc_productdb)
    • product_info
    • product_pic_info
    • product_supplier_info
    • product_comment
    • product_category
    • product_brand_info
  • 订单数据库(mc_orderdb)
    • order_master
    • order_detail
    • order_customer_addr
    • warehouse_info
    • shipping_info
    • order_cart
    • warehouse_product

建立数据库

#创建数据库
mysql -uroot -p  -e"create database mc_customerdb"
#导入sql文件
mysql -uroot -p mc_customerdb < mc_customerdb.sql

商品模块

品牌信息表

CREATE TABLE brand_info(
brand_id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL comment '品牌ID',
brand_name VARCHAR(50) NOT NULL comment '品牌名称',
telephone VARCHAR(50) NOT NULL comment '联系电话',
brand_web VARCHAR(100) comment '品牌网站',
brand_logo VARCHAR(100) comment '品牌logo url',
brand_desc VARCHAR(150) comment '品牌描述',
brand_status TINYINT NOT NULL DEFAULT 0 comment '品牌状态,0禁用,1启用',
brand_order TINYINT NOT NULL DEFAULT 0 comment '排序',
modify_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '最后修改时间',
PRIMARY KEY pk_brandid(brand_id)
) engine =innodb comment '品牌信息表';

分类信息表

CREATE TABLE product_category(
category_id SMALLINT UNSIGNED auto_increment NOT NULL comment '分类ID',
category_name VARCHAR(10) NOT NULL comment '分类名称',
category_code VARCHAR(10) NOT NULL comment '分类编码',
parent_id SMALLINT UNSIGNED NOT NULL DEFAULT 0 comment '父分类ID',
category_level TINYINT NOT NULL DEFAULT 1 comment '分类层级',
category_status TINYINT NOT NULL DEFAULT 1 comment '分类状态',
modify_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '最后修改时间',
PRIMARY KEY pk_categoryid (category_id)
)engine = innodb comment '商品分类表';

商品信息表

CREATE TABLE product_info(
product_id INT UNSIGNED auto_increment NOT NULL comment '商品ID',
product_code CHAR(16) NOT NULL comment '商品编码',
product_name VARCHAR(20) NOT NULL comment '商品名称',
bar_code VARCHAR(50) NOT NULL comment '国条码',
brand_id INT UNSIGNED NOT NULL comment '品牌表ID',
one_category_id SMALLINT UNSIGNED NOT NULL comment '一级分类ID',
two_category_id SMALLINT UNSIGNED NOT NULL comment '二级分类ID',
three_category_id SMALLINT UNSIGNED NOT NULL comment '三级分类ID',
supplier_id INT UNSIGNED NOT NULL comment '商品的供应商ID',
price DECIMAL(8,2) NOT NULL comment '商品售价价格',
average_cost DECIMAL(18,2) NOT NULL comment '商品加权平均成本',
publish_status TINYINT NOT NULL DEFAULT 0  comment '上下架状态:0下架,1上架',
audit_status TINYINT NOT NULL DEFAULT 0 comment '审核状态: 0未审核,1已审核',
weight FLOAT comment '商品重量',
length FLOAT comment '商品长度',
height FLOAT comment '商品重量',
width FLOAT comment '商品宽度',
color_type enum('红','黄'),
production_date DATETIME NOT NULL comment '生产日期',
shelf_life INT NOT NULL comment '商品有效期',
descript TEXT NOT NULL comment '商品描述',
indate TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP comment '商品录入时间',
modified_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '最后修改时间',
PRIMARY KEY pk_productid(product_id)
)engine = innodb comment '商品信息表';

商品图片信息表

CREATE TABLE product_pic_info(
product_pic_id INT UNSIGNED auto_increment NOT NULL comment '商品图片ID',
product_id INT UNSIGNED NOT NULL comment '商品ID',
pic_desc VARCHAR(50) comment '图片描述',
pic_url VARCHAR(200) NOT NULL comment '图片URL',
is_master TINYINT NOT NULL DEFAULT 0 comment '是否主图: 0非主图 1 主图',
pic_order TINYINT NOT NULL DEFAULT 0 comment '图片排序',
pic_status TINYINT NOT NULL DEFAULT 1 comment '图片是否有效:0 无效,1有效',
modified_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '最后修改时间',
PRIMARY KEY pk_picid(product_pic_id)
)engine = innodb comment '商品图片信息表';

订单实体

订单主表

CREATE TABLE order_master(
order_id INT UNSIGNED NOT NULL auto_increment comment '订单ID',
order_sn BIGINT UNSIGNED NOT NULL comment '订单编号 yyyymmddnn',
customer_id INT UNSIGNED NOT NULL comment '下单人ID',
shipping_user VARCHAR(10) NOT NULL comment '收货人姓名',
province SMALLINT NOT NULL comment '省',
city SMALLINT NOT NULL comment '市',
district SMALLINT NOT NULL comment '区',
adress VARCHAR(100) NOT NULL comment '地址',
payment_method TINYINT NOT NULL comment '支付方式:1现金,2余额,3网银,4支付宝,5微信',
order_money DECIMAL(8,2) NOT NULL comment '订单金额',
district_money DECIMAL(8,2) NOT NULL DEFAULT 0.00 comment '优惠金额',
shipping_money DECIMAL(8,2) NOT NULL DEFAULT 0.00 comment '运费金额',
payment_money DECIMAL(8,2) NOT NULL DEFAULT 0.00 comment '支付金额',
shipping_comp_name VARCHAR(10) comment '快递用丝名称',
shipping_sn VARCHAR(50) comment '快递单号',
create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP comment '下单时间',
shipping_time DATETIME comment '发货时间',
pay_time DATETIME comment '支付时间',
receive_time DATETIME comment '收货时间',
order_status TINYINT NOT NULL DEFAULT 0 comment '订单状态',
order_point INT UNSIGNED NOT NULL DEFAULT 0 comment '订单积分',
invoice_title VARCHAR(100) comment '发票抬头',
modified_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '最后修改时间',
PRIMARY KEY pk_orderid(order_id)
)engine = innodb comment '订单主表';

订单详情表

CREATE TABLE order_detail(
order_detail_id INT UNSIGNED NOT NULL auto_increment comment '自增主键ID,订单详情表ID',
order_id INT UNSIGNED NOT NULL comment '订单表Id',
product_id INT UNSIGNED NOT NULL comment '订单商品id',
product_name VARCHAR(50) NOT NULL comment '商品名称',
product_cnt INT NOT NULL DEFAULT 1 comment '购买商品数量',
product_price DECIMAL(8,2) NOT NULL comment '购买商品单价',
average_cost DECIMAL(8,2) NOT NULL DEFAULT 0.00 comment '平均成本价格',
weight FLOAT comment '商品重量',
fee_money DECIMAL(8,2) NOT NULL DEFAULT 0.00 comment '优惠分摊金额',
w_id INT UNSIGNED NOT NULL comment '仓库ID',
modified_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '最后修改时间',
PRIMARY KEY pk_orderdetailid(order_detail_id)
)engine = innodb comment '订单详情表';

购物车

CREATE TABLE order_cart(
cart_id INT UNSIGNED NOT NULL auto_increment comment '购物车ID',
customer_id INT UNSIGNED NOT NULL comment '用户ID',
product_id INT UNSIGNED NOT NULL comment '商品Id',
product_amount INT NOT NULL comment '加入购物车商品数量',
price DECIMAL(8,2) NOT NULL comment '商品价格',
add_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP comment '加入购物车时间',
modified_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '最后修改时间',
PRIMARY KEY pk_cartid(cart_id)
)engine = innodb comment '购物车表';

仓库信息表

CREATE TABLE warehouse_info(
w_id SMALLINT UNSIGNED NOT NULL auto_increment comment '仓库Id',
warehouse_sn CHAR(5) NOT NULL comment '仓库编码',
warehouse_name VARCHAR(10) NOT NULL comment '仓库电话',
contact VARCHAR(10) NOT NULL comment '仓库联系人',
province SMALLINT NOT NULL comment '省',
city SMALLINT NOT NULL comment '市',
district SMALLINT NOT NULL comment '区',
adress VARCHAR(100) NOT NULL comment '仓库地址',
warehouse_status TINYINT NOT NULL DEFAULT 1 comment '仓库状态:0禁用,1启用',
modified_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '最后修改时间',
PRIMARY KEY pk_wid(w_id)
)engine = innodb comment '仓库信息表';

商品库存表

CREATE TABLE warehouse_product(
wp_id INT UNSIGNED NOT NULL auto_increment comment '商品库存ID',
product_id INT UNSIGNED NOT NULL comment '商品ID',
w_id SMALLINT UNSIGNED NOT NULL comment '仓库ID',
current_cnt INT UNSIGNED NOT NULL DEFAULT 0 comment '当前商品的数量',
lock_cnt INT UNSIGNED NOT NULL DEFAULT 0 comment '当前占用数据',
in_transit_cnt INT UNSIGNED NOT NULL DEFAULT 0 comment '在途数据',
average_cost DECIMAL(8,2) NOT NULL DEFAULT 0.00 comment '移动加权成本',
modified_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '最后修改时间',
PRIMARY KEY pk_wpid(wp_id)
)engine = innodb comment '商品库存表';

物流公司表

CREATE TABLE shipping_info(
ship_id TINYINT UNSIGNED NOT NULL auto_increment comment '主键Id',
ship_name VARCHAR(20) NOT NULL comment '物流公司名称',
ship_contact VARCHAR(20) NOT NULL comment '物流公司联系人',
telphone VARCHAR(20) NOT NULL comment '物流公司联系电话',
price DECIMAL(8,2) NOT NULL DEFAULT 0.00 comment '配送价格',
modified_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '最后修改时间',
PRIMARY KEY pk_shipid(ship_id)
)engine = innodb comment '物流公司信息表';
posted @ 2018-10-08 10:55  NiRao  阅读(1764)  评论(0编辑  收藏  举报