/*!40101 SET NAMES utf8mb4 */;

/*!40101 SET SQL_MODE=''*/;

/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
CREATE DATABASE IF NOT EXISTS mall4cloud_order DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

USE `mall4cloud_order`;

/*Table structure for table `area` */

DROP TABLE IF EXISTS `area`;

CREATE TABLE `area` (
  `area_id` bigint NOT NULL AUTO_INCREMENT,
  `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `area_name` varchar(50) NOT NULL COMMENT '地址',
  `parent_id` bigint NOT NULL COMMENT '上级地址',
  `level` int NOT NULL COMMENT '等级（从1开始）',
  PRIMARY KEY (`area_id`),
  KEY `parent_id` (`parent_id`) COMMENT '上级id'
) ENGINE=InnoDB AUTO_INCREMENT=659041 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='省市区地区信息';

/*Data for the table `area` */

/*Table structure for table `delivery_company` */

DROP TABLE IF EXISTS `delivery_company`;

CREATE TABLE `delivery_company` (
  `delivery_company_id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `name` varchar(50) NOT NULL DEFAULT '' COMMENT '物流公司名称',
  `home_url` varchar(255) DEFAULT NULL COMMENT '公司主页',
  `ali_no` varchar(20) DEFAULT NULL COMMENT '物流公司编号(阿里)',
  `bird_no` varchar(20) DEFAULT NULL COMMENT '物流公司编号(快递鸟)',
  `hundred_no` varchar(20) DEFAULT NULL COMMENT '物流公司编号(快递100)',
  `other_no` varchar(20) DEFAULT NULL COMMENT '物流公司编号(其他不知名公司)',
  PRIMARY KEY (`delivery_company_id`)
) ENGINE=InnoDB AUTO_INCREMENT=46 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='物流公司';

/*Data for the table `delivery_company` */

insert  into `delivery_company`(`delivery_company_id`,`create_time`,`update_time`,`name`,`home_url`,`ali_no`,`bird_no`,`hundred_no`,`other_no`) values
  (14,'2015-08-20 11:58:03','2021-05-18 11:07:49','顺丰快递公司','http://www.sf-express.com','SFEXPRESS','SF','shunfeng',NULL),
  (15,'2015-08-20 11:58:24','2021-05-18 11:08:01','申通快递公司','http://www.sto-express.com','STO','STO','shentong',NULL),
  (16,'2015-08-20 11:58:48','2021-05-18 11:07:25','中通速递','http://www.zto.cn','ZTO','ZTO','zhongtong',NULL),
  (18,'2015-12-22 10:38:15','2021-05-18 11:07:15','EMS','http://www.ems.com.cn','EMS','EMS','ems',NULL),
  (20,'2015-12-22 10:39:46','2021-05-18 11:07:05','汇通快递','http://www.htky365.com','HTKY','HT','httx56',NULL),
  (21,'2015-12-22 10:40:44','2021-05-18 11:06:58','天天快递','http://www.ttkdex.com','TTKDEX','HHTT','tiantian',NULL),
  (22,'2015-12-22 10:42:55','2021-05-18 11:06:43','佳吉快运','http://www.jiaji.com','JIAJI','CNEX','jiajiwuliu',NULL),
  (23,'2015-12-22 10:43:35','2021-05-18 11:06:27','速尔快递','http://www.sure56.com','SURE','SURE','suer',NULL),
  (24,'2015-12-22 10:44:17','2021-05-18 11:06:11','信丰物流','http://www.xf-express.com.cn','XFEXPRESS','XFEX','xinfengwuliu',NULL),
  (25,'2015-12-22 10:44:51','2021-05-18 11:06:04','韵达快递','http://www.yundaex.com','YUNDA','YD','yunda',NULL),
  (26,'2015-12-22 10:45:20','2021-05-18 11:05:54','优速快递','http://www.uc56.com','UC56','UC','youshuwuliu',NULL),
  (27,'2015-12-22 10:45:58','2021-05-18 11:05:43','中邮物流','http://www.cnpl.com.cn','CNPL','ZYKD','zhongyouwuliu',NULL),
  (28,'2015-12-22 11:44:18','2021-05-18 11:05:34','圆通快递','http://www.yto.net.cn','YTO','YTO','yuantong',NULL),
  (29,'2015-12-22 11:45:55','2021-05-18 11:05:25','宅急送','http://www.zjs.com.cn','ZJS','ZJS','zhaijisong',NULL),
  (30,'2015-12-22 11:45:55','2021-05-18 11:05:11','百世快递','http://www.800bestex.com','HTKY','HTKY','huitongkuaidi',NULL),
  (31,'2015-12-22 11:45:55','2021-05-18 11:04:59','邮政快递包裹','http://yjcx.chinapost.com.cn','INTMAIL','YZPY','youzhengguonei',NULL),
  (32,'2015-12-22 11:45:55','2021-05-18 11:04:31','京东快递','http://www.jdwl.com','JD','JD','jd',NULL),
  (33,'2015-12-22 11:45:55','2021-05-18 11:04:21','德邦快递','http://www.deppon.com/newwebsite','DEPPON','DBL','debangkuaidi',NULL);

/*Table structure for table `station` */

DROP TABLE IF EXISTS `station`;

