|
|
|
1
|
+<?php
|
|
|
|
2
|
+
|
|
|
|
3
|
+namespace App\Http\Logic\Aside;
|
|
|
|
4
|
+
|
|
|
|
5
|
+use App\Helper\Arr;
|
|
|
|
6
|
+use App\Http\Logic\Logic;
|
|
|
|
7
|
+use App\Models\Blog\Blog;
|
|
|
|
8
|
+use App\Models\Domain\DomainInfo;
|
|
|
|
9
|
+use App\Models\News\News;
|
|
|
|
10
|
+use App\Models\Product\Keyword;
|
|
|
|
11
|
+use App\Models\Product\Product;
|
|
|
|
12
|
+use App\Models\Project\Project;
|
|
|
|
13
|
+use App\Services\ProjectServer;
|
|
|
|
14
|
+
|
|
|
|
15
|
+
|
|
|
|
16
|
+/**
|
|
|
|
17
|
+ * Class CollectLogic
|
|
|
|
18
|
+ * @package App\Http\Logic\Aside
|
|
|
|
19
|
+ * @author zbj
|
|
|
|
20
|
+ * @date 2023/11/10
|
|
|
|
21
|
+ */
|
|
|
|
22
|
+class CollectLogic extends Logic
|
|
|
|
23
|
+{
|
|
|
|
24
|
+ protected $project;
|
|
|
|
25
|
+ protected $domain;
|
|
|
|
26
|
+ protected $type;
|
|
|
|
27
|
+ protected $page_size = 100;
|
|
|
|
28
|
+
|
|
|
|
29
|
+ public function __construct()
|
|
|
|
30
|
+ {
|
|
|
|
31
|
+ $this->checkAuth();
|
|
|
|
32
|
+ }
|
|
|
|
33
|
+
|
|
|
|
34
|
+ /**
|
|
|
|
35
|
+ * 校验权限
|
|
|
|
36
|
+ * @throws \App\Exceptions\AsideGlobalException
|
|
|
|
37
|
+ * @throws \App\Exceptions\BsideGlobalException
|
|
|
|
38
|
+ * @author zbj
|
|
|
|
39
|
+ * @date 2023/11/10
|
|
|
|
40
|
+ */
|
|
|
|
41
|
+ public function checkAuth()
|
|
|
|
42
|
+ {
|
|
|
|
43
|
+ $request = request();
|
|
|
|
44
|
+ $site_token = $request->header('site-token');
|
|
|
|
45
|
+ $domain = $request->input('domain');
|
|
|
|
46
|
+ if (!$site_token) {
|
|
|
|
47
|
+ $this->fail('参数异常');
|
|
|
|
48
|
+ }
|
|
|
|
49
|
+ $this->project = Project::where('site_token', $site_token)->first();
|
|
|
|
50
|
+ if (!$this->project) {
|
|
|
|
51
|
+ $this->fail('授权码无效');
|
|
|
|
52
|
+ }
|
|
|
|
53
|
+ $domain_info = DomainInfo::where('project_id', $this->project->id)->where('domain', $domain)->first();
|
|
|
|
54
|
+ if (!$domain_info) {
|
|
|
|
55
|
+ $this->fail('域名不匹配');
|
|
|
|
56
|
+ }
|
|
|
|
57
|
+ $this->domain = 'https://' . $domain_info['domain'] . '/';
|
|
|
|
58
|
+ $this->type = $request->input('type', '');
|
|
|
|
59
|
+ }
|
|
|
|
60
|
+
|
|
|
|
61
|
+ public function collect_data()
|
|
|
|
62
|
+ {
|
|
|
|
63
|
+ ProjectServer::useProject($this->project->id);
|
|
|
|
64
|
+ $action = $this->type;
|
|
|
|
65
|
+ return $this->$action();
|
|
|
|
66
|
+ }
|
|
|
|
67
|
+
|
|
|
|
68
|
+ public function __call($name, $param)
|
|
|
|
69
|
+ {
|
|
|
|
70
|
+ return [];
|
|
|
|
71
|
+ }
|
|
|
|
72
|
+
|
|
|
|
73
|
+
|
|
|
|
74
|
+ public function product()
|
|
|
|
75
|
+ {
|
|
|
|
76
|
+ $this->model = new Product();
|
|
|
|
77
|
+ $where[] = ['status' => Product::STATUS_ON];
|
|
|
|
78
|
+ $sort = ['sort' => 'desc'];
|
|
|
|
79
|
+ $columns = ['title', 'content', 'gallery', 'seo_mate', 'intro', 'route', 'keyword_id'];
|
|
|
|
80
|
+ $list = self::getList($where,$sort, $columns, $this->page_size);
|
|
|
|
81
|
+ $data =[];
|
|
|
|
82
|
+ foreach ($list['list'] as $item){
|
|
|
|
83
|
+ //关键词标签 没有就取seo 键词
|
|
|
|
84
|
+ if($item['keyword_id']){
|
|
|
|
85
|
+ $keyword = Keyword::whereIn('id', $item['keyword_id'])->pluck('title')->toArray();
|
|
|
|
86
|
+ if($keyword){
|
|
|
|
87
|
+ $keyword = implode(',', $keyword);
|
|
|
|
88
|
+ }
|
|
|
|
89
|
+ }
|
|
|
|
90
|
+ $keyword = $keyword ?: ($item['seo_mate']['keyword'] ?? '');
|
|
|
|
91
|
+ $data[] = [
|
|
|
|
92
|
+ 'title' => $item['title'],
|
|
|
|
93
|
+ 'url' => $this->domain . $item['route'],
|
|
|
|
94
|
+ 'keywords' => $keyword,
|
|
|
|
95
|
+ 'description' => strip_tags($item['intro']?:''),
|
|
|
|
96
|
+ 'content' => strip_tags($item['content'] ?: ''),
|
|
|
|
97
|
+ 'img' => array_column($item['gallery'] ?: [], 'url')
|
|
|
|
98
|
+ ];
|
|
|
|
99
|
+ }
|
|
|
|
100
|
+ $list['list'] = $data;
|
|
|
|
101
|
+ return $list;
|
|
|
|
102
|
+ }
|
|
|
|
103
|
+
|
|
|
|
104
|
+ public function news()
|
|
|
|
105
|
+ {
|
|
|
|
106
|
+ $this->model = new News();
|
|
|
|
107
|
+ $where[] = ['status' => News::STATUS_ONE];
|
|
|
|
108
|
+ $sort = ['sort' => 'desc'];
|
|
|
|
109
|
+ $columns = ['name', 'text', 'image', 'seo_keywords', 'remark', 'url'];
|
|
|
|
110
|
+ $list = self::getList($where,$sort, $columns, $this->page_size);
|
|
|
|
111
|
+ $data =[];
|
|
|
|
112
|
+ foreach ($list['list'] as $item){
|
|
|
|
113
|
+ $data[] = [
|
|
|
|
114
|
+ 'title' => $item['name'],
|
|
|
|
115
|
+ 'url' => $this->domain . $item['url'],
|
|
|
|
116
|
+ 'keywords' => $item['seo_keywords'],
|
|
|
|
117
|
+ 'description' => strip_tags($item['remark']?:''),
|
|
|
|
118
|
+ 'content' => strip_tags($item['text'] ?: ''),
|
|
|
|
119
|
+ 'img' => $item['image'] ?:''
|
|
|
|
120
|
+ ];
|
|
|
|
121
|
+ }
|
|
|
|
122
|
+ $list['list'] = $data;
|
|
|
|
123
|
+ return $list;
|
|
|
|
124
|
+ }
|
|
|
|
125
|
+
|
|
|
|
126
|
+ public function blog()
|
|
|
|
127
|
+ {
|
|
|
|
128
|
+ $this->model = new Blog();
|
|
|
|
129
|
+ $where[] = ['status' => Blog::STATUS_ONE];
|
|
|
|
130
|
+ $sort = ['sort' => 'desc'];
|
|
|
|
131
|
+ $columns = ['name', 'text', 'image', 'seo_keywords', 'remark', 'url'];
|
|
|
|
132
|
+ $list = self::getList($where,$sort, $columns, $this->page_size);
|
|
|
|
133
|
+ $data =[];
|
|
|
|
134
|
+ foreach ($list['list'] as $item){
|
|
|
|
135
|
+ $data[] = [
|
|
|
|
136
|
+ 'title' => $item['name'],
|
|
|
|
137
|
+ 'url' => $this->domain . $item['url'],
|
|
|
|
138
|
+ 'keywords' => $item['seo_keywords'],
|
|
|
|
139
|
+ 'description' => strip_tags($item['remark']?:''),
|
|
|
|
140
|
+ 'content' => strip_tags($item['text'] ?: ''),
|
|
|
|
141
|
+ 'img' => $item['image'] ?:''
|
|
|
|
142
|
+ ];
|
|
|
|
143
|
+ }
|
|
|
|
144
|
+ $list['list'] = $data;
|
|
|
|
145
|
+ return $list;
|
|
|
|
146
|
+ }
|
|
|
|
147
|
+} |