BlogLabelLogic.php
4.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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
namespace App\Http\Logic\Bside\Blog;
use App\Enums\Common\Code;
use App\Helper\Common;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Blog\Blog as BlogModel;
use App\Models\Blog\BlogLabel as BlogLabelModel;
class BlogLabelLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new BlogLabelModel();
$this->param = $this->requestAll;
}
/**
* @param $v
* @name :获取分类名称
* @return void
* @author :liyuhang
* @method
*/
public function getLabelName($label_id){
$label_name = '';
if(!empty($label_id)){
$label_arr = $this->model->formatQuery(['id'=>['in',explode(',',trim($label_id,','))]])->pluck('name')->toArray();
$label_name = explode(',',$label_arr);
}
return $this->success($label_name);
}
/**
* @name :新增标签
* @return void
* @author :liyuhang
* @method
*/
public function add_blog_label(){
$this->verifyParamName($this->param['name']);
$this->param['create_id'] = $this->user['id'];
$this->param['operator_id'] = $this->user['id'];
$this->param['project_id'] = $this->user['project_id'];
$rs = $this->model->add($this->param);
if($rs === false){
$this->fail('error');
}
return $this->success();
}
/**
* @name :编辑标签
* @return void
* @author :liyuhang
* @method
*/
public function edit_blog_label(){
$this->verifyParamName($this->param['name'],$this->param['id']);
$this->param['operator_id'] = $this->user['id'];
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->fail('error');
}
return $this->success();
}
/**
* @name :编辑状态
* @return array
* @author :liyuhang
* @method
*/
public function status_blog_label(){
$this->param['operator_id'] = $this->user['id'];
$rs = $this->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->fail('error');
}
return $this->success();
}
/**
* @name :删除标签
* @return array
* @author :liyuhang
* @method
*/
public function del_blog_label(){
$ids = $this->param['id'];
foreach ($ids as $v){
//查看当前分内下是否有博客
$blogModel = new BlogModel();
$rs = $blogModel->read(['label_id'=>$v],['id']);
if($rs !== false){
$this->response('当前标签拥有博客,不允许删除');
}
}
$this->param['id'] = ['in',$this->param['id']];
$rs = $this->model->del($this->param);
if($rs === false){
$this->fail('error');
}
return $this->success();
}
/**
* @remark :批量添加数据
* @name :batchAdd
* @author :lyh
* @method :post
* @time :2023/8/28 14:03
*/
public function batchAdd(){
if(!empty($this->param['name']) && is_array($this->param['name'])){
foreach ($this->param['name'] as $v){
$this->verifyParamName($v);
$param['create_id'] = $this->user['id'];
$param['operator_id'] = $this->user['id'];
$param['project_id'] = $this->user['project_id'];
$param['name'] = $v;
$this->model->add($param);
}
}
return $this->success();
}
/**
* @name :(验证名称是否存在)verifyParamName
* @author :lyh
* @method :post
* @time :2023/6/13 11:41
*/
public function verifyParamName($name,$id = ''){
if(isset($id) && !empty($id)){
$condition = [
'id'=>['!=',$id],
'name'=>$name,
];
}else{
$condition = [
'name'=>$name
];
}
$info = $this->model->read($condition);
if($info !== false){
$this->fail('当前名称已存在');
}
return $this->success();
}
}