/*增加店铺表，同时为相关表添加店铺id*/

/*增加店铺表*/
CREATE TABLE `sale_shop`  (
                              `id` bigint NOT NULL AUTO_INCREMENT COMMENT '店铺id',
                              `name` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '店铺名称',
                              `status` tinyint NOT NULL DEFAULT 1 COMMENT '店铺状态',
                              `merchant_id` bigint NOT NULL DEFAULT 0 COMMENT '商户id',

                              `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
                              `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                              `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
                              `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
                              `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
                              `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号',
                              PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '店铺表' ROW_FORMAT = Dynamic;



ALTER TABLE product_property ADD COLUMN shop_id bigint COMMENT '店铺id';  --  商品属性项表加店铺id
ALTER TABLE product_property_value ADD COLUMN shop_id bigint COMMENT '店铺id';  --  商品属性值表加店铺id
ALTER TABLE product_spu ADD COLUMN shop_id bigint COMMENT '店铺id';  --  商品SPU表加店铺id
ALTER TABLE product_sku ADD COLUMN shop_id bigint COMMENT '店铺id';  --  商品SKU表加店铺id
ALTER TABLE trade_order ADD COLUMN shop_id bigint COMMENT '店铺id';  --  订单主表加店铺id
ALTER TABLE product_comment ADD COLUMN shop_id bigint COMMENT '店铺id';  --  商品评价表加店铺id
ALTER TABLE trade_after_sale ADD COLUMN shop_id bigint COMMENT '店铺id';  --  售后订单表加店铺id
ALTER TABLE trade_delivery_express_template ADD COLUMN shop_id bigint COMMENT '店铺id';  --  快递运费模板主表加店铺id
ALTER TABLE trade_delivery_pick_up_store ADD COLUMN shop_id bigint COMMENT '店铺id';  --  自提门店表加店铺id


/*增加商户表*/
CREATE TABLE `sale_merchant`  (
                                  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '商户id',
                                  `name` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '商户名称',
                                  `status` tinyint NOT NULL DEFAULT 1 COMMENT '商户状态',
                                  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '商户描述',
                                  `contact` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '负责人',
                                  `address` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '地址',
                                  `contact_number` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '负责人电话',
                                  `website` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '官网',
                                  `expire_time` datetime NULL COMMENT '到期时间',

                                  `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
                                  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                  `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
                                  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
                                  `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
                                  `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号',
                                  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '店铺表' ROW_FORMAT = Dynamic;

ALTER TABLE product_property ADD COLUMN merchant_id bigint COMMENT '商户id';  --  商品属性项表加店铺id
ALTER TABLE product_property_value ADD COLUMN merchant_id bigint COMMENT '商户id';  --  商品属性值表加店铺id
ALTER TABLE product_spu ADD COLUMN merchant_id bigint COMMENT '商户id';  --  商品SPU表加店铺id
ALTER TABLE product_sku ADD COLUMN merchant_id bigint COMMENT '商户id';  --  商品SKU表加店铺id
ALTER TABLE trade_order ADD COLUMN merchant_id bigint COMMENT '商户id';  --  订单主表加店铺id
ALTER TABLE product_comment ADD COLUMN merchant_id bigint COMMENT '商户id';  --  商品评价表加店铺id
ALTER TABLE trade_after_sale ADD COLUMN merchant_id bigint COMMENT '商户id';  --  售后订单表加店铺id
ALTER TABLE trade_delivery_express_template ADD COLUMN merchant_id bigint COMMENT '商户id';  --  快递运费模板主表加店铺id
ALTER TABLE trade_delivery_pick_up_store ADD COLUMN merchant_id bigint COMMENT '商户id';  --  自提门店表加店铺id


ALTER TABLE product_spu ADD COLUMN hidden bit(1) NOT NULL DEFAULT b'0' COMMENT '是否隐藏。隐藏：1，不隐藏：0';  --  控制商品是否显示。


/*增加店铺状态表*/
CREATE TABLE `sale_shop_status`  (
                                     `id` bigint NOT NULL COMMENT 'id',
                                     `name` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '名称',

                                     `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
                                     `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                     `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
                                     `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
                                     `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
                                     `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号',
                                     PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '店铺状态表' ROW_FORMAT = Dynamic;

INSERT INTO sale_shop_status (id,name) VALUES(1,'营业中');
INSERT INTO sale_shop_status (id,name) VALUES(2,'暂停营业');
INSERT INTO sale_shop_status (id,name) VALUES(3,'停用');

commit;

/*增加用户类型表*/
CREATE TABLE `system_user_category`  (
                                         `id` bigint NOT NULL COMMENT 'id',
                                         `name` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '名称',

                                         `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
                                         `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                         `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
                                         `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
                                         `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
                                         `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号',
                                         PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '店铺状态表' ROW_FORMAT = Dynamic;

INSERT INTO system_user_category (id,name) VALUES(1,'系统管理员');
INSERT INTO system_user_category (id,name) VALUES(5,'店铺管理员');
commit;

/*用户表、角色、菜单表 添加用户类型字段。*/
ALTER TABLE system_users ADD COLUMN category_id bigint NULL COMMENT '用户类型'; -- 用户表添加用户类型字段
ALTER TABLE system_role ADD COLUMN category_id bigint NULL COMMENT '用户类型'; -- 角色表添加用户类型字段
ALTER TABLE system_menu ADD COLUMN category_id bigint NULL COMMENT '用户类型'; -- 菜单表添加用户类型字段

/*用户表system_users还要添加店铺ID字段*/
ALTER TABLE system_users ADD COLUMN shop_id bigint NULL COMMENT '店铺id';




