MenuLogic.php
2.2 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
<?php
namespace App\Http\Logic\Aside\Manage;
use App\Helper\Arr;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Manage\Group;
use App\Models\Manage\Menu;
/**
* Class MenuLogic
* @package App\Http\Logic\Aside
* @author zbj
* @date 2023/4/19
*/
class MenuLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new Menu();
}
public function getInfo($id)
{
$info = parent::getInfo($id);
return $this->success($info);
}
public function save($param){
if(!empty($param['pid'])){
if(!empty($param['id']) && $param['pid'] == $param['id']){
$this->fail('上级菜单不能是本菜单');
}
$p_menu = $this->getCacheInfo($param['pid']);
if(!$p_menu){
$this->fail('上级菜单不存在');
}
}
return parent::save($param);
}
public function delete($ids, $map = []){
$ids= array_filter(Arr::splitFilterToArray($ids), 'intval');
foreach ($ids as $id){
$info = $this->getCacheInfo($id);
if(!$info){
continue;
}
//是否有子菜单
if(Menu::where('pid', $id)->count()){
$this->fail("菜单{$info['title']}存在子菜单,不能删除");
}
}
return parent::delete($ids);
}
public function getAllMenu(){
$map[] = ['type' => Menu::TYPE_MENU];
$map[] = ['status' => Menu::STATUS_NORMAL];
$list = parent::getList($map, ['id' => 'desc'], ['id', 'pid', 'title', 'icon', 'type', 'menu_path'], 0);
return $this->success(Arr::listToTree($list));
}
public function getMenuByGroupId($gid){
$rights = Group::where(['id' => $gid, 'status' => Group::STATUS_NORMAL])->pluck('rights')->first();
$map[] = ['type' => Menu::TYPE_MENU];
$map[] = ['status' => Menu::STATUS_NORMAL];
$map[] = ['id', 'in', $rights];
$list = parent::getList($map, ['id' => 'desc'], ['id', 'pid', 'title', 'icon', 'type', 'menu_path'], 0);
return $this->success(Arr::listToTree($list));
}
}