数据库设计
商品数据库
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `mc_productdb` ;
/*品牌信息表*/
CREATE TABLE `product_brand_info` (
`brand_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT COMMENT '品牌ID',
`brand_name` varchar(50) NOT NULL COMMENT '品牌名称',
`telephone` varchar(50) NOT NULL COMMENT '联系电话',
`brand_web` varchar(100) DEFAULT NULL COMMENT '品牌网站',
`brand_logo` varchar(100) DEFAULT NULL COMMENT '品牌logo URL',
`brand_desc` varchar(150) DEFAULT NULL COMMENT '品牌描述',
`brand_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '品牌状态,0禁用,1启用',
`brand_order` tinyint(4) NOT NULL DEFAULT '0' COMMENT '排序',
`modified_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间',
PRIMARY KEY (`brand_id`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8 COMMENT='品牌信息表';
/*商品信息表*/
CREATE TABLE `product_category` (
`category_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT COMMENT '分类ID',
`category_name` varchar(10) NOT NULL COMMENT '分类名称',
`category_code` varchar(10) NOT NULL COMMENT '分类编码',
`parent_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT '父分类ID',
`category_level` tinyint(4) NOT NULL DEFAULT '1' COMMENT '分类层级',
`category_status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '分类状态',
`modified_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间',
PRIMARY KEY (`category_id`)
) ENGINE=InnoDB AUTO_INCREMENT=73 DEFAULT CHARSET=utf8 COMMENT='商品分类表';
/*商品评论表*/
CREATE TABLE `product_comment` (
`comment_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '评论ID',
`product_id` int(10) unsigned NOT NULL COMMENT '商品ID',
`order_id` bigint(20) unsigned NOT NULL COMMENT '订单ID',
`customer_id` int(10) unsigned NOT NULL COMMENT '用户ID',
`title` varchar(50) NOT NULL COMMENT '评论标题',
`content` varchar(300) NOT NULL COMMENT '评论内容',
`audit_status` tinyint(4) NOT NULL COMMENT '审核状态:0未审核1已审核',
`audit_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '评论时间',
`modified_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间',
PRIMARY KEY (`comment_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='商品评论表';
/*商品信息表*/
CREATE TABLE `product_info` (
`product_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '商品ID',
`product_code` char(16) NOT NULL COMMENT '商品编码',
`product_name` varchar(50) NOT NULL COMMENT '商品名称',
`bar_code` varchar(50) NOT NULL COMMENT '国条码',
`brand_id` int(10) unsigned NOT NULL COMMENT '品牌表的ID',
`one_category_id` smallint(5) unsigned NOT NULL COMMENT '一级分类ID',
`two_category_id` smallint(5) unsigned NOT NULL COMMENT '二级分类ID',
`three_category_id` smallint(5) unsigned NOT NULL COMMENT '三级分类ID',
`supplier_id` int(10) unsigned NOT NULL COMMENT '商品的供应商id',
`price` decimal(8,2) NOT NULL COMMENT '商品销售价格',
`average_cost` decimal(18,2) NOT NULL COMMENT '商品加权平均成本',
`publish_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '上下架状态:0下架1上架',
`audit_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '审核状态:0未审核,1已审核',
`weight` float DEFAULT NULL COMMENT '商品重量',
`length` float DEFAULT NULL COMMENT '商品长度',
`heigh` float DEFAULT NULL COMMENT '商品高度',
`width` float DEFAULT NULL COMMENT '商品宽度',
`color_type` enum('红','黄','蓝','黒') DEFAULT NULL,
`production_date` datetime NOT NULL COMMENT '生产日期',
`shelf_life` int(11) 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 (`product_id`)
) ENGINE=InnoDB AUTO_INCREMENT=262141 DEFAULT CHARSET=utf8 COMMENT='商品信息表';
/*商品图片信息表*/
CREATE TABLE `product_pic_info` (
`product_pic_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '商品图片ID',
`product_id` int(10) unsigned NOT NULL COMMENT '商品ID',
`pic_desc` varchar(50) DEFAULT NULL COMMENT '图片描述',
`pic_url` varchar(200) NOT NULL COMMENT '图片URL',
`is_master` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否主图:0.非主图1.主图',
`pic_order` tinyint(4) NOT NULL DEFAULT '0' COMMENT '图片排序',
`pic_status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '图片是否有效:0无效 1有效',
`modified_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间',
PRIMARY KEY (`product_pic_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='商品图片信息表';
/*供应商信息表*/
CREATE TABLE `product_supplier_info` (
`supplier_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '供应商ID',
`supplier_code` char(8) NOT NULL COMMENT '供应商编码',
`supplier_name` char(50) NOT NULL COMMENT '供应商名称',
`supplier_type` tinyint(4) NOT NULL COMMENT '供应商类型:1.自营,2.平台',
`link_man` varchar(10) NOT NULL COMMENT '供应商联系人',
`phone_number` varchar(50) NOT NULL COMMENT '联系电话',
`bank_name` varchar(50) NOT NULL COMMENT '供应商开户银行名称',
`bank_account` varchar(50) NOT NULL COMMENT '银行账号',
`address` varchar(200) NOT NULL COMMENT '供应商地址',
`supplier_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '状态:0禁用,1启用',
`modified_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间',
PRIMARY KEY (`supplier_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='供应商信息表';
/*serial*/
CREATE TABLE `serial` (
`id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2076 DEFAULT CHARSET=utf8;
用户信息库
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `mc_userdb` ;
/*用户余额变动表*/
CREATE TABLE `customer_balance_log` (
`balance_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '余额日志id',
`customer_id` int(10) unsigned NOT NULL COMMENT '用户ID',
`source` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '记录来源:1订单,2退货单',
`source_sn` int(10) unsigned NOT NULL COMMENT '相关单据ID',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '记录生成时间',
`amount` decimal(8,2) NOT NULL DEFAULT '0.00' COMMENT '变动金额',
PRIMARY KEY (`balance_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户余额变动表';
/*用户信息表*/
CREATE TABLE `customer_inf` (
`customer_inf_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键ID',
`customer_id` int(10) unsigned NOT NULL COMMENT 'customer_login表的自增ID',
`customer_name` varchar(20) NOT NULL COMMENT '用户真实姓名',
`identity_card_type` tinyint(4) NOT NULL DEFAULT '1' COMMENT '证件类型:1 身份证,2军官证,3护照',
`identity_card_no` varchar(20) DEFAULT NULL COMMENT '证件号码',
`mobile_phone` int(10) unsigned DEFAULT NULL COMMENT '手机号',
`customer_email` varchar(50) DEFAULT NULL COMMENT '邮箱',
`gender` char(1) DEFAULT NULL COMMENT '性别',
`user_point` int(11) NOT NULL DEFAULT '0' COMMENT '用户积分',
`register_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '注册时间',
`birthday` datetime DEFAULT NULL COMMENT '会员生日',
`customer_level` tinyint(4) NOT NULL DEFAULT '1' COMMENT '会员级别:1普通会员,2青铜会员,3白银会员,4黄金会员,5钻石会员',
`user_money` decimal(8,2) NOT NULL DEFAULT '0.00' COMMENT '用户余额',
`modified_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间',
PRIMARY KEY (`customer_inf_id`)
) ENGINE=InnoDB AUTO_INCREMENT=16384 DEFAULT CHARSET=utf8 COMMENT='用户信息表';
/*用户登陆表*/
CREATE TABLE `customer_login` (
`customer_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '用户ID',
`login_name` varchar(20) NOT NULL COMMENT '用户登陆名',
`password` char(32) NOT NULL COMMENT 'md5加密的密码',
`user_stats` tinyint(4) NOT NULL DEFAULT '1' COMMENT '用户状态',
`modified_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间',
PRIMARY KEY (`customer_id`)
) ENGINE=InnoDB AUTO_INCREMENT=10011 DEFAULT CHARSET=utf8 COMMENT='用户登陆表';
/*用户登录日志表*/
CREATE TABLE `customer_login_log` (
`login_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '登录日志ID',
`customer_id` int(10) unsigned NOT NULL COMMENT '登录用户ID',
`login_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '用户登录时间',
`login_ip` int(10) unsigned NOT NULL COMMENT '登录IP',
`login_type` tinyint(4) NOT NULL COMMENT '登录类型:0未成功 1成功',
PRIMARY KEY (`login_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户登录日志表';
/*用户积分日志表*/
CREATE TABLE `customer_point_log` (
`point_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '积分日志ID',
`customer_id` int(10) unsigned NOT NULL COMMENT '用户ID',
`source` tinyint(3) unsigned NOT NULL COMMENT '积分来源:0订单,1登录,2活动',
`refer_number` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '积分来源相关编号',
`change_point` smallint(6) NOT NULL DEFAULT '0' COMMENT '变更积分数',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '积分日志生成时间',
PRIMARY KEY (`point_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户积分日志表';
订单表
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `mc_orderdb` ;
/*购物车表*/
CREATE TABLE `order_cart` (
`cart_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '购物车ID',
`customer_id` int(10) unsigned NOT NULL COMMENT '用户ID',
`product_id` int(10) unsigned NOT NULL COMMENT '商品ID',
`product_amount` int(11) 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 (`cart_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='购物车表';
/*用户地址表*/
CREATE TABLE `order_customer_addr` (
`customer_addr_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键ID',
`customer_id` int(10) unsigned NOT NULL COMMENT 'customer_login表的自增ID',
`zip` int(11) NOT NULL COMMENT '邮编',
`province` int(11) NOT NULL COMMENT '地区表中省份的id',
`city` int(11) NOT NULL COMMENT '地区表中城市的id',
`district` int(11) NOT NULL COMMENT '地区表中的区id',
`address` varchar(200) NOT NULL COMMENT '具体的地址门牌号',
`is_default` tinyint(4) NOT NULL COMMENT '是否默认',
`modified_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间',
PRIMARY KEY (`customer_addr_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户地址表';
/*订单详情表*/
CREATE TABLE `order_detail` (
`order_detail_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键ID,订单详情表ID',
`order_id` int(10) unsigned NOT NULL COMMENT '订单表ID',
`product_id` int(10) unsigned NOT NULL COMMENT '订单商品ID',
`product_name` varchar(50) NOT NULL COMMENT '商品名称',
`product_cnt` int(11) 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 DEFAULT NULL COMMENT '商品重量',
`fee_money` decimal(8,2) NOT NULL DEFAULT '0.00' COMMENT '优惠分摊金额',
`w_id` int(10) unsigned NOT NULL COMMENT '仓库ID',
`modified_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间',
PRIMARY KEY (`order_detail_id`)
) ENGINE=InnoDB AUTO_INCREMENT=29698 DEFAULT CHARSET=utf8 COMMENT='订单详情表';
/*订单主表*/
CREATE TABLE `order_master` (
`order_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '订单ID',
`order_sn` bigint(20) unsigned NOT NULL COMMENT '订单编号 yyyymmddnnnnnnnn',
`customer_id` int(10) unsigned NOT NULL COMMENT '下单人ID',
`shipping_user` varchar(10) NOT NULL COMMENT '收货人姓名',
`province` smallint(6) NOT NULL COMMENT '收货人所在省',
`city` smallint(6) NOT NULL COMMENT '收货人所在市',
`district` smallint(6) NOT NULL COMMENT '收货人所在区',
`address` varchar(100) NOT NULL COMMENT '收货人详细地址',
`payment_method` tinyint(4) 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) DEFAULT NULL COMMENT '快递公司名称',
`shipping_sn` varchar(50) DEFAULT NULL COMMENT '快递单号',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '下单时间',
`shipping_time` datetime DEFAULT NULL COMMENT '发货时间',
`pay_time` datetime DEFAULT NULL COMMENT '支付时间',
`receive_time` datetime DEFAULT NULL COMMENT '收货时间',
`order_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '订单状态',
`order_point` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '订单积分',
`invoice_title` varchar(100) DEFAULT NULL COMMENT '发票抬头',
`modified_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间',
PRIMARY KEY (`order_id`),
UNIQUE KEY `ux_ordersn` (`order_sn`)
) ENGINE=InnoDB AUTO_INCREMENT=10011 DEFAULT CHARSET=utf8 COMMENT='订单主表';
/*地区信息表*/
CREATE TABLE `region_info` (
`region_id` smallint(6) NOT NULL AUTO_INCREMENT COMMENT '主键id',
`parent_id` smallint(6) NOT NULL DEFAULT '0' COMMENT '上级地区id',
`region_name` varchar(150) NOT NULL COMMENT '城市名称',
`region_level` tinyint(1) NOT NULL COMMENT '级别',
PRIMARY KEY (`region_id`)
) ENGINE=InnoDB AUTO_INCREMENT=17625 DEFAULT CHARSET=utf8 COMMENT='地区信息表';
/*物流公司信息表*/
CREATE TABLE `shipping_info` (
`ship_id` tinyint(3) 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 (`ship_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='物流公司信息表';
/*仓库信息表*/
CREATE TABLE `warehouse_info` (
`w_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT COMMENT '仓库ID',
`warehouse_sn` char(5) NOT NULL COMMENT '仓库编码',
`warehouse_name` varchar(10) NOT NULL COMMENT '仓库名称',
`warehouse_phone` varchar(20) NOT NULL COMMENT '仓库电话',
`contact` varchar(10) NOT NULL COMMENT '仓库联系人',
`province` smallint(6) NOT NULL COMMENT '省',
`city` smallint(6) NOT NULL COMMENT '市',
`district` smallint(6) NOT NULL COMMENT '区',
`address` varchar(100) NOT NULL COMMENT '仓库地址',
`warehouse_status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '仓库状态:0禁用,1启用',
`modified_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间',
PRIMARY KEY (`w_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='仓库信息表';
/*商品库存表*/
CREATE TABLE `warehouse_proudct` (
`wp_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '商品库存ID',
`product_id` int(10) unsigned NOT NULL COMMENT '商品id',
`w_id` smallint(5) unsigned NOT NULL COMMENT '仓库ID',
`currnet_cnt` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '当前商品数量',
`lock_cnt` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '当前占用数据',
`in_transit_cnt` int(10) 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 (`wp_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='商品库存表';