NavLogic.php
3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
namespace App\Http\Logic\Bside\Nav;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Nav\BNav;
use App\Models\RouteMap\RouteMap;
use Illuminate\Support\Facades\DB;
/**
* @remark :菜单管理
* @name :NavLogic
* @author :lyh
* @method :post
* @time :2023/8/23 11:14
*/
class NavLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->param = $this->requestAll;
$this->model = new BNav();
}
/**
* @remark :保存数据
* @name :navSave
* @author :lyh
* @method :post
* @time :2023/8/23 11:14
*/
public function navSave()
{
DB::beginTransaction();
try {
if(isset($this->param['id']) && !empty($this->param['id'])){
$this->handleEditParam();//验证是否可编辑分类
$this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
$this->param['project_id'] = $this->user['project_id'];
$this->model->add($this->param);
}
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('error');
}
//编辑菜单后,通知更新
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_NAV, 'route'=>'all']);
return $this->success();
}
/**
* @remark :验证是否可编辑
* @name :handleEditParam
* @author :lyh
* @method :post
* @time :2023/9/7 14:36
*/
public function handleEditParam(){
$info = $this->model->read(['id'=>$this->param['id']]);
if($this->param['pid'] == $info['id']){
$this->fail('不允许成为自己的上级');
}
$pid_info = $this->model->read(['pid'=>$this->param['id']]);
if(($pid_info !== false) && $this->param['pid'] != $info['pid']){
$this->fail('当前菜单拥有子集不允许修改上级');
}
return $this->success();
}
/**
* @remark :删除菜单
* @name :navDelete
* @author :lyh
* @method :post
* @time :2023/8/23 11:12
*/
public function navDelete()
{
//判断当前菜单是否拥有下级
$info = $this->model->read(['pid'=>$this->param['id']]);
if($info !== false){
$this->fail('当前菜单存在下级,不允许删除');
}
$rs = $this->model->del($this->param);
if($rs === false){
$this->fail('error');
}
//编辑菜单后,通知更新
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_NAV, 'route'=>'all']);
return $this->success();
}
/**
* @remark :排序
* @name :navSort
* @author :lyh
* @method :post
* @time :2023/8/22 9:54
*/
public function navSort(){
$rs = $this->model->edit(['sort'=>$this->param['sort']],['id'=>$this->param['id']]);
if($rs === false){
$this->fail('error');
}
return $this->success();
}
}