Your Name 5 tháng trước cách đây
mục cha
commit
5edfa6493b

+ 28 - 28
app/Module/GameItems_obsolete/OBSOLETE_MIGRATION.md

@@ -2,37 +2,37 @@
 
 ## 1. 模块重构概述
 原`GameItems`模块已拆分为四个独立模块:
-- **Item**: 基础物品管理
-- **ItemChest**: 宝箱系统
-- **ItemCraft**: 物品合成
-- **ItemDismantle**: 物品分解
+- **Item**: 基础物品管理(表前缀:`item_`)
+- **ItemChest**: 宝箱系统(表前缀:`item_chest_`)
+- **ItemCraft**: 物品合成(表前缀:`item_craft_`)
+- **ItemDismantle**: 物品分解(表前缀:`item_dismantle_`)
 
 ## 2. 数据表迁移总表
 
-| 旧表名                 | 新模块      | 新表名             | 处理状态 | 说明                     |
-|------------------------|-------------|--------------------|----------|--------------------------|
-| **基础物品表**         |             |                    |          |                          |
-| item_items             | Item        | items              | ✅ 已迁移 | 基础物品定义             |
-| item_categories        | -           | -                  | ⚠️ 废弃  | 分类功能由标签系统替代   |
-| item_instances         | Item        | user_items         | ✅ 已迁移 | 单独属性物品表           |
-| item_users             | Item        | user_items         | ✅ 已迁移 | 用户物品关联表           |
-| **物品组表**           |             |                    |          |                          |
-| item_groups            | Item        | groups             | ✅ 已迁移 | 物品组定义               |
-| item_group_items       | Item        | group_items        | ✅ 已迁移 | 物品组内容               |
-| **宝箱系统表**         |             |                    |          |                          |
-| item_chest_configs     | ItemChest   | chest_configs      | ✅ 已迁移 | 宝箱配置                 |
-| item_pity_times        | ItemChest   | pity_times         | ✅ 已迁移 | 保底计数                 |
-| item_chest_open_logs   | ItemChest   | open_logs          | ✅ 已迁移 | 开启日志                 |
-| **物品合成表**         |             |                    |          |                          |
-| item_recipes           | ItemCraft   | recipes            | ✅ 已迁移 | 配方定义                 |
-| item极recipe_materials| ItemCraft   | recipe_materials   | ✅ 已迁移 | 配方材料                 |
-| item_user_recipes      | ItemCraft   | user_recipes       | ✅ 已迁移 | 用户配方                 |
-| item_craft_logs        | ItemCraft   | craft_logs         | ✅ 已迁移 | 合成日志                 |
-| **物品分解表**         |             |                    |          |                          |
-| item_dismantle_rules   | ItemDismantle | dismantle_rules    | ✅ 已迁移 | 分解规则                 |
-| item_dismantle_logs    | ItemDismantle | dismantle_logs     | ✅ 已迁移 | 分解日志                 |
-| **物品变更日志**       |             |                    |          |                          |
-| item_transaction_logs  | Item        | transaction_logs   | ✅ 已迁移 | 物品获取/消耗记录        |
+| 旧表名                 | 新模块      | 新表名(带前缀)      | 处理状态 | 说明                     |
+|------------------------|-------------|----------------------|----------|--------------------------|
+| **基础物品表**         |             |                      |          |                          |
+| item_items             | Item        | item_items           | ✅ 已迁移 | 基础物品定义             |
+| item_categories        | -           | -                    | ⚠️ 废弃  | 分类功能由标签系统替代   |
+| item_instances         | Item        | item_instances       | ✅ 已迁移 | 单独属性物品表           |
+| item_users             | Item        | item_user            | ✅ 已迁移 | 用户物品关联表           |
+| **物品组表**           |             |                      |          |                          |
+| item_groups            | Item        | item_groups          | ✅ 已迁移 | 物品组定义               |
+| item_group_items       | Item        | item_group_items     | ✅ 已迁移 | 物品组内容               |
+| **宝箱系统表**         |             |                      |          |                          |
+| item_chest_configs     | ItemChest   | item_chest_configs   | ✅ 已迁移 | 宝箱配置                 |
+| item_pity_times        | ItemChest   | item_chest_pity_times| ✅ 已迁移 | 保底计数                 |
+| item_chest_open_logs   | ItemChest   | item_chest_open_logs | ✅ 已迁移 | 开启日志                 |
+| **物品合成表**         |             |                      |          |                          |
+| item_recipes           | ItemCraft   | item_craft_recipes   | ✅ 已迁移 | 配方定义                 |
+| item_recipe_materials  | ItemCraft   | item_craft_materials | ✅ 已迁移 | 配方材料                 |
+| item_user_recipes      | ItemCraft   | item_craft_user_recipes| ✅ 已迁移 | 用户配方               |
+| item_craft_logs        | ItemCraft   | item_craft_logs      | ✅ 已迁移 | 合成日志                 |
+| **物品分解表**         |             |                      |          |                          |
+| item_dismantle_rules   | ItemDismantle | item_dismantle_rules | ✅ 已迁移 | 分解规则                 |
+| item_dismantle_logs    | ItemDismantle | item_dismantle_logs  | ✅ 已迁移 | 分解日志                 |
+| **物品变更日志**       |             |                      |          |                          |
+| item_transaction_logs  | Item        | item_transaction_logs| ✅ 已迁移 | 物品获取/消耗记录        |
 
 ## 3. 特殊处理表(废弃)
 

