数据表结构设计
1.用户登录日志表 customer_login
CREATE TABLE customer_login(
login_id INT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '登陆日志ID',
login_name VARCHAR(20) NOT NULL COMMENT '用户登录名',
password CHAR(256) NOT NULL COMMENT 'SHA256加密的密码',
user_stats TINYINT NOT NULL DEFAULT 1 COMMENT '用户状态',
login_time TIMESTAMP NOT NULL COMMENT '用户登陆时间',
login_ip INT UNSIGNED NOT NULL COMMENT '最后登陆IP',
login_type TINYINT NOT NULL COMMENT '登陆类型:0失败,1成功',
PRIMARY KEY pk_loginid(login_id)
) ENGINE = innodb COMMENT '用户登陆日志表';
2.用户信息表(customer_inf)
CREATE TABLE customer_inf(
customer_inf_id INT UNSIGNED AUTO_INCREMENT NOT NULL COMMENT '自增主键ID',
customer_id INT UNSIGNED NOT NULL COMMENT 'customer_login表的自增ID',
mobile_phone INT UNSIGNED COMMENT '手机号',
register_time TIMESTAMP NOT NULL COMMENT '注册时间',
customer_level TINYINT NOT NULL DEFAULT 1 COMMENT '会员级别:1 普通会员,2 青铜,3白银,4黄金,5钻石',
user_money DECIMAL(8,2) NOT NULL DEFAULT 0.00 COMMENT '用户余额',
user_codin DECIMAL(8,2) NOT NULL DEFAULT 0.00 COMMENT '用户codin',
user_money_back TINYINT NOT NULL DEFAULT 0 COMMENT '是否回本:0未回本,1回本',
PRIMARY KEY pk_customerinfid(customer_inf_id)
) ENGINE = innodb COMMENT '用户信息表';
3.用户交易余额变动表(customer_balance_log)
CREATE TABLE customer_balance_log(
balance_id INT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '余额日志ID',
customer_id INT UNSIGNED NOT NULL COMMENT '用户ID',
source TINYINT UNSIGNED NOT NULL DEFAULT 1 COMMENT '记录来源:1订单,2退货单,3.每日结算',
everyday_12time_XCH UNSIGNED NOT NULL 0.00 COMMENT '每天12点XCH的价格',
order_id INT 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 pk_balanceid(balance_id)
) ENGINE = innodb COMMENT '用户余额变动表';
4.购物车表(order_cart)
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 '购物车表';
5.商品库存表(warehouse_product)
CREATE TABLE warehouse_product(
wp_id INT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '商品库存ID',
product_id INT UNSIGNED NOT NULL COMMENT '商品ID',
product_img INT UNSIGNED NOT NULL COMMENT '商品图片',
current_cnt INT UNSIGNED NOT NULL DEFAULT 0 COMMENT '当前商品数量',
modified_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间',
PRIMARY KEY pk_wpid(wp_id)
)ENGINE = innodb COMMENT '商品库存表'
6.订单主表(order_master)
CREATE TABLE order_master(
order_id INT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '订单ID',
order_sn BIGINT UNSIGNED NOT NULL COMMENT '订单编号 yyyymmddnnnnnnnn',
customer_id INT UNSIGNED NOT NULL COMMENT '下单人ID',
payment_method TINYINT NOT NULL COMMENT '支付方式:1现金,2余额,3虚拟币',
order_money DECIMAL(8,2) NOT NULL COMMENT '订单金额',
create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '下单时间',
shipping_time DATETIME COMMENT '服务器开通时间',
pay_time DATETIME COMMENT '支付时间',
order_status TINYINT NOT NULL DEFAULT 0 COMMENT '订单状态',
order_point INT UNSIGNED NOT NULL DEFAULT 0 COMMENT '订单积分',
invoice_time 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 '订单主表';
(写法参考)
DROP TABLE IF EXISTS `yuedu_categories`;
CREATE TABLE `yuedu_categories` (
`cate_id` int(10) NOT NULL AUTO_INCREMENT,
`cate_pid` int(10) DEFAULT '0',
`cate_name` varchar(50) DEFAULT NULL,
`cate_order` int(10) DEFAULT NULL,
PRIMARY KEY (`cate_id`),
KEY `cate_pid` (`cate_pid`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4;
-- ----------------------------
-- Records of yuedu_categories
-- ----------------------------
INSERT INTO `yuedu_categories` VALUES ('1', '0', '美文', '1');
INSERT INTO `yuedu_categories` VALUES ('2', '0', '互联网', '2');
INSERT INTO `yuedu_categories` VALUES ('3', '0', '汽车', '3');
DB规划
为以后数据库迁移提供方便
避免跨库操作,把经常一起关联查询的表放到一个DB中
为方便识别表所在的DB,在表名前增加库名前缀
用户数据表(mc_customer)
customer_inf 用户信息表
customer_login 用户登录日志表
customer_balance_log 用户交易余额变动表
warehouse_produc 商品库存表
order_master 订单主表