USE yami_bbc;

ALTER TABLE `tz_notice`
    ADD COLUMN `user_ids` VARCHAR(500) NULL COMMENT '指定用户ids';

ALTER TABLE `tz_sys_access_key`
    ADD COLUMN `prem_type` TINYINT(0) NOT NULL DEFAULT '0' COMMENT '密钥权限类型 0.全部权限 1.指定权限';


# 店铺地址详情相关字段修改到同城配送

ALTER TABLE `tz_same_city`
    ADD COLUMN `province_id` bigint(0) NULL NULL COMMENT '省ID',
ADD COLUMN `province` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL NULL COMMENT '省' AFTER `province_id`,
ADD COLUMN `city_id` bigint(0) NULL NULL COMMENT '城市ID' AFTER `province`,
ADD COLUMN `city` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL NULL COMMENT '城市' AFTER `city_id`,
ADD COLUMN `area_id` bigint(0) NULL NULL COMMENT '区ID' AFTER `city`,
ADD COLUMN `area` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL NULL COMMENT '区' AFTER `area_id`,
ADD COLUMN `shop_address` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL NULL COMMENT '详细地址' AFTER `area`,
ADD COLUMN `shop_lng` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL NULL COMMENT '店铺所在经度' AFTER `shop_address`,
ADD COLUMN `shop_lat` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL NULL COMMENT '店铺所在维度' AFTER `shop_lng`;

UPDATE `tz_same_city`  sc
    INNER JOIN ( SELECT shop_lng, shop_lat, province_id, province, city_id, city, area_id, area, shop_address, shop_id FROM `tz_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.shop_address = sd.shop_address;

# 删除店铺相关字段
ALTER TABLE `tz_shop_detail`
DROP COLUMN `email`,
DROP COLUMN `shop_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`;




UPDATE `tz_leaf_alloc` SET max_id = 1 WHERE biz_tag IN ("mall4j-pay", "mall4j-order", "mall4j-refund", "mall4j-station", "mall4j-virtual");

UPDATE `tz_leaf_alloc` SET max_id = 1000000000000 WHERE biz_tag IN ("mall4j-product", "mall4j-stock", "mall4j-authorization", "mall4j-alllinpay-update-company-sn", "mall4j-withdraw-cash");

UPDATE `tz_leaf_alloc` SET max_id = 100000000000000 WHERE biz_tag = "mall4j-file-upload";


INSERT INTO `yami_bbc`.`tz_leaf_alloc` (`biz_tag`, `max_id`, `step`, `description`)
VALUES
    ("mall4j-purchases-order", 1, 100, "采购订单编号"),
    ("mall4j-ent-pay-order-no", 1, 100, "分销提现商家转账订单号"),
    ("mall4j-distribution-card-no", 1000000000000, 100, "分销员卡号"),
    ("mall4j-distribution-ticket", 1000000000000, 100, "分销商品二维码"),
    ("mall4j-seckill-order-path", 1000000000000, 100, "秒杀订单路径");
