NavLogic.php
2.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
<?php
namespace App\Http\Logic\Bside\Nav;
use App\Enums\Common\Code;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\BNav;
/**
* @author:dc
* @time 2023/5/11 16:51
* Class NavLogic
* @package App\Http\Logic\Bside
*/
class NavLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new BNav();
}
/**
* @return array
* @author:dc
* @time 2023/5/12 9:23
*/
public function list(){
$where = [];
if(!empty($this->requestAll['location'])){
$where[] = ['location','=',$this->requestAll['location']];
}
$lists = $this->getList($where,['sort'=>'asc'],['*'],false);
$isTree = $this->requestAll['tree']??false;
if($isTree){
$lists = list_to_tree($lists);
}
return $lists;
}
public function save($data)
{
if($data['pid']){
// 验证是否存在上级
$all = BNav::_all($this->user['project_id'],$data['location']);
if(!$all->where('id',$data['pid'])->count()){
$this->fail('上级栏目不存在');
}
// 上级不允许是自己的下级
if(!empty($data['id'])){
$all = list_to_tree($all->toArray(),$data['id']);
$all = tree_to_list($all);
if(in_array($data['pid'],array_column($all,'id'))){
$this->fail('上级栏目不允许为本身的下级');
}
}
}
$data['url'] = $data['url'] ?: '';
// 保存
$id = parent::save($data);
return $this->getInfo($id['id']);
}
/**
* @param $ids
* @return array
* @throws \App\Exceptions\AsideGlobalException
* @throws \App\Exceptions\BsideGlobalException
* @author:dc
* @time 2023/5/11 16:59
*/
public function delete($ids,$map = [])
{
if(BNav::isChild($ids,$this->user['project_id'])){
$this->fail('存在下级无法删除');
}
return parent::delete($ids,$map); // TODO: Change the autogenerated stub
}
}