CollectLogic.php
4.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
<?php
namespace App\Http\Logic\Aside;
use App\Helper\Arr;
use App\Http\Logic\Logic;
use App\Models\Blog\Blog;
use App\Models\Domain\DomainInfo;
use App\Models\News\News;
use App\Models\Product\Keyword;
use App\Models\Product\Product;
use App\Models\Project\Project;
use App\Services\ProjectServer;
/**
* Class CollectLogic
* @package App\Http\Logic\Aside
* @author zbj
* @date 2023/11/10
*/
class CollectLogic extends Logic
{
protected $project;
protected $domain;
protected $type;
protected $page_size = 100;
public function __construct()
{
$this->checkAuth();
}
/**
* 校验权限
* @throws \App\Exceptions\AsideGlobalException
* @throws \App\Exceptions\BsideGlobalException
* @author zbj
* @date 2023/11/10
*/
public function checkAuth()
{
$request = request();
$site_token = $request->header('site-token');
$domain = $request->input('domain');
if (!$site_token) {
$this->fail('参数异常');
}
$this->project = Project::where('site_token', $site_token)->first();
if (!$this->project) {
$this->fail('授权码无效');
}
$domain_info = DomainInfo::where('project_id', $this->project->id)->where('domain', $domain)->first();
if (!$domain_info) {
$this->fail('域名不匹配');
}
$this->domain = 'https://' . $domain_info['domain'] . '/';
$this->type = $request->input('type', '');
}
public function collect_data()
{
ProjectServer::useProject($this->project->id);
$action = $this->type;
return $this->$action();
}
public function __call($name, $param)
{
return [];
}
public function product()
{
$this->model = new Product();
$where[] = ['status' => Product::STATUS_ON];
$sort = ['sort' => 'desc'];
$columns = ['title', 'content', 'gallery', 'seo_mate', 'intro', 'route', 'keyword_id'];
$list = self::getList($where,$sort, $columns, $this->page_size);
$data =[];
foreach ($list['list'] as $item){
//关键词标签 没有就取seo 键词
$keyword = '';
if($item['keyword_id']){
$keyword = Keyword::whereIn('id', $item['keyword_id'])->pluck('title')->toArray();
if($keyword){
$keyword = implode(',', $keyword);
}
}
$keyword = $keyword ?: ($item['seo_mate']['keyword'] ?? '');
$data[] = [
'title' => $item['title'],
'url' => $this->domain . $item['route'],
'keywords' => $keyword,
'desc' => strip_tags($item['intro']?:''),
'content' => strip_tags($item['content'] ?: ''),
'images' => getImageUrl(array_column($item['gallery'] ?: [], 'url'))
];
}
$list['list'] = $data;
return $list;
}
public function news()
{
$this->model = new News();
$where[] = ['status' => News::STATUS_ONE];
$sort = ['sort' => 'desc'];
$columns = ['name', 'text', 'image', 'seo_keywords', 'remark', 'url'];
$list = self::getList($where,$sort, $columns, $this->page_size);
$data =[];
foreach ($list['list'] as $item){
$data[] = [
'title' => $item['name'],
'url' => $this->domain . $item['url'],
'keywords' => $item['seo_keywords'],
'desc' => strip_tags($item['remark']?:''),
'content' => strip_tags($item['text'] ?: ''),
'images' => getImageUrl([$item['image']] ?:[])
];
}
$list['list'] = $data;
return $list;
}
public function blog()
{
$this->model = new Blog();
$where[] = ['status' => Blog::STATUS_ONE];
$sort = ['sort' => 'desc'];
$columns = ['name', 'text', 'image', 'seo_keywords', 'remark', 'url'];
$list = self::getList($where,$sort, $columns, $this->page_size);
$data =[];
foreach ($list['list'] as $item){
$data[] = [
'title' => $item['name'],
'url' => $this->domain . $item['url'],
'keywords' => $item['seo_keywords'],
'desc' => strip_tags($item['remark']?:''),
'content' => strip_tags($item['text'] ?: ''),
'images' => getImageUrl([$item['image']] ?:[])
];
}
$list['list'] = $data;
return $list;
}
}