💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
``` <?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; } } ```