public static function deleteTopicTags($topicId, $tagNames) { if ($oldTags = static::find(['id'])->where(['name' => $tagNames])->asArray()->all()) { $tagIds = ArrayHelper::getColumn($oldTags, 'id'); TagTopic::deleteAll(['topic_id' => $topicId, 'tag_id' => $tagIds]); static::updateAll(['updated_at' => time(), 'topic_count' => new Expression('`topic_count` - 1')], ['and', ['id' => $tagIds], ['>', 'topic_count', 0]]); } }