-- ******************************************************************
-- 表 kku_transfer_orders 的创建SQL
-- 对应的Model: App\Module\Transfer\Models\TransferOrder
-- 警告: 此文件由系统自动生成，禁止修改！
-- ******************************************************************

CREATE TABLE `kku_transfer_orders` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `transfer_app_id` int unsigned NOT NULL COMMENT '划转应用ID',
  `out_id` int NOT NULL COMMENT '外部应用ID',
  `out_order_id` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '外部订单ID',
  `out_user_id` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '外部用户ID',
  `user_id` int unsigned NOT NULL COMMENT '内部用户ID',
  `currency_id` int NOT NULL COMMENT '货币类型ID',
  `fund_id` int NOT NULL COMMENT '资金账户类型ID',
  `type` tinyint NOT NULL COMMENT '订单类型(1=转入,2=转出)',
  `status` tinyint NOT NULL DEFAULT '1' COMMENT '订单状态',
  `out_amount` decimal(30,10) NOT NULL COMMENT '外部金额',
  `amount` decimal(30,10) NOT NULL COMMENT '内部金额',
  `exchange_rate` decimal(10,4) NOT NULL COMMENT '使用汇率',
  `callback_data` json DEFAULT NULL COMMENT '回调数据',
  `error_message` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '错误信息',
  `remark` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '备注信息',
  `processed_at` timestamp NULL DEFAULT NULL COMMENT '处理时间',
  `callback_at` timestamp NULL DEFAULT NULL COMMENT '回调时间',
  `completed_at` timestamp NULL DEFAULT NULL COMMENT '完成时间',
  `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间',
  `updated_at` timestamp NULL DEFAULT NULL COMMENT '更新时间',
  `deleted_at` timestamp NULL DEFAULT NULL COMMENT '删除时间',
  `fee_rate` decimal(8,5) DEFAULT '0.00000' COMMENT '使用的手续费率',
  `fee_amount` decimal(15,4) DEFAULT '0.0000' COMMENT '手续费金额',
  `actual_amount` decimal(15,4) DEFAULT '0.0000' COMMENT '实际到账金额(扣除手续费后)',
  `totle_amount` decimal(15,4) DEFAULT '0.0000' COMMENT '支付扣除金额',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_transfer_app_id` (`transfer_app_id`) USING BTREE,
  KEY `idx_user_id` (`user_id`) USING BTREE,
  KEY `idx_status` (`status`) USING BTREE,
  KEY `idx_type` (`type`) USING BTREE,
  KEY `idx_created_at` (`created_at`) USING BTREE,
  KEY `idx_processed_at` (`processed_at`) USING BTREE,
  CONSTRAINT `fk_transfer_orders_app` FOREIGN KEY (`transfer_app_id`) REFERENCES `kku_transfer_apps` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='划转订单表';
