>数据表设计
|序号|字段名|必选|备注|
|:-|-|-|-|
|1|id|*|primary key|
|2|name|*|项目名|
|3|level|*|级别|
|4|type||级别类型|
|5|status||当前级别状态|
|6|pid|*|当前级别夫类|
>示例参数数据
![](https://img.kancloud.cn/2d/81/2d81f0c9f14a3de92d425b7c5c0743f2_1678x571.png)
>示例源码
```php
<?php
namespace app\\index\\model;
use think\Model;
class Rule extends Model{
public function getPlevel($pid){
$data = [
'id' =>$pid
];
return $this->where($data)->column('level');
}
public function getPid($id){
$data = [
'id' =>$id
];
return $this->where($data)->column('pid');
}
public function getdatas($id){
$data = [
'id' => $id
];
return $this->where($data)->select();
}
public function tree(){
$rule = [
'status' => 1,
'type' =>1
];
$data=$this->where($rule)->select();
return $this->sort($data);
}
public function sort($data,$pid=0){
static $arr=array();
foreach ($data as $k => $v) {
if($v['pid']==$pid){
$arr[]=$v;
$this->sort($data,$v['id']);
}
}
return $arr;
}
}
```