123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <?php
- namespace app\admin\controller;
- /**
- * 导航管理
- */
- class Navi extends Admin{
- protected $Navi = null;
- protected function _initialize(){
- parent::_initialize();
- $this->Navi = model('Navi');
- }
- //导航列表
- public function index(){
- $pid = input('get.pid',0);
- $pnavi = $this->Navi->where(['id'=>$pid])->find();
- if ($pnavi) {
- $position = $pnavi['position'];
- }else{
- $position = input('param.position','admin');
- }
- $this->assign('pnavi',$pnavi);
- $this->assign('position',$position);
- $this->assign('meta_title','导航列表');
- return $this->fetch();
- }
- public function load(){
- $role = $this->user['role'];
- $Navi = model('Navi');
- $level = input('get.level',3);
- $pid = input('get.pid',0);
- $pnavi = $this->Navi->get($pid);
- if ($pnavi) {
- $position = $pnavi['position'];
- }else{
- $position = input('get.position');
- }
- $list = $Navi->navis($pid,$position,[],$level);
- return json(['data'=>$list,'code'=>0,'msg'=>'加载成功']);
- }
- //排序
- public function sort(){
- $id = input('post.id');
- $navi = $this->Navi->get($id);
- if ($navi) {
- $sort = input('post.sort');
- $navi->sort = $sort;
- $result = $navi->save();
- if ($result) {
- return json(['data'=>null,'code'=>0,'msg'=>'排序成功']);
- }
- }
- return json(['data'=>$_POST,'code'=>1,'msg'=>'参数错误']);
- }
- public function add(){
- if ($this->request->isPost()) {
- $this->Navi->pid = input('post.pid');
- $this->Navi->position = input('post.position');
- $this->Navi->name = input('post.name');
- $this->Navi->cname = input('post.cname');
- $this->Navi->icon = input('post.icon');
- $this->Navi->image = input('post.image');
- $this->Navi->action = input('post.action');
- $this->Navi->target = input('post.target');
- $this->Navi->type = input('post.type');
- $result = $this->Navi->save();
- if ($result) {
- return json(['data'=>$this->Navi->id,'code'=>0,'msg'=>'添加导航成功']);
- }
- return json(['data'=>$_POST,'code'=>1,'msg'=>'添加导航失败']);
- }else{
- $pid = input('param.pid');
- $pnavi = $this->Navi->get($pid);
- $this->assign('pnavi',$pnavi);
- $position = input('param.position');
- $this->assign('position',$position);
- $this->assign('meta_title','添加菜单');
- return $this->fetch();
- }
- }
- public function edit(){
- if ($this->request->isPost()) {
- $id = input('post.id');
- $navi = $this->Navi->where(['id'=>$id])->find();
- if ($navi) {
- $navi->name = input('post.name');
- $navi->cname = input('post.cname');
- $navi->icon = input('post.icon');
- $navi->image = input('post.image');
- $navi->action = input('post.action');
- $navi->target = input('post.target');
- $navi->type = input('post.type');
- $result = $navi->save();
- if ($result) {
- return json(['data'=>null,'code'=>0,'msg'=>'编辑导航成功']);
- }
- return json(['data'=>$_POST,'code'=>1,'msg'=>'编辑导航失败']);
- }
- return json(['data'=>$_POST,'code'=>1,'msg'=>'参数错误']);
- }else{
- $id = input('param.id');
- $navi = $this->Navi->where(['id'=>$id])->find();
- if (!$navi) {
- $this->error('参数错误');
- }
- $this->assign('navi',$navi);
- $this->assign('meta_title','删除菜单');
- return $this->fetch();
- }
- }
- public function delete(){
- if ($this->request->isPost()) {
- $id = input('post.id');
- $navi = $this->Navi->where(['id'=>$id])->find();
- if (!$navi) {
- return json(['data'=>null,'code'=>1,'msg'=>'参数错误']);
- }
- $result = $navi->delete();
- if ($result) {
- return json(['data'=>null,'code'=>0,'msg'=>'删除成功']);
- }
- return json(['data'=>null,'code'=>1,'msg'=>'删除失败']);
- }
- }
- }
|