# 添加mongodb的索引
# 注意：这部分为mongodn的sql

db.coupon_user.ensureIndex({"userId": 1}, {"name": "user_idx"});
db.coupon_user.ensureIndex({"couponId": 1}, {"name": "coupon_idx"});
db.coupon_user.ensureIndex({"shopId": 1}, {"name": "shop_idx"});

db.group_order.ensureIndex({"userId": 1}, {"name": "user_idx"});
db.group_order.ensureIndex({"shopId": 1}, {"name": "shop_idx"});
db.group_order.ensureIndex({"groupActivityId": 1}, {"name": "group_activity_idx"});

db.group_team.ensureIndex({"shopId": 1}, {"name": "shop_idx"});
db.group_team.ensureIndex({"shareUserId": 1}, {"name": "share_user_idx"});
db.group_team.ensureIndex({"groupSpuId": 1}, {"name": "group_spu_idx"});
db.group_team.ensureIndex({"groupActivityId": 1}, {"name": "group_activity_idx"});

db.order.ensureIndex({"userId": 1}, {"name": "user_idx"});
db.order.ensureIndex({"shopId": 1}, {"name": "shop_idx"});
db.order.ensureIndex({"supplierId": 1}, {"name": "supplier_idx"});
db.order.ensureIndex({"stationId": 1}, {"name": "station_idx"});

db.order_refund.ensureIndex({"orderId": 1}, {"name": "order_idx"});
db.order_refund.ensureIndex({"payId": 1}, {"name": "pay_idx"});
db.order_refund.ensureIndex({"userId": 1}, {"name": "user_idx"});
db.order_refund.ensureIndex({"shopId": 1}, {"name": "shop_idx"});
db.order_refund.ensureIndex({"supplierId": 1}, {"name": "supplier_idx"});

db.order_virtual_info_log.ensureIndex({"orderId": 1}, {"name": "order_idx"});
db.order_virtual_info_log.ensureIndex({"shopId": 1}, {"name": "shop_idx"});
db.order_virtual_info_log.ensureIndex({"stationId": 1}, {"name": "station_idx"});

db.purchase_order.ensureIndex({"orderId": 1}, {"name": "order_idx"});
db.purchase_order.ensureIndex({"supplierId": 1}, {"name": "supplier_idx"});

db.stock_bill_log.ensureIndex({"sourceOrderNo": 1}, {"name": "source_order_no_idx"});
db.stock_bill_log.ensureIndex({"shopId": 1}, {"name": "shop_idx"});
db.stock_bill_log.ensureIndex({"stockBillNo": 1, "type": 1}, {"name": "id_order_no"});

db.supplier_wallet_log.ensureIndex({"supplierId": 1, "reason": 1}, {"name": "supplierId_reason_idx"});
db.supplier_wallet_log.ensureIndex({"orderId": 1}, {"name": "order_idx"});

db.flow_regional.ensureIndex({"dateType": 1, "provinceId": 1}, {"name": "data_type_province_idx"});
db.flow_spu.ensureIndex({"dateType": 1, "shopId": 1}, {"name": "data_type_shop_idx"});
db.flow_spu_user.ensureIndex({"spuId": 1, "userId": 1}, {"name": "spu_user_idx"});
db.flow_system.ensureIndex({"dateType": 1, "systemType": 1}, {"name": "date_type_system_type_idx"});
db.flow_system.ensureIndex({"spuId": 1, "userId": 1}, {"name": "spu_user_idx"});
db.flow_system_user.ensureIndex({"userId": 1}, {"name": "user_idx"});
db.flow_system_user.ensureIndex({"dateType": 1, "systemType": 1}, {"name": "date_type_system_type_idx"});
db.flow_user.ensureIndex({"dateType": 1, "type": 1}, {"name": "date_type_type_idx"});
db.flow_user_footprint.ensureIndex({"dateType": 1}, {"name": "date_type_idx"});
db.flow_user_operation.ensureIndex({"userId": 1}, {"name": "user_idx"});
db.flow_user_retain.ensureIndex({"retainType": 1}, {"name": "retain_type_idx"});


