DeptLogic.php
1.3 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
<?php
namespace App\Http\Logic\Aside;
use App\Helper\Arr;
use App\Models\Manage\Dept;
use Illuminate\Database\Eloquent\Model;
/**
* Class DeptLogic
* @package App\Http\Logic\Aside\dept
* @author zbj
* @date 2023/4/20
*/
class DeptLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new Dept();
}
public function save($param){
if(!empty($param['pid'])){
if(!empty($param['id']) && $param['pid'] == $param['id']){
$this->fail('上级部门不能是本部门');
}
$p_cate = $this->getCacheInfo($param['pid']);
if(!$p_cate){
$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(Dept::where('pid', $id)->count()){
$this->fail("部门{$info['title']}存在下级部门,不能删除");
}
}
return parent::delete($ids);
}
}