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

CREATE TABLE `kku_team_profits` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `user_id` bigint NOT NULL COMMENT '获得收益的用户ID',
  `team_member_id` bigint NOT NULL COMMENT '团队成员ID',
  `source_id` bigint NOT NULL COMMENT '收益来源ID',
  `source_type` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '收益来源类型',
  `item_id` bigint NOT NULL COMMENT '物品ID',
  `profit_amount` int NOT NULL COMMENT '分成收益数量',
  `profit_rate` decimal(5,4) NOT NULL COMMENT '分成比例',
  `relation_type` tinyint(1) NOT NULL DEFAULT '1' COMMENT '关系类型:1直推,2间推',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_user_id` (`user_id`) USING BTREE,
  KEY `idx_team_member_id` (`team_member_id`) USING BTREE,
  KEY `idx_source` (`source_type`,`source_id`) USING BTREE,
  KEY `idx_relation_type` (`relation_type`) USING BTREE,
  KEY `idx_created_at` (`created_at`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='团队收益记录表';