+ 78 - 7
app/Module/Item/Docs/Database.md

@@ -25,25 +25,54 @@
 | created_at | TIMESTAMP | 创建时间 |  |
 | updated_at | TIMESTAMP | 更新时间 |  |
 
-### 1.3 user_items 用户物品表
+### 1.3 item_instances 物品实例表
+| 字段 | 类型 | 说明 | 索引 |
+|------|------|------|------|
+| id | BIGINT | 实例ID,主键 | PK |
+| item_id | BIGINT | 物品ID | IDX_item |
+| attributes | JSON | 实例属性数据 |  |
+| created_at | TIMESTAMP | 创建时间 |  |
+| updated_at | TIMESTAMP | 更新时间 |  |
+
+### 1.4 user_items 用户物品表
 | 字段 | 类型 | 说明 | 索引 |
 |------|------|------|------|
 | id | BIGINT | 记录ID,主键 | PK |
 | user_id | BIGINT | 用户ID | IDX_user |
 | item_id | BIGINT | 物品ID | IDX_item |
+| instance_id | BIGINT | 物品实例ID | IDX_instance |
 | warehouse_id | BIGINT | 仓库ID | IDX_warehouse |
 | quantity | INT | 数量(仅堆叠物品) |  |
-| instance_data | JSON | 单独属性数据 |  |
 | expire_at | TIMESTAMP | 用户物品过期时间 | IDX_expire |
 | created_at | TIMESTAMP | 创建时间 |  |
 | updated_at | TIMESTAMP | 更新时间 |  |
 
-### 1.4 transaction_logs 物品变更日志表
+### 1.5 item_groups 物品组表
+| 字段 | 类型 | 说明 | 索引 |
+|------|------|------|------|
+| id | BIGINT | 物品组ID,主键 | PK |
+| name | VARCHAR(100) | 物品组名称 |  |
+| type | ENUM('daily','weekly','event') | 物品组类型 |  |
+| created_at | TIMESTAMP | 创建时间 |  |
+| updated_at | TIMESTAMP | 更新时间 |  |
+
+### 1.6 item_group_items 物品组内容表
+| 字段 | 类型 | 说明 | 索引 |
+|------|------|------|------|
+| id | BIGINT | 记录ID,主键 | PK |
+| group_id | BIGINT | 物品组ID | IDX_group |
+| item_id | BIGINT | 物品ID | IDX_item |
+| weight | SMALLINT | 权重 |  |
+| created_at | TIMESTAMP | 创建时间 |  |
+| updated_at | TIMESTAMP | 更新时间 |  |
+
+### 1.7 transaction_logs 物品变更日志表
 | 字段 | 类型 | 说明 | 索引 |
 |------|------|------|------|
 | id | BIGINT | 日志ID,主键 | PK |
 | user_id | BIGINT | 用户ID | IDX_user |
 | item_id | BIGINT | 物品ID | IDX_item |
