input('id/d',0), 'name' => input('name','','trim'), 'org_id' => input('orgId/d',0), 'parent_id' => input('parentId/d',0), ]; $result = validate('DocumentCate')->check($data,[],''); if(true !== $result){ HelpHander::error(validate('DocumentCate')->getError()); } $id = $data['id']; unset($data['id']); if($id > 0){ $ret = $this->allowField(true)->save($data,['id'=>$id]); }else{ $ret = $this->allowField(true)->save($data); } if(!$ret){ HelpHander::error('操作失败'); } return true; } public function info($id){ $info = $this->where('id',$id)->find(); if(!$info){ HelpHander::error('数据不存在'); } return $info->toArray(); } public function lists($orgId){ $lists = $this->where('org_id',$orgId)->select(); $lists = $lists?$lists->toArray():[]; $ids = []; foreach ($lists as $v){ $ids[] = $v['id']; } $lists = list_to_tree($lists, 'parent_id', 'childList'); return ['ids' => $ids, 'tree' => $lists]; } public function all($orgId){ $lists = $this->select(); $lists = $lists?$lists->toArray():[]; return $lists; } public function del($id){ // 检查是否已被使用 $info = Db::name('document') ->where('cate_id',$id) ->where('del',0) ->find(); if($info){ HelpHander::error('已被使用,无法删除'); } $cate = Db::name('document_cate')->where('parent_id',$id)->find(); if($cate){ HelpHander::error('已被使用,无法删除'); } $ret = $this->where('id',$id)->delete(); if(!$ret){ HelpHander::error('删除失败'); } return true; } public function queryDocumentList($title,$userId,$orgId){ if(!$title){ // 为空取一级分类 $lists = Db::name('document_cate') ->where('org_id',$orgId) ->where('parent_id',0) ->order('id asc') ->select(); } else { $lists = model('Document')->getAppList($title,$userId,$orgId); } return $lists?$lists:[]; } public function getSubList($cateId,$orgId){ $lists = Db::name('document_cate') ->where('org_id',$orgId) ->where('parent_id',$cateId) ->order('id asc') ->select(); $lists = $lists?$lists:[]; foreach ($lists as $k=>$v){ $lists[$k]['type'] = 0; $lists[$k]['file'] = ''; $lists[$k]['source_file'] = ''; } return $lists; } }