Your Name 8 meses atrás
pai
commit
f1dd411ffc
1 arquivos alterados com 158 adições e 35 exclusões
  1. 158 35
      app/Module/Task/Docs/数据库设计.md

+ 158 - 35
app/Module/Task/Docs/数据库设计.md

@@ -6,21 +6,22 @@
 
 ### 1.1 任务定义相关表
 
-1. **task_categories** - 任务分类表
-2. **task_tasks** - 任务定义表
-3. **task_conditions** - 任务条件表
-4. **task_achievement_conditions** - 任务达成条件表
+1. **task_categories** - 任务分类表:存储任务的分类信息,用于对任务进行分组和管理。
+2. **task_tasks** - 任务定义表:存储任务的基本定义信息,包括任务名称、描述、类型等。
+3. **task_rewards** - 任务奖励定义表:存储任务的奖励内容,与任务定义表一对多关联。
+4. **task_conditions** - 任务条件表:定义系统中所有可用的条件类型,每种条件类型对应一个处理器类。
+5. **task_achievement_conditions** - 任务达成条件表:关联任务和具体的条件,定义了完成任务需要满足的条件。
 
 ### 1.2 任务完成相关表
 
-5. **task_user_tasks** - 用户任务关联表
-6. **task_user_progress** - 用户任务进度表
+6. **task_user_tasks** - 用户任务关联表:存储用户与任务的关联信息,包括任务状态、进度、完成时间等。
+7. **task_user_progress** - 用户任务进度表:存储用户任务的详细进度信息,关联到具体的任务达成条件。
 
 ### 1.3 日志记录相关表
 
-7. **task_completion_logs** - 任务完成日志表
-8. **task_reward_logs** - 任务奖励发放日志表
-9. **task_reset_logs** - 任务重置日志表
+8. **task_completion_logs** - 任务完成日志表:记录用户完成任务的详细信息,用于审计和数据分析。
+9. **task_reward_logs** - 任务奖励发放日志表:记录任务奖励的发放情况,包括奖励内容、发放时间等。
+10. **task_reset_logs** - 任务重置日志表:记录任务重置的情况,包括重置类型、重置时间、影响的任务数等。
 
 ## 2. 表结构详细设计
 
@@ -46,7 +47,7 @@
 
 ### 2.1.2 任务定义表 (task_tasks)
 
-存储任务的基本定义信息,包括任务名称、描述、奖励等。目标相关字段已拆分到任务达成条件表。
+存储任务的基本定义信息,包括任务名称、描述等。目标相关字段已拆分到任务达成条件表,奖励相关字段已拆分到任务奖励定义表。
 
 | 字段名 | 类型 | 允许空 | 默认值 | 说明 |
 |-------|------|-------|-------|------|
@@ -55,7 +56,6 @@
 | name | varchar(100) | 否 | - | 任务名称 |
 | description | varchar(500) | 是 | NULL | 任务描述 |
 | type | varchar(20) | 否 | - | 任务类型(daily, weekly, achievement, event, tutorial, team) |
-| rewards | json | 否 | - | 奖励内容(JSON格式) |
 | prerequisite_tasks | json | 是 | NULL | 前置任务ID(JSON格式) |
 | level_required | int | 否 | 0 | 所需等级 |
 | time_limit | int | 是 | NULL | 时间限制(秒,NULL表示无限制) |
@@ -72,7 +72,27 @@
 - KEY `idx_type` (`type`)
 - KEY `idx_active_time` (`is_active`, `start_time`, `end_time`)
 
