商品表

    1. CREATE TABLE product_info (
    2. product_id VARCHAR(32) NOT NULL,
    3. product_name VARCHAR(64) NOT NULL,
    4. product_price DECIMAL(8, 2) NOT NULL,
    5. product_stock INT NOT NULL COMMENT '库存',
    6. product_description VARCHAR(64) COMMENT '描述' ,
    7. product_icon VARCHAR(512) COMMENT '图片链接 ',
    8. category_type INT NOT NULL COMMENT '类目编号',
    9. create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    10. update_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    11. PRIMARY KEY (product_id)
    12. ) ENGINE = innodb COMMENT '商品表';

    类目表

    1. CREATE TABLE product_category (
    2. category_id INT NOT NULL AUTO_INCREMENT,
    3. category_name VARCHAR(64) NOT NULL,
    4. category_type INT NOT NULL COMMENT '类目编号',
    5. create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    6. update_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    7. PRIMARY KEY (category_id),
    8. UNIQUE KEY uqe_category_type (category_type) # 唯一外键
    9. ) ENGINE = INNODB COMMENT '类目表';

    订单表

    1. CREATE TABLE order_master (
    2. order_id VARCHAR(32) NOT NULL,
    3. buyer_name VARCHAR(32) NOT NULL,
    4. buyer_phone VARCHAR(32) NOT NULL,
    5. buyer_address VARCHAR(128) NOT NULL,
    6. buyer_openid VARCHAR(64) NOT NULL,
    7. order_amount DECIMAL(8,2) NOT NULL,
    8. order_status TINYINT(3) DEFAULT '0' NOT NULL COMMENT 'order status, default is zero',
    9. pay_status TINYINT(0) NOT NULL DEFAULT '0' COMMENT 'payment status default is zero means do not paid',
    10. create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    11. update_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    12. PRIMARY KEY (order_id),
    13. KEY idx_buyer_openid (buyer_openid)
    14. ) ENGINE = INNODB COMMENT '订单主表';

    订单详情

    1. CREATE TABLE order_detail (
    2. detail_id VARCHAR(32) NOT NULL,
    3. order_id VARCHAR(32) NOT NULL,
    4. product_id VARCHAR(32) NOT NULL,
    5. product_name VARCHAR(64) NOT NULL,
    6. product_price DECIMAL(8,2) NOT NULL,
    7. product_quantity INT NOT NULL,
    8. product_icon VARCHAR(512),
    9. create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    10. update_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    11. PRIMARY KEY (detail_id),
    12. KEY idx_order_id (order_id)
    13. ) ENGINE = INNODB COMMENT '订单详情';