model = new \app\admin\model\department\Department; $this->tree = Tree::instance(); $this->keyword = $this->request->request("quick_search"); } public function index() { if ($this->request->param('select')) { $this->select(); } $this->success('', [ 'list' => $this->getDepartment(), 'remark' => get_route_remark(), ]); } public function edit($id = null) { $row = $this->model->find($id); if (!$row) { $this->error(__('Record not found')); } if ($this->request->isPost()) { parent::edit($id); } $this->success('', [ 'row' => $row ]); } public function select() { $isTree = $this->request->param('isTree'); $data = $this->getDepartment([['status', '=', '1']]); if ($isTree && !$this->keyword) { $data = $this->tree->assembleTree($this->tree->getTreeArray($data, 'name')); } $this->success('', [ 'options' => $data ]); } protected function getDepartment($where = []) { if ($this->keyword) { $keyword = explode(' ', $this->keyword); foreach ($keyword as $item) { $where[] = [$this->quickSearchField, 'like', '%' . $item . '%']; } } $data = $this->model->where($where)->order('weigh desc,id asc')->select()->toArray(); return $this->tree->assembleChild($data); } }