-### 2.1.3 任务条件表 (task_conditions)
+### 2.1.3 任务奖励定义表 (task_rewards)
+
+存储任务的奖励内容,一个任务可以有多个不同类型的奖励。
+
+| 字段名 | 类型 | 允许空 | 默认值 | 说明 |
+|-------|------|-------|-------|------|
+| id | int | 否 | 自增 | 主键 |
+| task_id | int | 否 | - | 任务ID,外键关联task_tasks表 |
+| reward_type | varchar(50) | 否 | - | 奖励类型(item, currency, experience, feature_unlock等) |
+| reward_id | int | 是 | NULL | 奖励ID(如物品ID、功能ID等) |
+| quantity | int | 否 | 1 | 奖励数量 |
+| extra_data | json | 是 | NULL | 额外数据(JSON格式) |
+| created_at | timestamp | 是 | NULL | 创建时间 |
+| updated_at | timestamp | 是 | NULL | 更新时间 |
+
+**索引:**
+- PRIMARY KEY (`id`)
+- KEY `idx_task_id` (`task_id`)
+- KEY `idx_reward_type` (`reward_type`)
+
+### 2.1.4 任务条件表 (task_conditions)
 
 定义系统中所有可用的条件类型,每种条件类型对应一个处理器类,负责验证和更新该类型条件的进度。
 
@@ -92,7 +112,7 @@
 - PRIMARY KEY (`id`)
 - UNIQUE KEY `idx_code` (`code`)
 
-### 2.1.4 任务达成条件表 (task_achievement_conditions)
+### 2.1.5 任务达成条件表 (task_achievement_conditions)
 
 关联任务和具体的条件,定义了完成任务需要满足的条件。一个任务可以有多个条件,通过这个表可以实现复杂的任务逻辑。条件分为两种类型:前置条件和进度条件。
 
@@ -230,10 +250,101 @@
 
 ## 3. 数据关系
 
-### 3.1 主要关系图
+### 3.1 数据关系图
+
+```mermaid
+erDiagram
+    task_categories ||--o{ task_tasks : "包含"
+    task_tasks ||--o{ task_rewards : "定义"
+    task_tasks ||--o{ task_achievement_conditions : "设置"
+    task_conditions ||--o{ task_achievement_conditions : "使用"
+    task_tasks ||--o{ task_user_tasks : "接取"
+    task_achievement_conditions ||--o{ task_user_progress : "进度"
+    task_user_tasks ||--o{ task_completion_logs : "记录完成"
+    task_user_tasks ||--o{ task_reward_logs : "记录奖励"
+    task_reset_logs ||--o{ task_tasks : "重置"
+
+    task_categories {
+        int id PK "主键"
+        varchar name "分类名称"
+        varchar code "分类编码"
+    }
+
+    task_tasks {
+        int id PK "主键"
+        int category_id FK "分类ID"
+        varchar name "任务名称"
+        varchar type "任务类型"
+        json prerequisite_tasks "前置任务"
+    }
+
+    task_rewards {
+        int id PK "主键"
+        int task_id FK "任务ID"
+        varchar reward_type "奖励类型"
+        int reward_id "奖励ID"
+        int quantity "数量"
+    }
+
+    task_conditions {
+        int id PK "主键"
+        varchar code "条件代码"
+        varchar name "条件名称"
+        varchar handler_class "处理器类"
+    }
+
+    task_achievement_conditions {
+        int id PK "主键"
+        int task_id FK "任务ID"
+        int condition_id FK "条件ID"
+        varchar condition_type "条件类型"
+        int target_value "目标值"
+    }
+
+    task_user_tasks {
+        int id PK "主键"
+        int user_id "用户ID"
+        int task_id FK "任务ID"
+        tinyint status "状态"
+        int progress "进度"
+    }
+
+    task_user_progress {
+        int id PK "主键"
+        int user_id "用户ID"
+        int task_id FK "任务ID"
+        int achievement_condition_id FK "条件ID"
+        int current_value "当前值"
+    }
+
+    task_completion_logs {
+        int id PK "主键"
+        int user_id "用户ID"
+        int task_id FK "任务ID"
+        timestamp completed_at "完成时间"
+    }
+
+    task_reward_logs {
+        int id PK "主键"
+        int user_id "用户ID"
+        int task_id FK "任务ID"
+        int user_task_id FK "用户任务ID"
+        json rewards "奖励内容"
+    }
+
+    task_reset_logs {
+        int id PK "主键"
+        varchar reset_type "重置类型"
+        timestamp reset_time "重置时间"
+        int affected_count "影响数量"
+    }
+```
+
+### 3.2 文本关系图
 
 ```
 task_categories 1 --< task_tasks
+task_tasks 1 --< task_rewards
 task_conditions 1 --< task_achievement_conditions
 task_tasks 1 --< task_achievement_conditions
 task_tasks 1 --< task_user_tasks
@@ -242,15 +353,17 @@ task_user_tasks 1 --< task_completion_logs
 task_user_tasks 1 --< task_reward_logs
 ```
 
