KeywordController.php
6.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php
namespace App\Http\Controllers\Bside\Product;
use App\Enums\Common\Code;
use App\Helper\Arr;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Product\KeywordLogic;
use App\Http\Requests\Bside\Product\KeywordRequest;
use App\Models\Product\Keyword;
use App\Models\Product\KeywordRelated;
use App\Models\Product\Product;
use App\Models\RouteMap\RouteMap;
use App\Rules\Ids;
use Illuminate\Http\Request;
/**
* Class KeywordVideoController
* @package App\Http\Controllers\Bside
* @author zbj
* @date 2023/4/15
*/
class KeywordController extends BaseController
{
/**
* @remark :关键字列表
* @name :index
* @author :lyh
* @method :post
* @time :2023/8/17 10:57
*/
public function index(Keyword $keyword)
{
$this->map = $this->searchParam($this->map);
$filed = ['id', 'project_id', 'title', 'seo_title', 'seo_keywords', 'seo_description', 'status', 'created_at','route','keyword_title'];
$data = $keyword->lists($this->map,$this->page,$this->row,$this->order,$filed);
if(!empty($data)){
foreach ($data['list'] as &$v){
$v['product_num'] = Product::where('keyword_id','like' ,'%,'.$v['id'].',%')->count();
if(!empty($v['seo_title']) || !empty($v['seo_keywords']) || !empty($v['seo_description'])){
$v['tdk'] = 1;
}else{
$v['tdk'] = 0;
}
$v = $this->handleReturnInfo($v);
$v['url'] = $this->user['domain'] . $v['route'].'/';
}
}
return $this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :单独处理图片文件
* @name :HandleReturnInfo
* @author :lyh
* @method :post
* @time :2024/1/26 9:44
*/
public function handleReturnInfo($param){
if(isset($param['keyword_top_banner']) && !empty($param['keyword_top_banner'])){
$param['keyword_top_banner'] = getImageUrl($param['keyword_top_banner'],$this->user['storage_type'],$this->user['project_location']);
}
if(isset($param['keyword_foot_banner']) && !empty($param['keyword_foot_banner'])){
$param['keyword_foot_banner'] = getImageUrl($param['keyword_foot_banner'],$this->user['storage_type'],$this->user['project_location']);
}
return $this->success($param);
}
/**
* @remark :搜索
* @name :searchParam
* @author :lyh
* @method :post
* @time :2023/12/21 17:40
*/
public function searchParam($map){
if(!empty($map['title'])){
$map['title'] = ['like','%'.$map['title'].'%'];
}
if(!empty($map['keyword_title'])){
$map['keyword_title'] = ['like','%'.$map['keyword_title'].'%'];
}
$map['route'] = ['<>',''];
$map['project_id'] = $this->user['project_id'];
return $this->success($map);
}
/**
* @remark :获取数据详情
* @name :info
* @author :lyh
* @method :post
* @time :2023/8/23 16:57
*/
public function info(Request $request, KeywordLogic $logic){
$data = $logic->getKeywordInfo();
if($data !== false){
$data = $this->handleReturnInfo($data);
}
$this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :保存
* @name :save
* @author :lyh
* @method :post
* @time :2023/8/28 14:24
*/
public function save(KeywordRequest $request, KeywordLogic $logic)
{
$request->validated();
$data = $logic->keywordSave();
$this->response('success',Code::SUCCESS,$data);
}
/**
* 批量添加关键词
* FIXME 添加通知, 异步处理任务
* @param KeywordLogic $logic
* @throws \App\Exceptions\AsideGlobalException
* @throws \App\Exceptions\BsideGlobalException
*/
public function batchAdd(KeywordLogic $logic){
$this->request->validate([
'title'=>['required','array', 'max:1000']
],[
'title.required' => 'title不能为空',
'title.array' => 'title为数组',
'title.max' => '批量操作不能超过1000条数据'
]);
$rs = $logic->batchAdd();
if($rs === false){
$this->response('创建任务添加关键词任务失败,请稍后重试!',Code::SYSTEM_ERROR);
}
$this->response('关键词后台异步添加中,请稍后刷新查看!');
}
/**
* @remark :删除数据
* @name :delete
* @author :lyh
* @method :post
* @time :2023/8/23 17:44
*/
public function delete(KeywordLogic $logic)
{
$this->request->validate([
'ids'=>['required', new Ids()]
],[
'ids.required' => 'ID不能为空'
]);
$logic->keywordDelete();
$this->response('success');
}
/**
* 批量删除
* @param KeywordLogic $logic
* @author zbj
* @date 2023/11/22
*/
public function batchDel(KeywordLogic $logic){
$this->request->validate([
'title'=>['required','array', 'max:1000']
],[
'title.required' => 'title不能为空',
'title.array' => 'title为数组',
'title.max' => '批量操作不能超过1000条数据'
]);
$logic->batchDel();
$this->response('success');
}
/**
* @remark :批量清除关键词相关内容
* @name :batchKeywordFiled
* @author :lyh
* @method :post
* @time :2024/4/22 10:27
*/
public function batchKeywordFiled(){
$param = [];
if(isset($this->param['keyword'])){
$param['seo_keywords'] = null;
}
if(isset($this->param['description'])){
$param['seo_description'] = null;
}
if(isset($this->param['title'])){
$param['keyword_title'] = null;
}
if(isset($this->param['content'])){
$param['keyword_content'] = null;
}
$keywordModel = new Keyword();
$rs = $keywordModel->edit($param,['id'=>['!=',0]]);
if($rs === false){
$this->fail('保存失败,请联系管理员');
}
$this->response('success');
}
}