#添加订单分库分表的平台介入配置
USE mall4cloud_nacos;
UPDATE config_info
set content = '# 数据源\nspring:\n  data:\n    mongodb:\n      host: 192.168.193.128\n      port: 27017\n      database: mall4cloud\n      username: mall4cloud\n      password: [REDACTED]      authentication-database: mall4cloud\n  shardingsphere:\n    database:\n      default:\n        size: 8\n    table:\n      default:\n        size: 64\n      refund:\n        size: 32\n      purchase:\n        size: 2\n      city:\n        size: 64\n    props:\n      sql:\n        show: true\n    # 数据源配置\n    datasource:\n      names: ds,ds0,ds1,ds2,ds3,ds4,ds5,ds6,ds7\n      ds:\n        type: com.zaxxer.hikari.HikariDataSource\n        driver-class-name: com.mysql.cj.jdbc.Driver\n        jdbc-url: jdbc:mysql://${MYSQL_HOST:192.168.193.128}:${MYSQL_PORT:3306}/${MYSQL_DATABASE:mall4cloud_order}?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true&useAffectedRows=true\n        username: ${MYSQL_USERNAME:root}\n        password: ${MYSQL_PASSWORD:[REDACTED]        minimum-idle: 0\n        maximum-pool-size: 20\n        idle-timeout: 25000\n        auto-commit: true\n        connection-test-query: SELECT 1\n      ds0:\n        type: com.zaxxer.hikari.HikariDataSource\n        driver-class-name: com.mysql.cj.jdbc.Driver\n        jdbc-url: jdbc:mysql://${MYSQL_HOST:192.168.193.128}:${MYSQL_PORT:3306}/${MYSQL_DATABASE:mall4cloud_order}_0?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true&useAffectedRows=true\n        username: ${MYSQL_USERNAME:root}\n        password: ${MYSQL_PASSWORD:[REDACTED]        minimum-idle: 0\n        maximum-pool-size: 20\n        idle-timeout: 25000\n        auto-commit: true\n        connection-test-query: SELECT 1\n      ds1:\n        type: com.zaxxer.hikari.HikariDataSource\n        driver-class-name: com.mysql.cj.jdbc.Driver\n        jdbc-url: jdbc:mysql://${MYSQL_HOST:192.168.193.128}:${MYSQL_PORT:3306}/${MYSQL_DATABASE:mall4cloud_order}_1?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true&useAffectedRows=true\n        username: ${MYSQL_USERNAME:root}\n        password: ${MYSQL_PASSWORD:[REDACTED]        minimum-idle: 0\n        maximum-pool-size: 20\n        idle-timeout: 25000\n        auto-commit: true\n        connection-test-query: SELECT 1\n      ds2:\n        type: com.zaxxer.hikari.HikariDataSource\n        driver-class-name: com.mysql.cj.jdbc.Driver\n        jdbc-url: jdbc:mysql://${MYSQL_HOST:192.168.193.128}:${MYSQL_PORT:3306}/${MYSQL_DATABASE:mall4cloud_order}_2?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true&useAffectedRows=true\n        username: ${MYSQL_USERNAME:root}\n        password: ${MYSQL_PASSWORD:[REDACTED]        minimum-idle: 0\n        maximum-pool-size: 20\n        idle-timeout: 25000\n        auto-commit: true\n        connection-test-query: SELECT 1\n      ds3:\n        type: com.zaxxer.hikari.HikariDataSource\n        driver-class-name: com.mysql.cj.jdbc.Driver\n        jdbc-url: jdbc:mysql://${MYSQL_HOST:192.168.193.128}:${MYSQL_PORT:3306}/${MYSQL_DATABASE:mall4cloud_order}_3?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true&useAffectedRows=true\n        username: ${MYSQL_USERNAME:root}\n        password: ${MYSQL_PASSWORD:[REDACTED]        minimum-idle: 0\n        maximum-pool-size: 20\n        idle-timeout: 25000\n        auto-commit: true\n        connection-test-query: SELECT 1\n      ds4:\n        type: com.zaxxer.hikari.HikariDataSource\n        driver-class-name: com.mysql.cj.jdbc.Driver\n        jdbc-url: jdbc:mysql://${MYSQL_HOST:192.168.193.128}:${MYSQL_PORT:3306}/${MYSQL_DATABASE:mall4cloud_order}_4?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true&useAffectedRows=true\n        username: ${MYSQL_USERNAME:root}\n        password: ${MYSQL_PASSWORD:[REDACTED]        minimum-idle: 0\n        maximum-pool-size: 20\n        idle-timeout: 25000\n        auto-commit: true\n        connection-test-query: SELECT 1\n      ds5:\n        type: com.zaxxer.hikari.HikariDataSource\n        driver-class-name: com.mysql.cj.jdbc.Driver\n        jdbc-url: jdbc:mysql://${MYSQL_HOST:192.168.193.128}:${MYSQL_PORT:3306}/${MYSQL_DATABASE:mall4cloud_order}_5?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true&useAffectedRows=true\n        username: ${MYSQL_USERNAME:root}\n        password: ${MYSQL_PASSWORD:[REDACTED]        minimum-idle: 0\n        maximum-pool-size: 20\n        idle-timeout: 25000\n        auto-commit: true\n        connection-test-query: SELECT 1\n      ds6:\n        type: com.zaxxer.hikari.HikariDataSource\n        driver-class-name: com.mysql.cj.jdbc.Driver\n        jdbc-url: jdbc:mysql://${MYSQL_HOST:192.168.193.128}:${MYSQL_PORT:3306}/${MYSQL_DATABASE:mall4cloud_order}_6?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true&useAffectedRows=true\n        username: ${MYSQL_USERNAME:root}\n        password: ${MYSQL_PASSWORD:[REDACTED]        minimum-idle: 0\n        maximum-pool-size: 20\n        idle-timeout: 25000\n        auto-commit: true\n        connection-test-query: SELECT 1\n      ds7:\n        type: com.zaxxer.hikari.HikariDataSource\n        driver-class-name: com.mysql.cj.jdbc.Driver\n        jdbc-url: jdbc:mysql://${MYSQL_HOST:192.168.193.128}:${MYSQL_PORT:3306}/${MYSQL_DATABASE:mall4cloud_order}_7?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true&useAffectedRows=true\n        username: ${MYSQL_USERNAME:root}\n        password: ${MYSQL_PASSWORD:[REDACTED]        minimum-idle: 0\n        maximum-pool-size: 20\n        idle-timeout: 25000\n        auto-commit: true\n        connection-test-query: SELECT 1\n    # 分片配置\n    sharding:\n      default-data-source-name: ds\n      # 分表配置\n      tables:\n        # 正向订单业务表\n        order:\n          actual-data-nodes: ds$->{0..7}.order_$->{0..63}\n          database-strategy:\n            complex:\n              sharding-columns: order_id,user_id,refund_id,order_item_id,order_item_lang_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomDatabaseComplexKeysShardingAlgorithm\n          table-strategy:\n            complex:\n              sharding-columns: order_id,user_id,refund_id,order_item_id,order_item_lang_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomTableComplexKeysShardingAlgorithm\n        order_item:\n          actual-data-nodes: ds$->{0..7}.order_item_$->{0..63}\n          database-strategy:\n            complex:\n              sharding-columns: order_id,user_id,refund_id,order_item_id,order_item_lang_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomDatabaseComplexKeysShardingAlgorithm\n          table-strategy:\n            complex:\n              sharding-columns: order_id,user_id,refund_id,order_item_id,order_item_lang_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomTableComplexKeysShardingAlgorithm\n        order_item_lang:\n          actual-data-nodes: ds$->{0..7}.order_item_lang_$->{0..63}\n          database-strategy:\n            complex:\n              sharding-columns: order_id,user_id,refund_id,order_item_id,order_item_lang_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomDatabaseComplexKeysShardingAlgorithm\n          table-strategy:\n            complex:\n              sharding-columns: order_id,user_id,refund_id,order_item_id,order_item_lang_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomTableComplexKeysShardingAlgorithm\n        order_settlement:\n          actual-data-nodes: ds$->{0..7}.order_settlement_$->{0..63}\n          database-strategy:\n            complex:\n              sharding-columns: order_id,user_id,refund_id,order_item_id,settlement_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomDatabaseComplexKeysShardingAlgorithm\n          table-strategy:\n            complex:\n              sharding-columns: order_id,user_id,refund_id,order_item_id,settlement_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomTableComplexKeysShardingAlgorithm\n        order_pre_sale_info:\n          actual-data-nodes: ds$->{0..7}.order_pre_sale_info_$->{0..63}\n          database-strategy:\n            complex:\n              sharding-columns: order_id,order_pre_sale_info_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomDatabaseComplexKeysShardingAlgorithm\n          table-strategy:\n            complex:\n              sharding-columns: order_id,order_pre_sale_info_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomTableComplexKeysShardingAlgorithm\n        order_addr:\n          actual-data-nodes: ds$->{0..7}.order_addr_$->{0..63}\n          database-strategy:\n            complex:\n              sharding-columns: order_id,user_id,refund_id,order_item_id,order_addr_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomDatabaseComplexKeysShardingAlgorithm\n          table-strategy:\n            complex:\n              sharding-columns: order_id,user_id,refund_id,order_item_id,order_addr_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomTableComplexKeysShardingAlgorithm\n        order_invoice:\n          actual-data-nodes: ds$->{0..7}.order_invoice_$->{0..63}\n          database-strategy:\n            complex:\n              sharding-columns: order_id,user_id,refund_id,order_item_id,order_invoice_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomDatabaseComplexKeysShardingAlgorithm\n          table-strategy:\n            complex:\n              sharding-columns: order_id,user_id,refund_id,order_item_id,order_invoice_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomTableComplexKeysShardingAlgorithm\n        order_self_station:\n          actual-data-nodes: ds$->{0..7}.order_self_station_$->{0..63}\n          database-strategy:\n            complex:\n              sharding-columns: order_id,user_id,id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomDatabaseComplexKeysShardingAlgorithm\n          table-strategy:\n            complex:\n              sharding-columns: order_id,user_id,id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomTableComplexKeysShardingAlgorithm\n        order_virtual_info:\n          actual-data-nodes: ds$->{0..7}.order_virtual_info_$->{0..63}\n          database-strategy:\n            complex:\n              sharding-columns: order_id,order_virtual_info_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomDatabaseComplexKeysShardingAlgorithm\n          table-strategy:\n            complex:\n              sharding-columns: order_id,order_virtual_info_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomTableComplexKeysShardingAlgorithm\n#       退款业务表\n        order_refund:\n          actual-data-nodes: ds$->{0..7}.order_refund_$->{0..31}\n          database-strategy:\n            complex:\n              sharding-columns: order_id,user_id,refund_id,order_item_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomDatabaseComplexKeysShardingAlgorithm\n          table-strategy:\n            complex:\n              sharding-columns: order_id,user_id,refund_id,order_item_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomTableComplexKeysShardingAlgorithm\n        order_refund_addr:\n          actual-data-nodes: ds$->{0..7}.order_refund_addr_$->{0..31}\n          database-strategy:\n            complex:\n              sharding-columns: order_id,user_id,refund_id,order_item_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomDatabaseComplexKeysShardingAlgorithm\n          table-strategy:\n            complex:\n              sharding-columns: order_id,user_id,refund_id,order_item_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomTableComplexKeysShardingAlgorithm\n        order_refund_intervention:\n          actual-data-nodes: ds$->{0..7}.order_refund_intervention_$->{0..31}\n          database-strategy:\n            complex:\n              sharding-columns: refund_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomDatabaseComplexKeysShardingAlgorithm\n          table-strategy:\n            complex:\n              sharding-columns: refund_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomTableComplexKeysShardingAlgorithm\n        order_refund_settlement:\n          actual-data-nodes: ds$->{0..7}.order_refund_settlement_$->{0..31}\n          database-strategy:\n            complex:\n              sharding-columns: order_id,user_id,refund_id,order_item_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomDatabaseComplexKeysShardingAlgorithm\n          table-strategy:\n            complex:\n              sharding-columns: order_id,user_id,refund_id,order_item_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomTableComplexKeysShardingAlgorithm\n        # 采购订单业务表\n        purchase_order:\n          actual-data-nodes: ds$->{0..7}.purchase_order_$->{0..1}\n          database-strategy:\n            complex:\n              sharding-columns: purchase_order_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomDatabaseComplexKeysShardingAlgorithm\n          table-strategy:\n            complex:\n              sharding-columns: purchase_order_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomTableComplexKeysShardingAlgorithm\n        purchase_order_item:\n          actual-data-nodes: ds$->{0..7}.purchase_order_item_$->{0..1}\n          database-strategy:\n            complex:\n              sharding-columns: purchase_item_id,purchase_order_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomDatabaseComplexKeysShardingAlgorithm\n          table-strategy:\n            complex:\n              sharding-columns: purchase_item_id,purchase_order_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomTableComplexKeysShardingAlgorithm\n        purchase_order_item_lang:\n          actual-data-nodes: ds$->{0..7}.purchase_order_item_lang_$->{0..1}\n          database-strategy:\n            complex:\n              sharding-columns: purchase_item_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomDatabaseComplexKeysShardingAlgorithm\n          table-strategy:\n            complex:\n              sharding-columns: purchase_item_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomTableComplexKeysShardingAlgorithm\n        purchase_order_lang:\n          actual-data-nodes: ds$->{0..7}.purchase_order_lang_$->{0..1}\n          database-strategy:\n            complex:\n              sharding-columns: purchase_order_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomDatabaseComplexKeysShardingAlgorithm\n          table-strategy:\n            complex:\n              sharding-columns: purchase_order_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomTableComplexKeysShardingAlgorithm\n        purchase_order_addr:\n          actual-data-nodes: ds$->{0..7}.purchase_order_addr_$->{0..1}\n          database-strategy:\n            complex:\n              sharding-columns: purchase_order_addr_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomDatabaseComplexKeysShardingAlgorithm\n          table-strategy:\n            complex:\n              sharding-columns: purchase_order_addr_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomTableComplexKeysShardingAlgorithm\n        delivery_order:\n          actual-data-nodes: ds$->{0..7}.delivery_order_$->{0..63}\n          database-strategy:\n            complex:\n              sharding-columns: delivery_order_id,order_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomDatabaseComplexKeysShardingAlgorithm\n          table-strategy:\n            complex:\n              sharding-columns: delivery_order_id,order_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomTableComplexKeysShardingAlgorithm\n        delivery_order_item:\n          actual-data-nodes: ds$->{0..7}.delivery_order_item_$->{0..63}\n          database-strategy:\n            complex:\n              sharding-columns: delivery_order_id,delivery_order_item_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomDatabaseComplexKeysShardingAlgorithm\n          table-strategy:\n            complex:\n              sharding-columns: delivery_order_id,delivery_order_item_id\n              algorithm-class-name: com.tmerclub.cloud.config.sharding.CustomTableComplexKeysShardingAlgorithm\n      # 绑定表配置\n      binding-tables:\n        - order,order_item,order_addr,order_item_lang,order_settlement,order_invoice,order_refund,order_refund_addr,order_refund_intervention,order_refund_settlement,order_pre_sale_info,purchase_order,purchase_order_item,purchase_order_item_lang,purchase_order_lang,purchase_order_addr,order_self_station,order_virtual_info,delivery_order,delivery_order_item\nmall4cloud:\n  order:\n    thread:\n      coreSize: 0\n      maxSize: 200\n      keepAliveTime: 60\n\nmanagement:\n  health:\n    db:\n      enabled: false'
where data_id = "mall4cloud-order.yml";

