CREATE TABLE `customer_login` ( `customer_id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '用戶ID', `login_name` varchar(20) NOT NULL COMMENT '用戶登錄名', `password` char(32) NOT NULL COMMENT 'md5加密的密碼', `user_stats` tinyint NOT NULL DEFAULT '1' COMMENT '用戶狀態', `modified_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最後修改時間', PRIMARY KEY (`customer_id`) ) ENGINE=InnoDB COMMENT='用戶登錄表';
CREATE TABLE `customer_inf` ( `customer_inf_id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主鍵ID', `customer_id` int unsigned NOT NULL COMMENT 'customer_login表的自增ID', `customer_name` varchar(20) NOT NULL COMMENT '用戶真實姓名', `identity_card_type` tinyint NOT NULL DEFAULT '1' COMMENT '證件類型:1 身份證,2軍官證,3護照', `identity_card_no` varchar(20) DEFAULT NULL COMMENT '證件號碼', `mobile_phone` int unsigned DEFAULT NULL COMMENT '手機號', `customer_email` varchar(50) DEFAULT NULL COMMENT '郵箱', `gender` char(1) DEFAULT NULL COMMENT '性別', `user_point` int 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 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 COMMENT='用戶信息表';
CREATE TABLE `customer_level_inf` ( `customer_level` tinyint NOT NULL AUTO_INCREMENT COMMENT '會員級別ID', `level_name` varchar(10) NOT NULL COMMENT '會員級別名稱', `min_point` int unsigned NOT NULL DEFAULT 0 COMMENT '該級別最低積分', `max_point` int unsigned NOT NULL DEFAULT 0 COMMENT '該級別最高積分', `modified_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最後修改時間', PRIMARY KEY (`customer_level`) ) ENGINE=InnoDB COMMENT='用戶信息表';
CREATE TABLE `order_customer_addr` ( `customer_addr_id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主鍵ID', `customer_id` int unsigned NOT NULL COMMENT 'customer_login表的自增ID', `zip` smallint NOT NULL COMMENT '郵編', `province` smallint NOT NULL COMMENT '地區表中省份的id', `city` smallint NOT NULL COMMENT '地區表中城市的id', `district` smallint NOT NULL COMMENT '地區表中的區id', `address` varchar(200) NOT NULL COMMENT '具體的地址門牌號', `is_default` tinyint NOT NULL COMMENT '是否默認', `modified_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最後修改時間', PRIMARY KEY (`customer_addr_id`) ) ENGINE=InnoDB COMMENT='用戶地址表';
CREATE TABLE `customer_point_log` ( `point_id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '積分日誌ID', `customer_id` int unsigned NOT NULL COMMENT '用戶ID', `source` tinyint unsigned NOT NULL COMMENT '積分來源:0訂單,1登陸,2活動', `refer_number` int unsigned NOT NULL DEFAULT '0' COMMENT '積分來源相關編號', `change_point` smallint NOT NULL DEFAULT '0' COMMENT '變動積分數', `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '積分日誌生成時間', PRIMARY KEY (`point_id`) ) ENGINE=InnoDB COMMENT='用戶積分日誌表';
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退貨單', `source_sn` 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 (`balance_id`) ) ENGINE=InnoDB COMMENT='用戶餘額變更表';
CREATE TABLE `customer_login_log` ( `login_id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '登陸日誌ID', `customer_id` int unsigned NOT NULL COMMENT '登陸用戶ID', `login_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '用戶登陸時間', `login_ip` int unsigned NOT NULL COMMENT '登陸IP', `login_type` tinyint NOT NULL COMMENT '登陸類型:0未成功 1成功', PRIMARY KEY (`login_id`) ) ENGINE=InnoDB COMMENT='用戶登陸日誌表';
CREATE TABLE `product_brand_info` ( `brand_id` smallint 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 NOT NULL DEFAULT '0' COMMENT '品牌狀態,0禁用,1啓用', `brand_order` tinyint NOT NULL DEFAULT '0' COMMENT '排序', `modified_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最後修改時間', PRIMARY KEY (`brand_id`) ) ENGINE=InnoDB COMMENT='品牌信息表';
CREATE TABLE `product_category` ( `category_id` smallint unsigned NOT NULL AUTO_INCREMENT 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 '分類狀態', `modified_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最後修改時間', PRIMARY KEY (`category_id`) ) ENGINE=InnoDB COMMENT='商品分類表';
CREATE TABLE `product_supplier_info` ( `supplier_id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '供應商ID', `supplier_code` char(8) NOT NULL COMMENT '供應商編碼', `supplier_name` char(50) NOT NULL COMMENT '供應商名稱', `supplier_type` tinyint 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 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 COMMENT='供應商信息表';
CREATE TABLE `product_info` ( `product_id` int 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 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 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 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 COMMENT='商品信息表';
CREATE TABLE `product_pic_info` ( `product_pic_id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '商品圖片ID', `product_id` int unsigned NOT NULL COMMENT '商品ID', `pic_desc` varchar(50) DEFAULT NULL 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 (`product_pic_id`) ) ENGINE=InnoDB COMMENT='商品圖片信息表';
CREATE TABLE `product_comment` ( `comment_id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '評論ID', `product_id` int unsigned NOT NULL COMMENT '商品ID', `order_id` bigint unsigned NOT NULL COMMENT '訂單ID', `customer_id` int unsigned NOT NULL COMMENT '用戶ID', `title` varchar(50) NOT NULL COMMENT '評論標題', `content` varchar(300) NOT NULL COMMENT '評論內容', `audit_status` tinyint 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 COMMENT='商品評論表';
CREATE TABLE `order_master` ( `order_id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '訂單ID', `order_sn` bigint(20) unsigned NOT NULL COMMENT '訂單編號 yyyymmddnnnnnnnn', `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 '收貨人所在區', `address` 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) 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 NOT NULL DEFAULT '0' COMMENT '訂單狀態', `order_point` int 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 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 DEFAULT NULL 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 (`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 (`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 '倉庫名稱', `warehouse_phone` varchar(20) NOT NULL COMMENT '倉庫電話', `contact` varchar(10) NOT NULL COMMENT '倉庫聯繫人', `province` smallint NOT NULL COMMENT '省', `city` smallint NOT NULL COMMENT '市', `district` smallint NOT NULL COMMENT '區', `address` 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 (`w_id`) ) ENGINE=InnoDB COMMENT='倉庫信息表';
CREATE TABLE `warehouse_proudct` ( `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', `currnet_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 (`wp_id`) ) ENGINE=InnoDB 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='物流公司信息表';
用戶數據庫(mc_userdb):用戶信息表(customer_inf)、用戶登陸表(customer_login)、 用戶級別表(customer_level_inf)、用戶積分日誌表(customer_point_log)、用戶餘額變更表(customer_balance_log)、 用戶登陸日誌表(customer_login_log)
商品數據庫(mc_productdb):品牌信息表(product_brand_info)、商品分類表(product_category)、供應商信息表(product_supplier_info)、商品信息表(product_info)、商品圖片信息表(product_pic_info)、商品評論表(product_comment)
訂單數據庫(mc_orderdb):訂單主表(order_master)、訂單詳情表(order_detail)、用戶地址表(customer_addr)、倉庫信息表(warehouse_info)、物流公司信息表(shipping_info)、 購物車表(order_cart)web