KeywordController.php
10.5 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
<?php
namespace App\Http\Controllers\Bside\Product;
use App\Enums\Common\Code;
use App\Helper\Common;
use App\Helper\Gpt;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Product\KeywordLogic;
use App\Http\Requests\Bside\Product\KeywordRequest;
use App\Models\Ai\AiCommand;
use App\Models\Product\Keyword;
use App\Models\Product\KeywordPage;
use App\Models\Product\KeywordRelated;
use App\Models\Product\Product;
use App\Models\Project\AggregateKeywordComment;
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','is_video_keyword'];
$data = $keyword->lists($this->map,$this->page,$this->row,$this->order,$filed);
if(!empty($data)){
foreach ($data['list'] as &$v){
$v['product_num'] = KeywordRelated::where('keyword_id',$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'].'%'];
}
if(empty($map['is_video_keyword'])){
unset($map['is_video_keyword']);
}
$map['route'] = ['<>',''];
$map['project_id'] = $this->user['project_id'];
$map['deleted_at'] = null;
return $this->success($map);
}
/**
* @remark :获取数据详情
* @name :info
* @author :lyh
* @method :post
* @time :2023/8/23 16:57
*/
public function info(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['seo_title'])){
$param['seo_title'] = null;
}
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');
}
/**
* @remark :批量操作关键字是否展示视频
* @name :batchKeywordIsVideo
* @author :lyh
* @method :post
* @time :2024/5/30 14:29
*/
public function batchKeywordIsVideo(){
$this->request->validate([
'title'=>['required','array', 'max:500']
],[
'title.required' => 'title不能为空',
'title.array' => 'title为数组',
'title.max' => '批量操作不能超过500条数据'
]);
$keywordModel = new Keyword();
$rs = $keywordModel->edit(['is_video_keyword'=>$this->param['is_video_keyword'] ?? 0],['title'=>['in',$this->param['title']]]);
if($rs === false){
$this->fail('编辑失败,请联系管理员');
}
if($this->param['is_video_keyword'] == 1){
$url = [];
$keywordList = $keywordModel->list(['title'=>['in',$this->param['title']]],'id',['id','route','is_video_keyword']);
foreach ($keywordList as $v){
$url[] = $v['route'];
}
$this->sendHttpC($url);
}
$this->response('success');
}
/**
* @remark :批量提交更新关键词
* @name :batchUpdateKeyword
* @author :lyh
* @method :post
* @time :2024/7/2 10:14
*/
public function batchUpdateKeyword(){
$this->request->validate([
'text'=>'required|array',
'update_object'=>'required|array',
'update_method'=>'required'
],[
'text.required' => '文件内容不能为空',
'update_object.required' => '更新对象不为空',
'update_object.array' => '更新对象为数组',
'update_method.required' => '请求方式不为空'
]);
$keywordPageModel = new KeywordPage();
$this->param['text'] = json_encode($this->param['text']);
$this->param['update_object'] = json_encode($this->param['update_object']);
$this->param['project_id'] = $this->user['project_id'];
$id = $keywordPageModel->addReturnId($this->param);
$this->response('success',Code::SUCCESS,['id'=>$id]);
}
/**
* @remark :删除关联关系
* @name :delRelated
* @author :lyh
* @method :post
* @time :2024/11/28 10:30
*/
public function delRelated(KeywordLogic $logic){
$this->request->validate([
'keyword_id'=>'required',
'product_id'=>'required',
],[
'keyword_id.required' => '关键词id不能为空',
'product_id.required' => '产品id不为空',
]);
$logic->delRelated($this->param['keyword_id'],$this->param['product_id']);
$this->response('success');
}
/**
* @remark :清除当前项目所有关键字
* @name :delAllKeyword
* @author :lyh
* @method :post
* @time :2024/12/5 16:34
*/
public function delAllKeyword(KeywordLogic $logic){
$logic->delAllKeyword();
$this->response('success');
}
/**
* @remark :删除关键词所有关联产品
* @name :delRelatedProductId
* @author :lyh
* @method :post
* @time :2025/4/17 11:01
*/
public function delRelatedProductId(KeywordLogic $logic){
$this->request->validate([
'keyword_id'=>'required',
],[
'keyword_id.required' => '关键词ID不能为空',
]);
$logic->delAllRelated($this->param['keyword_id']);
$this->response('success');
}
/**
* @remark :生成评论
* @name :sendComment
* @author :lyh
* @method :post
* @time :2025/6/9 11:10
*/
public function sendComment(KeywordLogic $logic){
$this->request->validate([
'count'=>'required|max:10',
],[
'count.required' => '生成条数不能为空',
'count.max'=>'count最大10',
]);
$data = $logic->sendComment();
$this->response('success',Code::SUCCESS,$data);
}
}