USE mall4cloud_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
(2,'执行平台介入超时处理，超时默认平台拒绝退款','2023-10-09 16:20:28','2023-10-09 16:20:28','admin','','CRON','0 0/1 * * * ?','DO_NOTHING','FIRST','refundInterventionTimeOut','','SERIAL_EXECUTION','0','0','BEAN','','GLUE代码初始化','2023-10-09 16:20:28','',1, 0, 0);

# 修改订单退款表
USE `mall4cloud_order_0`;

DELIMITER //
DROP PROCEDURE IF EXISTS createTable//
CREATE PROCEDURE createTable()
BEGIN
    DECLARE i INT;
    SET i = 0;
    WHILE i<32 DO

            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 COMMENT '系统类型，0.普通用户 1.商家端 2.平台端 3.供应商端',
			`voucher_desc` varchar(200) DEFAULT NULL COMMENT '凭证说明',
			`img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '文件凭证(逗号隔开)',
			 PRIMARY KEY (`refund_intervertion_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 @update_order_refund_table = CONCAT(
                'ALTER TABLE order_refund_', i,
                "
    		ADD COLUMN `shop_img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '商家/供应商文件凭证(逗号隔开)' AFTER `img_urls`,
			ADD COLUMN `platform_intervention_status` TINYINT NOT NULL DEFAULT '-1' COMMENT '平台介入状态 -1.没有介入 1.用户申请介入 2.平台同意介入 3.平台拒绝介入 5.平台同意退款成功',
			ADD COLUMN `apply_intervention_reason` VARCHAR(300) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '用户申请介入理由' AFTER `platform_intervention_status`,
    		ADD COLUMN `apply_intervention_img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '申请介入的文件凭证(逗号隔开)' AFTER `apply_intervention_reason`,
			ADD COLUMN `intervention_refund_type` TINYINT DEFAULT NULL COMMENT '平台介入退款方式 1.商家承担 2.商家供应商承担（供应商发货订单） 3.不同意退款'  AFTER `apply_intervention_img_urls`,
			ADD COLUMN `after_intervention_refund_amount` BIGINT DEFAULT NULL COMMENT '平台介入前的退款金额' AFTER `intervention_refund_type`,
			ADD COLUMN `platform_message` VARCHAR(300) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '平台留言' AFTER `after_intervention_refund_amount`,
			ADD COLUMN `apply_intervention_time` DATETIME DEFAULT NULL COMMENT '申请介入时间' AFTER `platform_message`,
			ADD COLUMN `intervention_finish_time` DATETIME DEFAULT NULL COMMENT '介入完成时间' AFTER `apply_intervention_time`;
		");
PREPARE update_order_refund_table FROM @update_order_refund_table;
EXECUTE update_order_refund_table;

SET i = i+1;
END WHILE;

END//
CALL createTable()//
DELIMITER ;

USE `mall4cloud_order_1`;

DELIMITER //
DROP PROCEDURE IF EXISTS createTable//
CREATE PROCEDURE createTable()
BEGIN
    DECLARE i INT;
    SET i = 0;
    WHILE i<32 DO

            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 COMMENT '系统类型，0.普通用户 1.商家端 2.平台端 3.供应商端',
			`voucher_desc` varchar(200) DEFAULT NULL COMMENT '凭证说明',
			`img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '文件凭证(逗号隔开)',
			 PRIMARY KEY (`refund_intervertion_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 @update_order_refund_table = CONCAT(
                'ALTER TABLE order_refund_', i,
                "
    		ADD COLUMN `shop_img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '商家/供应商文件凭证(逗号隔开)' AFTER `img_urls`,
			ADD COLUMN `platform_intervention_status` TINYINT NOT NULL DEFAULT '-1' COMMENT '平台介入状态 -1.没有介入 1.用户申请介入 2.平台同意介入 3.平台拒绝介入 5.平台同意退款成功',
			ADD COLUMN `apply_intervention_reason` VARCHAR(300) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '用户申请介入理由' AFTER `platform_intervention_status`,
    		ADD COLUMN `apply_intervention_img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '申请介入的文件凭证(逗号隔开)' AFTER `apply_intervention_reason`,
			ADD COLUMN `intervention_refund_type` TINYINT DEFAULT NULL COMMENT '平台介入退款方式 1.商家承担 2.商家供应商承担（供应商发货订单） 3.不同意退款'  AFTER `apply_intervention_img_urls`,
			ADD COLUMN `after_intervention_refund_amount` BIGINT DEFAULT NULL COMMENT '平台介入前的退款金额' AFTER `intervention_refund_type`,
			ADD COLUMN `platform_message` VARCHAR(300) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '平台留言' AFTER `after_intervention_refund_amount`,
			ADD COLUMN `apply_intervention_time` DATETIME DEFAULT NULL COMMENT '申请介入时间' AFTER `platform_message`,
			ADD COLUMN `intervention_finish_time` DATETIME DEFAULT NULL COMMENT '介入完成时间' AFTER `apply_intervention_time`;
		");
PREPARE update_order_refund_table FROM @update_order_refund_table;
EXECUTE update_order_refund_table;

SET i = i+1;
END WHILE;

END//
CALL createTable()//
DELIMITER ;

# 修改订单退款表
USE `mall4cloud_order_1`;

DELIMITER //
DROP PROCEDURE IF EXISTS createTable//
CREATE PROCEDURE createTable()
BEGIN
    DECLARE i INT;
    SET i = 0;
    WHILE i<32 DO

            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 COMMENT '系统类型，0.普通用户 1.商家端 2.平台端 3.供应商端',
			`voucher_desc` varchar(200) DEFAULT NULL COMMENT '凭证说明',
			`img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '文件凭证(逗号隔开)',
			 PRIMARY KEY (`refund_intervertion_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 @update_order_refund_table = CONCAT(
                'ALTER TABLE order_refund_', i,
                "
    		ADD COLUMN `shop_img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '商家/供应商文件凭证(逗号隔开)' AFTER `img_urls`,
			ADD COLUMN `platform_intervention_status` TINYINT NOT NULL DEFAULT '-1' COMMENT '平台介入状态 -1.没有介入 1.用户申请介入 2.平台同意介入 3.平台拒绝介入 5.平台同意退款成功',
			ADD COLUMN `apply_intervention_reason` VARCHAR(300) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '用户申请介入理由' AFTER `platform_intervention_status`,
    		ADD COLUMN `apply_intervention_img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '申请介入的文件凭证(逗号隔开)' AFTER `apply_intervention_reason`,
			ADD COLUMN `intervention_refund_type` TINYINT DEFAULT NULL COMMENT '平台介入退款方式 1.商家承担 2.商家供应商承担（供应商发货订单） 3.不同意退款'  AFTER `apply_intervention_img_urls`,
			ADD COLUMN `after_intervention_refund_amount` BIGINT DEFAULT NULL COMMENT '平台介入前的退款金额' AFTER `intervention_refund_type`,
			ADD COLUMN `platform_message` VARCHAR(300) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '平台留言' AFTER `after_intervention_refund_amount`,
			ADD COLUMN `apply_intervention_time` DATETIME DEFAULT NULL COMMENT '申请介入时间' AFTER `platform_message`,
			ADD COLUMN `intervention_finish_time` DATETIME DEFAULT NULL COMMENT '介入完成时间' AFTER `apply_intervention_time`;
		");
PREPARE update_order_refund_table FROM @update_order_refund_table;
EXECUTE update_order_refund_table;

SET i = i+1;
END WHILE;

END//
CALL createTable()//
DELIMITER ;

# 修改订单退款表
USE `mall4cloud_order_2`;

DELIMITER //
DROP PROCEDURE IF EXISTS createTable//
CREATE PROCEDURE createTable()
BEGIN
    DECLARE i INT;
    SET i = 0;
    WHILE i<32 DO

            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 COMMENT '系统类型，0.普通用户 1.商家端 2.平台端 3.供应商端',
			`voucher_desc` varchar(200) DEFAULT NULL COMMENT '凭证说明',
			`img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '文件凭证(逗号隔开)',
			 PRIMARY KEY (`refund_intervertion_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 @update_order_refund_table = CONCAT(
                'ALTER TABLE order_refund_', i,
                "
    		ADD COLUMN `shop_img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '商家/供应商文件凭证(逗号隔开)' AFTER `img_urls`,
			ADD COLUMN `platform_intervention_status` TINYINT NOT NULL DEFAULT '-1' COMMENT '平台介入状态 -1.没有介入 1.用户申请介入 2.平台同意介入 3.平台拒绝介入 5.平台同意退款成功',
			ADD COLUMN `apply_intervention_reason` VARCHAR(300) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '用户申请介入理由' AFTER `platform_intervention_status`,
    		ADD COLUMN `apply_intervention_img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '申请介入的文件凭证(逗号隔开)' AFTER `apply_intervention_reason`,
			ADD COLUMN `intervention_refund_type` TINYINT DEFAULT NULL COMMENT '平台介入退款方式 1.商家承担 2.商家供应商承担（供应商发货订单） 3.不同意退款'  AFTER `apply_intervention_img_urls`,
			ADD COLUMN `after_intervention_refund_amount` BIGINT DEFAULT NULL COMMENT '平台介入前的退款金额' AFTER `intervention_refund_type`,
			ADD COLUMN `platform_message` VARCHAR(300) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '平台留言' AFTER `after_intervention_refund_amount`,
			ADD COLUMN `apply_intervention_time` DATETIME DEFAULT NULL COMMENT '申请介入时间' AFTER `platform_message`,
			ADD COLUMN `intervention_finish_time` DATETIME DEFAULT NULL COMMENT '介入完成时间' AFTER `apply_intervention_time`;
		");
PREPARE update_order_refund_table FROM @update_order_refund_table;
EXECUTE update_order_refund_table;

SET i = i+1;
END WHILE;

END//
CALL createTable()//
DELIMITER ;

# 修改订单退款表
USE `mall4cloud_order_3`;

DELIMITER //
DROP PROCEDURE IF EXISTS createTable//
CREATE PROCEDURE createTable()
BEGIN
    DECLARE i INT;
    SET i = 0;
    WHILE i<32 DO

            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 COMMENT '系统类型，0.普通用户 1.商家端 2.平台端 3.供应商端',
			`voucher_desc` varchar(200) DEFAULT NULL COMMENT '凭证说明',
			`img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '文件凭证(逗号隔开)',
			 PRIMARY KEY (`refund_intervertion_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 @update_order_refund_table = CONCAT(
                'ALTER TABLE order_refund_', i,
                "
    		ADD COLUMN `shop_img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '商家/供应商文件凭证(逗号隔开)' AFTER `img_urls`,
			ADD COLUMN `platform_intervention_status` TINYINT NOT NULL DEFAULT '-1' COMMENT '平台介入状态 -1.没有介入 1.用户申请介入 2.平台同意介入 3.平台拒绝介入 5.平台同意退款成功',
			ADD COLUMN `apply_intervention_reason` VARCHAR(300) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '用户申请介入理由' AFTER `platform_intervention_status`,
    		ADD COLUMN `apply_intervention_img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '申请介入的文件凭证(逗号隔开)' AFTER `apply_intervention_reason`,
			ADD COLUMN `intervention_refund_type` TINYINT DEFAULT NULL COMMENT '平台介入退款方式 1.商家承担 2.商家供应商承担（供应商发货订单） 3.不同意退款'  AFTER `apply_intervention_img_urls`,
			ADD COLUMN `after_intervention_refund_amount` BIGINT DEFAULT NULL COMMENT '平台介入前的退款金额' AFTER `intervention_refund_type`,
			ADD COLUMN `platform_message` VARCHAR(300) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '平台留言' AFTER `after_intervention_refund_amount`,
			ADD COLUMN `apply_intervention_time` DATETIME DEFAULT NULL COMMENT '申请介入时间' AFTER `platform_message`,
			ADD COLUMN `intervention_finish_time` DATETIME DEFAULT NULL COMMENT '介入完成时间' AFTER `apply_intervention_time`;
		");
PREPARE update_order_refund_table FROM @update_order_refund_table;
EXECUTE update_order_refund_table;

SET i = i+1;
END WHILE;

END//
CALL createTable()//
DELIMITER ;

# 修改订单退款表
USE `mall4cloud_order_4`;

DELIMITER //
DROP PROCEDURE IF EXISTS createTable//
CREATE PROCEDURE createTable()
BEGIN
    DECLARE i INT;
    SET i = 0;
    WHILE i<32 DO

            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 COMMENT '系统类型，0.普通用户 1.商家端 2.平台端 3.供应商端',
			`voucher_desc` varchar(200) DEFAULT NULL COMMENT '凭证说明',
			`img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '文件凭证(逗号隔开)',
			 PRIMARY KEY (`refund_intervertion_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 @update_order_refund_table = CONCAT(
                'ALTER TABLE order_refund_', i,
                "
    		ADD COLUMN `shop_img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '商家/供应商文件凭证(逗号隔开)' AFTER `img_urls`,
			ADD COLUMN `platform_intervention_status` TINYINT NOT NULL DEFAULT '-1' COMMENT '平台介入状态 -1.没有介入 1.用户申请介入 2.平台同意介入 3.平台拒绝介入 5.平台同意退款成功',
			ADD COLUMN `apply_intervention_reason` VARCHAR(300) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '用户申请介入理由' AFTER `platform_intervention_status`,
    		ADD COLUMN `apply_intervention_img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '申请介入的文件凭证(逗号隔开)' AFTER `apply_intervention_reason`,
			ADD COLUMN `intervention_refund_type` TINYINT DEFAULT NULL COMMENT '平台介入退款方式 1.商家承担 2.商家供应商承担（供应商发货订单） 3.不同意退款'  AFTER `apply_intervention_img_urls`,
			ADD COLUMN `after_intervention_refund_amount` BIGINT DEFAULT NULL COMMENT '平台介入前的退款金额' AFTER `intervention_refund_type`,
			ADD COLUMN `platform_message` VARCHAR(300) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '平台留言' AFTER `after_intervention_refund_amount`,
			ADD COLUMN `apply_intervention_time` DATETIME DEFAULT NULL COMMENT '申请介入时间' AFTER `platform_message`,
			ADD COLUMN `intervention_finish_time` DATETIME DEFAULT NULL COMMENT '介入完成时间' AFTER `apply_intervention_time`;
		");
PREPARE update_order_refund_table FROM @update_order_refund_table;
EXECUTE update_order_refund_table;

SET i = i+1;
END WHILE;

END//
CALL createTable()//
DELIMITER ;

# 修改订单退款表
USE `mall4cloud_order_5`;

DELIMITER //
DROP PROCEDURE IF EXISTS createTable//
CREATE PROCEDURE createTable()
BEGIN
    DECLARE i INT;
    SET i = 0;
    WHILE i<32 DO

            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 COMMENT '系统类型，0.普通用户 1.商家端 2.平台端 3.供应商端',
			`voucher_desc` varchar(200) DEFAULT NULL COMMENT '凭证说明',
			`img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '文件凭证(逗号隔开)',
			 PRIMARY KEY (`refund_intervertion_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 @update_order_refund_table = CONCAT(
                'ALTER TABLE order_refund_', i,
                "
    		ADD COLUMN `shop_img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '商家/供应商文件凭证(逗号隔开)' AFTER `img_urls`,
			ADD COLUMN `platform_intervention_status` TINYINT NOT NULL DEFAULT '-1' COMMENT '平台介入状态 -1.没有介入 1.用户申请介入 2.平台同意介入 3.平台拒绝介入 5.平台同意退款成功',
			ADD COLUMN `apply_intervention_reason` VARCHAR(300) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '用户申请介入理由' AFTER `platform_intervention_status`,
    		ADD COLUMN `apply_intervention_img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '申请介入的文件凭证(逗号隔开)' AFTER `apply_intervention_reason`,
			ADD COLUMN `intervention_refund_type` TINYINT DEFAULT NULL COMMENT '平台介入退款方式 1.商家承担 2.商家供应商承担（供应商发货订单） 3.不同意退款'  AFTER `apply_intervention_img_urls`,
			ADD COLUMN `after_intervention_refund_amount` BIGINT DEFAULT NULL COMMENT '平台介入前的退款金额' AFTER `intervention_refund_type`,
			ADD COLUMN `platform_message` VARCHAR(300) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '平台留言' AFTER `after_intervention_refund_amount`,
			ADD COLUMN `apply_intervention_time` DATETIME DEFAULT NULL COMMENT '申请介入时间' AFTER `platform_message`,
			ADD COLUMN `intervention_finish_time` DATETIME DEFAULT NULL COMMENT '介入完成时间' AFTER `apply_intervention_time`;
		");
PREPARE update_order_refund_table FROM @update_order_refund_table;
EXECUTE update_order_refund_table;

SET i = i+1;
END WHILE;

END//
CALL createTable()//
DELIMITER ;

# 修改订单退款表
USE `mall4cloud_order_6`;

DELIMITER //
DROP PROCEDURE IF EXISTS createTable//
CREATE PROCEDURE createTable()
BEGIN
    DECLARE i INT;
    SET i = 0;
    WHILE i<32 DO

            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 COMMENT '系统类型，0.普通用户 1.商家端 2.平台端 3.供应商端',
			`voucher_desc` varchar(200) DEFAULT NULL COMMENT '凭证说明',
			`img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '文件凭证(逗号隔开)',
			 PRIMARY KEY (`refund_intervertion_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 @update_order_refund_table = CONCAT(
                'ALTER TABLE order_refund_', i,
                "
    		ADD COLUMN `shop_img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '商家/供应商文件凭证(逗号隔开)' AFTER `img_urls`,
			ADD COLUMN `platform_intervention_status` TINYINT NOT NULL DEFAULT '-1' COMMENT '平台介入状态 -1.没有介入 1.用户申请介入 2.平台同意介入 3.平台拒绝介入 5.平台同意退款成功',
			ADD COLUMN `apply_intervention_reason` VARCHAR(300) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '用户申请介入理由' AFTER `platform_intervention_status`,
    		ADD COLUMN `apply_intervention_img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '申请介入的文件凭证(逗号隔开)' AFTER `apply_intervention_reason`,
			ADD COLUMN `intervention_refund_type` TINYINT DEFAULT NULL COMMENT '平台介入退款方式 1.商家承担 2.商家供应商承担（供应商发货订单） 3.不同意退款'  AFTER `apply_intervention_img_urls`,
			ADD COLUMN `after_intervention_refund_amount` BIGINT DEFAULT NULL COMMENT '平台介入前的退款金额' AFTER `intervention_refund_type`,
			ADD COLUMN `platform_message` VARCHAR(300) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '平台留言' AFTER `after_intervention_refund_amount`,
			ADD COLUMN `apply_intervention_time` DATETIME DEFAULT NULL COMMENT '申请介入时间' AFTER `platform_message`,
			ADD COLUMN `intervention_finish_time` DATETIME DEFAULT NULL COMMENT '介入完成时间' AFTER `apply_intervention_time`;
		");
PREPARE update_order_refund_table FROM @update_order_refund_table;
EXECUTE update_order_refund_table;

SET i = i+1;
END WHILE;

END//
CALL createTable()//
DELIMITER ;

# 修改订单退款表
USE `mall4cloud_order_7`;

DELIMITER //
DROP PROCEDURE IF EXISTS createTable//
CREATE PROCEDURE createTable()
BEGIN
    DECLARE i INT;
    SET i = 0;
    WHILE i<32 DO

            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 COMMENT '系统类型，0.普通用户 1.商家端 2.平台端 3.供应商端',
			`voucher_desc` varchar(200) DEFAULT NULL COMMENT '凭证说明',
			`img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '文件凭证(逗号隔开)',
			 PRIMARY KEY (`refund_intervertion_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 @update_order_refund_table = CONCAT(
                'ALTER TABLE order_refund_', i,
                "
    		ADD COLUMN `shop_img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '商家/供应商文件凭证(逗号隔开)' AFTER `img_urls`,
			ADD COLUMN `platform_intervention_status` TINYINT NOT NULL DEFAULT '-1' COMMENT '平台介入状态 -1.没有介入 1.用户申请介入 2.平台同意介入 3.平台拒绝介入 5.平台同意退款成功',
			ADD COLUMN `apply_intervention_reason` VARCHAR(300) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '用户申请介入理由' AFTER `platform_intervention_status`,
    		ADD COLUMN `apply_intervention_img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '申请介入的文件凭证(逗号隔开)' AFTER `apply_intervention_reason`,
			ADD COLUMN `intervention_refund_type` TINYINT DEFAULT NULL COMMENT '平台介入退款方式 1.商家承担 2.商家供应商承担（供应商发货订单） 3.不同意退款'  AFTER `apply_intervention_img_urls`,
			ADD COLUMN `after_intervention_refund_amount` BIGINT DEFAULT NULL COMMENT '平台介入前的退款金额' AFTER `intervention_refund_type`,
			ADD COLUMN `platform_message` VARCHAR(300) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '平台留言' AFTER `after_intervention_refund_amount`,
			ADD COLUMN `apply_intervention_time` DATETIME DEFAULT NULL COMMENT '申请介入时间' AFTER `platform_message`,
			ADD COLUMN `intervention_finish_time` DATETIME DEFAULT NULL COMMENT '介入完成时间' AFTER `apply_intervention_time`;
		");
PREPARE update_order_refund_table FROM @update_order_refund_table;
EXECUTE update_order_refund_table;

SET i = i+1;
END WHILE;

END//
CALL createTable()//
DELIMITER ;

# 电子面单优化
USE mall4cloud_order;
# 添加网点配置地址字段
ALTER TABLE outlet_config
    ADD COLUMN `print_addr` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '发货地址' AFTER `is_default`;
# 更新商家地址信息至网点配置
UPDATE mall4cloud_order.outlet_config oc
    JOIN mall4cloud_admin.`shop_refund_addr` sra ON oc.`shop_addr_id` = sra.`shop_refund_addr_id`
SET oc.`print_addr` = CONCAT(sra.`province`, sra.`city`, sra.`area`, sra.`addr`)
WHERE oc.`shop_id` IS NOT NULL;
# 更新供应商地址信息至网点配置
UPDATE mall4cloud_order.outlet_config oc
    JOIN mall4cloud_admin.`supplier_refund_addr` sra ON oc.`shop_addr_id` = sra.`supplier_refund_addr_id`
SET oc.`print_addr` = CONCAT(sra.`province`, sra.`city`, sra.`area`, sra.`addr`)
WHERE oc.`supplier_id` IS NOT NULL;
# 删除网点配置地址关联字段
USE mall4cloud_order;
ALTER TABLE outlet_config DROP COLUMN shop_addr_id;

# 结算明细菜单变更
# parent_id = 325 465分别是商家和供应商的'结算明细'；
# parent_id = 663 666分别是商家和供应商的'财务'；
USE mall4cloud_auth;
UPDATE　`menu`
SET `parent_id` = 663
WHERE `menu_id` = 325;

UPDATE　`menu`
SET `parent_id` = 666
WHERE `menu_id` = 465;