-### 3.2 关系说明
+### 3.3 关系说明
 
 1. 一个任务分类可以包含多个任务
-2. 一个条件类型可以用于多个任务达成条件
-3. 一个任务可以有多个达成条件
-4. 一个任务可以被多个用户接取
-5. 一个任务达成条件可以有多个用户进度记录
-6. 一个用户任务完成后会生成一条完成日志
-7. 一个用户任务领取奖励后会生成一条奖励发放日志
+2. 一个任务可以有多个奖励定义
+3. 一个条件类型可以用于多个任务达成条件
+4. 一个任务可以有多个达成条件
+5. 一个任务可以被多个用户接取
+6. 一个任务达成条件可以有多个用户进度记录
+7. 一个用户任务完成后会生成一条完成日志
+8. 一个用户任务领取奖励后会生成一条奖励发放日志
+9. 任务重置日志记录系统定期重置任务的情况
 
 ## 4. JSON字段结构
 
@@ -276,18 +389,18 @@ task_user_tasks 1 --< task_reward_logs
 }
 ```
 
-### 4.2 奖励内容 (rewards)
+### 4.2 奖励内容 (extra_data)
+
+任务奖励定义表中的extra_data字段可以存储额外的奖励信息,例如:
 
 ```json
 {
-  "items": [
-    {"item_id": 1001, "quantity": 10},
-    {"item_id": 1002, "quantity": 5}
-  ],
-  "experience": 100,
-  "special_rewards": {
-    "type": "unlock_feature",
-    "feature_id": 3
+  "display_name": "高级化肥礼包",
+  "icon_url": "items/fertilizer_premium.png",
+  "description": "包含多种高级化肥的礼包",
+  "unlock_requirements": {
+    "level": 10,
+    "vip": 2
   }
 }
 ```
@@ -501,7 +614,9 @@ abstract class BaseConditionHandler implements ConditionHandlerInterface
   - 参数:{}
   - 运算符:=
 奖励:
-  - 金币 x 100
+  - 类型:currency
+  - 奖励ID:1(金币)
+  - 数量:100
 ```
 
 ### 9.2 多条件任务:农场管理
@@ -527,8 +642,12 @@ abstract class BaseConditionHandler implements ConditionHandlerInterface
     运算符:>=
     是否必须:是
 奖励:
-  - 高级化肥 x 3
-  - 金币 x 500
+  - 类型:item
+  - 奖励ID:2001(高级化肥)
+  - 数量:3
+  - 类型:currency
+  - 奖励ID:1(金币)
+  - 数量:500
 ```
 
 ### 9.3 带前置条件的任务示例
@@ -562,8 +681,12 @@ abstract class BaseConditionHandler implements ConditionHandlerInterface
     条件类型:progress
     是否必须:是
 奖励:
-  - 稀有种子 x 1
-  - 金币 x 1000
+  - 类型:item
+  - 奖励ID:3001(稀有种子)
+  - 数量:1
+  - 类型:currency
+  - 奖励ID:1(金币)
+  - 数量:1000
 ```
 
 ## 10. 日志记录相关设计