CREATE TABLE `station` (
  `station_id` bigint NOT NULL AUTO_INCREMENT 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',
  `station_name` varchar(255) DEFAULT NULL COMMENT '自提点名称',
  `img_url` varchar(1000) DEFAULT NULL COMMENT '自提点图片',
  `mobile_prefix` varchar(20) DEFAULT NULL COMMENT '电话区号',
  `mobile` varchar(20) DEFAULT NULL COMMENT '手机/电话号码',
  `province_id` bigint DEFAULT NULL COMMENT '省ID',
  `province` varchar(100) DEFAULT NULL COMMENT '省',
  `city_id` bigint DEFAULT NULL COMMENT '城市ID',
  `city` varchar(20) DEFAULT NULL COMMENT '城市',
  `area_id` bigint DEFAULT NULL COMMENT '区ID',
  `area` varchar(20) DEFAULT NULL COMMENT '区',
  `post_code` varchar(15) DEFAULT NULL COMMENT '邮编',
  `addr` varchar(255) DEFAULT NULL COMMENT '地址',
  `lng` decimal(12,6) DEFAULT NULL COMMENT '经度',
  `lat` decimal(12,6) DEFAULT NULL COMMENT '纬度',
  `time_info` json DEFAULT NULL COMMENT '时间数据',
  `status` tinyint DEFAULT NULL COMMENT '0:关闭 1:营业 2:强制关闭 3:审核中 4:审核失败',
  `account` varchar(30) NULL DEFAULT NULL COMMENT '账号名',
  `stock_mode` tinyint DEFAULT NULL COMMENT '库存模式 1共享总部库存 2独立销售库存',
  PRIMARY KEY (`station_id`),
  KEY `idx_shop_id` (`shop_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='自提点信息';

/*Data for the table `station` */

/*Table structure for table `same_city` */

DROP TABLE IF EXISTS `same_city`;

CREATE TABLE `same_city` (
  `samecity_id` bigint NOT NULL AUTO_INCREMENT COMMENT '同城配送',
  `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',
  `position_info` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '配送区域经纬度json',
  `charge_type` tinyint DEFAULT NULL COMMENT '收费类型 1按区域收取固定配送费 2按距离收取配送费',
  `start_fee` bigint DEFAULT NULL COMMENT '起送价 是优惠券/码和满减优惠抵扣前的商品金额，运费不计入起送价。',
  `delivery_fee` bigint DEFAULT NULL COMMENT '配送费',
  `default_distance` decimal(15,1) DEFAULT '0.0' COMMENT '默认距离(km)',
  `over_distance` decimal(15,1) DEFAULT '0.0' COMMENT '每超出距离(km)',
  `over_distance_fee` bigint DEFAULT NULL COMMENT '每超出距离费用',
  `free_weight` decimal(15,2) DEFAULT '0.00' COMMENT '免费重量',
  `over_weight` decimal(15,2) DEFAULT '0.00' COMMENT '续重重量',
  `over_weight_fee` bigint DEFAULT NULL COMMENT '续重费用',
  `status` tinyint DEFAULT NULL COMMENT '启用状态 1启用 0未启用',
  `lng` decimal(10,6) DEFAULT NULL COMMENT '经度',
  `lat` decimal(10,6) DEFAULT NULL COMMENT '纬度',
  `province_id` bigint(0) NULL DEFAULT NULL COMMENT '省ID',
  `province` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '省',
  `city_id` bigint(0) NULL DEFAULT NULL COMMENT '城市ID',
   `city` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '城市',
   `area_id` bigint(0) NULL DEFAULT NULL COMMENT '区ID',
   `area` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '区',
   `detail_address` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '详细地址',
   `shop_lng` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '店铺所在经度',
   `shop_lat` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '店铺所在维度',
  PRIMARY KEY (`samecity_id`),
  KEY `idx_shop_id` (`shop_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='同城配送信息';

/*Data for the table `same_city` */

/*Table structure for table `transcity` */

DROP TABLE IF EXISTS `transcity`;

CREATE TABLE `transcity` (
  `transcity_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 '更新时间',
  `transfee_id` bigint DEFAULT NULL COMMENT '运费项id',
  `city_id` bigint DEFAULT NULL COMMENT '城市id',
  PRIMARY KEY (`transcity_id`),
  KEY `idx_transfee_id` (`transfee_id`),
  KEY `idx_city_id` (`city_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='运费项和运费城市关联信息';

/*Data for the table `transcity` */

/*Table structure for table `transcity_free` */

DROP TABLE IF EXISTS `transcity_free`;

CREATE TABLE `transcity_free` (
  `transcity_free_id` bigint NOT NULL AUTO_INCREMENT COMMENT '指定条件包邮城市项id',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '建立时间',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `transfee_free_id` bigint DEFAULT NULL COMMENT '指定条件包邮项id',
  `free_city_id` bigint DEFAULT NULL COMMENT '城市id',
  PRIMARY KEY (`transcity_free_id`),
  KEY `idx_transfee_free_id` (`transfee_free_id`),
  KEY `idx_city_id` (`free_city_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='指定条件包邮城市项';

/*Data for the table `transcity_free` */

/*Table structure for table `transfee` */

DROP TABLE IF EXISTS `transfee`;

CREATE TABLE `transfee` (
  `transfee_id` bigint NOT NULL AUTO_INCREMENT COMMENT '运费项id',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '建立时间',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `transport_id` bigint DEFAULT NULL COMMENT '运费模板id',
  `continuous_piece` decimal(15,2) DEFAULT NULL COMMENT '续件数量',
  `first_piece` decimal(15,2) DEFAULT NULL COMMENT '首件数量',
  `continuous_fee` bigint DEFAULT NULL COMMENT '续件费用',
  `first_fee` bigint DEFAULT NULL COMMENT '首件费用',
  PRIMARY KEY (`transfee_id`),
  KEY `idx_transport_id` (`transport_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='运费项';

/*Data for the table `transfee` */

/*Table structure for table `transfee_free` */

DROP TABLE IF EXISTS `transfee_free`;

CREATE TABLE `transfee_free` (
  `transfee_free_id` bigint NOT NULL AUTO_INCREMENT COMMENT '指定条件包邮项id',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '建立时间',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `transport_id` bigint DEFAULT NULL COMMENT '运费模板id',
  `free_type` tinyint DEFAULT NULL COMMENT '包邮方式 （0 满x件/重量/体积包邮 1满金额包邮 2满x件/重量/体积且满金额包邮）',
  `amount` bigint DEFAULT NULL COMMENT '需满金额',
  `piece` decimal(15,2) DEFAULT NULL COMMENT '包邮x件/重量/体积',
  PRIMARY KEY (`transfee_free_id`),
  KEY `transport_id` (`transport_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='指定条件包邮项';

/*Data for the table `transfee_free` */

/*Table structure for table `transport` */

DROP TABLE IF EXISTS `transport`;

CREATE TABLE `transport` (
  `transport_id` bigint NOT NULL AUTO_INCREMENT COMMENT '运费模板id',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '建立时间',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `trans_name` varchar(36) DEFAULT NULL COMMENT '运费模板名称',
  `shop_id` bigint DEFAULT NULL COMMENT '店铺id',
  `sys_type` tinyint NOT NULL COMMENT '用户类型见SysTypeEnum 0.普通用户系统 1.商家端 2平台端 3供应商端',
  `charge_type` tinyint DEFAULT NULL COMMENT '收费方式（0 按件数,1 按重量 2 按体积）',
  `is_free_fee` tinyint DEFAULT NULL COMMENT '是否包邮 0:不包邮 1:包邮',
  `has_free_condition` tinyint DEFAULT NULL COMMENT '是否含有包邮条件 0 否 1是',
  PRIMARY KEY (`transport_id`),
  KEY `shop_id` (`shop_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='运费模板';

/*Data for the table `transport` */

/*Table structure for table `outlet_config` */

DROP TABLE IF EXISTS `outlet_config`;

CREATE TABLE `outlet_config` (
  `outlet_config_id` bigint NOT NULL AUTO_INCREMENT 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',
  `supplier_id` bigint DEFAULT NULL COMMENT '供应商id',
  `delivery_company_type` tinyint NOT NULL COMMENT '快递公司类型',
  `shipper` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '发货人',
  `mobile` varchar(20) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '发货人电话',
  `partner_id` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '电子面单客户账户或月结账号',
  `partner_key` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '电子面单密码',
  `net` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '收件网点名称',
  `paper_size` tinyint DEFAULT '1' COMMENT '纸张规格 1.一联面单 2.二联面单',
  `is_default` tinyint NOT NULL DEFAULT '0' COMMENT '是否默认 0否1是',
  `print_addr` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '发货地址',
  PRIMARY KEY (`outlet_config_id`),
  KEY `shop_idx`(`shop_id`),
  KEY `supplier_shop_idx`(`supplier_id`, `shop_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='网点配置';

/*Table structure for table `printer` */

DROP TABLE IF EXISTS `printer`;

CREATE TABLE `printer` (
  `printer_id` bigint NOT NULL AUTO_INCREMENT 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',
  `supplier_id` bigint DEFAULT NULL COMMENT '供应商id',
  `printer_name` varchar(50) COLLATE utf8mb4_general_ci NOT NULL COMMENT '打印机名称',
  `siid` varchar(50) COLLATE utf8mb4_general_ci NOT NULL COMMENT '设备码',
  `printer_remark` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '打印机备注',
  `is_default` tinyint DEFAULT '0' COMMENT '是否默认 0否1是',
  PRIMARY KEY (`printer_id`),
  KEY `shop_idx`(`shop_id`),
  KEY `supplier_shop_idx`(`supplier_id`, `shop_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='打印机';

/*Table structure for table `leaf_alloc` */

CREATE TABLE IF NOT EXISTS `leaf_alloc` (
  `biz_tag` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '区分业务',
  `max_id` bigint unsigned NOT NULL DEFAULT '1' COMMENT '该biz_tag目前所被分配的ID号段的最大值',
  `step` int NOT NULL COMMENT '每次分配的号段长度',
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `description` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '描述',
  PRIMARY KEY (`biz_tag`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

/*Data for the table `leaf_alloc` */

/*Table structure for table `undo_log` */

DROP TABLE IF EXISTS `undo_log`;

CREATE TABLE `undo_log` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `branch_id` bigint NOT NULL,
  `xid` varchar(100) NOT NULL,
  `context` varchar(128) NOT NULL,
  `rollback_info` longblob NOT NULL,
  `log_status` int NOT NULL,
  `log_created` datetime NOT NULL,
  `log_modified` datetime NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

/*Data for the table `undo_log` */



/*Table structure for table `order` */

USE mall4cloud_order;

DELIMITER //
DROP PROCEDURE IF EXISTS createTable//
CREATE PROCEDURE createTable()
BEGIN
    DECLARE i INT;


    # ============================== 订单   ==============================


    SET i = 0;
    WHILE i<50 DO

        SET @create_order_table = CONCAT(
                'CREATE TABLE IF NOT EXISTS order_', i,
                "
                (
                `order_id` bigint unsigned 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',
                `user_id` bigint NOT NULL COMMENT '用户ID',
                `order_addr_id` bigint DEFAULT NULL COMMENT '用户订单地址Id',
                `delivery_type` tinyint DEFAULT NULL COMMENT '配送类型 1:快递 2:自提 3：无需快递 4同城配送',
                `pay_sys_type` tinyint NOT NULL DEFAULT '0' COMMENT '支付系统类型 0默认1通联支付',
                `shop_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '店铺名称',
                `total` bigint NOT NULL COMMENT '总值',
                `actual_total` bigint DEFAULT NULL COMMENT '实际总值',
                `freight_amount` bigint DEFAULT NULL COMMENT '订单运费',
                `order_score` bigint DEFAULT NULL COMMENT '订单使用积分',
                `status` tinyint NOT NULL DEFAULT '0' COMMENT '订单状态 1:待付款 2:待发货(待自提) 3:待收货(已发货) 5:成功 6:失败 7:待成团 9.待付尾款',
                `pay_type` tinyint unsigned DEFAULT NULL COMMENT '支付方式 请参考枚举PayType',
                `order_type` tinyint DEFAULT NULL COMMENT '订单类型 1团购订单 2秒杀订单 3积分订单',
                `all_count` int DEFAULT NULL COMMENT '订单商品总数',
                `reduce_amount` bigint NOT NULL DEFAULT '0' COMMENT '优惠总额',
                `score_amount` bigint NOT NULL DEFAULT '0' COMMENT '积分抵扣金额',
                `member_amount` bigint NOT NULL DEFAULT '0' COMMENT '会员折扣金额',
                `platform_coupon_amount` bigint NOT NULL DEFAULT '0' COMMENT '平台优惠券优惠金额',
                `shop_coupon_amount` bigint NOT NULL DEFAULT '0' COMMENT '商家优惠券优惠金额',
                `discount_amount` bigint NOT NULL DEFAULT '0' COMMENT '满减优惠金额',
                `shop_combo_amount` bigint NOT NULL DEFAULT '0' COMMENT '套餐优惠金额',
                `platform_free_freight_amount` bigint NOT NULL DEFAULT '0' COMMENT '平台运费减免金额',
                `free_freight_amount` bigint NOT NULL DEFAULT '0' COMMENT '商家运费减免金额',
                `shop_change_free_amount` bigint NOT NULL DEFAULT '0' COMMENT '店铺改价优惠金额',
                `distribution_amount` bigint NOT NULL DEFAULT '0' COMMENT '分销佣金',
                `platform_amount` bigint NOT NULL DEFAULT '0' COMMENT '平台优惠金额',
                `platform_commission` bigint NOT NULL DEFAULT '0' COMMENT '平台佣金',
                `pay_time` datetime DEFAULT NULL COMMENT '付款时间',
                `delivery_time` datetime DEFAULT NULL COMMENT '发货时间',
                `finally_time` datetime DEFAULT NULL COMMENT '完成时间',
                `settled_time` datetime DEFAULT NULL COMMENT '结算时间',
                `cancel_time` datetime DEFAULT NULL COMMENT '取消时间',
                `book_time` datetime DEFAULT NULL COMMENT '预售发货时间',
                `is_payed` tinyint(1) DEFAULT NULL COMMENT '是否已支付，1.已支付0.未支付',
                `close_type` tinyint DEFAULT NULL COMMENT '订单关闭原因 1-超时未支付 2-退款关闭 4-买家取消 15-已通过货到付款交易',
                `refund_status` tinyint DEFAULT NULL COMMENT '订单退款状态（1:申请退款 2:退款成功 3:部分退款成功 4:退款失败）',
                `shop_remarks` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '卖家备注',
                `remarks` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '买家备注',
                `delete_status` tinyint DEFAULT '0' COMMENT '用户订单删除状态，0：没有删除， 1：回收站， 2：永久删除',
                `version` int DEFAULT NULL COMMENT '订单版本号，每处理一次订单，版本号+1',
                `is_settled` tinyint DEFAULT NULL COMMENT '是否已经进行结算',
                `supplier_id` bigint NOT NULL DEFAULT '0' COMMENT '供应商id',
                `wait_purchase` tinyint NOT NULL DEFAULT '0' COMMENT '是否待采购 1.是 0.否 2.已处理',
                `supplier_delivery_type` tinyint NOT NULL DEFAULT '0' COMMENT '供应商商品发货方式 1.供应商发货 2.仓库发货',
                `purchase_spread_amount` bigint NOT NULL DEFAULT '0' COMMENT '商家采购价差（需要商家从结算金额补上采购价的金额）',
                `pre_sale_type` tinyint DEFAULT '-1' COMMENT '预售类型 0.全款预售类型 1.定金预售',
                `order_mold` tinyint DEFAULT '0' COMMENT '是否为虚拟商品订单 1.是 0.否',
                `write_off_status` tinyint(1) DEFAULT NULL COMMENT '订单核销状态 0.待核销 1.核销完成',
                `write_off_num` int DEFAULT NULL COMMENT '核销次数 -1.多次核销 0.无需核销 1.单次核销',
                `write_off_multiple_count` int DEFAULT NULL COMMENT '核销次数 -1.无限次',
                `write_off_start` datetime DEFAULT NULL COMMENT '核销开始时间',
                `write_off_end` datetime DEFAULT NULL COMMENT '核销结束时间',
                `write_off_count` int(0) NULL DEFAULT NULL COMMENT '订单被核销次数',
                     main_order_id BIGINT NOT NULL DEFAULT '0' COMMENT '主单号,在组合/套餐商品拆单时会存在',
                PRIMARY KEY (`order_id`),
                KEY `idx_shop_id` (`shop_id`),
                KEY `idx_user_id` (`user_id`),
                KEY `idx_addr_order_id` (`order_addr_id`),
                KEY `idx_finally_time` (`finally_time`)
                ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='订单信息'
              "
            );
        PREPARE sql_create_table FROM @create_order_table;
        EXECUTE sql_create_table;

        SET @create_order_addr_table = CONCAT(
                'CREATE TABLE IF NOT EXISTS order_addr_', i,
                "
                (
                  `order_addr_id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
                  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
                  `user_id` bigint DEFAULT NULL COMMENT '用户ID',
                  `consignee` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci 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 '区',
                  `addr` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '地址',
                  `post_code` varchar(15) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '邮编',
                  `mobile` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '手机',
                  `lng` decimal(12,6) DEFAULT NULL COMMENT '经度',
                  `lat` decimal(12,6) DEFAULT NULL COMMENT '纬度',
                  PRIMARY KEY (`order_addr_id`),
                  KEY `idx_user_id` (`user_id`)
                  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='用户订单配送地址'
                "
            );
        PREPARE create_order_addr_table FROM @create_order_addr_table;
        EXECUTE create_order_addr_table;

        SET @create_order_item_table = CONCAT(
                'CREATE TABLE IF NOT EXISTS order_item_', i,
                "
                (
                  `order_item_id` bigint unsigned NOT NULL AUTO_INCREMENT 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 NOT NULL COMMENT '店铺id',
                  `order_id` bigint NOT NULL COMMENT '订单id',
                  `category_id` bigint DEFAULT NULL COMMENT '分类id',
                  `spu_id` bigint unsigned NOT NULL COMMENT '产品ID',
                  `sku_id` bigint unsigned NOT NULL COMMENT '产品SkuID',
                  `user_id` bigint NOT NULL COMMENT '用户Id',
                  `final_refund_id` bigint DEFAULT NULL COMMENT '最终的退款id',
                  `distribution_user_id` bigint DEFAULT NULL COMMENT '推广员id',
                  `count` int DEFAULT '0' COMMENT '购物车产品个数',
                  `spu_name` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '产品名称',
                  `sku_name` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT 'sku名称',
                  `spu_code` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '商品编码',
                  `party_code` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT 'sku编码',
                  `pic` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '产品主图片路径',
                  `is_comm` tinyint NOT NULL DEFAULT '0' COMMENT '是否以评价(0.未评价1.已评价)',
                  `comm_time` datetime DEFAULT NULL COMMENT '评论时间',
                  `refund_status` tinyint DEFAULT NULL COMMENT '订单项退款状态（1:申请退款 2:退款成功 3:部分退款成功 4:退款失败）',
                  `be_delivered_num` int DEFAULT NULL COMMENT '0全部发货 其他数量为剩余待发货数量',
                  `delivery_type` tinyint DEFAULT NULL COMMENT '单个orderItem的配送类型 1:快递 2:自提 3：无需快递 4:同城配送',
                  `shop_cart_time` datetime DEFAULT NULL COMMENT '加入购物车时间',
                  `price` bigint NOT NULL COMMENT '产品价格',
                  `spu_total_amount` bigint NOT NULL COMMENT '商品总金额',
                  `actual_total` bigint NOT NULL DEFAULT '0' COMMENT '商品实际金额 = 商品总金额 - 分摊的优惠金额',
                  `share_reduce` bigint NOT NULL DEFAULT '0' COMMENT '分摊的优惠金额(商家分摊 + 平台补贴)',
                  `platform_share_reduce` bigint NOT NULL DEFAULT '0' COMMENT '平台优惠金额',
                  `distribution_amount` bigint NOT NULL DEFAULT '0' COMMENT '推广员佣金',
                  `distribution_parent_amount` bigint NOT NULL DEFAULT '0' COMMENT '上级推广员佣金',
                  `use_score` bigint NOT NULL DEFAULT '0' COMMENT '使用积分',
                  `gain_score` bigint NOT NULL DEFAULT '0' COMMENT '获得积分',
                  `rate` decimal(15,6) NOT NULL DEFAULT '0.000000' COMMENT '分账比例',
                  `platform_commission` bigint NOT NULL DEFAULT '0' COMMENT '平台佣金(商品实际金额 * 分账比例)',
                  `score_amount` bigint NOT NULL DEFAULT '0' COMMENT '积分抵扣金额',
                  `member_amount` bigint NOT NULL DEFAULT '0' COMMENT '会员折扣金额',
                  `platform_coupon_amount` bigint NOT NULL DEFAULT '0' COMMENT '平台优惠券优惠金额',
                  `shop_coupon_amount` bigint NOT NULL DEFAULT '0' COMMENT '商家优惠券优惠金额',
                  `discount_amount` bigint NOT NULL DEFAULT '0' COMMENT '满减优惠金额',
                  `platform_free_freight_amount` bigint NOT NULL DEFAULT '0' COMMENT '平台运费减免金额',
                  `free_freight_amount` bigint NOT NULL DEFAULT '0' COMMENT '商家运费减免金额',
                  `shop_change_free_amount` bigint NOT NULL DEFAULT '0' COMMENT '店铺改价优惠金额',
                  `score_fee` bigint DEFAULT NULL COMMENT '积分价格（单价）',
                  `item_purchase_amount` bigint NOT NULL DEFAULT '0' COMMENT '采购价',
                  `purchase_platform_commission` bigint NOT NULL DEFAULT '0' COMMENT '供应商佣金',
                  `supplier_rate` decimal(15,6) NOT NULL DEFAULT '0.000000' COMMENT '供应商佣金比例',
                  `supplier_spu_id` bigint DEFAULT NULL COMMENT '供应商商品id',
                  `supplier_sku_id` bigint DEFAULT NULL COMMENT '供应商规格id',
                  `giveaway_amount` decimal(15,2) NOT NULL DEFAULT '0.00' COMMENT '赠品金额',
                  `main_giveaway` tinyint DEFAULT NULL COMMENT '主赠品',
                  `spu_mold` tinyint DEFAULT '0' COMMENT '商品类别 0.实物商品 1. 虚拟商品',
                  `is_refund` tinyint DEFAULT NULL COMMENT '是否可以退款 1.可以 0不可以',
                  `virtual_remark` json DEFAULT NULL COMMENT '虚拟商品的留言备注',
                  `combo_amount` bigint DEFAULT '0' COMMENT '套餐优惠金额',
                  `activity_id` bigint DEFAULT NULL COMMENT '活动id',
                  `activity_type` tinyint DEFAULT '0' COMMENT '活动类型 具体类型参考枚举类:OrderActivityType',
                  `supplier_pic` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '产品供应商主图片路径',
                     `write_off_num` INT DEFAULT NULL COMMENT '核销次数 -1.多次核销 0.无需核销 1.单次核销',
                     `write_off_multiple_count` INT DEFAULT NULL COMMENT '核销次数 -1.无限次',
                     `write_off_start` DATETIME DEFAULT NULL COMMENT '核销开始时间',
                     `write_off_end` DATETIME DEFAULT NULL COMMENT '核销结束时间',
                    `stock_point_id` bigint DEFAULT NULL COMMENT '库存点id',
                  PRIMARY KEY (`order_item_id`),
                  KEY `idx_order_id` (`order_id`),
                  KEY `idx_shop_id` (`shop_id`),
                  KEY `idx_spu_id` (`spu_id`),
                  KEY `idx_sku_id` (`sku_id`),
                  KEY `idx_user_id` (`user_id`),
                  KEY `idx_final_refund_id` (`final_refund_id`),
                  KEY `idx_distribution_user_id` (`distribution_user_id`)
                  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='订单项'
            "
            );
        PREPARE create_order_item_table FROM @create_order_item_table;
        EXECUTE create_order_item_table;

        SET @create_order_item_lang_table = CONCAT(
                'CREATE TABLE IF NOT EXISTS order_item_lang_', i,
                "
                (
                  `order_item_id` bigint NOT NULL COMMENT '订单项ID',
                  `lang` tinyint NOT NULL COMMENT '语言 1.中文 2.英文',
                  `spu_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '商品名称',
                  `sku_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT 'sku名称',
                  `supplier_spu_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '供应商商品名称',
                  `supplier_sku_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '供应商sku名称',
                  PRIMARY KEY (`order_item_id`)
                  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='订单项-国际化'
                "
            );
        PREPARE create_order_item_lang_table FROM @create_order_item_lang_table;
        EXECUTE create_order_item_lang_table;

        SET @create_order_settlement_table = CONCAT(
                'CREATE TABLE IF NOT EXISTS order_settlement_', i,
                "
                (
                  `settlement_id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '支付结算单据ID',
                  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
                  `order_id` bigint DEFAULT NULL COMMENT '订单id',
                  `pay_id` bigint DEFAULT NULL COMMENT '支付单号',
                  `pay_ids` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '支付单号集合，目前只有预售订单存在多条',
                  `user_id` bigint NOT NULL COMMENT '用户ID',
                  `pay_type` tinyint DEFAULT NULL COMMENT '支付方式',
                  `is_clearing` tinyint DEFAULT NULL COMMENT '是否清算 0:否 1:是',
                  `pay_score` bigint DEFAULT NULL COMMENT '支付积分',
                  `pay_amount` bigint DEFAULT NULL COMMENT '支付金额',
                  `clearing_time` datetime DEFAULT NULL COMMENT '清算时间',
                  `version` int DEFAULT NULL COMMENT '版本号',
                  `is_payed` tinyint DEFAULT NULL COMMENT '是否已支付，1.已支付0.未支付',
                  PRIMARY KEY (`settlement_id`),
                  KEY `idx_pay_id` (`pay_id`),
                  KEY `idx_order_id` (`order_id`),
                  KEY `idx_user_id` (`user_id`)
                  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='订单结算表'
                "
            );
        PREPARE create_order_settlement_table FROM @create_order_settlement_table;
        EXECUTE create_order_settlement_table;

        SET @create_order_pre_sale_info_table = CONCAT(
                'CREATE TABLE IF NOT EXISTS order_pre_sale_info_', i,
                "
                (
                  `order_pre_sale_info_id` bigint NOT NULL AUTO_INCREMENT,
                  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
                  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间',
                  `order_id` bigint DEFAULT NULL COMMENT '订单编号',
                  `deposit_amount` bigint DEFAULT '0' COMMENT '定金金额',
                  `deposit_reduce_amount` bigint DEFAULT '0' COMMENT '定金优惠金额',
                  `deposit_expansion_amount` bigint DEFAULT '0' COMMENT '定金膨胀金额',
                  `balance_amount` bigint DEFAULT '0' COMMENT '尾款金额',
                  `pre_sale_type` tinyint DEFAULT '0' COMMENT '预售类型 0.全款预售类型 1.定金预售',
                  `pay_status` tinyint DEFAULT '0' COMMENT '定金预售支付状态 1.已支付定金 2.已支付尾款',
                  `balance_start_time` datetime DEFAULT NULL COMMENT '尾款支付开始时间',
                  `balance_end_time` datetime DEFAULT NULL COMMENT '尾款支付结束时间',
                  `balance_pay_time` datetime DEFAULT NULL COMMENT '尾款支付时间',
                  `pre_sale_delivery_type` tinyint DEFAULT NULL COMMENT '预售发货类型 -1.固定时间 x.（尾款）支付后x天发货',
                  `pre_sale_delivery_time` datetime DEFAULT NULL COMMENT '预售发货时间',
                  PRIMARY KEY (`order_pre_sale_info_id`),
                  KEY `idx_order_id` (`order_id`)
                  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='订单预售信息'
                "
            );
        PREPARE create_order_pre_sale_info_table FROM @create_order_pre_sale_info_table;
        EXECUTE create_order_pre_sale_info_table;

        SET @create_order_invoice_table = CONCAT(
                'CREATE TABLE IF NOT EXISTS order_invoice_', i,
                "
                (
                  `order_invoice_id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '订单发票ID',
                  `order_id` bigint NOT NULL COMMENT '订单id',
                  `shop_id` bigint NOT NULL COMMENT '店铺id',
                  `supplier_id` bigint NULL COMMENT '供应商id',
                  `invoice_type` tinyint NOT NULL DEFAULT '1' COMMENT '发票类型 1.电子普通发票',
                  `header_type` tinyint NOT NULL COMMENT '抬头类型 1.单位 2.个人',
                  `header_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '抬头名称',
                  `invoice_tax_number` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '发票税号',
                  `invoice_context` tinyint NOT NULL DEFAULT '1' COMMENT '发票内容 1.商品明细',
                  `invoice_state` tinyint NOT NULL COMMENT '发票状态 1.申请中 2.已开票',
                  `file_id` bigint DEFAULT NULL COMMENT '文件id',
                  `application_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '申请时间',
                  `upload_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '上传时间',
                  PRIMARY KEY (`order_invoice_id`),
                  KEY `shop_idx`(`shop_id`)
                  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
                "
            );
        PREPARE create_order_invoice_table FROM @create_order_invoice_table;
        EXECUTE create_order_invoice_table;

        SET @create_order_self_station_table = CONCAT(
                'CREATE TABLE IF NOT EXISTS order_self_station_', i,
                "
                (
                  `order_self_station_id` bigint NOT NULL,
                  `shop_id` bigint DEFAULT NULL COMMENT '店铺id',
                  `user_id` bigint NOT NULL COMMENT '用户id',
                  `order_id` bigint DEFAULT NULL COMMENT '订单编号',
                  `station_id` bigint DEFAULT NULL COMMENT '自提点id',
                  `station_user_mobile` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '自提人的手机',
                  `station_user_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '自提人的名字',
                  `station_time` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '自提时间(用户下单时选择)',
                  `station_code` varchar(9) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '自提提货码',
                  `station_address` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '上门自提点的地址',
                  `station_phone` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '上门自提点的联系电话',
                  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
                  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
                  PRIMARY KEY (`order_self_station_id`),
                  KEY `STATION` (`station_id`)
                  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='订单自提信息'
                ");
        PREPARE create_order_self_station_table FROM @create_order_self_station_table;
        EXECUTE create_order_self_station_table;

        SET @create_order_virtual_info_table = CONCAT(
                'CREATE TABLE IF NOT EXISTS order_virtual_info_', i,
                "
                (
                  `order_virtual_info_id` bigint NOT NULL ,
                  `order_id` bigint unsigned NOT NULL COMMENT '订单ID',
                   `order_item_id` bigint NOT NULL DEFAULT '0' COMMENT '订单项id',
                  `shop_id` bigint DEFAULT NULL COMMENT '店铺id',
                  `station_id` bigint DEFAULT NULL COMMENT '核销门店id',
                  `write_off_code` varchar(13) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '核销码',
                  `is_write_off` tinyint DEFAULT NULL COMMENT '是否核销 1.已核销 0.未核销',
                  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
                  `write_off_time` datetime DEFAULT NULL COMMENT '核销时间',
                  `write_off_multiple_count` int DEFAULT NULL COMMENT '剩余核销次数 -1.无限次',
                  PRIMARY KEY (`order_virtual_info_id`),
                  KEY `order_id` (`order_id`)
                  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='订单虚拟商品信息'
                ");
        PREPARE create_order_virtual_info_table FROM @create_order_virtual_info_table;
        EXECUTE create_order_virtual_info_table;

        SET @create_delivery_order_table = CONCAT(
                'CREATE TABLE IF NOT EXISTS delivery_order_', i,
                "
                (
                  `delivery_order_id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '订单物流包裹id',
                  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '建立时间',
                  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
                  `order_id` bigint NOT NULL COMMENT '订单号',
                  `user_id` bigint NOT NULL COMMENT '用户id',
                  `delivery_company_id` bigint DEFAULT NULL COMMENT '快递公司id',
                  `delivery_no` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '快递单号',
                  `consignee_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '收件人姓名',
                  `consignee_mobile` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '收件人电话（顺丰快递需要）',
                  `status` tinyint DEFAULT NULL COMMENT '物流状态 1正常 -1删除',
                  `all_count` int DEFAULT NULL COMMENT '包裹商品总数',
                  `delete_time` datetime DEFAULT NULL COMMENT '删除时间',
                  `delivery_type` int DEFAULT NULL COMMENT '发货方式(1.快递 3.无需物流)',
                  PRIMARY KEY (`delivery_order_id`),
                  KEY `idx_order_id` (`order_id`),
                  KEY `idx_user_id` (`user_id`),
                  KEY `idx_delivery_company_id` (`delivery_company_id`)
                  ) ENGINE=InnoDB AUTO_INCREMENT=96 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='订单快递信息'
                "
            );
        PREPARE create_delivery_order_table FROM @create_delivery_order_table;
        EXECUTE create_delivery_order_table;

        SET @create_delivery_order_item_table = CONCAT(
                'CREATE TABLE IF NOT EXISTS delivery_order_item_', i,
                "
                (
                  `delivery_order_item_id` bigint NOT NULL AUTO_INCREMENT COMMENT 'id',
                  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '建立时间',
                  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
                  `delivery_order_id` bigint DEFAULT NULL COMMENT '订单物流包裹id',
                  `img_url` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '商品图片',
                  `spu_name` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '商品名称',
                  `count` int DEFAULT '0' COMMENT '商品数量',
                  `supplier_img_url` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '供应商商品图片',
                  `supplier_spu_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '供应商商品名称',
                  PRIMARY KEY (`delivery_order_item_id`),
                  KEY `idx_order_delivery_id` (`delivery_order_id`)
                  ) ENGINE=InnoDB AUTO_INCREMENT=37 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='物流订单项信息'
                "
            );
        PREPARE create_delivery_order_item_table FROM @create_delivery_order_item_table;
        EXECUTE create_delivery_order_item_table;


        SET @create_order_refund_table = CONCAT(
          'CREATE TABLE IF NOT EXISTS order_refund_', i,
          "
          (
            `refund_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 NOT NULL COMMENT '店铺ID',
            `user_id` bigint NOT NULL COMMENT '买家ID',
            `order_id` bigint NOT NULL COMMENT '订单号',
            `order_item_id` bigint NOT NULL DEFAULT '0' COMMENT '订单项ID(0:为全部订单项)',
            `refund_count` int DEFAULT '0' COMMENT '退货数量(0:为全部订单项)',
            `refund_score` bigint DEFAULT NULL COMMENT '退还积分',
            `refund_amount` bigint DEFAULT NULL COMMENT '退款金额',
            `platform_refund_commission` bigint DEFAULT NULL COMMENT '平台佣金退款金额',
            `platform_refund_amount` bigint DEFAULT NULL COMMENT '平台退款金额（退款时将这部分钱退回给平台，所以商家要扣除从平台这里获取的金额）',
            `distribution_total_amount` bigint DEFAULT NULL COMMENT '退款单总分销金额',
            `refund_type` tinyint NOT NULL DEFAULT '0' COMMENT '退款单类型（1:整单退款,2:单个物品退款）',
            `apply_type` tinyint NOT NULL COMMENT '申请类型:1,仅退款,2退款退货',
            `pay_sys_type` tinyint NOT NULL DEFAULT '0' COMMENT '支付系统类型 0默认1通联支付',
            `is_received` tinyint DEFAULT NULL COMMENT '是否接收到商品(1:已收到,0:未收到)',
            `close_type` tinyint DEFAULT NULL COMMENT '退款关闭原因(1.买家撤销退款 2.卖家拒绝退款 3.退款申请超时被系统关闭)',
            `return_money_sts` tinyint NOT NULL DEFAULT '0' COMMENT '处理退款状态:(1.买家申请 2.卖家接受 3.买家发货 4.卖家收货 5.退款成功  -1.退款关闭)详情见ReturnMoneyStsType',
            `buyer_reason` tinyint DEFAULT NULL COMMENT '申请原因(具体见BuyerReasonType)',
            `buyer_desc` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '申请说明',
            `buyer_mobile` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '联系方式（退款时留下的手机号码）',
            `img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '文件凭证(逗号隔开)',
            `over_time` datetime DEFAULT NULL COMMENT '超时时间（超过该时间不处理，系统将自动处理）（保留字段）',
            `reject_message` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '拒绝原因',
            `seller_msg` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '卖家备注',
            `shop_seller_msg` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '商家备注(移交供应商处理时保存)',
            `handel_time` datetime DEFAULT NULL COMMENT '受理时间',
            `supplier_time` datetime DEFAULT NULL COMMENT '移交供应商时间',
            `delivery_time` datetime DEFAULT NULL COMMENT '发货时间',
            `receive_time` datetime DEFAULT NULL COMMENT '收货时间',
            `close_time` datetime DEFAULT NULL COMMENT '关闭时间',
            `decision_time` datetime DEFAULT NULL COMMENT '确定时间(确定退款时间)',
            `refund_time` datetime DEFAULT NULL COMMENT '退款时间',
            `supplier_id` bigint NOT NULL DEFAULT '0' COMMENT '供应商id',
            `supplier_handle_status` tinyint DEFAULT '-1' COMMENT '供应商处理状态， -1.商家自行处理 0.待供应商处理 1.供应商已同意 2.供应商已拒绝',
            `purchase_refund_amount` bigint DEFAULT '0' COMMENT '采购退款金额',
            `pur_platform_refund_commission` bigint DEFAULT '0' COMMENT '采购的平台佣金退款金额',
            `return_giveaway_ids` varchar(150) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '退款退回的赠品订单项ids',
            `refund_actual_total` decimal(15,2) DEFAULT NULL COMMENT '当前退款的实付金额（实付金额减去不退回赠品的金额）',
            `shop_img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '商家/供应商文件凭证(逗号隔开)',
            `platform_intervention_status` tinyint NOT NULL DEFAULT '-1' COMMENT '平台介入状态 -1.没有介入 1.用户申请介入 2.平台同意介入 3.平台拒绝介入 5.平台同意退款成功',
            `apply_intervention_reason` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '用户申请介入理由',
            `apply_intervention_img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '申请介入的文件凭证(逗号隔开)',
            `intervention_refund_type` tinyint DEFAULT NULL COMMENT '平台介入退款方式 1.商家承担 2.商家供应商承担（供应商发货订单） 3.不同意退款',
            `after_intervention_refund_amount` bigint DEFAULT NULL COMMENT '平台介入前的退款金额',
            `platform_message` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '平台留言',
            `apply_intervention_time` datetime DEFAULT NULL COMMENT '申请介入时间',
            `intervention_finish_time` datetime DEFAULT NULL COMMENT '介入完成时间',
            PRIMARY KEY (`refund_id`),
            KEY `idx_order_id` (`order_id`),
            KEY `idx_order_item_id` (`order_item_id`),
            KEY `idx_user_id` (`user_id`),
            KEY `idx_shop_id` (`shop_id`)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='订单退款记录信息'
          "
        );
        PREPARE create_order_refund_table FROM @create_order_refund_table;
        EXECUTE create_order_refund_table;

        SET @create_order_refund_intervention_table = CONCAT(
          'CREATE TABLE IF NOT EXISTS order_refund_intervention_', i,
          "
          (
            `refund_intervertion_id` bigint NOT NULL AUTO_INCREMENT COMMENT '记录ID',
            `refund_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 '更新时间',
            `biz_id` bigint DEFAULT '0' COMMENT '商家/供应商/用户id',
            `sys_type` tinyint DEFAULT NULL COMMENT '系统类型，0.普通用户 1.商家端 2.平台端 3.供应商端',
            `voucher_desc` varchar(200) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '凭证说明',
            `img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '文件凭证(逗号隔开)',
            PRIMARY KEY (`refund_intervertion_id`),
            KEY `idx_refund_id` (`refund_id`),
            KEY `idx_biz_id` (`biz_id`)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='订单退款介入记录'
          "
          );
        PREPARE create_order_refund_intervention_table FROM @create_order_refund_intervention_table;
        EXECUTE create_order_refund_intervention_table;

        SET @create_order_refund_addr_table = CONCAT(
          'CREATE TABLE IF NOT EXISTS order_refund_addr_', i,
          "
          (
            `refund_addr_id` bigint NOT NULL AUTO_INCREMENT 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',
            `refund_id` bigint NOT NULL COMMENT '退款号',
            `user_id` bigint NOT NULL COMMENT '买家ID',
            `delivery_company_id` bigint DEFAULT NULL COMMENT '物流公司ID',
            `delivery_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '物流公司名称',
            `delivery_no` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '物流单号',
            `consignee_name` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '收件人姓名',
            `consignee_mobile` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '收件人电话（顺丰快递需要）',
            `consignee_telephone` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '收件人座机',
            `consignee_post_code` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '收件人邮政编码',
            `consignee_addr` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '收件人地址',
            `sender_mobile` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '发送人手机号码',
            `sender_remarks` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '买家备注',
            `imgs` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '图片凭证',
            PRIMARY KEY (`refund_addr_id`),
            KEY `idx_shop_id` (`shop_id`),
            KEY `idx_refund_id` (`refund_id`),
            KEY `idx_user_id` (`user_id`),
            KEY `idx_delivery_company_id` (`delivery_company_id`)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='用户退货物流地址'
          "
        );
        PREPARE create_order_refund_addr_table FROM @create_order_refund_addr_table;
        EXECUTE create_order_refund_addr_table;

        SET @create_order_refund_settlement_table = CONCAT(
          'CREATE TABLE IF NOT EXISTS order_refund_settlement_', i,
          "
          (
            `settlement_id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '退款结算单据id',
            `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
            `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
            `pay_id` bigint DEFAULT NULL COMMENT '订单支付单号',
            `order_id` bigint DEFAULT NULL COMMENT '订单编号',
            `refund_id` bigint DEFAULT NULL COMMENT '退款单编号（本系统退款单号）',
            `user_id` bigint DEFAULT NULL COMMENT '用户ID',
            `biz_refund_no` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '微信/支付宝退款单号（支付平台退款单号）',
            `pay_type` tinyint DEFAULT NULL COMMENT '支付方式(1:微信支付 2支付宝支付)',
            `refund_status` tinyint DEFAULT NULL COMMENT '退款状态(1:申请中 2：已完成 -1失败)',
            `refund_amount` bigint DEFAULT NULL COMMENT '退款金额',
            `order_total_amount` bigint DEFAULT NULL COMMENT '订单总额',
            `version` int DEFAULT '0' COMMENT '版本号',
            PRIMARY KEY (`settlement_id`),
            UNIQUE KEY `uni_refund_id` (`refund_id`),
            KEY `idx_order_id` (`order_id`),
            KEY `idx_user_id` (`user_id`),
            KEY `idx_pay_id` (`pay_id`),
            KEY `idx_biz_refund_no` (`biz_refund_no`)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='退款支付结算单据'
          "
        );
        PREPARE create_order_refund_settlement_table FROM @create_order_refund_settlement_table;
        EXECUTE create_order_refund_settlement_table;

        SET @create_purchase_order_table = CONCAT(
          'CREATE TABLE IF NOT EXISTS purchase_order_', i,
          "
          (
            `purchase_order_id` bigint NOT NULL AUTO_INCREMENT COMMENT '采购id',
            `shop_id` bigint DEFAULT NULL COMMENT '店铺id',
            `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
            `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
            `deliver_time` datetime DEFAULT NULL COMMENT '送达时间',
            `delivery_time` datetime DEFAULT NULL COMMENT '发货时间',
            `supplier_id` bigint NOT NULL COMMENT '供应商id',
            `total_amount` bigint NOT NULL COMMENT '总采购金额',
            `total_stock` int NOT NULL COMMENT '总采购库存数量',
            `actual_total_stock` int DEFAULT NULL COMMENT '实际总库存数量',
            `status` tinyint DEFAULT NULL COMMENT '状态 0:已作废 1:待入库 2:已发货 3.部分入库 5:已完成',
            `remark` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '备注',
            `employee_id` bigint DEFAULT NULL COMMENT '操作员工id',
            `delivery_type` tinyint DEFAULT NULL COMMENT '配送类型 1:快递 2:自提 3：无需快递 4同城配送',
            `purchase_order_addr_id` bigint DEFAULT NULL COMMENT '采购订单地址Id',
            `voucher_img_urls` VARCHAR(1000) DEFAULT NULL COMMENT '付款凭证图片 多个图片逗号分隔',
               `warehouse_id` bigint(0) NULL COMMENT '仓库id',
               `supplier_warehouse_id` bigint(0) NULL COMMENT '供应商仓库id',
               `stock_point_type` int(1) NULL COMMENT '库存点类型(1:仓库, 2:门店)',
            PRIMARY KEY (`purchase_order_id`),
            KEY `idx_supplier_id` (`supplier_id`)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='采购订单'
          "
        );
        PREPARE create_purchase_order_table FROM @create_purchase_order_table;
        EXECUTE create_purchase_order_table;

        SET @create_purchase_order_lang_table = CONCAT(
          'CREATE TABLE IF NOT EXISTS purchase_order_lang_', i,
          "
            (
            `purchase_order_id` bigint NOT NULL,
            `lang` tinyint NOT NULL,
            `spu_name` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
            PRIMARY KEY (`purchase_order_id`)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='采购订单-国际化'
          "
        );
        PREPARE create_purchase_order_lang_table FROM @create_purchase_order_lang_table;
        EXECUTE create_purchase_order_lang_table;

        SET @create_purchase_order_item_table = CONCAT(
          'CREATE TABLE IF NOT EXISTS purchase_order_item_', i,
          "
          (
            `purchase_item_id` bigint NOT NULL COMMENT 'id',
            `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
            `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
            `purchase_order_id` bigint DEFAULT NULL COMMENT '采购订单id',
            `spu_id` bigint DEFAULT NULL COMMENT '商品id',
            `sku_id` bigint DEFAULT NULL COMMENT 'sku id',
            `spu_code` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '商品编码',
            `party_code` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT 'sku编码',
            `pic` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '商品图片',
            `purchase_amount` bigint DEFAULT NULL COMMENT '采购金额',
            `purchase_price` bigint DEFAULT NULL COMMENT '采购价',
            `purchase_stock` int DEFAULT NULL COMMENT '采购库存数量',
            `actual_stock` int DEFAULT NULL COMMENT '实际库存数量',
            `delivery_type` tinyint DEFAULT NULL COMMENT '订单项退款状态（1:申请退款 2:退款成功 3:部分退款成功 4:退款失败）',
            `status` tinyint DEFAULT NULL COMMENT '状态 0:已作废 1:待入库 2:已发货 3.部分入库 5:已完成',
            `be_delivered_num` int DEFAULT NULL COMMENT '0全部发货 其他数量为剩余待发货数量',
            PRIMARY KEY (`purchase_item_id`),
            KEY `idx_purchase_order_id` (`purchase_order_id`)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='采购订单项'
          "
        );
        PREPARE create_purchase_order_item_table FROM @create_purchase_order_item_table;
        EXECUTE create_purchase_order_item_table;

        SET @create_purchase_order_item_lang_table = CONCAT(
          'CREATE TABLE IF NOT EXISTS purchase_order_item_lang_', i,
          "
          (
            `purchase_item_id` bigint NOT NULL COMMENT '订单项ID',
            `lang` tinyint NOT NULL COMMENT '语言 1.中文 2.英文',
            `spu_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '商品名称',
            `sku_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT 'sku名称',
            PRIMARY KEY (`purchase_item_id`)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='订单项-国际化'
          "
        );
        PREPARE create_purchase_order_item_lang_table FROM @create_purchase_order_item_lang_table;
        EXECUTE create_purchase_order_item_lang_table;

        SET @create_purchase_order_addr_table = CONCAT(
          'CREATE TABLE IF NOT EXISTS purchase_order_addr_', i,
          "
          (
            `purchase_order_addr_id` bigint unsigned NOT NULL AUTO_INCREMENT 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',
            `consignee` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci 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 '区',
            `addr` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '地址',
            `mobile` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '手机',
            PRIMARY KEY (`purchase_order_addr_id`),
            KEY `idx_shop_id` (`shop_id`)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='采购订单配送地址'
          "
        );
        PREPARE create_purchase_order_addr_table FROM @create_purchase_order_addr_table;
        EXECUTE create_purchase_order_addr_table;

            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 createTable()//
DELIMITER ;
