showAllTree(); $this->assign('tree',$tree); return $this->fetch(); } /** * 新增 */ public function add($pid=0,$t=0){ if(request()->isPost()){ $res = model('Org')->addSave(); if($res){ $this->success('操作成功',url('index')); }else{ $this->error(model('Org')->getError()); } }else{ $this->assign('pid',$pid); $this->assign('t',$t); return $this->fetch(); } } /** * 编辑 */ public function edit($id=0){ if(request()->isPost()){ $res = model('Org')->editSave(); if($res){ $this->success('操作成功',url('index')); }else{ $this->error(model('Org')->getError()); } }else{ $info = db('org')->where('id',$id)->find(); $info['location'] = ''; if($info && $info['lat'] && $info['lng']){ $info['location'] = $info['lat'].'-'.$info['lng']; } $this->assign('info',$info); $this->assign('t',$info['type']); return $this->fetch(); } } public function changeEnable($id=0,$enable=0){ if($id <= 0){ $this->error('参数错误'); } $ret = Db::name('org')->where('id',$id)->setField('enable',$enable); if(!$ret){ $this->error('操作失败'); } $this->success('操作成功'); } /** * 删除记录 * @param int $id */ public function del($id=0){ if(!$id){ $this->error('参数错误'); } // 检查是否有子级 $ret = Db::name('org')->where('parent_id',$id)->where('del',0)->find(); if($ret){ $this->error('有子级不能删除'); } $res = Db::name('org')->where('id',$id)->setField('del',1); if($res){ $this->success('删除成功'); }else{ $this->error('删除失败'); } } /** * 授权 */ public function auth(){ if(request()->isPost()){ $res = model('Org')->authSave(); if($res){ $this->success('操作成功',url('index')); }else{ $this->error(model('Org')->getError()); } }else{ $orgId = input('id/d',0); $meuns = model('Menu')->getAllMenuTree(); $this->assign('menus',$meuns); $sauth = model('Org')->getOrgAuths($orgId,1); $this->assign('sauth',$sauth); $appauths = model('AppIcon')->getAllIconTree(); $this->assign('appauths',$appauths); $sappauth = model('Org')->getOrgAuths($orgId,2); $this->assign('sappauth',$sappauth); $this->assign('orgId',$orgId); return $this->fetch(); } } }