public function insertTags($tags, $beforeCount = true, $afterCount = true) { if (!is_array($tags)) { return false; } $this->deleteTags($beforeCount); //先删除标签 //插入新标签 $tagIds = Tag::scanTags($tags); if ($tagIds) { foreach ($tagIds as $v) { $model = new Relationship(); $model->cid = $this->cid; $model->mid = $v; $model->insert(false); if ($afterCount) { //更新标签文章数 Tag::updateAllCounters(['count' => 1], ['mid' => $v]); } } } return true; }