任务时间: 2025年6月5日 10:26
任务状态: ✅ 已完成
任务类型: 系统修复
修复 GenerateChestJsonCommand 生成宝箱JSON数据命令的报错问题。原因是宝箱系统已经从旧的 chest_contents 和 chest_costs 系统迁移到了新的组系统(使用 ItemChestConfig),但命令仍在使用旧的关系方法。
Call to undefined relationship [chest_contents] on model [App\Module\GameItems\Models\Item].
chest_contents 和 chest_costs 关系方法修改前:
$chests = Item::query()
->where('type', ITEM_TYPE::CHEST)
->with([
'chest_contents' => function ($query) {
// 旧的宝箱内容查询
},
'chest_costs' => function ($query) {
// 旧的宝箱消耗查询
}
])
修改后:
$chests = Item::query()
->where('type', ITEM_TYPE::CHEST)
->with([
'chestConfig' => function ($query) {
$query->where('is_active', true)
->with([
'consumeGroup.consumeItems',
'rewardGroup.rewardItems',
'conditionGroup'
]);
}
])
宝箱内容处理:
chest_contents 改为从 rewardGroup.rewardItems 获取rewardItem->getTargetName() 获取物品名称from_reward_group宝箱消耗处理:
chest_costs 改为从 consumeGroup.consumeItems 获取consumeItem->getTargetName() 获取目标名称from_consume_groupCHEST_COST_TYPE 枚举导入php artisan gameitems:generate-chest-json
测试结果:
生成的JSON数据包含正确的字段:
{
"generated_ts": 1749090315,
"chests": {
"0": {
"id": 27,
"name": "铜宝箱",
"contents": [
{
"id": 51,
"weight": 50,
"min_quantity": 200,
"max_quantity": 2000,
"item_id": 2,
"item_name": "萝卜",
"type": "item",
"from_reward_group": true,
"reward_group_id": 30,
"reward_group_name": "铜宝箱_奖励组"
}
],
"costs": [
{
"consume_type": 1,
"target_id": 2,
"quantity": 500,
"from_consume_group": true,
"consume_group_id": 31,
"consume_group_name": "铜宝箱-开启消耗",
"target_name": "萝卜"
}
]
}
}
}
| 方面 | 旧系统 | 新系统 |
|---|---|---|
| 宝箱内容 | chest_contents 表 | 奖励组系统 |
| 开启消耗 | chest_costs 表 | 消耗组系统 |
| 配置管理 | 分散配置 | 统一的 ItemChestConfig |
| 数据关联 | 直接关联 | 通过组系统关联 |
修复GenerateChestJsonCommand适配新宝箱组系统
- 更新命令使用新的ItemChestConfig和组系统架构
- 替换旧的chest_contents/chest_costs关系为chestConfig关系
- 从奖励组获取宝箱内容,从消耗组获取开启消耗
- 修复物品名称显示问题,使用getTargetName()方法
- 移除不再使用的白名单过滤器和枚举导入
- 测试通过:成功处理4个宝箱,8个内容项,7个消耗项
✅ 已完成并推送到远程仓库