💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
## 代码 ``` <?php namespace app\agent\model; use think\Model; class AgentCategoryModel extends Model { public function editCategory($data) { $result = true; $id = intval($data['id']); $parentId = intval($data['parent_id']); $oldCategory = $this->where('id', $id)->find(); if (empty($parentId)) { $newPath = '0-' . $id; } else { $parentPath = $this->where('id', intval($data['parent_id']))->value('path'); if ($parentPath === false) { $newPath = false; } else { $newPath = "$parentPath-$id"; } } if (empty($oldCategory) || empty($newPath)) { $result = false; } else { $data['path'] = $newPath; $this->isUpdate(true)->allowField(true)->save($data, ['id' => $id]); $children = $this->field('id,path')->where('path', 'like', "%-$id-%")->select(); if (!empty($children)) { foreach ($children as $child) { $childPath = str_replace($oldCategory['path'] . '-', $newPath . '-', $child['path']); $this->isUpdate(true)->save(['path' => $childPath], ['id' => $child['id']]); } } } return $result; } } ```