DeptLogic.php
1.9 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
<?php
namespace App\Http\Logic\Aside\Manage;
use App\Helper\Arr;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Manage\Dept;
/**
* Class DeptLogic
* @package App\Http\Logic\Aside\dept
* @author zbj
* @date 2023/4/20
*/
class DeptLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->param = $this->requestAll;
$this->model = new Dept();
}
/**
* @remark :保存
* @name :save
* @author :lyh
* @method :post
* @time :2023/8/28 15:10
*/
public function deptSave(){
if(isset($this->param['id']) && !empty($this->param['id'])){
if(isset($this->param['pid']) && !empty($this->param['pid'])){
if($this->param['pid'] == $this->param['id']){
$this->fail('当前上级分类不能为自己');
}
$info = $this->model->read(['id'=>$this->param['pid']]);
if($info !== false && ($this->param['id']) == $info['pid']){
$this->fail('不能选择自己的下级');
}
}
$this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
$this->model->add($this->param);
}
return $this->success();
}
/**
* @remark :删除
* @name :delete
* @author :lyh
* @method :post
* @time :2023/8/28 15:22
*/
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);
}
}