-- GameItems模块数据库表结构 -- 游戏物品模块,负责游戏内所有物品的管理 -- 物品分类表 CREATE TABLE `kku_item_categories` ( `id` int NOT NULL AUTO_INCREMENT COMMENT '分类ID,主键', `name` varchar(255) NOT NULL COMMENT '分类名称', `code` varchar(100) NOT NULL COMMENT '分类编码(唯一)', `icon` varchar(255) DEFAULT NULL COMMENT '分类图标', `sort` int DEFAULT '0' COMMENT '排序权重', `parent_id` int DEFAULT NULL COMMENT '父分类ID(可为空,用于实现分类层级)', `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间', `updated_at` timestamp NULL DEFAULT NULL COMMENT '更新时间', PRIMARY KEY (`id`), UNIQUE KEY `idx_code` (`code`), KEY `idx_parent_id` (`parent_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='物品分类表'; -- 统一属性物品表 CREATE TABLE `kku_item_items` ( `id` int NOT NULL AUTO_INCREMENT COMMENT '物品ID,主键', `name` varchar(255) NOT NULL COMMENT '物品名称', `description` text COMMENT '物品描述', `category_id` int NOT NULL COMMENT '物品分类ID,外键关联kku_item_categories表', `type` tinyint NOT NULL COMMENT '物品类型(1:可使用, 2:可装备, 3:可合成, 4:可交任务, 5:可开启...)', `is_unique` tinyint DEFAULT '0' COMMENT '是否是单独属性物品(0:否,默认, 1:是)', `icon` varchar(255) DEFAULT NULL COMMENT '物品图标路径', `max_stack` int DEFAULT '1' COMMENT '最大堆叠数量', `sell_price` int DEFAULT '0' COMMENT '出售价格', `tradable` tinyint DEFAULT '1' COMMENT '是否可交易(0:不可交易, 1:可交易,默认)', `dismantlable` tinyint DEFAULT '1' COMMENT '是否可分解(0:不可分解, 1:可分解,默认)', `default_expire_seconds` int DEFAULT '0' COMMENT '玩家获取物品后的默认有效秒数(0表示永久有效)', `display_attributes` json DEFAULT NULL COMMENT '展示属性,以JSON格式存储键值对,用于界面展示和描述的属性', `numeric_attributes` json DEFAULT NULL COMMENT '数值属性,以JSON格式存储键值对,用于计算和游戏逻辑的属性', `global_expire_at` timestamp NULL DEFAULT NULL COMMENT '物品全局过期时间(可为空)', `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间', `updated_at` timestamp NULL DEFAULT NULL COMMENT '更新时间', PRIMARY KEY (`id`), KEY `idx_category_id` (`category_id`), KEY `idx_type` (`type`), KEY `idx_is_unique` (`is_unique`), KEY `idx_tradable` (`tradable`), KEY `idx_dismantlable` (`dismantlable`), KEY `idx_global_expire_at` (`global_expire_at`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='统一属性物品表'; -- 单独属性物品表 CREATE TABLE `kku_item_instances` ( `id` int NOT NULL AUTO_INCREMENT COMMENT '唯一物品ID,主键', `item_id` int NOT NULL COMMENT '关联的基础物品ID,外键关联kku_item_items表', `name` varchar(255) DEFAULT NULL COMMENT '物品名称(可以与基础物品不同)', `display_attributes` json DEFAULT NULL COMMENT '展示属性,以JSON格式存储键值对', `numeric_attributes` json DEFAULT NULL COMMENT '数值属性,以JSON格式存储键值对', `tradable` tinyint DEFAULT '1' COMMENT '是否可交易(0:不可交易, 1:可交易,默认)', `is_bound` tinyint DEFAULT '0' COMMENT '是否已绑定(0:未绑定, 1:已绑定)', `bound_to` varchar(255) DEFAULT NULL COMMENT '绑定对象(账号ID或角色ID)', `bind_exp_time` timestamp NULL DEFAULT NULL COMMENT '绑定过期时间(为空表示永久绑定)', `expire_at` timestamp NULL DEFAULT NULL COMMENT '物品过期时间(可为空)', `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间', `updated_at` timestamp NULL DEFAULT NULL COMMENT '更新时间', PRIMARY KEY (`id`), KEY `idx_item_id` (`item_id`), KEY `idx_tradable` (`tradable`), KEY `idx_is_bound` (`is_bound`), KEY `idx_bound_to` (`bound_to`), KEY `idx_bind_exp_time` (`bind_exp_time`), KEY `idx_expire_at` (`expire_at`), CONSTRAINT `fk_instance_item` FOREIGN KEY (`item_id`) REFERENCES `kku_item_items` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='单独属性物品表'; -- 用户物品关联表 CREATE TABLE `kku_item_users` ( `id` int NOT NULL AUTO_INCREMENT COMMENT '记录ID,主键', `user_id` int NOT NULL COMMENT '用户ID', `item_id` int NOT NULL COMMENT '统一属性物品ID,外键关联kku_item_items表', `instance_id` int DEFAULT NULL COMMENT '单独属性物品ID,外键关联kku_item_instances表(可为空)', `quantity` int NOT NULL DEFAULT '1' COMMENT '数量(对于单独属性物品,该值始终为1)', `expire_at` timestamp NULL DEFAULT NULL COMMENT '用户物品过期时间(可为空)', `created_at` timestamp NULL DEFAULT NULL COMMENT '获取时间', `updated_at` timestamp NULL DEFAULT NULL COMMENT '更新时间', PRIMARY KEY (`id`), KEY `idx_user_item` (`user_id`, `item_id`), KEY `idx_user_instance` (`user_id`, `instance_id`), KEY `idx_expire_at` (`expire_at`), CONSTRAINT `fk_user_item` FOREIGN KEY (`item_id`) REFERENCES `kku_item_items` (`id`) ON DELETE CASCADE, CONSTRAINT `fk_user_instance` FOREIGN KEY (`instance_id`) REFERENCES `kku_item_instances` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户物品关联表'; -- 物品组表 CREATE TABLE `kku_item_groups` ( `id` int NOT NULL AUTO_INCREMENT COMMENT '物品组ID,主键', `name` varchar(255) NOT NULL COMMENT '物品组名称', `code` varchar(100) NOT NULL COMMENT '物品组编码(唯一)', `description` text COMMENT '物品组描述', `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间', `updated_at` timestamp NULL DEFAULT NULL COMMENT '更新时间', PRIMARY KEY (`id`), UNIQUE KEY `idx_code` (`code`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='物品组表'; -- 物品组内容表 CREATE TABLE `kku_item_group_items` ( `id` int NOT NULL AUTO_INCREMENT COMMENT '记录ID,主键', `group_id` int NOT NULL COMMENT '物品组ID,外键关联kku_item_groups表', `item_id` int NOT NULL COMMENT '物品ID,外键关联kku_item_items表', `weight` decimal(5,3) NOT NULL COMMENT '权重,决定从物品组中选择该物品的概率', `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间', `updated_at` timestamp NULL DEFAULT NULL COMMENT '更新时间', PRIMARY KEY (`id`), KEY `idx_group_id` (`group_id`), KEY `idx_item_id` (`item_id`), CONSTRAINT `fk_group_group` FOREIGN KEY (`group_id`) REFERENCES `kku_item_groups` (`id`) ON DELETE CASCADE, CONSTRAINT `fk_group_item` FOREIGN KEY (`item_id`) REFERENCES `kku_item_items` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='物品组内容表'; -- 宝箱内容配置表 CREATE TABLE `kku_item_chest_contents` ( `id` int NOT NULL AUTO_INCREMENT COMMENT '记录ID,主键', `chest_id` int NOT NULL COMMENT '宝箱物品ID,外键关联kku_item_items表', `item_id` int DEFAULT NULL COMMENT '可能获得的物品ID,外键关联kku_item_items表(与group_id二选一)', `group_id` int DEFAULT NULL COMMENT '物品组ID,外键关联kku_item_groups表(与item_id二选一)', `min_quantity` int DEFAULT '1' COMMENT '最小数量', `max_quantity` int DEFAULT '1' COMMENT '最大数量', `weight` decimal(5,3) NOT NULL COMMENT '权重,决定获取概率', `allow_duplicate` tinyint DEFAULT '0' COMMENT '是否允许在同一宝箱中重复掉落(0:不允许, 1:允许)', `pity_count` int DEFAULT '0' COMMENT '保底次数,当玩家连续未获得该内容达到次数后必定获得(0表示不启用保底)', `pity_weight_factor` float DEFAULT '1.0' COMMENT '保底权重因子,用于递增概率计算(默认1.0)', `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间', `updated_at` timestamp NULL DEFAULT NULL COMMENT '更新时间', PRIMARY KEY (`id`), KEY `idx_chest_id` (`chest_id`), KEY `idx_item_id` (`item_id`), KEY `idx_group_id` (`group_id`), KEY `idx_pity_count` (`pity_count`), CONSTRAINT `fk_chest_content_chest` FOREIGN KEY (`chest_id`) REFERENCES `kku_item_items` (`id`) ON DELETE CASCADE, CONSTRAINT `fk_chest_content_item` FOREIGN KEY (`item_id`) REFERENCES `kku_item_items` (`id`) ON DELETE CASCADE, CONSTRAINT `fk_chest_content_group` FOREIGN KEY (`group_id`) REFERENCES `kku_item_groups` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='宝箱内容配置表'; -- 用户宝箱内容保底计数表 CREATE TABLE `kku_item_pity_times` ( `id` int NOT NULL AUTO_INCREMENT COMMENT '记录ID,主键', `user_id` int NOT NULL COMMENT '用户ID', `chest_id` int NOT NULL COMMENT '宝箱ID,外键关联kku_item_items表', `chest_content_id` int NOT NULL COMMENT '宝箱内容ID,外键关联kku_item_chest_contents表', `current_count` int NOT NULL DEFAULT '0' COMMENT '当前计数,每开启一次宝箱增加1', `last_reset_time` timestamp NULL DEFAULT NULL COMMENT '上次重置时间(可用于周期性重置)', `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间', `updated_at` timestamp NULL DEFAULT NULL COMMENT '更新时间', PRIMARY KEY (`id`), UNIQUE KEY `idx_user_chest_content` (`user_id`, `chest_id`, `chest_content_id`), CONSTRAINT `fk_pity_chest` FOREIGN KEY (`chest_id`) REFERENCES `kku_item_items` (`id`) ON DELETE CASCADE, CONSTRAINT `fk_pity_content` FOREIGN KEY (`chest_content_id`) REFERENCES `kku_item_chest_contents` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户宝箱内容保底计数表'; -- 物品产出限制表 CREATE TABLE `kku_item_output_limits` ( `id` int NOT NULL AUTO_INCREMENT COMMENT '记录ID,主键', `item_id` int NOT NULL COMMENT '物品ID,外键关联kku_item_items表', `limit_type` tinyint NOT NULL COMMENT '限制类型(1:全局总量, 2:单个用户, 3:单日全局, 4:单日用户)', `max_quantity` int NOT NULL COMMENT '最大产出数量', `current_quantity` int DEFAULT '0' COMMENT '当前已产出数量(全局限制时使用)', `reset_type` tinyint DEFAULT '0' COMMENT '重置类型(0:不重置, 1:每日, 2:每周, 3:每月)', `last_reset_time` timestamp NULL DEFAULT NULL COMMENT '上次重置时间', `related_items` json DEFAULT NULL COMMENT '关联物品ID列表,这些物品共享同一个限制额度', `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间', `updated_at` timestamp NULL DEFAULT NULL COMMENT '更新时间', PRIMARY KEY (`id`), KEY `idx_item_id` (`item_id`), KEY `idx_limit_reset` (`limit_type`, `reset_type`), CONSTRAINT `fk_limit_item` FOREIGN KEY (`item_id`) REFERENCES `kku_item_items` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='物品产出限制表'; -- 用户物品产出限制计数表 CREATE TABLE `kku_item_user_output_counters` ( `id` int NOT NULL AUTO_INCREMENT COMMENT '记录ID,主键', `user_id` int NOT NULL COMMENT '用户ID', `limit_id` int NOT NULL COMMENT '产出限制ID,外键关联kku_item_output_limits表', `current_count` int NOT NULL DEFAULT '0' COMMENT '当前产出计数', `record_date` date DEFAULT NULL COMMENT '记录日期(用于日期统计和重置)', `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间', `updated_at` timestamp NULL DEFAULT NULL COMMENT '更新时间', PRIMARY KEY (`id`), KEY `idx_user_limit` (`user_id`, `limit_id`), KEY `idx_record_date` (`record_date`), CONSTRAINT `fk_user_limit` FOREIGN KEY (`limit_id`) REFERENCES `kku_item_output_limits` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户物品产出限制计数表'; -- 物品获取/消耗记录表 CREATE TABLE `kku_item_transaction_logs` ( `id` int NOT NULL AUTO_INCREMENT COMMENT '记录ID,主键', `user_id` int NOT NULL COMMENT '用户ID', `item_id` int NOT NULL COMMENT '物品ID,外键关联kku_item_items表', `instance_id` int DEFAULT NULL COMMENT '单独属性物品ID,外键关联kku_item_instances表(可为空)', `quantity` int NOT NULL COMMENT '数量(正数表示获取,负数表示消耗)', `transaction_type` tinyint NOT NULL COMMENT '交易类型(1:获取, 2:消耗, 3:交易获得, 4:交易失去, 5:过期失效)', `source_type` varchar(100) DEFAULT NULL COMMENT '来源类型(如任务奖励、商店购买、宝箱开启等)', `source_id` int DEFAULT NULL COMMENT '来源ID(如任务ID、订单ID、宝箱ID等)', `attributes` json DEFAULT NULL COMMENT '额外属性,存储交易相关的详细信息', `expire_at` timestamp NULL DEFAULT NULL COMMENT '物品过期时间(如果有)', `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间', `ip_address` varchar(100) DEFAULT NULL COMMENT '操作的IP地址(用于安全审计)', `device_info` varchar(255) DEFAULT NULL COMMENT '设备信息(用于安全审计)', PRIMARY KEY (`id`), KEY `idx_user_created` (`user_id`, `created_at`), KEY `idx_item_id` (`item_id`), KEY `idx_transaction_source` (`transaction_type`, `source_type`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='物品获取/消耗记录表'; -- 宝箱开启记录表 CREATE TABLE `kku_item_chest_open_logs` ( `id` int NOT NULL AUTO_INCREMENT COMMENT '记录ID,主键', `user_id` int NOT NULL COMMENT '用户ID', `chest_id` int NOT NULL COMMENT '宝箱ID,外键关联kku_item_items表', `open_time` timestamp NULL DEFAULT NULL COMMENT '开启时间', `open_quantity` int NOT NULL COMMENT '开启数量', `result_items` json NOT NULL COMMENT '获得的物品列表,包含物品ID、数量等信息', `pity_triggered` tinyint DEFAULT '0' COMMENT '是否触发保底机制(0:否, 1:是)', `pity_content_id` int DEFAULT NULL COMMENT '触发保底的内容ID,外键关联kku_item_chest_contents表(可为空)', `ip_address` varchar(100) DEFAULT NULL COMMENT '操作的IP地址(用于安全审计)', `device_info` varchar(255) DEFAULT NULL COMMENT '设备信息(用于安全审计)', `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间', PRIMARY KEY (`id`), KEY `idx_user_open` (`user_id`, `open_time`), KEY `idx_chest_id` (`chest_id`), KEY `idx_pity_triggered` (`pity_triggered`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='宝箱开启记录表'; -- 物品合成配方表 CREATE TABLE `kku_item_recipes` ( `id` int NOT NULL AUTO_INCREMENT COMMENT '配方ID,主键', `name` varchar(255) NOT NULL COMMENT '配方名称', `result_item_id` int NOT NULL COMMENT '产出物品ID,外键关联kku_item_items表', `result_min_quantity` int DEFAULT '1' COMMENT '最小产出数量', `result_max_quantity` int DEFAULT '1' COMMENT '最大产出数量', `success_rate` decimal(5,2) NOT NULL COMMENT '成功率(百分比,最大100)', `coin_cost` json DEFAULT NULL COMMENT '货币成本,以JSON格式存储多种货币类型和数量', `level_required` int DEFAULT '1' COMMENT '所需等级', `is_default_unlocked` tinyint DEFAULT '0' COMMENT '是否默认解锁(0:否, 1:是)', `unlock_condition` json DEFAULT NULL COMMENT '解锁条件,以JSON格式存储', `cooldown_seconds` int DEFAULT '0' COMMENT '冷却时间(秒)', `category_id` int DEFAULT NULL COMMENT '配方分类ID', `sort_order` int DEFAULT '0' COMMENT '排序权重', `is_active` tinyint DEFAULT '1' COMMENT '是否激活(0:否, 1:是)', `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间', `updated_at` timestamp NULL DEFAULT NULL COMMENT '更新时间', PRIMARY KEY (`id`), KEY `idx_result_item` (`result_item_id`), KEY `idx_category` (`category_id`), CONSTRAINT `fk_recipe_item` FOREIGN KEY (`result_item_id`) REFERENCES `kku_item_items` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='物品合成配方表'; -- 配方材料需求表 CREATE TABLE `kku_item_recipe_materials` ( `id` int NOT NULL AUTO_INCREMENT COMMENT '记录ID,主键', `recipe_id` int NOT NULL COMMENT '配方ID,外键关联kku_item_recipes表', `item_id` int NOT NULL COMMENT '材料物品ID,外键关联kku_item_items表', `quantity` int NOT NULL COMMENT '所需数量', `is_consumed` tinyint DEFAULT '1' COMMENT '是否消耗(0:不消耗, 1:消耗)', `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间', `updated_at` timestamp NULL DEFAULT NULL COMMENT '更新时间', PRIMARY KEY (`id`), KEY `idx_recipe_id` (`recipe_id`), KEY `idx_item_id` (`item_id`), CONSTRAINT `fk_material_recipe` FOREIGN KEY (`recipe_id`) REFERENCES `kku_item_recipes` (`id`) ON DELETE CASCADE, CONSTRAINT `fk_material_item` FOREIGN KEY (`item_id`) REFERENCES `kku_item_items` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='配方材料需求表'; -- 用户配方解锁状态表 CREATE TABLE `kku_item_user_recipes` ( `id` int NOT NULL AUTO_INCREMENT COMMENT '记录ID,主键', `user_id` int NOT NULL COMMENT '用户ID', `recipe_id` int NOT NULL COMMENT '配方ID,外键关联kku_item_recipes表', `is_unlocked` tinyint DEFAULT '0' COMMENT '是否已解锁(0:否, 1:是)', `unlock_time` timestamp NULL DEFAULT NULL COMMENT '解锁时间', `last_craft_time` timestamp NULL DEFAULT NULL COMMENT '最后合成时间', `craft_count` int DEFAULT '0' COMMENT '合成次数', `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间', `updated_at` timestamp NULL DEFAULT NULL COMMENT '更新时间', PRIMARY KEY (`id`), UNIQUE KEY `idx_user_recipe` (`user_id`, `recipe_id`), CONSTRAINT `fk_user_recipe` FOREIGN KEY (`recipe_id`) REFERENCES `kku_item_recipes` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户配方解锁状态表'; -- 物品合成记录表 CREATE TABLE `kku_item_craft_logs` ( `id` int NOT NULL AUTO_INCREMENT COMMENT '记录ID,主键', `user_id` int NOT NULL COMMENT '用户ID', `recipe_id` int NOT NULL COMMENT '配方ID,外键关联kku_item_recipes表', `materials` json NOT NULL COMMENT '消耗的材料,以JSON格式存储', `result_item_id` int NOT NULL COMMENT '获得的物品ID,外键关联kku_item_items表', `result_instance_id` int DEFAULT NULL COMMENT '获得的单独属性物品ID,外键关联kku_item_instances表(可为空)', `result_quantity` int NOT NULL COMMENT '获得的物品数量', `is_success` tinyint NOT NULL COMMENT '是否成功(0:失败, 1:成功)', `craft_time` timestamp NULL DEFAULT NULL COMMENT '合成时间', `ip_address` varchar(100) DEFAULT NULL COMMENT '操作的IP地址', `device_info` varchar(255) DEFAULT NULL COMMENT '设备信息', `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间', PRIMARY KEY (`id`), KEY `idx_user_recipe` (`user_id`, `recipe_id`), KEY `idx_craft_time` (`craft_time`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='物品合成记录表'; -- 物品分解规则表 CREATE TABLE `kku_item_dismantle_rules` ( `id` int NOT NULL AUTO_INCREMENT COMMENT '规则ID,主键', `item_id` int DEFAULT NULL COMMENT '物品ID,外键关联kku_item_items表', `category_id` int DEFAULT NULL COMMENT '分类ID,外键关联kku_item_categories表', `min_rarity` tinyint DEFAULT '1' COMMENT '最小适用稀有度', `max_rarity` tinyint DEFAULT '1' COMMENT '最大适用稀有度', `priority` int DEFAULT '0' COMMENT '规则优先级', `is_active` tinyint DEFAULT '1' COMMENT '是否激活(0:否, 1:是)', `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间', `updated_at` timestamp NULL DEFAULT NULL COMMENT '更新时间', PRIMARY KEY (`id`), KEY `idx_item_id` (`item_id`), KEY `idx_category_id` (`category_id`), KEY `idx_priority` (`priority`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='物品分解规则表'; -- 物品分解结果配置表 CREATE TABLE `kku_item_dismantle_results` ( `id` int NOT NULL AUTO_INCREMENT COMMENT '记录ID,主键', `rule_id` int NOT NULL COMMENT '分解规则ID,外键关联kku_item_dismantle_rules表', `result_item_id` int NOT NULL COMMENT '结果物品ID,外键关联kku_item_items表', `min_quantity` int DEFAULT '1' COMMENT '最小数量', `max_quantity` int DEFAULT '1' COMMENT '最大数量', `base_chance` decimal(5,2) NOT NULL COMMENT '基础获取概率(百分比,最大100)', `rarity_factor` decimal(5,2) DEFAULT '1.0' COMMENT '稀有度影响因子', `quality_factor` decimal(5,2) DEFAULT '1.0' COMMENT '品质影响因子', `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间', `updated_at` timestamp NULL DEFAULT NULL COMMENT '更新时间', PRIMARY KEY (`id`), KEY `idx_rule_id` (`rule_id`), KEY `idx_result_item` (`result_item_id`), CONSTRAINT `fk_result_rule` FOREIGN KEY (`rule_id`) REFERENCES `kku_item_dismantle_rules` (`id`) ON DELETE CASCADE, CONSTRAINT `fk_result_item` FOREIGN KEY (`result_item_id`) REFERENCES `kku_item_items` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='物品分解结果配置表'; -- 物品分解记录表 CREATE TABLE `kku_item_dismantle_logs` ( `id` int NOT NULL AUTO_INCREMENT COMMENT '记录ID,主键', `user_id` int NOT NULL COMMENT '用户ID', `item_id` int NOT NULL COMMENT '被分解的物品ID,外键关联kku_item_items表', `instance_id` int DEFAULT NULL COMMENT '被分解的单独属性物品ID,外键关联kku_item_instances表(可为空)', `quantity` int NOT NULL COMMENT '分解数量', `rule_id` int NOT NULL COMMENT '使用的分解规则ID,外键关联kku_item_dismantle_rules表', `results` json NOT NULL COMMENT '分解结果,包含获得的物品ID、数量等信息', `dismantle_time` timestamp NULL DEFAULT NULL COMMENT '分解时间', `ip_address` varchar(100) DEFAULT NULL COMMENT '操作的IP地址', `device_info` varchar(255) DEFAULT NULL COMMENT '设备信息', `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间', PRIMARY KEY (`id`), KEY `idx_user_item` (`user_id`, `item_id`), KEY `idx_dismantle_time` (`dismantle_time`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='物品分解记录表';