KeywordController.php
3.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
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
<?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 KeywordController
* @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)
{
if(!empty($this->map['title'])){
$this->map['title'] = ['like','%'.$this->map['title'].'%'];
}
$this->map['project_id'] = $this->user['project_id'];
$filed = ['id', 'project_id', 'title', 'seo_title', 'seo_keywords', 'seo_description', 'status', 'created_at','route'];
$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['url'] = $this->user['domain'] . $v['route'];
}
}
return $this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :获取数据详情
* @name :info
* @author :lyh
* @method :post
* @time :2023/8/23 16:57
*/
public function info(Request $request, KeywordLogic $logic){
$request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$data = $logic->getKeywordInfo();
return $this->success($data);
}
/**
* @remark :保存
* @name :save
* @author :lyh
* @method :post
* @time :2023/8/28 14:24
*/
public function save(KeywordRequest $request, KeywordLogic $logic)
{
$request->validated();
$logic->keywordSave();
$this->response('success');
}
/**
* @remark :批量添加
* @name :batchAdd
* @author :lyh
* @method :post
* @time :2023/8/28 14:25
*/
public function batchAdd(KeywordLogic $logic){
$this->request->validate([
'title'=>['required','array']
],[
'title.required' => 'title不能为空',
'title.array' => 'title为数组'
]);
$logic->batchAdd();
$this->response('success');
}
/**
* @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');
}
}