USE yami_bbc;
CREATE TABLE `tz_order_refund_intervention` (
                                                `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.平台端',
                                                `voucher_desc` varchar(200) CHARACTER SET utf8mb4 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_biz_id` (`biz_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='订单退款介入记录';


ALTER TABLE tz_order_refund
    ADD COLUMN `shop_img_urls` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '商家/供应商文件凭证(逗号隔开)' AFTER `photo_files`,
    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`;


ALTER TABLE `tz_order_item`
    ADD COLUMN `platform_intervention_status` tinyint(0) NULL DEFAULT -1 COMMENT '平台介入状态 -1.没有介入 1.用户申请介入 2.平台同意介入 3.平台拒绝介入 5.平台同意退款成功' AFTER `properties`;

# 商家菜单添加接口权限
UPDATE `tz_shop_menu` SET `perms` = 'admin:form:list,admin:form:info' WHERE `menu_id` in (607,608);


# 平台介入超时处理定时任务
USE `xxl_job`;
INSERT INTO `xxl_job_info`(`job_group`, `job_desc`, `add_time`, `update_time`, `author`, `alarm_email`, `schedule_type`, `schedule_conf`, `misfire_strategy`, `executor_route_strategy`, `executor_handler`, `executor_param`, `executor_block_strategy`, `executor_timeout`, `executor_fail_retry_count`, `glue_type`, `glue_source`, `glue_remark`, `glue_updatetime`, `child_jobid`, `trigger_status`, `trigger_last_time`, `trigger_next_time`)
VALUES
    (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, 1701833880000, 1701833940000);