+| instance_id | BIGINT | 物品实例ID | IDX_instance |
 | warehouse_id | BIGINT | 仓库ID | IDX_warehouse |
 | quantity | INT | 变动数量 |  |
 | operation | ENUM('add','remove','transfer') | 操作类型 |  |
@@ -57,7 +86,11 @@
 erDiagram
     users ||--o{ warehouses : "1:N"
     warehouses ||--o{ user_items : "1:N"
+    items ||--o{ item_instances : "1:N"
     items ||--o{ user_items : "1:N"
+    items ||--o{ item_group_items : "1:N"
+    item_groups ||--o{ item_group_items : "1:N"
+    item_instances ||--o{ user_items : "1:1"
     user_items ||--o{ transaction_logs : "1:N"
     
     users {
@@ -70,16 +103,30 @@ erDiagram
     items {
         BIGINT id PK
     }
+    item_instances {
+        BIGINT id PK
+        BIGINT item_id FK
+    }
+    item_groups {
+        BIGINT id PK
+    }
+    item_group_items {
+        BIGINT id PK
+        BIGINT group_id FK
+        BIGINT item_id FK
+    }
     user_items {
         BIGINT id PK
         BIGINT user_id FK
         BIGINT item_id FK
+        BIGINT instance_id FK
         BIGINT warehouse_id FK
     }
     transaction_logs {
         BIGINT id PK
         BIGINT user_id FK
         BIGINT item_id FK
+        BIGINT instance_id FK
         BIGINT warehouse_id FK
     }
 ```
@@ -104,7 +151,13 @@ CREATE INDEX idx_item_expire ON items(global_expire_at);
 CREATE INDEX idx_item_type ON items(type);
 ```
 
-### 3.3 用户物品表索引
+### 3.3 物品实例表索引
+```sql
+-- 物品实例查询
+CREATE INDEX idx_instance_item ON item_instances(item_id);
+```
+
+### 3.4 用户物品表索引
 ```sql
 -- 用户物品查询
 CREATE INDEX idx_user_item_user ON user_items(user_id);
@@ -112,11 +165,24 @@ CREATE INDEX idx_user_item_user ON user_items(user_id);
 -- 仓库物品查询
 CREATE INDEX idx_user_item_warehouse ON user_items(warehouse_id);
 
+-- 物品实例查询
+CREATE INDEX idx_user_item_instance ON user_items(instance_id);
+
 -- 过期物品管理
 CREATE INDEX idx_user_item_expire ON user_items(expire_at);
 ```
 
-### 3.4 事务日志表索引
+### 3.5 物品组表索引
+```sql
+-- 物品组查询
+CREATE INDEX idx_group_type ON item_groups(type);
+
+-- 物品组内容查询
+CREATE INDEX idx_group_item_group ON item_group_items(group_id);
+CREATE INDEX idx_group_item_item ON item_group_items(item_id);
+```
+
+### 3.6 事务日志表索引
 ```sql
 -- 用户操作历史
 CREATE INDEX idx_log_user_operation ON transaction_logs(user_id, operation);
@@ -124,6 +190,9 @@ CREATE INDEX idx_log_user_operation ON transaction_logs(user_id, operation);
 -- 物品操作记录
 CREATE INDEX idx_log_item ON transaction_logs(item_id);
 
+-- 物品实例操作记录
+CREATE INDEX idx_log_instance ON transaction_logs(instance_id);
+
 -- 时间范围查询
 CREATE INDEX idx_log_created ON transaction_logs(created_at);
 ```
@@ -166,13 +235,15 @@ GROUP BY w.id;
 
 ### 4.4 查询物品变更历史
 ```sql
-SELECT 
+SELECT
     tl.operation,
     tl.quantity,
     tl.created_at,
-    i.name AS item_name
+    i.name AS item_name,
+    ii.attributes->>'$.quality' AS quality
 FROM transaction_logs tl
 JOIN items i ON tl.item_id = i.id
+LEFT JOIN item_instances ii ON tl.instance_id = ii.id
 WHERE tl.user_id = 123
   AND tl.created_at BETWEEN '2023-01-01' AND '2023-12-31'
 ORDER BY tl.created_at DESC;