['name' => 'pid', 'title' => '父ID', 'type' => 'bigint', 'is_must' => '0'], 'title' => ['name' => 'title', 'title' => '岗位名称', 'type' => 'varchar', 'is_must' => '1'], 'level' => ['name' => 'level', 'title' => '数据等级', 'type' => 'tinyint', 'is_must' => '0'], 'description' => ['name' => 'description', 'title' => '岗位描述', 'type' => 'varchar', 'is_must' => '0'], 'base_salary' => ['name' => 'base_salary', 'title' => '基础工资', 'type' => 'decimal', 'is_must' => '0'], 'status' => ['name' => 'status', 'title' => '岗位状态: 1 开启 2 关闭', 'type' => 'tinyint', 'is_must' => '0'], 'rules' => ['name' => 'rules', 'title' => '规则id,多个规则 , 隔开', 'type' => 'varchar', 'is_must' => '0'], ]; public function getTree($status, $pid = 0) { $data = []; if($status){ $this->where('status', $status); } $list = $this->where('pid', $pid)->get(); foreach ($list as $item) { $row = [ 'id' => $item->id, 'pid' => $item->pid, 'title' => $item->title, 'level' => $item->level, 'description' => $item->description, 'base_salary' => $item->base_salary, 'status' => $item->status, 'rules' => $item->rules, ]; $children = $this->getTree($status, $item->id); if(count($children) > 0){ $row['children'] = $children; } $data[] = $row; } return $data; } }