4、微服务数据库设计(1)

# 1、 renrenmall_pms --->人人商城-商品服务 <img src="https://cos.easydoc.net/40732029/files/kt1dz27i.png"/> ```sql drop table if exists pms_attr; drop table if exists pms_attr_attrgroup_relation; drop table if exists pms_attr_group; drop table if exists pms_brand; drop table if exists pms_category; drop table if exists pms_category_brand_relation; drop table if exists pms_comment_replay; drop table if exists pms_product_attr_value; drop table if exists pms_sku_images; drop table if exists pms_sku_info; drop table if exists pms_sku_sale_attr_value; drop table if exists pms_spu_comment; drop table if exists pms_spu_images; drop table if exists pms_spu_info; drop table if exists pms_spu_info_desc; /*==============================================================*/ /* Table: pms_attr */ /*==============================================================*/ create table pms_attr ( attr_id bigint not null auto_increment comment '属性id', attr_name char(30) comment '属性名', search_type tinyint comment '是否需要检索[0-不需要,1-需要]', icon varchar(255) comment '属性图标', value_select char(255) comment '可选值列表[用逗号分隔]', attr_type tinyint comment '属性类型[0-销售属性,1-基本属性,2-既是销售属性又是基本属性]', enable bigint comment '启用状态[0 - 禁用,1 - 启用]', catelog_id bigint comment '所属分类', show_desc tinyint comment '快速展示【是否展示在介绍上;0-否 1-是】,在sku中仍然可以调整', primary key (attr_id) ); alter table pms_attr comment '商品属性'; /*==============================================================*/ /* Table: pms_attr_attrgroup_relation */ /*==============================================================*/ create table pms_attr_attrgroup_relation ( id bigint not null auto_increment comment 'id', attr_id bigint comment '属性id', attr_group_id bigint comment '属性分组id', attr_sort int comment '属性组内排序', primary key (id) ); alter table pms_attr_attrgroup_relation comment '属性&属性分组关联'; /*==============================================================*/ /* Table: pms_attr_group */ /*==============================================================*/ create table pms_attr_group ( attr_group_id bigint not null auto_increment comment '分组id', attr_group_name char(20) comment '组名', sort int comment '排序', descript varchar(255) comment '描述', icon varchar(255) comment '组图标', catelog_id bigint comment '所属分类id', primary key (attr_group_id) ); alter table pms_attr_group comment '属性分组'; /*==============================================================*/ /* Table: pms_brand */ /*==============================================================*/ create table pms_brand ( brand_id bigint not null auto_increment comment '品牌id', name char(50) comment '品牌名', logo varchar(2000) comment '品牌logo地址', descript longtext comment '介绍', show_status tinyint comment '显示状态[0-不显示;1-显示]', first_letter char(1) comment '检索首字母', sort int comment '排序', primary key (brand_id) ); alter table pms_brand comment '品牌'; /*==============================================================*/ /* Table: pms_category */ /*==============================================================*/ create table pms_category ( cat_id bigint not null auto_increment comment '分类id', name char(50) comment '分类名称', parent_cid bigint comment '父分类id', cat_level int comment '层级', show_status tinyint comment '是否显示[0-不显示,1显示]', sort int comment '排序', icon char(255) comment '图标地址', product_unit char(50) comment '计量单位', product_count int comment '商品数量', primary key (cat_id) ); alter table pms_category comment '商品三级分类'; /*==============================================================*/ /* Table: pms_category_brand_relation */ /*==============================================================*/ create table pms_category_brand_relation ( id bigint not null auto_increment, brand_id bigint comment '品牌id', catelog_id bigint comment '分类id', brand_name varchar(255), catelog_name varchar(255), primary key (id) ); alter table pms_category_brand_relation comment '品牌分类关联'; /*==============================================================*/ /* Table: pms_comment_replay */ /*==============================================================*/ create table pms_comment_replay ( id bigint not null auto_increment comment 'id', comment_id bigint comment '评论id', reply_id bigint comment '回复id', primary key (id) ); alter table pms_comment_replay comment '商品评价回复关系'; /*==============================================================*/ /* Table: pms_product_attr_value */ /*==============================================================*/ create table pms_product_attr_value ( id bigint not null auto_increment comment 'id', spu_id bigint comment '商品id', attr_id bigint comment '属性id', attr_name varchar(200) comment '属性名', attr_value varchar(200) comment '属性值', attr_sort int comment '顺序', quick_show tinyint comment '快速展示【是否展示在介绍上;0-否 1-是】', primary key (id) ); alter table pms_product_attr_value comment 'spu属性值'; /*==============================================================*/ /* Table: pms_sku_images */ /*==============================================================*/ create table pms_sku_images ( id bigint not null auto_increment comment 'id', sku_id bigint comment 'sku_id', img_url varchar(255) comment '图片地址', img_sort int comment '排序', default_img int comment '默认图[0 - 不是默认图,1 - 是默认图]', primary key (id) ); alter table pms_sku_images comment 'sku图片'; /*==============================================================*/ /* Table: pms_sku_info */ /*==============================================================*/ create table pms_sku_info ( sku_id bigint not null auto_increment comment 'skuId', spu_id bigint comment 'spuId', sku_name varchar(255) comment 'sku名称', sku_desc varchar(2000) comment 'sku介绍描述', catalog_id bigint comment '所属分类id', brand_id bigint comment '品牌id', sku_default_img varchar(255) comment '默认图片', sku_title varchar(255) comment '标题', sku_subtitle varchar(2000) comment '副标题', price decimal(18,4) comment '价格', sale_count bigint comment '销量', primary key (sku_id) ); alter table pms_sku_info comment 'sku信息'; /*==============================================================*/ /* Table: pms_sku_sale_attr_value */ /*==============================================================*/ create table pms_sku_sale_attr_value ( id bigint not null auto_increment comment 'id', sku_id bigint comment 'sku_id', attr_id bigint comment 'attr_id', attr_name varchar(200) comment '销售属性名', attr_value varchar(200) comment '销售属性值', attr_sort int comment '顺序', primary key (id) ); alter table pms_sku_sale_attr_value comment 'sku销售属性&值'; /*==============================================================*/ /* Table: pms_spu_comment */ /*==============================================================*/ create table pms_spu_comment ( id bigint not null auto_increment comment 'id', sku_id bigint comment 'sku_id', spu_id bigint comment 'spu_id', spu_name varchar(255) comment '商品名字', member_nick_name varchar(255) comment '会员昵称', star tinyint(1) comment '星级', member_ip varchar(64) comment '会员ip', create_time datetime comment '创建时间', show_status tinyint(1) comment '显示状态[0-不显示,1-显示]', spu_attributes varchar(255) comment '购买时属性组合', likes_count int comment '点赞数', reply_count int comment '回复数', resources varchar(1000) comment '评论图片/视频[json数据;[{type:文件类型,url:资源路径}]]', content text comment '内容', member_icon varchar(255) comment '用户头像', comment_type tinyint comment '评论类型[0 - 对商品的直接评论,1 - 对评论的回复]', primary key (id) ); alter table pms_spu_comment comment '商品评价'; /*==============================================================*/ /* Table: pms_spu_images */ /*==============================================================*/ create table pms_spu_images ( id bigint not null auto_increment comment 'id', spu_id bigint comment 'spu_id', img_name varchar(200) comment '图片名', img_url varchar(255) comment '图片地址', img_sort int comment '顺序', default_img tinyint comment '是否默认图', primary key (id) ); alter table pms_spu_images comment 'spu图片'; /*==============================================================*/ /* Table: pms_spu_info */ /*==============================================================*/ create table pms_spu_info ( id bigint not null auto_increment comment '商品id', spu_name varchar(200) comment '商品名称', spu_description varchar(1000) comment '商品描述', catalog_id bigint comment '所属分类id', brand_id bigint comment '品牌id', weight decimal(18,4), publish_status tinyint comment '上架状态[0 - 下架,1 - 上架]', create_time datetime, update_time datetime, primary key (id) ); alter table pms_spu_info comment 'spu信息'; /*==============================================================*/ /* Table: pms_spu_info_desc */ /*==============================================================*/ create table pms_spu_info_desc ( spu_id bigint not null comment '商品id', decript longtext comment '商品介绍', primary key (spu_id) ); alter table pms_spu_info_desc comment 'spu信息介绍'; ``` # 2、renrenmall_wms ---> 人人商城-仓储服务 <img src="https://cos.easydoc.net/40732029/files/kt1f19ay.png"/> ```sql /*Table structure for table `undo_log` */ DROP TABLE IF EXISTS `undo_log`; CREATE TABLE `undo_log` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `branch_id` bigint(20) NOT NULL, `xid` varchar(100) NOT NULL, `context` varchar(128) NOT NULL, `rollback_info` longblob NOT NULL, `log_status` int(11) NOT NULL, `log_created` datetime NOT NULL, `log_modified` datetime NOT NULL, `ext` varchar(100) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*Data for the table `undo_log` */ /*Table structure for table `wms_purchase` */ DROP TABLE IF EXISTS `wms_purchase`; CREATE TABLE `wms_purchase` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `assignee_id` bigint(20) DEFAULT NULL, `assignee_name` varchar(255) DEFAULT NULL, `phone` char(13) DEFAULT NULL, `priority` int(4) DEFAULT NULL, `status` int(4) DEFAULT NULL, `ware_id` bigint(20) DEFAULT NULL, `amount` decimal(18,4) DEFAULT NULL, `create_time` datetime DEFAULT NULL, `update_time` datetime DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='采购信息'; /*Data for the table `wms_purchase` */ /*Table structure for table `wms_purchase_detail` */ DROP TABLE IF EXISTS `wms_purchase_detail`; CREATE TABLE `wms_purchase_detail` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `purchase_id` bigint(20) DEFAULT NULL COMMENT '采购单id', `sku_id` bigint(20) DEFAULT NULL COMMENT '采购商品id', `sku_num` int(11) DEFAULT NULL COMMENT '采购数量', `sku_price` decimal(18,4) DEFAULT NULL COMMENT '采购金额', `ware_id` bigint(20) DEFAULT NULL COMMENT '仓库id', `status` int(11) DEFAULT NULL COMMENT '状态[0新建,1已分配,2正在采购,3已完成,4采购失败]', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; /*Data for the table `wms_purchase_detail` */ /*Table structure for table `wms_ware_info` */ DROP TABLE IF EXISTS `wms_ware_info`; CREATE TABLE `wms_ware_info` ( `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id', `name` varchar(255) DEFAULT NULL COMMENT '仓库名', `address` varchar(255) DEFAULT NULL COMMENT '仓库地址', `areacode` varchar(20) DEFAULT NULL COMMENT '区域编码', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='仓库信息'; /*Data for the table `wms_ware_info` */ /*Table structure for table `wms_ware_order_task` */ DROP TABLE IF EXISTS `wms_ware_order_task`; CREATE TABLE `wms_ware_order_task` ( `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id', `order_id` bigint(20) DEFAULT NULL COMMENT 'order_id', `order_sn` varchar(255) DEFAULT NULL COMMENT 'order_sn', `consignee` varchar(100) DEFAULT NULL COMMENT '收货人', `consignee_tel` char(15) DEFAULT NULL COMMENT '收货人电话', `delivery_address` varchar(500) DEFAULT NULL COMMENT '配送地址', `order_comment` varchar(200) DEFAULT NULL COMMENT '订单备注', `payment_way` tinyint(1) DEFAULT NULL COMMENT '付款方式【 1:在线付款 2:货到付款】', `task_status` tinyint(2) DEFAULT NULL COMMENT '任务状态', `order_body` varchar(255) DEFAULT NULL COMMENT '订单描述', `tracking_no` char(30) DEFAULT NULL COMMENT '物流单号', `create_time` datetime DEFAULT NULL COMMENT 'create_time', `ware_id` bigint(20) DEFAULT NULL COMMENT '仓库id', `task_comment` varchar(500) DEFAULT NULL COMMENT '工作单备注', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='库存工作单'; /*Data for the table `wms_ware_order_task` */ /*Table structure for table `wms_ware_order_task_detail` */ DROP TABLE IF EXISTS `wms_ware_order_task_detail`; CREATE TABLE `wms_ware_order_task_detail` ( `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id', `sku_id` bigint(20) DEFAULT NULL COMMENT 'sku_id', `sku_name` varchar(255) DEFAULT NULL COMMENT 'sku_name', `sku_num` int(11) DEFAULT NULL COMMENT '购买个数', `task_id` bigint(20) DEFAULT NULL COMMENT '工作单id', `ware_id` bigint(20) DEFAULT NULL COMMENT '仓库id', `lock_status` int(1) DEFAULT NULL COMMENT '1-已锁定 2-已解锁 3-扣减', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='库存工作单'; /*Data for the table `wms_ware_order_task_detail` */ /*Table structure for table `wms_ware_sku` */ DROP TABLE IF EXISTS `wms_ware_sku`; CREATE TABLE `wms_ware_sku` ( `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id', `sku_id` bigint(20) DEFAULT NULL COMMENT 'sku_id', `ware_id` bigint(20) DEFAULT NULL COMMENT '仓库id', `stock` int(11) DEFAULT NULL COMMENT '库存数', `sku_name` varchar(200) DEFAULT NULL COMMENT 'sku_name', `stock_locked` int(11) DEFAULT '0' COMMENT '锁定库存', PRIMARY KEY (`id`), KEY `sku_id` (`sku_id`) USING BTREE, KEY `ware_id` (`ware_id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='商品库存'; /*Data for the table `wms_ware_sku` */ /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; ``` # 3、renrenmall_oms ---> 人人商城-订单服务 <img src="https://cos.easydoc.net/40732029/files/kt1faq5i.png"/> ```sql drop table if exists oms_order; drop table if exists oms_order_item; drop table if exists oms_order_operate_history; drop table if exists oms_order_return_apply; drop table if exists oms_order_return_reason; drop table if exists oms_order_setting; drop table if exists oms_payment_info; drop table if exists oms_refund_info; /*==============================================================*/ /* Table: oms_order */ /*==============================================================*/ create table oms_order ( id bigint not null auto_increment comment 'id', member_id bigint comment 'member_id', order_sn char(32) comment '订单号', coupon_id bigint comment '使用的优惠券', create_time datetime comment 'create_time', member_username varchar(200) comment '用户名', total_amount decimal(18,4) comment '订单总额', pay_amount decimal(18,4) comment '应付总额', freight_amount decimal(18,4) comment '运费金额', promotion_amount decimal(18,4) comment '促销优化金额(促销价、满减、阶梯价)', integration_amount decimal(18,4) comment '积分抵扣金额', coupon_amount decimal(18,4) comment '优惠券抵扣金额', discount_amount decimal(18,4) comment '后台调整订单使用的折扣金额', pay_type tinyint comment '支付方式【1->支付宝;2->微信;3->银联; 4->货到付款;】', source_type tinyint comment '订单来源[0->PC订单;1->app订单]', status tinyint comment '订单状态【0->待付款;1->待发货;2->已发货;3->已完成;4->已关闭;5->无效订单】', delivery_company varchar(64) comment '物流公司(配送方式)', delivery_sn varchar(64) comment '物流单号', auto_confirm_day int comment '自动确认时间(天)', integration int comment '可以获得的积分', growth int comment '可以获得的成长值', bill_type tinyint comment '发票类型[0->不开发票;1->电子发票;2->纸质发票]', bill_header varchar(255) comment '发票抬头', bill_content varchar(255) comment '发票内容', bill_receiver_phone varchar(32) comment '收票人电话', bill_receiver_email varchar(64) comment '收票人邮箱', receiver_name varchar(100) comment '收货人姓名', receiver_phone varchar(32) comment '收货人电话', receiver_post_code varchar(32) comment '收货人邮编', receiver_province varchar(32) comment '省份/直辖市', receiver_city varchar(32) comment '城市', receiver_region varchar(32) comment '区', receiver_detail_address varchar(200) comment '详细地址', note varchar(500) comment '订单备注', confirm_status tinyint comment '确认收货状态[0->未确认;1->已确认]', delete_status tinyint comment '删除状态【0->未删除;1->已删除】', use_integration int comment '下单时使用的积分', payment_time datetime comment '支付时间', delivery_time datetime comment '发货时间', receive_time datetime comment '确认收货时间', comment_time datetime comment '评价时间', modify_time datetime comment '修改时间', primary key (id) ); alter table oms_order comment '订单'; /*==============================================================*/ /* Table: oms_order_item */ /*==============================================================*/ create table oms_order_item ( id bigint not null auto_increment comment 'id', order_id bigint comment 'order_id', order_sn char(32) comment 'order_sn', spu_id bigint comment 'spu_id', spu_name varchar(255) comment 'spu_name', spu_pic varchar(500) comment 'spu_pic', spu_brand varchar(200) comment '品牌', category_id bigint comment '商品分类id', sku_id bigint comment '商品sku编号', sku_name varchar(255) comment '商品sku名字', sku_pic varchar(500) comment '商品sku图片', sku_price decimal(18,4) comment '商品sku价格', sku_quantity int comment '商品购买的数量', sku_attrs_vals varchar(500) comment '商品销售属性组合(JSON)', promotion_amount decimal(18,4) comment '商品促销分解金额', coupon_amount decimal(18,4) comment '优惠券优惠分解金额', integration_amount decimal(18,4) comment '积分优惠分解金额', real_amount decimal(18,4) comment '该商品经过优惠后的分解金额', gift_integration int comment '赠送积分', gift_growth int comment '赠送成长值', primary key (id) ); alter table oms_order_item comment '订单项信息'; /*==============================================================*/ /* Table: oms_order_operate_history */ /*==============================================================*/ create table oms_order_operate_history ( id bigint not null auto_increment comment 'id', order_id bigint comment '订单id', operate_man varchar(100) comment '操作人[用户;系统;后台管理员]', create_time datetime comment '操作时间', order_status tinyint comment '订单状态【0->待付款;1->待发货;2->已发货;3->已完成;4->已关闭;5->无效订单】', note varchar(500) comment '备注', primary key (id) ); alter table oms_order_operate_history comment '订单操作历史记录'; /*==============================================================*/ /* Table: oms_order_return_apply */ /*==============================================================*/ create table oms_order_return_apply ( id bigint not null auto_increment comment 'id', order_id bigint comment 'order_id', sku_id bigint comment '退货商品id', order_sn char(32) comment '订单编号', create_time datetime comment '申请时间', member_username varchar(64) comment '会员用户名', return_amount decimal(18,4) comment '退款金额', return_name varchar(100) comment '退货人姓名', return_phone varchar(20) comment '退货人电话', status tinyint(1) comment '申请状态[0->待处理;1->退货中;2->已完成;3->已拒绝]', handle_time datetime comment '处理时间', sku_img varchar(500) comment '商品图片', sku_name varchar(200) comment '商品名称', sku_brand varchar(200) comment '商品品牌', sku_attrs_vals varchar(500) comment '商品销售属性(JSON)', sku_count int comment '退货数量', sku_price decimal(18,4) comment '商品单价', sku_real_price decimal(18,4) comment '商品实际支付单价', reason varchar(200) comment '原因', description述 varchar(500) comment '描述', desc_pics varchar(2000) comment '凭证图片,以逗号隔开', handle_note varchar(500) comment '处理备注', handle_man varchar(200) comment '处理人员', receive_man varchar(100) comment '收货人', receive_time datetime comment '收货时间', receive_note varchar(500) comment '收货备注', receive_phone varchar(20) comment '收货电话', company_address varchar(500) comment '公司收货地址', primary key (id) ); alter table oms_order_return_apply comment '订单退货申请'; /*==============================================================*/ /* Table: oms_order_return_reason */ /*==============================================================*/ create table oms_order_return_reason ( id bigint not null auto_increment comment 'id', name varchar(200) comment '退货原因名', sort int comment '排序', status tinyint(1) comment '启用状态', create_time datetime comment 'create_time', primary key (id) ); alter table oms_order_return_reason comment '退货原因'; /*==============================================================*/ /* Table: oms_order_setting */ /*==============================================================*/ create table oms_order_setting ( id bigint not null auto_increment comment 'id', flash_order_overtime int comment '秒杀订单超时关闭时间(分)', normal_order_overtime int comment '正常订单超时时间(分)', confirm_overtime int comment '发货后自动确认收货时间(天)', finish_overtime int comment '自动完成交易时间,不能申请退货(天)', comment_overtime int comment '订单完成后自动好评时间(天)', member_level tinyint(2) comment '会员等级【0-不限会员等级,全部通用;其他-对应的其他会员等级】', primary key (id) ); alter table oms_order_setting comment '订单配置信息'; /*==============================================================*/ /* Table: oms_payment_info */ /*==============================================================*/ create table oms_payment_info ( id bigint not null auto_increment comment 'id', order_sn char(32) comment '订单号(对外业务号)', order_id bigint comment '订单id', alipay_trade_no varchar(50) comment '支付宝交易流水号', total_amount decimal(18,4) comment '支付总金额', subject varchar(200) comment '交易内容', payment_status varchar(20) comment '支付状态', create_time datetime comment '创建时间', confirm_time datetime comment '确认时间', callback_content varchar(4000) comment '回调内容', callback_time datetime comment '回调时间', primary key (id) ); alter table oms_payment_info comment '支付信息表'; /*==============================================================*/ /* Table: oms_refund_info */ /*==============================================================*/ create table oms_refund_info ( id bigint not null auto_increment comment 'id', order_return_id bigint comment '退款的订单', refund decimal(18,4) comment '退款金额', refund_sn varchar(64) comment '退款交易流水号', refund_status tinyint(1) comment '退款状态', refund_channel tinyint comment '退款渠道[1-支付宝,2-微信,3-银联,4-汇款]', refund_content varchar(5000), primary key (id) ); alter table oms_refund_info comment '退款信息'; ```