-- URS合伙人分红相关表

-- 合伙人分红记录表
CREATE TABLE `kku_urs_promotion_partner_dividend_records` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `dividend_date` date NOT NULL COMMENT '分红日期',
  `total_fee_amount` decimal(20,10) NOT NULL DEFAULT '0.0000000000' COMMENT '当日总手续费金额',
  `dividend_amount` decimal(20,10) NOT NULL DEFAULT '0.0000000000' COMMENT '分红总金额(总手续费的20%)',
  `partner_count` int(11) NOT NULL DEFAULT '0' COMMENT '合伙人数量',
  `per_partner_amount` decimal(20,10) NOT NULL DEFAULT '0.0000000000' COMMENT '每个合伙人分红金额',
  `transfer_app_id` int(11) NOT NULL DEFAULT '0' COMMENT '转账应用ID',
  `status` varchar(20) NOT NULL DEFAULT 'pending' COMMENT '状态:pending待处理,processing处理中,completed已完成,failed失败',
  `error_message` text COMMENT '错误信息',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_dividend_date` (`dividend_date`),
  KEY `idx_status` (`status`),
  KEY `idx_transfer_app_id` (`transfer_app_id`),
  KEY `idx_created_at` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='URS合伙人分红记录表';

-- 合伙人分红详情表
CREATE TABLE `kku_urs_promotion_partner_dividend_details` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `dividend_record_id` int(11) NOT NULL COMMENT '分红记录ID',
  `user_id` int(11) NOT NULL COMMENT '用户ID(农场用户ID)',
  `urs_user_id` int(11) NOT NULL COMMENT 'URS用户ID',
  `talent_level` tinyint(4) NOT NULL DEFAULT '0' COMMENT '达人等级',
  `dividend_amount` decimal(20,10) NOT NULL DEFAULT '0.0000000000' COMMENT '分红金额',
  `status` varchar(20) NOT NULL DEFAULT 'pending' COMMENT '状态:pending待处理,completed已完成,failed失败',
  `error_message` text COMMENT '错误信息',
  `transfer_order_id` int(11) DEFAULT NULL COMMENT '转账订单ID',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`),
  KEY `idx_dividend_record_id` (`dividend_record_id`),
  KEY `idx_user_id` (`user_id`),
  KEY `idx_urs_user_id` (`urs_user_id`),
  KEY `idx_status` (`status`),
  KEY `idx_transfer_order_id` (`transfer_order_id`),
  KEY `idx_created_at` (`created_at`),
  CONSTRAINT `fk_dividend_details_record` FOREIGN KEY (`dividend_record_id`) REFERENCES `kku_urs_promotion_partner_dividend_records` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='URS合伙人分红详情表';
