owner->andWhere(['parent_id' => $parentId]); } /** * 获取指定子节点上边的父元素 * * @param int $childId * @return $this */ public function byChildId(int $childId): ActiveQuery { return $this->owner->andWhere(['child_id' => $childId]); } /** * 通过非child_id过滤 * * @param int $childId * @return $this */ public function byNotChildId(int $childId): ActiveQuery { return $this->owner->andWhere(['!=', 'child_id', $childId]); } /** * 按父级别筛选 * * @param int $parentLevel * @return ActiveQuery */ public function byParentLevel(int $parentLevel): ActiveQuery { return $this->owner->andWhere(['parent_level' => $parentLevel]); } /** * 按子级别筛选 * * @param int $childLevel * @return ActiveQuery */ public function byChildLevel(int $childLevel): ActiveQuery { return $this->owner->andWhere(['child_level' => $childLevel]); } /** * 确定该节点是否为父节点的子节点 * * @param int $parentId * @param int $childId * @return ActiveQuery */ public function isChildOf(int $parentId, int $childId): ActiveQuery { return $this->owner ->byParentId($parentId) ->byChildId($childId) ->byNotChildId($parentId); } }