KeywordPrefixLogic.php
2.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
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
<?php
/**
* @remark :
* @name :KeywordPrefixLogic.php
* @author :lyh
* @method :post
* @time :2023/9/6 14:40
*/
namespace App\Http\Logic\Aside\Project;
use App\Enums\Common\Code;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Project\KeywordPrefix;
class KeywordPrefixLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->param = $this->requestAll;
$this->model = new KeywordPrefix();
}
/**
* @remark :保存关键字
* @name :prefixSave
* @author :lyh
* @method :post
* @time :2023/9/6 14:42
*/
public function prefixSave(){
if(isset($this->param['id']) && !empty($this->param['id'])){
$condition = [
'keyword'=>$this->param['keyword'],
'id'=>['!=',$this->param['id']]
];
$prefixInfo = $this->model->read($condition);
if($prefixInfo !== false){
$this->fail('当前关键字已存在');
}
$data = [
'keyword'=>$this->param['keyword']
];
$this->model->edit($data,['id'=>$this->param['id']]);
}else{
$data = [
'project_id'=>$this->param['project_id'] ?? 0,
'keyword'=>$this->param['keyword'],
'type'=>$this->param['type']
];
$prefixInfo = $this->model->read($data);
if($prefixInfo !== false){
$this->fail('当前关键字已存在');
}
$this->model->add($data);
}
return $this->success();
}
/**
* @remark :删除关键字
* @name :prefixDel
* @author :lyh
* @method :post
* @time :2023/12/16 13:48
*/
public function prefixDel(){
$ids = $this->param['id'];
try {
foreach ($ids as $id){
$info = $this->model->read(['id'=>$id]);
if($info !== false){
if($info['project_id'] != 0){
$this->model->del(['id'=>$id]);
}
}
}
}catch (\Exception $e){
$this->fail('删除失败,请联系管理员');
}
return $this->success();
}
}