PHPackages                             hotarunohikari/dr-tree - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hotarunohikari/dr-tree

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hotarunohikari/dr-tree
======================

1.0.0(6y ago)02MITPHPPHP &gt;=7.0.0

Since Apr 14Pushed 6y ago1 watchersCompare

[ Source](https://github.com/hotarunohikari/dr-tree)[ Packagist](https://packagist.org/packages/hotarunohikari/dr-tree)[ RSS](/packages/hotarunohikari-dr-tree/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

dr-tree
=======

[](#dr-tree)

基于TP5+的树形结构工具

```
/**
 * 设置数据表,不带前缀
 * @param $tableName
 * @return mixed
 */
function setTable($tableName);

/**
 * 获取所有记录
 * @param array $where 查询条件
 * @param array|null $join 关联查询(TP语法)
 * @param string|bool $field 要返回的字段
 * @return mixed
 */
function getAll($where = [], $join = null, $field = true);

/**
 * 向下获取团队
 * @param int $topId 顶点ID
 * @param bool $withSelf 是否包含自己,默认包含
 * @param int $deep 相对深度,-1为全部
 * @param array $where 查询条件
 * @param array|null $join 关联查询(TP语法)
 * @param string|bool $field 要返回的字段
 * @return mixed
 */
function getTeam($topId = 1, $withSelf = true, $deep = -1, $where = [], $join = null, $field = true);

/**
 * 向下获取团队ID集合
 * @param int $topId 顶点ID
 * @param bool $withSelf 是否包含自己,默认包含
 * @param int $deep 相对深度,-1为全部
 * @param array $where 查询条件
 * @param array|null $join 关联查询(TP语法)
 * @return mixed
 */
function getTeamIds($topId, $withSelf = true, $deep = -1, $where = [], $join = null);

/**
 * 向下获取团队总人数统计
 * @param $topId
 * @param bool $withSelf 是否包含自己,默认包含
 * @param int $deep 相对深度,-1为全部
 * @param array $where 查询条件
 * @param array|null $join 关联查询(TP语法)
 * @return mixed
 */
function countTeam($topId, $withSelf = true, $deep = -1, $where = [], $join = null);

/**
 * 向下获取所有的子代(直推)
 * @param int $topId 顶点ID
 * @param array $where 查询条件
 * @param array|null $join 关联查询(TP语法)
 * @param string|bool $field 要返回的字段
 * @return mixed
 */
function getChildren($topId, $where = [], $join = null, $field = true);

/**
 * 向下获取所有的子代(直推)ID集合
 * @param int $topId 顶点ID
 * @param array $where 查询条件
 * @param array|null $join 关联查询(TP语法)
 * @return mixed
 */
function getChildrenIds($topId, $where = [], $join = null);

/**
 * 向下获取子代(直推)人数统计;
 * @param int $topId 顶点ID
 * @param array $where 查询条件
 * @param array|null $join 关联查询(TP语法)
 * @return mixed
 */
function countChildren($topId, $where = [], $join = null);

/**
 * 向上获取母级节点信息
 * @param int $botId 底部ID
 * @param array $where 查询条件
 * @param array|null $join 关联查询(TP语法)
 * @param string|bool $field 要返回的字段
 * @return mixed
 */
function getParent($botId, $where = [], $join = null, $field = true);

/**
 * 向上获取所有的祖先节点信息
 * @param int $botId 底部ID
 * @param int $deep 相对深度,-1表示所有
 * @param array $where 查询条件
 * @param array|null $join 关联查询(TP语法)
 * @param string|bool $field 要返回的字段
 * @return mixed
 */
function getAncestors($botId, $deep = -1, $where = [], $join = null, $field = true);

/**
 * 向上获取所有的祖先ID集合
 * @param int $botId 底部ID
 * @param int $deep 相对深度,-1表示所有
 * @param array $where 查询条件
 * @param array|null $join 关联查询(TP语法)
 * @return mixed
 */
function getAncestorIds($botId, $deep = -1, $where = [], $join = null);

/**
 * 判断两个节点是否属于同一条线
 * @param $id1
 * @param $id2
 * @return mixed
 */
function inOneLine($id1, $id2);

/**
 * 获取给定两个ID之间的所有的节点
 * @param int $mid1 成员ID
 * @param int $mid2 成员ID
 * @param array $where 查询条件
 * @param array|null $join 关联查询(TP语法)
 * @param string|bool $field 要返回的字段
 * @return mixed
 */
function getRange($mid1, $mid2, $where = [], $join = null, $field = true);

/**
 * 获取给定两个ID之间的所有的节点ID集合
 * @param int $mid1 成员ID
 * @param int $mid2 成员ID
 * @param array $where 查询条件
 * @param array|null $join 关联查询(TP语法)
 * @param string|bool $field 要返回的字段
 * @return mixed
 */
function getRangeIds($mid1, $mid2, $where = [], $join = null, $field = true);

/**
 * 数据转树形结构
 * @param array $arr 数据
 * @param string $midField 成员ID字段
 * @param string $pidField 成员母级ID字段
 * @param string $sonTag 子代标签
 * @return array
 */
function buildTree($arr, $midField = 'mid', $pidField = 'pid', $sonTag = 'son');

/**
 * 新增
 * @param int $parentId 母级成员ID
 * @param array $data 新增的数据,必须含有成员ID
 * @param bool $atBottom 默认添加于其所有兄弟成员的尾部
 * @return bool
 */
function add($parentId, array $data = [], $atBottom = true);

/**
 * 将一个节点及其全部后代移动到另个一节点下,两者为母子级关系
 * @param $mid
 * @param $parentId
 * @param bool $atBottom 默认将分支在最后加入
 * @return bool
 */
function moveUnder($mid, $parentId, $atBottom = true);

/**
 * 删除某个分支,默认删除某个成员及所有后代
 * @param int $mid 成员ID
 * @param bool $withSelf 默认包含自己
 * @return bool
 */
function remove($mid, $withSelf = true);

/**
 * 递归重建
 * @param int $mid 成员ID
 * @param int $left 成员左键
 * @return int
 * @throws \think\db\exception\BindParamException
 * @throws \think\exception\PDOException
 */
function rebuild($mid, $left);

/**
 * 根据指定表构建预排序遍历树
 * @param string $tableName 表名
 * @param string $midField 成员ID字段
 * @param string $pidField 成员母级ID字段
 * @return mixed
 */
function generate($tableName, $midField = 'id', $pidField = 'pid');

```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2217d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/47f6cfe87caf5c95a781c6518d6d9dcb49e5e1999792ea7d66799f4f81410517?d=identicon)[hotarunohikari](/maintainers/hotarunohikari)

---

Top Contributors

[![CorderWei](https://avatars.githubusercontent.com/u/7877655?v=4)](https://github.com/CorderWei "CorderWei (3 commits)")

### Embed Badge

![Health badge](/badges/hotarunohikari-dr-tree/health.svg)

```
[![Health](https://phpackages.com/badges/hotarunohikari-dr-tree/health.svg)](https://phpackages.com/packages/hotarunohikari-dr-tree)
```

###  Alternatives

[topthink/think-captcha

captcha package for thinkphp

132934.4k68](/packages/topthink-think-captcha)[topthink/think-worker

workerman extend for thinkphp

202227.2k9](/packages/topthink-think-worker)[yunwuxin/think-cron

计划任务

17416.2k](/packages/yunwuxin-think-cron)[zzstudio/think-addons

The ThinkPHP6 Addons Package

1518.6k](/packages/zzstudio-think-addons)[topthink/think-annotation

Annotation For ThinkPHP

4831.5k8](/packages/topthink-think-annotation)[liliuwei/thinkphp-jump

适用于thinkphp6.0的跳转扩展

2874.4k1](/packages/liliuwei-thinkphp-jump)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
