-- 供应商结算单（由交易订单完成支付时生成；结算模块维护）
SET NAMES utf8mb4;

CREATE TABLE IF NOT EXISTS `biz_supplier_settlement` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `settlement_no` varchar(14) NOT NULL COMMENT '结算单编号JSD+YYYYMMDD+3位序号',
  `order_id` bigint(20) NOT NULL COMMENT '关联交易订单ID',
  `order_no` varchar(11) NOT NULL COMMENT '关联订单编号冗余',
  `supplier_id` bigint(20) NOT NULL COMMENT '供应商ID',
  `total_heads` int(11) NOT NULL COMMENT '交易总头数',
  `total_amount` decimal(12,2) NOT NULL COMMENT '交易总金额元',
  `fee_method` tinyint(4) NOT NULL COMMENT '快照1按户2按头3按额',
  `fee_standard` decimal(12,2) DEFAULT NULL COMMENT '快照收费标准元/头',
  `transaction_fee_rate` decimal(5,2) DEFAULT NULL COMMENT '快照交易费率%',
  `management_fee_rate` decimal(5,2) DEFAULT NULL COMMENT '快照管理费率%',
  `service_fee_amount` decimal(12,2) NOT NULL COMMENT '服务费金额元',
  `payable_amount` decimal(12,2) NOT NULL COMMENT '实际应付结算金额元',
  `settlement_status` char(1) NOT NULL DEFAULT '0' COMMENT '0待结算 1已完成',
  `settle_voucher_url` varchar(512) DEFAULT NULL COMMENT '结算凭证URL',
  `settle_voucher_path` varchar(512) DEFAULT NULL COMMENT '结算凭证路径',
  `settle_finish_time` datetime DEFAULT NULL COMMENT '结算完成时间',
  `del_flag` char(1) NOT NULL DEFAULT '0' COMMENT '0存在 2删除',
  `create_by` varchar(64) DEFAULT '' COMMENT '创建者',
  `create_time` datetime DEFAULT NULL COMMENT '结算创建时间',
  `update_by` varchar(64) DEFAULT '' COMMENT '更新者',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `remark` varchar(500) DEFAULT NULL COMMENT '备注',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_settlement_no` (`settlement_no`),
  UNIQUE KEY `uk_order_id` (`order_id`),
  KEY `idx_order_no` (`order_no`),
  KEY `idx_supplier` (`supplier_id`),
  KEY `idx_settlement_status` (`settlement_status`),
  KEY `idx_create_time` (`create_time`),
  KEY `idx_del_flag` (`del_flag`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='供应商结算单';
