ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
``` <?php namespace app\agent\model; use think\Model; class AgentCategoryModel extends Model { /** * 添加文章分类 * @param $data * @return bool */ public function addCategory($data) { $result = true; self::startTrans(); try { $this->allowField(true)->save($data); $id = $this->id; if (empty($data['parent_id'])) { $this->where( ['id' => $id])->update(['path' => '0-' . $id]); } else { $parentPath = $this->where('id', intval($data['parent_id']))->value('path'); $this->where( ['id' => $id])->update(['path' => "$parentPath-$id"]); } self::commit(); } catch (\Exception $e) { self::rollback(); $result = false; } return $result; } } ```