|
@@ -19,7 +19,7 @@ class NavLogic extends BaseLogic |
|
@@ -19,7 +19,7 @@ class NavLogic extends BaseLogic |
|
19
|
public function __construct()
|
19
|
public function __construct()
|
|
20
|
{
|
20
|
{
|
|
21
|
parent::__construct();
|
21
|
parent::__construct();
|
|
22
|
-
|
22
|
+ $this->param = $this->requestAll;
|
|
23
|
$this->model = new BNav();
|
23
|
$this->model = new BNav();
|
|
24
|
}
|
24
|
}
|
|
25
|
|
25
|
|
|
@@ -33,41 +33,35 @@ class NavLogic extends BaseLogic |
|
@@ -33,41 +33,35 @@ class NavLogic extends BaseLogic |
|
33
|
if(!empty($this->requestAll['location'])){
|
33
|
if(!empty($this->requestAll['location'])){
|
|
34
|
$where[] = ['location','=',$this->requestAll['location']];
|
34
|
$where[] = ['location','=',$this->requestAll['location']];
|
|
35
|
}
|
35
|
}
|
|
36
|
-
|
|
|
|
37
|
$lists = $this->getList($where,['sort'=>'asc'],['*'],false);
|
36
|
$lists = $this->getList($where,['sort'=>'asc'],['*'],false);
|
|
38
|
-
|
|
|
|
39
|
$isTree = $this->requestAll['tree']??false;
|
37
|
$isTree = $this->requestAll['tree']??false;
|
|
40
|
-
|
|
|
|
41
|
if($isTree){
|
38
|
if($isTree){
|
|
42
|
$lists = list_to_tree($lists);
|
39
|
$lists = list_to_tree($lists);
|
|
43
|
}
|
40
|
}
|
|
44
|
-
|
|
|
|
45
|
return $lists;
|
41
|
return $lists;
|
|
46
|
}
|
42
|
}
|
|
47
|
|
43
|
|
|
48
|
|
44
|
|
|
49
|
- public function save($data)
|
45
|
+ public function navSave()
|
|
50
|
{
|
46
|
{
|
|
51
|
- if($data['pid']){
|
|
|
|
52
|
- // 验证是否存在上级
|
|
|
|
53
|
- $all = BNav::_all($this->user['project_id'],$data['location']);
|
|
|
|
54
|
- if(!$all->where('id',$data['pid'])->count()){
|
|
|
|
55
|
- $this->fail('上级栏目不存在');
|
47
|
+ if(isset($this->param['id']) && !empty($this->param['id'])){
|
|
|
|
48
|
+
|
|
|
|
49
|
+ $info = $this->model->read(['id'=>$this->param['id']]);
|
|
|
|
50
|
+ if($this->param['pid'] == $info['id']){
|
|
|
|
51
|
+ $this->fail('不允许成为自己的上级');
|
|
56
|
}
|
52
|
}
|
|
57
|
- // 上级不允许是自己的下级
|
|
|
|
58
|
- if(!empty($data['id'])){
|
|
|
|
59
|
- $all = list_to_tree($all->toArray(),$data['id']);
|
|
|
|
60
|
- $all = tree_to_list($all);
|
|
|
|
61
|
- if(in_array($data['pid'],array_column($all,'id'))){
|
|
|
|
62
|
- $this->fail('上级栏目不允许为本身的下级');
|
|
|
|
63
|
- }
|
53
|
+ $pid_info = $this->model->read(['pid'=>$this->param['id']]);
|
|
|
|
54
|
+ if(($pid_info !== false) && $this->param['pid'] != $info['pid']){
|
|
|
|
55
|
+ $this->fail('当前菜单拥有子集不允许修改上级');
|
|
64
|
}
|
56
|
}
|
|
|
|
57
|
+ $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
|
|
|
|
58
|
+ }else{
|
|
|
|
59
|
+ $rs = $this->model->add($this->param);
|
|
65
|
}
|
60
|
}
|
|
66
|
- $data['url'] = $data['url'] ?: '';
|
|
|
|
67
|
- // 保存
|
|
|
|
68
|
- $id = parent::save($data);
|
|
|
|
69
|
-
|
|
|
|
70
|
- return $this->getInfo($id['id']);
|
61
|
+ if($rs === false){
|
|
|
|
62
|
+ $this->fail('error');
|
|
|
|
63
|
+ }
|
|
|
|
64
|
+ return $this->success();
|
|
71
|
}
|
65
|
}
|
|
72
|
|
66
|
|
|
73
|
/**
|
67
|
/**
|