流程:sql
商品展現-加入購物車-下單-在線支付-發貨-查看物流-收貨
下單:生成訂單(建立對應用戶的訂單)-確認訂單(更新訂單狀態,總金額,地址和快遞方式)-支付(更新訂單狀態)-發貨(更新訂單快遞單號)-查看物流(根據物流單號進行第三方查詢)-收貨(更新訂單狀態)
sql:數據庫
-- 建立數據庫 DROP DATABASE IF EXISTS `shop`; CREATE DATABASE IF NOT EXISTS `shop` DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_general_ci; -- 建立測試表 DROP TABLE IF EXISTS `test`; CREATE TABLE `mg_test` ( `id` int unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT '自增id', `username` varchar(32) NOT NULL DEFAULT '' COMMENT 'test', `password` varchar(32) NOT NULL DEFAULT '' COMMENT 'password' ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 COMMENT='測試表'; insert into mg_test(username, password) values('test', md5('123456')); -- 插入一條測試數據 -- 建立管理員表 DROP TABLE IF EXISTS `shop_admin`; CREATE TABLE IF NOT EXISTS `shop_admin` ( `adminid` int unsigned NOT NULL AUTO_INCREMENT COMMENT '主鍵ID', `adminuser` varchar(32) NOT NULL DEFAULT '' COMMENT '管理員帳號', `adminpass` CHAR(32) NOT NULL DEFAULT '' COMMENT '管理員密碼', `adminemail` varchar(50) NOT NULL DEFAULT '' COMMENT '管理員電子郵箱', `logintime` int unsigned NOT NULL DEFAULT '0' COMMENT '登錄時間', `loginip` BIGINT NOT NULL DEFAULT '0' COMMENT '登錄IP', `createtime` int unsigned NOT NULL DEFAULT '0' COMMENT '建立時間', PRIMARY KEY (`adminid`), UNIQUE shop_admin_adminuser_adminpass(`adminuser`, `adminpass`), UNIQUE shop_admin_adminuser_adminemail(`adminuser`, `adminemail`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '管理員表'; insert into `shop_admin`(adminuser, adminpass, adminemail, createtime) values('admin', md5(123456), 'maoriaty@sina.com', unix_timestamp()) -- 會員表 DROP TABLE IF EXISTS `shop_user`; CREATE TABLE IF NOT EXISTS `shop_user` ( `userid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主鍵id', `openid` char(32) NOT NULL DEFAULT '0' COMMENT 'OPENID', `username` VARCHAR(32) NOT NULL DEFAULT '' COMMENT '用戶名', `userpass` VARCHAR(32) NOT NULL DEFAULT '' COMMENT '用戶密碼', `useremail` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '用戶郵箱', `createtime` INT UNSIGNED NOT NULL DEFAULT '0' COMMENT '建立時間', PRIMARY KEY (`userid`), UNIQUE shop_user_username_userpass(`username`, `userpass`), UNIQUE shop_user_useremail_userpass(`useremail`, `userpass`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '會員表'; -- 會員詳細信息 DROP TABLE IF EXISTS `shop_profile`; CREATE TABLE IF NOT EXISTS `shop_profile` ( `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主鍵id', `truename` VARCHAR(32) NOT NULL DEFAULT '' COMMENT '真實姓名', `age` TINYINT UNSIGNED NOT NULL DEFAULT '0' COMMENT '年齡', `sex` ENUM('0', '1', '2') NOT NULL DEFAULT '0' COMMENT '性別', `birthday` date NOT NULL DEFAULT '1992-12-05' COMMENT '生日', `nickname` VARCHAR(32) NOT NULL DEFAULT '' COMMENT '暱稱', `company` VARCHAR(32) NOT NULL DEFAULT '' COMMENT '公司', `userid` BIGINT UNSIGNED NOT NULL DEFAULT '0' COMMENT '用戶id', `createtime` INT UNSIGNED NOT NULL DEFAULT '0' COMMENT '建立時間', PRIMARY KEY (`id`), UNIQUE shop_profile_userid(`userid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '會員詳細信息表'; -- 無限級商品分類表 DROP TABLE IF EXISTS `shop_category`; CREATE TABLE IF NOT EXISTS `shop_category` ( `cateid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主鍵id', `title` VARCHAR(32) NOT NULL DEFAULT '' COMMENT '標題', `parentid` BIGINT UNSIGNED NOT NULL DEFAULT '0' COMMENT '父級id', `createtime` INT UNSIGNED NOT NULL DEFAULT '0' COMMENT '建立時間', PRIMARY KEY (`cateid`), KEY shop_category_parentid(`parentid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '無限級商品分類表'; -- 商品表 DROP TABLE IF EXISTS `shop_product`; CREATE TABLE IF NOT EXISTS `shop_product` ( `productid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '商品id', `cateid` BIGINT UNSIGNED NOT NULL DEFAULT '0' COMMENT '商品分類id', `title` VARCHAR(200) NOT NULL DEFAULT '' COMMENT '商品標題', `description` TEXT COMMENT '商品描述', `num` BIGINT UNSIGNED NOT NULL DEFAULT '0' COMMENT '庫存', `price` DECIMAL(10, 2) NOT NULL DEFAULT '0.00' COMMENT '價格', `cover` VARCHAR(200) NOT NULL DEFAULT '' COMMENT '封面圖', `pics` TEXT COMMENT '圖片集合', `issale` ENUM('0', '1') NOT NULL DEFAULT '0' COMMENT '是否促銷', `saleprice` DECIMAL(10, 2) NOT NULL DEFAULT '0.00' COMMENT '促銷價格', `ishot` ENUM('0', '1') NOT NULL DEFAULT '0' COMMENT '是否熱賣', `ison` ENUM('0', '1') NOT NULL DEFAULT '0' COMMENT '是否上架', `istui` ENUM('0', '1') NOT NULL DEFAULT '0' COMMENT '是否推薦', `createtime` INT UNSIGNED NOT NULL DEFAULT '0' COMMENT '建立時間', PRIMARY KEY (`productid`), KEY shop_product_cateid(`cateid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '商品表'; -- 購物車表 DROP TABLE IF EXISTS `shop_cart`; CREATE TABLE IF NOT EXISTS `shop_cart` ( `cartid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT '購物車id', `productid` BIGINT UNSIGNED NOT NULL DEFAULT '0' COMMENT '商品id', `userid` BIGINT UNSIGNED NOT NULL DEFAULT '0' COMMENT '用戶id', `productnum` INT UNSIGNED NOT NULL DEFAULT '0' COMMENT '加入購物車的商品數量', `price` DECIMAL(10, 2) NOT NULL DEFAULT '0.00' COMMENT '加入購物車時的商品價格', `createtime` INT UNSIGNED NOT NULL DEFAULT '0' COMMENT '建立時間', KEY shop_cart_userid(`userid`), KEY shop_cart_productid(`productid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '購物車表' -- 訂單表 DROP TABLE IF EXISTS `shop_order`; CREATE TABLE IF NOT EXISTS `shop_order` ( `orderid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT '訂單id', `userid` BIGINT UNSIGNED NOT NULL DEFAULT '0' COMMENT '下單人id', `amount` DECIMAL(10, 2) NOT NULL DEFAULT '0.00' COMMENT '訂單總價', `status` TINYINT UNSIGNED NOT NULL DEFAULT '0' COMMENT '訂單狀態', `addressid` BIGINT UNSIGNED NOT NULL DEFAULT '0' COMMENT '收貨地址', `expressid` INT UNSIGNED NOT NULL DEFAULT '0' COMMENT '快遞id', `expressno` VARCHAR(50) NOT NULL DEFAULT '' COMMENT '快遞單號', `tradeno` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '支付交易號', `tradeext` TEXT COMMENT '支付信息', `createtime` INT UNSIGNED NOT NULL DEFAULT '0' COMMENT '建立時間', `updatetime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新時間', KEY shop_order_userid(`userid`), KEY shop_order_addressid(`addressid`), KEY shop_order_expressid(`expressid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '訂單表'; -- 訂單詳情表 DROP TABLE IF EXISTS `shop_order_detail`; CREATE TABLE IF NOT EXISTS `shop_order_detail`( `detailid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT '訂單詳情id', `orderid` BIGINT UNSIGNED NOT NULL DEFAULT '0' COMMENT '訂單id', `productid` BIGINT UNSIGNED NULL DEFAULT '0' COMMENT '商品id', `price` DECIMAL(10, 2) NOT NULL DEFAULT '0.00' COMMENT '商品價格', `productnum` INT UNSIGNED NOT NULL DEFAULT '0' COMMENT '商品數量', `createtime` INT UNSIGNED NOT NULL DEFAULT '0' COMMENT '建立時間', KEY shop_order_detail_orderid(`orderid`), KEY shop_order_detail_productid(`productid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '訂單詳情表'; -- 收貨地址表 DROP TABLE IF EXISTS `shop_address`; CREATE TABLE IF NOT EXISTS `shop_address`( `addressid` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT '地址id', `firstname` VARCHAR(30) NOT NULL DEFAULT '' COMMENT '姓', `lastname` VARCHAR(30) NOT NULL DEFAULT '' COMMENT '名', `company` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '公司', `address` TEXT COMMENT '詳細地址', `postcode` CHAR(6) NOT NULL DEFAULT '' COMMENT '郵編', `email` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '郵箱', `telephone` VARCHAR(20) NOT NULL DEFAULT '' COMMENT '電話', `userid` BIGINT UNSIGNED NOT NULL DEFAULT '0' COMMENT '用戶id', `createtime` INT NOT NULL DEFAULT '0' COMMENT '建立時間', KEY shop_address_userid(`userid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '收貨地址表';