# 更改nacos的application.yml配置
# 原配置
# dubbo:
#   application:
#     name: ${spring.cloud.nacos.discovery.namespace}-${spring.application.name}-dubbo-server
# 更改为：
# dubbo:
#   application:
#     name: ${spring.cloud.nacos.discovery.namespace}-${spring.application.name}-dubbo-server
#     serialize-check-status: WARN













# 1 修改canal配置
# 修改canal/example/instance.properties文件，在参数"canal.instance.filter.regex"中补充上"tmerclub_order_[0-9]+.allot_order_[0-9]+:*"，然后重启


USE `tmerclub_product`;
# 商品组合商品相关字段
ALTER TABLE `spu`
    MODIFY `spu_mold` tinyint NOT NULL COMMENT '商品类别 0.实物商品 1.虚拟商品 2.组合商品',
    ADD COLUMN `is_all_entity` INT DEFAULT NULL COMMENT '是否为全部实物商品的组合商品 1.是 0.否';
ALTER TABLE spu DROP COLUMN is_compose;

CREATE TABLE `sku_combo` (
                             `sku_id` bigint NOT NULL COMMENT '规格id',
                             `combo_sku_id` bigint NOT NULL COMMENT '组合的skuid',
                             `combo_spu_id` bigint NOT NULL COMMENT '组合的spuid',
                             `combo_count` int NOT NULL COMMENT '组合数量',
                             `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                             `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                             PRIMARY KEY (`sku_id`,`combo_sku_id`),
                             KEY `idx_spu_id` (`combo_spu_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='规格组合商品管理表';

# 实物盘点字段补充
ALTER TABLE `take_stock`
    ADD COLUMN `warehouse_id` bigint(0) NULL COMMENT '仓库id' AFTER `maker_mobile`,
    ADD COLUMN `stock_point_type` tinyint(0) NULL COMMENT '库存点类型(1:仓库, 2:门店)' AFTER `warehouse_id`;


# 出入库原因添加系统类型字段
ALTER TABLE `stock_change_reason`
    ADD COLUMN `sys_type` tinyint(0) NULL COMMENT '系统类型';

# 添加库存管理表
CREATE TABLE `stock_point_sku` (
                                   `stock_point_sku_id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '库存商品关联skuid',
                                   `stock_point_id` bigint NOT NULL COMMENT '库存点id',
                                   `stock_point_type` tinyint NOT NULL COMMENT '库存点类型 1仓库 2门店',
                                   `spu_id` bigint DEFAULT NULL COMMENT 'spuId',
                                   `sku_id` bigint DEFAULT NULL COMMENT 'skuid',
                                   `supplier_sku_id` bigint DEFAULT NULL COMMENT '当商品为代销商品时，供应商商品skuid',
                                   `status` tinyint DEFAULT '0' COMMENT '状态 1:enable, 0:disable, -1:deleted',
                                   `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                   `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
                                   `type` tinyint DEFAULT '1' COMMENT '仓库类型（0默认仓库，1区域仓库）',
                                   `stock_mode` tinyint DEFAULT NULL COMMENT '库存模式 1共享总部库存 2独立销售库存',
                                   PRIMARY KEY (`stock_point_sku_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

# 新增仓库表
CREATE TABLE `warehouse` (
                             `warehouse_id` bigint NOT NULL COMMENT '仓库id',
                             `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '建立时间',
                             `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
                             `shop_id` bigint DEFAULT NULL COMMENT '店铺id',
                             `warehouse_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '仓库名称',
                             `type` tinyint DEFAULT NULL COMMENT '仓库类型（0默认仓库，1区域仓库）',
                             `address` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '仓库地址',
                             `manage` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '管理人',
                             `phone` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '管理电话',
                             `sys_type` tinyint DEFAULT NULL COMMENT '系统类型',
                             `province_id` bigint DEFAULT NULL COMMENT '省ID',
                             `province` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '省',
                             `city_id` bigint DEFAULT NULL COMMENT '城市ID',
                             `city` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '城市',
                             `area_id` bigint DEFAULT NULL COMMENT '区ID',
                             `area` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '区',
                             PRIMARY KEY (`warehouse_id`),
                             KEY `shop_id` (`shop_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

INSERT INTO `warehouse` (`warehouse_id`,`shop_id`, `warehouse_name`, `type`, `address`, `manage`, `phone`, `sys_type`, `province_id`, `province`, `city_id`, `city`, `area_id`, `area`)
VALUES
    (300000000000000,0,'默认仓库',0,NULL,NULL,NULL,2,NULL,NULL,NULL,NULL,NULL,NULL);

CREATE TABLE `warehouse_area` (
                                  `warehouse_area_id` bigint NOT NULL AUTO_INCREMENT,
                                  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '建立时间',
                                  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
                                  `warehouse_id` bigint DEFAULT NULL COMMENT '仓库id',
                                  `area_id` bigint DEFAULT NULL COMMENT '城市id',
                                  PRIMARY KEY (`warehouse_area_id`) USING BTREE,
                                  KEY `idx_warehouse_id` (`warehouse_id`) USING BTREE,
                                  KEY `idx_city_id` (`area_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='仓库项和供货城市关联信息';


INSERT INTO `leaf_alloc`(`biz_tag`, `max_id`, `step`, `update_time`, `description`) VALUES
    ('tmerclub-stock-point', 1000, 1000, '2023-12-15 17:28:15', '库存点id');

# 给旧门店数据创建一个门店仓库
INSERT INTO `tmerclub_product`.`warehouse` ( `warehouse_id`, `shop_id`, `sys_type`, `type`, `warehouse_name`, `phone`, `province_id`, `province`, `city_id`, `city`, `area_id`, `area`, `address` ) (
    SELECT
        station_id warehouse_id,
        station_id shop_id,
        '4' sys_type,
        '1' type,
        station_name warehouse_name,
        mobile phone,
        province_id,
        province,
        city_id,
        city,
        area_id,
        area,
        addr address
    FROM
        `tmerclub_order`.`station`);





USE tmerclub_order;

INSERT INTO `leaf_alloc`(`biz_tag`, `max_id`, `step`, `update_time`, `description`) VALUES
    ('tmerclub-stock-point', 1000, 1000, '2023-12-15 17:28:15', '库存点id');

# 所有门店添加库存模式，并统一为共享总部库存
ALTER TABLE `station`
    ADD COLUMN `stock_mode` tinyint DEFAULT NULL COMMENT '库存模式 1共享总部库存 2独立销售库存';

update station set stock_mode = 1;

# 删除店铺相关字段，修改店铺地址到同城配送
ALTER TABLE `same_city`
    ADD COLUMN `province_id` bigint(0) NULL DEFAULT NULL COMMENT '省ID' AFTER `lat`,
    ADD COLUMN `province` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '省' AFTER `province_id`,
    ADD COLUMN `city_id` bigint(0) NULL DEFAULT NULL COMMENT '城市ID' AFTER `province`,
    ADD COLUMN `city` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '城市' AFTER `city_id`,
    ADD COLUMN `area_id` bigint(0) NULL DEFAULT NULL COMMENT '区ID' AFTER `city`,
    ADD COLUMN `area` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '区' AFTER `area_id`,
    ADD COLUMN `detail_address` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '详细地址' AFTER `area`,
    ADD COLUMN `shop_lng` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '店铺所在经度' AFTER `detail_address`,
    ADD COLUMN `shop_lat` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '店铺所在维度' AFTER `shop_lng`;

UPDATE `tmerclub_order`.`same_city`  sc
    INNER JOIN ( SELECT shop_lng, shop_lat, province_id, province, city_id, city, area_id, area, detail_address, shop_id FROM `tmerclub_admin`.`shop_detail` ) AS sd ON sc.shop_id = sd.shop_id
    SET sc.shop_lng = sd.shop_lng,
        sc.shop_lat = sd.shop_lat,
        sc.province_id = sd.province_id,
        sc.province = sd.province,
        sc.city_id = sd.city_id,
        sc.city = sd.city,
        sc.area_id = sd.area_id,
        sc.area = sd.area,
        sc.detail_address = sd.detail_address;




# 新增组合商品订单相关字段,此处为了方便查看不重复写代码了,实际需要更改tmerclub_order_0-7的8个库的分库分表!!!!!
USE tmerclub_order_0;
DELIMITER //
DROP PROCEDURE IF EXISTS updateOrderInfo //
CREATE PROCEDURE updateOrderInfo()
BEGIN
    DECLARE i INT;
    SET i = 0;
    WHILE i < 64 DO
        SET @update_order_item = CONCAT("ALTER TABLE order_item_", i,"
                    ADD COLUMN `write_off_num` INT DEFAULT NULL COMMENT '核销次数 -1.多次核销 0.无需核销 1.单次核销' AFTER `supplier_pic`,
                    ADD COLUMN `write_off_multiple_count` INT DEFAULT NULL COMMENT '核销次数 -1.无限次' AFTER `write_off_num`,
                    ADD COLUMN `write_off_start` DATETIME DEFAULT NULL COMMENT '核销开始时间' AFTER `write_off_multiple_count`,
                    ADD COLUMN `write_off_end` DATETIME DEFAULT NULL COMMENT '核销结束时间' AFTER `write_off_start`;
                ");
PREPARE update_order_item FROM @update_order_item;
EXECUTE update_order_item;

SET @update_order = CONCAT( "ALTER TABLE order_", i,"
                    ADD COLUMN main_order_id BIGINT NOT NULL DEFAULT '0' COMMENT '主单号,在组合/套餐商品拆单时会存在' AFTER `write_off_count`;
                ");
PREPARE update_order FROM @update_order;
EXECUTE update_order;

SET @update_order_virtual_lang = CONCAT( "ALTER TABLE order_virtual_info_", i,"
                    ADD COLUMN `order_item_id` bigint NOT NULL DEFAULT '0' COMMENT '订单项id' AFTER `order_id`;
                ");
PREPARE update_order_virtual_lang FROM @update_order_virtual_lang;
EXECUTE update_order_virtual_lang;

SET @add_order_item = CONCAT( "ALTER TABLE order_item_", i, " ADD COLUMN `stock_point_id` bigint DEFAULT NULL COMMENT '库存点id';" );
PREPARE add_allot_order_item FROM @add_order_item;
EXECUTE add_allot_order_item;

SET @add_allot_order = CONCAT( "CREATE TABLE IF NOT EXISTS `allot_order_", i, "` (
          `allot_order_id` bigint(0) NOT NULL COMMENT '调拨订单id',
          `out_warehouse_id` bigint(0) NULL DEFAULT NULL COMMENT '调出点仓库id',
          `out_stock_point_type` int(0) NULL DEFAULT NULL COMMENT '调出点库存点类型(1:仓库, 2:门店)',
          `in_warehouse_id` bigint(0) NULL DEFAULT NULL COMMENT '调入点仓库id',
          `in_stock_point_type` int(0) NULL DEFAULT NULL COMMENT '调入点库存点类型(1:仓库, 2:门店)',
          `dvy_company_id` bigint(0) NULL DEFAULT NULL COMMENT '物流公司id',
          `dvy_type` int(0) NULL DEFAULT NULL COMMENT '物流方式(1:快递, 2:无需快递)',
          `dvy_order_number` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '物流单号',
          `status` int(0) NULL DEFAULT NULL COMMENT '状态(0:作废, 1:待入库, 2:部分入库, 3:已完成)',
          `total_allot_count` int(0) NULL DEFAULT NULL COMMENT '总调拨数量',
          `remark` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '备注',
          `shop_id` bigint(0) NULL COMMENT '店铺id',
          `sys_type` int(1) NULL COMMENT '系统类型',
          `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
          `update_time` datetime(0) NULL DEFAULT NULL COMMENT '更新时间',
          PRIMARY KEY (`allot_order_id`) USING BTREE
        ); " );
PREPARE add_allot_order FROM @add_allot_order;
EXECUTE add_allot_order;

SET @add_allot_order_item = CONCAT( "CREATE TABLE `allot_order_item_", i, "` (
              `allot_order_item_id` bigint NOT NULL COMMENT '调拨订单商品id',
              `allot_order_id` bigint NULL COMMENT '调拨订单id',
              `spu_id` bigint NULL COMMENT '商品spuId',
              `sku_id` bigint NULL COMMENT '商品skuId',
              `allot_count` int(255) NULL COMMENT '调拨数量',
              `allot_in_count` int(255) NULL COMMENT '调拨入库数量',
              `create_time` datetime NULL COMMENT '创建时间',
              `update_time` datetime NULL COMMENT '创建时间',
              PRIMARY KEY (`allot_order_item_id`)
            );" );
PREPARE add_allot_order_item FROM @add_allot_order_item;
EXECUTE add_allot_order_item;

SET i = i + 1;
END WHILE;

END //
CALL updateOrderInfo() //
DROP  PROCEDURE updateOrderInfo //
    DELIMITER ;





# 添加仓库菜单
USE `tmerclub_auth`;

UPDATE `menu` SET  `parent_id` = 424, `biz_type` = 1, `permission` = NULL, `path` = '/manage', `component` = 'inventory', `redirect` = NULL, `always_show` = NULL, `hidden` = 0, `name` = '库存管理', `title` = '库存管理', `icon` = '',  `seq` = 1 WHERE `menu_id` = 426;
UPDATE `menu` SET  `parent_id` = 424, `biz_type` = 1, `permission` = NULL, `path` = '/stock', `component` = 'stock', `redirect` = NULL, `always_show` = NULL, `hidden` = 0, `name` = '库存盘点', `title` = '库存盘点', `icon` = '',  `seq` = 4 WHERE `menu_id` = 575;
UPDATE `menu` SET  `parent_id` = 424, `biz_type` = 1, `permission` = NULL, `path` = '/rec-send-manage', `component` = 'inventory', `redirect` = NULL, `always_show` = NULL, `hidden` = 0, `name` = '出入库管理', `title` = '出入库管理', `icon` = '',  `seq` = 3 WHERE `menu_id` = 432;
UPDATE `menu` SET  `parent_id` = 424, `biz_type` = 1, `permission` = NULL, `path` = '/purchase-manage', `component` = 'inventory', `redirect` = NULL, `always_show` = NULL, `hidden` = 0, `name` = '采购管理', `title` = '采购管理', `icon` = '',  `seq` = 2 WHERE `menu_id` = 429;
UPDATE `menu` SET  `parent_id` = 0, `biz_type` = 3, `permission` = NULL, `path` = '/order', `component` = 'Layout', `redirect` = NULL, `always_show` = NULL, `hidden` = 0, `name` = 'order', `title` = '订单', `icon` = 'order',  `seq` = 3 WHERE `menu_id` = 448;
UPDATE `menu` SET  `parent_id` = 680, `biz_type` = 1, `permission` = NULL, `path` = 'station', `component` = 'order/delivery-manage/station', `redirect` = NULL, `always_show` = NULL, `hidden` = 0, `name` = '门店管理', `title` = '门店管理', `icon` = '',  `seq` = 1 WHERE `menu_id` = 599;


# ！！！680是仓库门店的菜单id，如果有改动需要自行根据id修改
INSERT INTO `menu`(`menu_id`, `create_time`, `update_time`, `parent_id`, `biz_type`, `permission`, `path`, `component`, `redirect`, `always_show`, `hidden`, `name`, `title`, `icon`, `no_cache`, `breadcrumb`, `affix`, `active_menu`, `seq`) VALUES
(680, '2023-11-16 13:46:14', '2023-11-28 14:33:09', 424, 1, NULL, '/stock/warehouse-store', 'inventory', NULL, NULL, 0, '仓库门店', '仓库门店', '', NULL, NULL, NULL, NULL, 0),
(681, '2023-11-16 13:47:53', '2023-11-28 14:33:43', 680, 1, NULL, 'warehouse-manage', 'stock/warehouse-store/warehouse-manage/index', NULL, NULL, 0, '仓库管理', '仓库管理', '', NULL, NULL, NULL, NULL, 0),
(682, '2023-11-20 11:54:19', '2023-11-20 11:54:40', 0, 3, NULL, '/stock', 'Layout', NULL, NULL, 0, '库存', '库存', '', NULL, NULL, NULL, NULL, 2),
(683, '2023-11-20 11:56:35', '2023-11-20 11:56:59', 682, 3, NULL, '/stock/warehouse', '-', NULL, NULL, 0, '仓库管理', '仓库管理', '', NULL, NULL, NULL, NULL, 0),
(684, '2023-11-20 11:58:11', '2023-11-20 13:33:26', 683, 3, NULL, 'warehouse/warehouse-manage', 'stock/warehouse/warehouse-manage', NULL, NULL, 0, '仓库管理', '仓库管理', '', NULL, NULL, NULL, NULL, 0),
(685, '2023-11-23 10:06:44', '2023-11-23 10:07:23', 682, 3, NULL, '/rec-send-manage', 'inventory', NULL, NULL, 0, '出入库管理', '出入库管理', '', NULL, NULL, NULL, NULL, 1),
(686, '2023-11-23 10:08:05', '2023-11-23 10:08:33', 685, 3, NULL, 'stock-send-add-or-update', 'stock/rec-send-manage/out-stock/add-or-update', NULL, NULL, 1, '新建出库明细', '新建出库明细', '', NULL, NULL, NULL, NULL, 0),
(687, '2023-11-23 10:09:15', '2023-11-23 10:09:15', 685, 3, NULL, 'receive-list', 'stock/rec-send-manage/in-stock', NULL, NULL, 0, '入库明细', '入库明细', '', NULL, NULL, NULL, NULL, 1),
(688, '2023-11-23 10:10:03', '2023-11-23 10:10:21', 685, 3, NULL, 'receive-detail', 'stock/rec-send-manage/in-stock/components/in-detail', NULL, NULL, 1, '入库明细详情', '入库明细详情', '', NULL, NULL, NULL, NULL, 0),
(689, '2023-11-23 10:10:56', '2023-11-27 16:52:00', 685, 3, NULL, 'stock-receive-add-or-update', 'stock/rec-send-manage/in-stock/add-or-update', NULL, NULL, 1, '新建入库明细', '新建入库明细', '', NULL, NULL, NULL, NULL, 0),
(690, '2023-11-23 10:11:30', '2023-11-23 10:11:30', 685, 3, NULL, 'customize-reason', 'stock/rec-send-manage/reason', NULL, NULL, 0, '出入库原因', '出入库原因', '', NULL, NULL, NULL, NULL, 2),
(691, '2023-11-23 10:12:02', '2023-11-23 10:12:02', 685, 3, NULL, 'send-list', 'stock/rec-send-manage/out-stock', NULL, NULL, 0, '出库明细', '出库明细', '', NULL, NULL, NULL, NULL, 3),
(692, '2023-11-23 10:13:12', '2023-11-23 10:53:23', 685, 3, NULL, 'send-detail', 'stock/rec-send-manage/out-stock/components/out-detail', NULL, NULL, 1, '出库明细详情', '出库明细详情', '', NULL, NULL, NULL, NULL, 3),
(694, '2023-11-28 14:26:29', '2023-12-14 09:18:33', 680, 1, NULL, 'transfer-order', 'stock/warehouse-store/transfer-order/index', NULL, NULL, 0, '调拨订单', '调拨订单', '', NULL, NULL, NULL, NULL, 2),
(695, '2023-11-28 14:29:21', '2023-11-28 14:32:35', 680, 1, NULL, 'transfer-order-create', 'stock/warehouse-store/transfer-order-create/index', NULL, NULL, 1, '新建调拨订单', '新建调拨订单', '', NULL, NULL, NULL, NULL, 2),
(696, '2023-12-04 16:39:48', '2023-12-04 16:50:11', 683, 3, NULL, 'transfer-order', 'stock/warehouse/transfer-order/index', NULL, NULL, 0, '调拨订单', '调拨订单', '', NULL, NULL, NULL, NULL, 1),
(697, '2023-12-04 16:46:12', '2023-12-04 16:50:39', 683, 3, NULL, 'transfer-order-create', 'stock/warehouse/transfer-order-create/index', NULL, NULL, 1, '新建调拨订单', '新建调拨订单', '', NULL, NULL, NULL, NULL, 0);


USE `tmerclub_seckill`;

ALTER TABLE `seckill`
    ADD COLUMN  `replenish` int DEFAULT NULL COMMENT '补充库存 0不补充 1补充';


CREATE TABLE `seckill_stock_point_sku` (
                                           `seckill_stock_point_sku_id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '库存商品关联skuid',
                                           `stock_point_id` bigint NOT NULL COMMENT '库存点id',
                                           `stock_point_type` tinyint NOT NULL COMMENT '库存点类型 1仓库 2门店',
                                           `sku_id` bigint DEFAULT NULL COMMENT 'sku_id',
                                           `seckill_sku_id` bigint DEFAULT NULL COMMENT '秒杀活动skuid',
                                           `status` tinyint DEFAULT '0' COMMENT '状态 1:enable, 0:disable, -1:deleted',
                                           `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                           `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
                                           `type` tinyint DEFAULT NULL COMMENT '仓库类型（0默认仓库，1区域仓库）',
                                           `seckill_origin_stocks` int DEFAULT NULL COMMENT '秒杀库存点原始库存',
                                           PRIMARY KEY (`seckill_stock_point_sku_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;




USE  `tmerclub_admin`;
ALTER TABLE `shop_detail`
DROP COLUMN `email`,
DROP COLUMN `detail_address`,
DROP COLUMN `shop_lng`,
DROP COLUMN `shop_lat`,
DROP COLUMN `province_id`,
DROP COLUMN `province`,
DROP COLUMN `city_id`,
DROP COLUMN `city`,
DROP COLUMN `area_id`,
DROP COLUMN `area`;

ALTER TABLE `supplier_detail`
DROP COLUMN `email`,
DROP COLUMN `detail_address`,
DROP COLUMN `province_id`,
DROP COLUMN `province`,
DROP COLUMN `city_id`,
DROP COLUMN `city`,
DROP COLUMN `area_id`,
DROP COLUMN `area`;


# 将原sku库存初始化为区域库存
USE tmerclub_job;
# 执行sql后，到xxl-job的控制台页面执行这两个定时任务，分别在商品和秒杀模块下，执行后即可删除，尽量不要重复执行
insert into `xxl_job_info` (`job_group`, `job_desc`, `add_time`, `update_time`, `author`, `alarm_email`, `schedule_type`, `schedule_conf`, `misfire_strategy`, `executor_route_strategy`, `executor_handler`, `executor_param`, `executor_block_strategy`, `executor_timeout`, `executor_fail_retry_count`, `glue_type`, `glue_source`, `glue_remark`, `glue_updatetime`, `child_jobid`, `trigger_status`, `trigger_last_time`, `trigger_next_time`) values
(4,'初始化秒杀区域库存','2023-07-10 09:51:23','2023-07-10 09:52:03','admin','','CRON','0 * * * * ?','DO_NOTHING','FIRST','initPointSeckillStock','','SERIAL_EXECUTION','0','0','BEAN','','GLUE代码初始化','2023-07-10 09:51:23','','0','0','0'),
(11,'初始化区域库存','2023-07-10 09:51:23','2023-07-10 09:52:03','admin','','CRON','0 * * * * ?','DO_NOTHING','FIRST','intiPointStock','','SERIAL_EXECUTION','0','0','BEAN','','GLUE代码初始化','2023-07-10 09:51:23','','0','0','0');
