1. 流程图。这个是自己项目的业务,仅供参考!
1. 脚本 如下
create database pgs_product;
use pgs_product;
-- 产品表
DROP TABLE IF EXISTS product;
CREATE TABLE product (
id bigint(11) UNSIGNED NOT NULL primary key AUTO_INCREMENT COMMENT '主键id',
name varchar(64) NOT NULL COMMENT '产品名称',
code varchar(64) DEFAULT NULL COMMENT '产品编码',
short_name varchar(32) DEFAULT NULL COMMENT '产品简称或者别名',
unit varchar(32) DEFAULT NULL COMMENT '单位',
category_id int(11) NULL COMMENT '分类ID',
status tinyint(1) UNSIGNED DEFAULT '1' COMMENT '产品状态,1上架 2下架',
description varchar(255) DEFAULT NULL COMMENT '描述',
deleted tinyint(1) UNSIGNED DEFAULT '0' COMMENT '删除标识 0未删除 1删除',
create_time timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT '创建时间',
update_time timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT '更新时间',
INDEX idx_id(id) USING BTREE,
UNIQUE uk_code(code) using btree
) engine = InnoDB Auto_increment = 1 character set = utf8mb4 collate = utf8mb4_general_ci comment = '产品表' row_format = dynamic;
-- 产品模型表 一条数据就是一个有规格属性的的商品.单品参加套餐其实就是一模一样的一条数据仅仅参与价格不同
DROP TABLE IF EXISTS product_model;
CREATE TABLE product_model (
id bigint(11) UNSIGNED NOT NULL primary key AUTO_INCREMENT COMMENT '主键id',
product_id int(11) NOT NULL COMMENT '关联的产品id',
model_code varchar(64) DEFAULT NULL COMMENT '编码',
property_options JSON NULL COMMENT '菜品关联的属性选项集合JSON(propertyId+Name+valueId+Name)',
picture_url varchar(255) DEFAULT NULL COMMENT '商品图片连接',
stock int(11) DEFAULT '-1000' NULL COMMENT '商品库存 默认-1000是没有库存限制',
price decimal(10,2) DEFAULT NULL COMMENT '此商品价格',
vip_price decimal(10,2) DEFAULT NULL COMMENT '商品的VIP价格',
package_price decimal(10,2) DEFAULT NULL COMMENT '商品参与的套餐价格',
deleted tinyint(1) UNSIGNED DEFAULT '0' COMMENT '删除标识 0未删除 1删除',
create_time timestamp(3) NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT '创建时间',
update_time timestamp(3) NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT '更新时间',
INDEX idx_productId(product_id) USING BTREE,
UNIQUE uk_modelCode(model_code) using btree
) engine = InnoDB Auto_increment = 1 character set = utf8mb4 collate = utf8mb4_general_ci comment = '产品模型表' row_format = dynamic;
-- 商品表 单品和套餐都是一条数据体现
DROP TABLE IF EXISTS commodity;
CREATE TABLE commodity (
id bigint(11) UNSIGNED NOT NULL primary key AUTO_INCREMENT COMMENT '主键id',
name varchar(64) NOT NULL COMMENT '商品名称',
code varchar(64) NOT NULL COMMENT '商品编码',
short_name varchar(32) DEFAULT NULL COMMENT '商品简称或者别名',
unit varchar(32) DEFAULT NULL COMMENT '单位',
category_id int(11) NULL COMMENT '分类ID',
picture_url JSON DEFAULT NULL COMMENT '商品图片连接集合',
product_ids JSON DEFAULT NULL COMMENT '关联的产品/商品集合(套餐必选产品才用)',
attach_commodity JSON DEFAULT NULL COMMENT '关联附属商品集合 比如口味商品',
type tinyint(1) UNSIGNED DEFAULT '1' COMMENT '商品类型,1单品2固定套餐3组合套餐4口味',
low_price decimal(10,2) DEFAULT NULL COMMENT '套餐最低价格,套餐可能才有',
high_price decimal(10,2) DEFAULT NULL COMMENT '套餐最高价格,套餐可能才有',
status tinyint(1) UNSIGNED DEFAULT '1' COMMENT '商品状态1在售2停售',
description varchar(255) DEFAULT NULL COMMENT '描述',
deleted tinyint(1) UNSIGNED DEFAULT '0' COMMENT '删除标识 0未删除 1删除',
create_time timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT '创建时间',
update_time timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT '更新时间',
INDEX idx_id(id) USING BTREE,
UNIQUE uk_code(code) using btree
) engine = InnoDB Auto_increment = 1 character set = utf8mb4 collate = utf8mb4_general_ci comment = '商品表' row_format = dynamic;
-- 商品关系表
DROP TABLE IF EXISTS commodity_relations;
CREATE TABLE commodity_relations (
id bigint(11) UNSIGNED NOT NULL primary key AUTO_INCREMENT COMMENT '主键id',
commodity_id int(11) NOT NULL COMMENT '关联的商品id',
product_model_id int(11) NOT NULL COMMENT '关联的产品模型id',
contain_sell_count int(11) UNSIGNED DEFAULT '1' COMMENT '关联的产品模型数量',
package_group_id int(11) NULL COMMENT '商品模型属于的组,只有组合套餐时候才有',
package_price decimal(10,2) DEFAULT NULL COMMENT '商品参与的套餐价格',
deleted tinyint(1) UNSIGNED DEFAULT '0' COMMENT '删除标识 0未删除 1删除',
create_time timestamp(3) NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT '创建时间',
update_time timestamp(3) NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT '更新时间',
INDEX idx_commodityId(commodity_id) USING BTREE
) engine = InnoDB Auto_increment = 1 character set = utf8mb4 collate = utf8mb4_general_ci comment = '商品关系表' row_format = dynamic;
-- 套餐分组表
DROP TABLE IF EXISTS package_group;
CREATE TABLE package_group (
id bigint(11) UNSIGNED NOT NULL primary key AUTO_INCREMENT COMMENT '主键id',
commodity_id int(11) NOT NULL COMMENT '商品id',
name varchar(255) NOT NULL COMMENT '组名称',
kind tinyint(1) DEFAULT '2' COMMENT '组合套餐类型,1:默认全选2:顾客自选',
max_commodity_count int(11) DEFAULT NULL COMMENT '可选数量 注:只有顾客自选时才有用',
create_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
update_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
deleted tinyint(1) NOT NULL DEFAULT '0' COMMENT '删除标识',
sort int(11) NOT NULL DEFAULT '1' COMMENT '排序',
INDEX idx_commodityId(commodity_id) USING BTREE
) engine = InnoDB Auto_increment = 1 character set = utf8mb4 collate = utf8mb4_general_ci comment = '套餐分组表' row_format = dynamic;