|
|
|
1
|
+<?php
|
|
|
|
2
|
+/**
|
|
|
|
3
|
+ * @remark :
|
|
|
|
4
|
+ * @name :OptimizationReportController.php
|
|
|
|
5
|
+ * @author :lyh
|
|
|
|
6
|
+ * @method :post
|
|
|
|
7
|
+ * @time :2024/3/7 15:57
|
|
|
|
8
|
+ */
|
|
|
|
9
|
+
|
|
|
|
10
|
+namespace App\Http\Controllers\Api;
|
|
|
|
11
|
+
|
|
|
|
12
|
+use App\Enums\Common\Code;
|
|
|
|
13
|
+use App\Helper\Arr;
|
|
|
|
14
|
+use App\Helper\FormGlobalsoApi;
|
|
|
|
15
|
+use App\Http\Logic\Aside\Project\DomainInfoLogic;
|
|
|
|
16
|
+use App\Http\Logic\Aside\Project\ProjectLogic;
|
|
|
|
17
|
+use App\Models\Domain\DomainInfo;
|
|
|
|
18
|
+use App\Models\HomeCount\Count;
|
|
|
|
19
|
+use App\Models\Inquiry\InquiryForm;
|
|
|
|
20
|
+use App\Models\Inquiry\InquiryFormData;
|
|
|
|
21
|
+use App\Models\Inquiry\InquiryOther;
|
|
|
|
22
|
+use App\Models\Project\Project;
|
|
|
|
23
|
+use App\Models\RankData\ExternalLinks;
|
|
|
|
24
|
+use App\Models\RankData\IndexedPages;
|
|
|
|
25
|
+use App\Models\RankData\RankData;
|
|
|
|
26
|
+use App\Models\RankData\RankWeek;
|
|
|
|
27
|
+use App\Models\RankData\Speed;
|
|
|
|
28
|
+use App\Models\Visit\Visit;
|
|
|
|
29
|
+use App\Models\Visit\VisitItem;
|
|
|
|
30
|
+use App\Services\ProjectServer;
|
|
|
|
31
|
+use App\Utils\HttpUtils;
|
|
|
|
32
|
+use Carbon\Carbon;
|
|
|
|
33
|
+use GuzzleHttp\Exception\GuzzleException;
|
|
|
|
34
|
+use Illuminate\Support\Facades\Cache;
|
|
|
|
35
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
36
|
+
|
|
|
|
37
|
+class OptimizationReportController extends BaseController
|
|
|
|
38
|
+{
|
|
|
|
39
|
+ /**
|
|
|
|
40
|
+ * @remark :优化报告
|
|
|
|
41
|
+ * @name :getOptimizationReport
|
|
|
|
42
|
+ * @author :lyh
|
|
|
|
43
|
+ * @method :post
|
|
|
|
44
|
+ * @time :2024/3/7 15:54
|
|
|
|
45
|
+ */
|
|
|
|
46
|
+ public function getOptimizationReport(){
|
|
|
|
47
|
+ ProjectServer::useProject($this->param['project_id']);
|
|
|
|
48
|
+ $data = [];
|
|
|
|
49
|
+ $projectModel = new Project();
|
|
|
|
50
|
+ $projectInfo = $projectModel->with('payment')->with('deploy_build')
|
|
|
|
51
|
+ ->with('deploy_optimize')->with('online_check')->where(['id'=>$this->param['project_id']])->first();
|
|
|
|
52
|
+ $domainModel = new DomainInfo();
|
|
|
|
53
|
+ $domain_info = $domainModel->where('project_id', $this->param['project_id'])->first();
|
|
|
|
54
|
+ if(!$domain_info){
|
|
|
|
55
|
+ return [];
|
|
|
|
56
|
+ }else{
|
|
|
|
57
|
+ $domain_info = [
|
|
|
|
58
|
+ 'domain' => 'https://'.$domain_info['domain'].'/',
|
|
|
|
59
|
+ 'domain_info' => date('Y-m-d', strtotime($domain_info['domain_start_time'])) . ' - ' .date('Y-m-d', strtotime($domain_info['domain_end_time'])),
|
|
|
|
60
|
+ 'cert_info' => date('Y-m-d', strtotime($domain_info['certificate_start_time'])) . ' - ' .date('Y-m-d', strtotime($domain_info['certificate_end_time'])),
|
|
|
|
61
|
+ ];
|
|
|
|
62
|
+ }
|
|
|
|
63
|
+ //方案信息
|
|
|
|
64
|
+ $data['plan_information'] = $this->plan_information($projectInfo);
|
|
|
|
65
|
+ //排名数据
|
|
|
|
66
|
+ $data['first_total'] = $this->first_total();
|
|
|
|
67
|
+ //关键词排名分析图
|
|
|
|
68
|
+ $data['rank_chat'] = $this->rank_chat();
|
|
|
|
69
|
+ //关键词排名明细
|
|
|
|
70
|
+ $data['keywords_rank_list'] = $this->keywords_rank_list($this->param['project_id'],$projectInfo);
|
|
|
|
71
|
+ //pv_ip统计
|
|
|
|
72
|
+ $data['pv_ip'] = $this->pv_ip($domain_info['domain']);
|
|
|
|
73
|
+ //30天统计
|
|
|
|
74
|
+ $data['count_30'] = $this->count_30_total();
|
|
|
|
75
|
+ //访问国家前10
|
|
|
|
76
|
+ $data['access_country_count'] = $this->access_country_count();
|
|
|
|
77
|
+ //外链周期分析
|
|
|
|
78
|
+ $external_links = ExternalLinks::where('project_id', $this->param['project_id'])->first();
|
|
|
|
79
|
+ //SEO数据周期分析图 外链数
|
|
|
|
80
|
+ $data['external_links_chat'] = [
|
|
|
|
81
|
+ 'labels' => array_keys($external_links['data'] ?? []),
|
|
|
|
82
|
+ 'data' => array_values($external_links['data'] ?? []),
|
|
|
|
83
|
+ ];
|
|
|
|
84
|
+ $indexed_pages = IndexedPages::where('project_id', $this->param['project_id'])->first();
|
|
|
|
85
|
+ //SEO数据周期分析图 收录数
|
|
|
|
86
|
+ $data['indexed_pages_chat'] = [
|
|
|
|
87
|
+ 'labels' => array_keys($indexed_pages['data'] ?? []),
|
|
|
|
88
|
+ 'data' => array_values($indexed_pages['data'] ?? []),
|
|
|
|
89
|
+ ];
|
|
|
|
90
|
+ //月统计报告
|
|
|
|
91
|
+ $data['month_count'] = $this->currentMonthCount();
|
|
|
|
92
|
+ //测速
|
|
|
|
93
|
+ $speed = Speed::where('project_id', $this->param['project_id'])->first();
|
|
|
|
94
|
+ $data['speed'] = $speed['data'] ?? [];
|
|
|
|
95
|
+ //询盘
|
|
|
|
96
|
+ $data['inquiry'] = $this->getApiList($projectInfo);
|
|
|
|
97
|
+ DB::disconnect('custom_mysql');
|
|
|
|
98
|
+ $this->response('success',Code::SUCCESS,$data);
|
|
|
|
99
|
+ }
|
|
|
|
100
|
+
|
|
|
|
101
|
+ /**
|
|
|
|
102
|
+ * @remark :获取当前月数据统计
|
|
|
|
103
|
+ * @name :currentMonth
|
|
|
|
104
|
+ * @author :lyh
|
|
|
|
105
|
+ * @method :post
|
|
|
|
106
|
+ * @time :2023/7/3 9:55
|
|
|
|
107
|
+ */
|
|
|
|
108
|
+ public function currentMonthCount(){
|
|
|
|
109
|
+ // 获取当前月的开始时间
|
|
|
|
110
|
+ $startTime = date('Y-m-01 00:00:00', strtotime('2024-01'));
|
|
|
|
111
|
+ // 获取当前月的结束时间
|
|
|
|
112
|
+ $endTime = date('Y-m-t 23:59:59', strtotime('2024-01'));
|
|
|
|
113
|
+ $arr = [];
|
|
|
|
114
|
+ $arr = $this->inquiryCount($arr,$startTime,$endTime,$this->user['domain']);
|
|
|
|
115
|
+ $arr = $this->flowCount($arr,$startTime,$endTime,$this->user['project_id']);
|
|
|
|
116
|
+ $arr = $this->sourceCount($arr,$startTime,$endTime,$this->user['domain']);
|
|
|
|
117
|
+ $arr['month'] = date('Y-m',time());
|
|
|
|
118
|
+ return $arr;
|
|
|
|
119
|
+ }
|
|
|
|
120
|
+
|
|
|
|
121
|
+ /**
|
|
|
|
122
|
+ * @param $domain
|
|
|
|
123
|
+ * @param $project_id
|
|
|
|
124
|
+ * @remark :询盘按月统计
|
|
|
|
125
|
+ * @name :inquiryCount
|
|
|
|
126
|
+ * @author :lyh
|
|
|
|
127
|
+ * @method :post
|
|
|
|
128
|
+ * @time :2023/6/30 14:29
|
|
|
|
129
|
+ */
|
|
|
|
130
|
+ public function inquiryCount(&$arr,&$startTime,&$endTime,$domain){
|
|
|
|
131
|
+ $inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000);
|
|
|
|
132
|
+ if(!empty($inquiry_list)){
|
|
|
|
133
|
+ //总数
|
|
|
|
134
|
+ $arr['total'] = $inquiry_list['data']['total'] ?? 0;
|
|
|
|
135
|
+ //数据详情
|
|
|
|
136
|
+ $data = $inquiry_list['data']['data'] ?? '';
|
|
|
|
137
|
+ $arr['month_total'] = 0;
|
|
|
|
138
|
+ $countryArr = [];
|
|
|
|
139
|
+ if(isset($data) && !empty($data)){
|
|
|
|
140
|
+ foreach ($data as $v){
|
|
|
|
141
|
+ if(($startTime.' 00:00:00' <= $v['submit_time']) && $v['submit_time'] <= $endTime.' 23:59:59'){
|
|
|
|
142
|
+ $arr['month_total']++;
|
|
|
|
143
|
+ if(isset($countryArr[$v['country']])){
|
|
|
|
144
|
+ $countryArr[$v['country']]++;
|
|
|
|
145
|
+ }else{
|
|
|
|
146
|
+ $countryArr[$v['country']] = 1;
|
|
|
|
147
|
+ }
|
|
|
|
148
|
+ }
|
|
|
|
149
|
+ }
|
|
|
|
150
|
+ }
|
|
|
|
151
|
+ }
|
|
|
|
152
|
+ //加上其他询盘
|
|
|
|
153
|
+ $arr['total'] += InquiryFormData::getCount();
|
|
|
|
154
|
+ $arr['month_total'] += InquiryFormData::getCount([$startTime, $endTime]);
|
|
|
|
155
|
+ $countryData = InquiryFormData::getCountryCount([$startTime, $endTime]);
|
|
|
|
156
|
+ foreach ($countryData as $v1){
|
|
|
|
157
|
+ if(isset($countryArr[$v1['country']])){
|
|
|
|
158
|
+ $countryArr[$v1['country']] += $v1['count'];
|
|
|
|
159
|
+ }else{
|
|
|
|
160
|
+ $countryArr[$v1['country']] = $v1['count'];
|
|
|
|
161
|
+ }
|
|
|
|
162
|
+ }
|
|
|
|
163
|
+ arsort($countryArr);
|
|
|
|
164
|
+ $top20 = array_slice($countryArr, 0, 15, true);
|
|
|
|
165
|
+ $arr['country'] = $top20;
|
|
|
|
166
|
+ return $arr;
|
|
|
|
167
|
+ }
|
|
|
|
168
|
+
|
|
|
|
169
|
+ /**
|
|
|
|
170
|
+ * @remark :流量统计
|
|
|
|
171
|
+ * @name :flowCount
|
|
|
|
172
|
+ * @author :lyh
|
|
|
|
173
|
+ * @method :post
|
|
|
|
174
|
+ * @time :2023/6/30 14:31
|
|
|
|
175
|
+ */
|
|
|
|
176
|
+ public function flowCount(&$arr,&$startTime,&$endTime,$project_id){
|
|
|
|
177
|
+ $pv_ip = DB::table('gl_count')
|
|
|
|
178
|
+ ->where(['project_id'=>$project_id])
|
|
|
|
179
|
+ ->whereBetween('date', [$startTime,$endTime])
|
|
|
|
180
|
+ ->select(DB::raw('SUM(pv_num) as pv_num'), DB::raw('SUM(ip_num) as ip_num'))
|
|
|
|
181
|
+ ->orderBy('id','desc')
|
|
|
|
182
|
+ ->first();
|
|
|
|
183
|
+ $arr['pv'] = $pv_ip->pv_num;
|
|
|
|
184
|
+ $arr['ip'] = $pv_ip->ip_num;
|
|
|
|
185
|
+ $arr['rate'] = 0;
|
|
|
|
186
|
+ if($arr['ip'] != 0){
|
|
|
|
187
|
+ $arr['rate'] = round(($arr['month_total'] / $arr['ip']) * 100,2);
|
|
|
|
188
|
+ }
|
|
|
|
189
|
+ return $arr;
|
|
|
|
190
|
+ }
|
|
|
|
191
|
+
|
|
|
|
192
|
+ /**
|
|
|
|
193
|
+ * @remark :来源访问前8
|
|
|
|
194
|
+ * @name :sourceCount
|
|
|
|
195
|
+ * @author :lyh
|
|
|
|
196
|
+ * @method :post
|
|
|
|
197
|
+ * @time :2023/6/30 16:14
|
|
|
|
198
|
+ */
|
|
|
|
199
|
+ public function sourceCount(&$arr,$startTime,$endTime,$domain){
|
|
|
|
200
|
+ //访问来源前10
|
|
|
|
201
|
+ $source = DB::connection('custom_mysql')->table('gl_customer_visit')
|
|
|
|
202
|
+ ->select('referrer_url', DB::raw('COUNT(*) as count'))
|
|
|
|
203
|
+ ->groupBy('referrer_url')
|
|
|
|
204
|
+ ->where('referrer_url','!=','')
|
|
|
|
205
|
+ ->whereBetween('updated_date', [$startTime,$endTime])
|
|
|
|
206
|
+ ->orderByDesc('count')->limit(10)->get()->toArray();
|
|
|
|
207
|
+ $arr['source'] = $source;
|
|
|
|
208
|
+ //访问国家前15
|
|
|
|
209
|
+ $query = DB::connection('custom_mysql')->table('gl_customer_visit')
|
|
|
|
210
|
+ ->select('country',DB::raw('COUNT(*) as ip'),DB::raw('SUM(depth) as pv'))
|
|
|
|
211
|
+ ->groupBy('country');
|
|
|
|
212
|
+ if(isset($this->project['is_record_china_visit']) && ($this->project['is_record_china_visit'] == 0)){
|
|
|
|
213
|
+ $query->where('country','<>','中国');
|
|
|
|
214
|
+ }
|
|
|
|
215
|
+ $source_country = $query->whereBetween('updated_date', [$startTime,$endTime])
|
|
|
|
216
|
+ ->orderBy('ip','desc')->limit(15)->get()->toArray();
|
|
|
|
217
|
+ $arr['source_country'] = $source_country;
|
|
|
|
218
|
+ //受访界面前15
|
|
|
|
219
|
+ $referrer_url = DB::connection('custom_mysql')->table('gl_customer_visit')
|
|
|
|
220
|
+ ->select('url',DB::raw('COUNT(*) as num'))
|
|
|
|
221
|
+ ->orderBy('num','desc')
|
|
|
|
222
|
+ ->whereBetween('updated_date', [$startTime,$endTime])
|
|
|
|
223
|
+ ->groupBy('url')
|
|
|
|
224
|
+ ->limit(15)->get()->toArray();
|
|
|
|
225
|
+ $arr['referrer_url'] = $referrer_url;
|
|
|
|
226
|
+ //访问断后
|
|
|
|
227
|
+ $referrer_port = DB::connection('custom_mysql')->table('gl_customer_visit')
|
|
|
|
228
|
+ ->select('device_port',DB::raw('COUNT(*) as num'))
|
|
|
|
229
|
+ ->orderBy('num','desc')
|
|
|
|
230
|
+ ->whereBetween('updated_date', [$startTime,$endTime])
|
|
|
|
231
|
+ ->groupBy('device_port')
|
|
|
|
232
|
+ ->limit(15)->get()->toArray();
|
|
|
|
233
|
+ $arr['referrer_port'] = $referrer_port;
|
|
|
|
234
|
+ return $arr;
|
|
|
|
235
|
+ }
|
|
|
|
236
|
+
|
|
|
|
237
|
+ public function getApiList($projectInfo,$export = false)
|
|
|
|
238
|
+ {
|
|
|
|
239
|
+ $this->form_globalso_api = new FormGlobalsoApi();
|
|
|
|
240
|
+ if(isset($this->request['row'])){
|
|
|
|
241
|
+ $page_size = $this->request['row'];
|
|
|
|
242
|
+ }else{
|
|
|
|
243
|
+ $page_size = $export ? 1000 : 20;
|
|
|
|
244
|
+ }
|
|
|
|
245
|
+ $search = $this->request['search'] ?: '';
|
|
|
|
246
|
+ $page = $this->request['page'] ?: 1;
|
|
|
|
247
|
+ $domain = (!empty($projectInfo['deploy_optimize']['domain']) ? ((new DomainInfo())->getDomain($projectInfo['deploy_optimize']['domain'])) : '');
|
|
|
|
248
|
+ $list = $this->form_globalso_api->getInquiryList($domain, $search, $page, $page_size);
|
|
|
|
249
|
+ //处理格式 免得前端又改
|
|
|
|
250
|
+ $data = [
|
|
|
|
251
|
+ "list" => [],
|
|
|
|
252
|
+ "total" => 0,
|
|
|
|
253
|
+ "page" => $page,
|
|
|
|
254
|
+ "total_page" => 1,
|
|
|
|
255
|
+ "size" => $page_size
|
|
|
|
256
|
+ ];
|
|
|
|
257
|
+ if (!empty($list['status']) && $list['status'] == 200) {
|
|
|
|
258
|
+ foreach ($list['data']['data'] as $item) {
|
|
|
|
259
|
+ $data['list'][] = $item;
|
|
|
|
260
|
+ }
|
|
|
|
261
|
+ $data['total'] = $list['data']['total'];
|
|
|
|
262
|
+ $data['total_page'] = $list['data']['last_page'];
|
|
|
|
263
|
+ }
|
|
|
|
264
|
+ return $data;
|
|
|
|
265
|
+ }
|
|
|
|
266
|
+
|
|
|
|
267
|
+ /**
|
|
|
|
268
|
+ * @remark :方案信息
|
|
|
|
269
|
+ * @name :plan_information
|
|
|
|
270
|
+ * @author :lyh
|
|
|
|
271
|
+ * @method :post
|
|
|
|
272
|
+ * @time :2024/3/7 17:00
|
|
|
|
273
|
+ */
|
|
|
|
274
|
+ public function plan_information($projectInfo){
|
|
|
|
275
|
+ return [
|
|
|
|
276
|
+ 'company' => $projectInfo['company'],
|
|
|
|
277
|
+ 'domain' => $domain_info['domain'] ?? '',
|
|
|
|
278
|
+ 'domain_info' => $domain_info['domain_info'] ?? '',
|
|
|
|
279
|
+ 'cert_info' => $domain_info['cert_info'] ?? '',
|
|
|
|
280
|
+ 'plan' => Project::planMap()[$projectInfo['deploy_build']['plan']],
|
|
|
|
281
|
+ 'keyword_num' => $projectInfo['deploy_build']['keyword_num'],
|
|
|
|
282
|
+ 'compliance_day' => $projectInfo['finish_remain_day'] ?? 0,
|
|
|
|
283
|
+ 'start_time' => $projectInfo['deploy_optimize']['start_date'] ?? '',
|
|
|
|
284
|
+ 'remain_day' => $projectInfo['deploy_build']['service_duration'] - ($projectInfo['finish_remain_day'] ?? 0),
|
|
|
|
285
|
+ ];
|
|
|
|
286
|
+ }
|
|
|
|
287
|
+
|
|
|
|
288
|
+ /**
|
|
|
|
289
|
+ * @remark :排名数据
|
|
|
|
290
|
+ * @name :ce
|
|
|
|
291
|
+ * @author :lyh
|
|
|
|
292
|
+ * @method :post
|
|
|
|
293
|
+ * @time :2024/3/7 16:58
|
|
|
|
294
|
+ */
|
|
|
|
295
|
+ public function first_total(){
|
|
|
|
296
|
+ $rank = RankData::where('project_id', $this->param['project_id'])->first();
|
|
|
|
297
|
+ return [
|
|
|
|
298
|
+ 'first_num' => $rank['first_num'] ?? 0,
|
|
|
|
299
|
+ 'first_page_num' => $rank['first_page_num'] ?? 0,
|
|
|
|
300
|
+ 'first_three_pages_num' => $rank['first_three_pages_num'] ?? 0,
|
|
|
|
301
|
+ 'first_five_pages_num' => $rank['first_five_pages_num'] ?? 0,
|
|
|
|
302
|
+ 'first_ten_pages_num' => $rank['first_ten_pages_num'] ?? 0,
|
|
|
|
303
|
+ 'indexed_pages_num' => $rank['indexed_pages_num'] ?? 0,
|
|
|
|
304
|
+ 'external_links_num' => $external_links['total'] ?? 0,
|
|
|
|
305
|
+ ];
|
|
|
|
306
|
+ }
|
|
|
|
307
|
+
|
|
|
|
308
|
+ /**
|
|
|
|
309
|
+ * @remark :关键词排名分析图
|
|
|
|
310
|
+ * @name :ceshi
|
|
|
|
311
|
+ * @author :lyh
|
|
|
|
312
|
+ * @method :post
|
|
|
|
313
|
+ * @time :2024/3/7 17:39
|
|
|
|
314
|
+ */
|
|
|
|
315
|
+ public function rank_chat(){
|
|
|
|
316
|
+ //关键词排名分析图
|
|
|
|
317
|
+ $rank_week = RankWeek::where('project_id', $this->param['project_id'])->first();
|
|
|
|
318
|
+ return [
|
|
|
|
319
|
+ 'data' => $rank_week['data'] ?? [],
|
|
|
|
320
|
+ 'labels' => $rank_week['date'] ?? [],
|
|
|
|
321
|
+ ];
|
|
|
|
322
|
+ }
|
|
|
|
323
|
+
|
|
|
|
324
|
+ /**
|
|
|
|
325
|
+ * @remark :30天统计
|
|
|
|
326
|
+ * @name :count_30_total
|
|
|
|
327
|
+ * @author :lyh
|
|
|
|
328
|
+ * @method :post
|
|
|
|
329
|
+ * @time :2024/3/7 16:56
|
|
|
|
330
|
+ */
|
|
|
|
331
|
+ public function count_30_total(){
|
|
|
|
332
|
+ $count_param = [
|
|
|
|
333
|
+ 'date' => ['between',[now()->subDays(30)->startOfDay()->toDateString(),now()->startOfDay()->toDateString()]],
|
|
|
|
334
|
+ 'project_id' => $this->user['project_id']
|
|
|
|
335
|
+ ];
|
|
|
|
336
|
+ return (new Count())->list($count_param,'date',['id','pv_num','ip_num','date']);
|
|
|
|
337
|
+ }
|
|
|
|
338
|
+
|
|
|
|
339
|
+ /**
|
|
|
|
340
|
+ * @remark :pv_ip
|
|
|
|
341
|
+ * @name :visit_data
|
|
|
|
342
|
+ * @author :lyh
|
|
|
|
343
|
+ * @method :post
|
|
|
|
344
|
+ * @time :2024/3/7 16:53
|
|
|
|
345
|
+ */
|
|
|
|
346
|
+ public function pv_ip($domain){
|
|
|
|
347
|
+ $pv = (new VisitItem())->count();
|
|
|
|
348
|
+ $ip = (new Visit())->count();
|
|
|
|
349
|
+ $inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000);
|
|
|
|
350
|
+ if(!empty($inquiry_list)){
|
|
|
|
351
|
+ $total = $inquiry_list['data']['total'] ?? 0;
|
|
|
|
352
|
+ }
|
|
|
|
353
|
+ return [
|
|
|
|
354
|
+ 'total_pv'=>$pv,
|
|
|
|
355
|
+ 'total_ip'=>$ip,
|
|
|
|
356
|
+ 'conversion_rate' => (isset($total) && !empty($total) && ($ip != 0)) ? round(($total / $ip) * 10,2) : 0,
|
|
|
|
357
|
+ ];
|
|
|
|
358
|
+ }
|
|
|
|
359
|
+
|
|
|
|
360
|
+ /**
|
|
|
|
361
|
+ * @name :(访问国家统计)access_country_count
|
|
|
|
362
|
+ * @author :lyh
|
|
|
|
363
|
+ * @method :post
|
|
|
|
364
|
+ * @time :2023/5/24 15:56
|
|
|
|
365
|
+ */
|
|
|
|
366
|
+ public function access_country_count(){
|
|
|
|
367
|
+ $customerVisitModel = new Visit();
|
|
|
|
368
|
+ $data = $customerVisitModel->select('country',DB::raw('COUNT(*) as ip'),DB::raw('SUM(depth) as pv'))
|
|
|
|
369
|
+ ->groupBy('country')
|
|
|
|
370
|
+ ->orderBy('ip','desc')->limit(11)->get()->toArray();
|
|
|
|
371
|
+ $result =array();
|
|
|
|
372
|
+ if(!empty($data)){
|
|
|
|
373
|
+ foreach ($data as $k => $v){
|
|
|
|
374
|
+ if(($this->project['is_record_china_visit'] != 1) && ($v['country'] == '中国')){
|
|
|
|
375
|
+ continue;
|
|
|
|
376
|
+ }else{
|
|
|
|
377
|
+ $v['pv'] = (int)$v['pv'];
|
|
|
|
378
|
+ $result[] = $v;
|
|
|
|
379
|
+ }
|
|
|
|
380
|
+ }
|
|
|
|
381
|
+ }
|
|
|
|
382
|
+ return $result;
|
|
|
|
383
|
+ }
|
|
|
|
384
|
+
|
|
|
|
385
|
+ public function keywords_rank_list($project_id,$projectInfo,$export = false)
|
|
|
|
386
|
+ {
|
|
|
|
387
|
+ $page = 1;
|
|
|
|
388
|
+ $lang = $this->request['lang'] ?: '';
|
|
|
|
389
|
+ $api_no = $projectInfo['deploy_optimize']['api_no'] ?? '';
|
|
|
|
390
|
+ $domain = (!empty($projectInfo['deploy_optimize']['domain']) ? ((new DomainInfo())->getDomain($projectInfo['deploy_optimize']['domain'])) : '');
|
|
|
|
391
|
+ $domain_arr = parse_url($domain);
|
|
|
|
392
|
+ $domain = $domain_arr['host'] ?? $domain_arr['path'];
|
|
|
|
393
|
+ //复制站点域名
|
|
|
|
394
|
+ $ext_projects = $this->getExtendProjects();
|
|
|
|
395
|
+ $flg_ext = $this->getExtFlag($ext_projects, $domain, $api_no);
|
|
|
|
396
|
+ $ext_domain = str_replace('www.', '', $this->getExtendProjects($api_no)['ext'] ?? '');
|
|
|
|
397
|
+ //AI站点域名
|
|
|
|
398
|
+ $ai_projects = $this->getAiProjects()['data'] ?? [];
|
|
|
|
399
|
+ $flg_ai = $this->getAiFlag($ai_projects, $domain);
|
|
|
|
400
|
+ $ai_domain = str_replace('www.', '', $this->getAiProjects($domain)['domain'] ?? '');
|
|
|
|
401
|
+ $list = RankData::where('project_id', $project_id)->where('lang', $lang)->value('data') ?: [];
|
|
|
|
402
|
+ $list30 = []; //排名前三十的
|
|
|
|
403
|
+ $list30_0 = []; //排名前三十且近三天没有排名的
|
|
|
|
404
|
+ $list100 = []; //排名前100的
|
|
|
|
405
|
+ $list0 = [];//排名为0的
|
|
|
|
406
|
+ foreach ($list as $key => $v) {
|
|
|
|
407
|
+ $last = Arr::last($v);
|
|
|
|
408
|
+ $data = [];
|
|
|
|
409
|
+ //处理日期
|
|
|
|
410
|
+ foreach ($v as $date => $position) {
|
|
|
|
411
|
+ $data[date('m-d', strtotime($date . '+ 1 day'))] = $position['position'];
|
|
|
|
412
|
+ }
|
|
|
|
413
|
+ //域名类型
|
|
|
|
414
|
+ $domain_text = '主域名:' . str_replace('www.', '', $domain);
|
|
|
|
415
|
+ if (!empty($last['r'])) {
|
|
|
|
416
|
+ $domain_text = 'AI域名:' . $last['r'];
|
|
|
|
417
|
+ if (in_array($flg_ext, [1, 2]) || $flg_ai == 1) {
|
|
|
|
418
|
+ if ($last['r'] == $ai_domain) {
|
|
|
|
419
|
+ $domain_text = '星链域名:' . $ai_domain;
|
|
|
|
420
|
+ } else if ($last['r'] == $ext_domain) {
|
|
|
|
421
|
+ $domain_text = '主域名2:' . $ext_domain;
|
|
|
|
422
|
+ } else {
|
|
|
|
423
|
+ $domain_text = 'AI域名:' . $last['r'];
|
|
|
|
424
|
+ }
|
|
|
|
425
|
+ }
|
|
|
|
426
|
+ }
|
|
|
|
427
|
+ $domain_arr = explode(':', $domain_text);
|
|
|
|
428
|
+ $v = [
|
|
|
|
429
|
+ 'keyword' => $key,
|
|
|
|
430
|
+ 'domain_type' => $domain_arr[0],
|
|
|
|
431
|
+ 'domain' => $domain_arr[1],
|
|
|
|
432
|
+ 'domain_text' => $domain_text,
|
|
|
|
433
|
+ 'g' => $last['g'], //1核心关键词
|
|
|
|
434
|
+ 'position' => $data,
|
|
|
|
435
|
+ ];
|
|
|
|
436
|
+ //图片排名
|
|
|
|
437
|
+ if(isset($last['p_img'])){
|
|
|
|
438
|
+ $v['img_position'] = $last['p_img'];
|
|
|
|
439
|
+ }
|
|
|
|
440
|
+ //视频排名
|
|
|
|
441
|
+ if(isset($last['p_vid'])){
|
|
|
|
442
|
+ $v['video_position'] = $last['p_vid'];
|
|
|
|
443
|
+ }
|
|
|
|
444
|
+
|
|
|
|
445
|
+ if ($last['position'] == 0) {
|
|
|
|
446
|
+ $list0[] = $v;
|
|
|
|
447
|
+ } elseif ($last['position'] <= 30) {
|
|
|
|
448
|
+ if (($v['position'][date('m-d', strtotime('-1day'))] ?? '') == 0 ||
|
|
|
|
449
|
+ ($v['position'][date('m-d', strtotime('-2day'))] ?? '') == 0) {
|
|
|
|
450
|
+ $list30_0[] = $v;
|
|
|
|
451
|
+ } else {
|
|
|
|
452
|
+ $list30[] = $v;
|
|
|
|
453
|
+ }
|
|
|
|
454
|
+ } else {
|
|
|
|
455
|
+ $list100[] = $v;
|
|
|
|
456
|
+ }
|
|
|
|
457
|
+ }
|
|
|
|
458
|
+ //排序 排名前30的 按关键词长短排序 最近三天无排名的排后; 后30名的按排名排序
|
|
|
|
459
|
+ $list30 = collect($list30)->sortBy(function ($item) {
|
|
|
|
460
|
+ return strlen($item['keyword']);
|
|
|
|
461
|
+ })->values()->all();
|
|
|
|
462
|
+ $list30_0 = collect($list30_0)->sortBy(function ($item) {
|
|
|
|
463
|
+ return strlen($item['keyword']);
|
|
|
|
464
|
+ })->values()->all();
|
|
|
|
465
|
+ $list100 = collect($list100)->sortBy(function ($item) {
|
|
|
|
466
|
+ return Arr::last($item['position']);
|
|
|
|
467
|
+ })->values()->all();
|
|
|
|
468
|
+ $list = collect($list30)->merge($list30_0)->merge($list100)->merge($list0)->filter(function ($item) {
|
|
|
|
469
|
+ //搜索
|
|
|
|
470
|
+ if ($this->request['search']) {
|
|
|
|
471
|
+ return strpos($item['keyword'], $this->request['search']) !== false;
|
|
|
|
472
|
+ }
|
|
|
|
473
|
+ //前几名
|
|
|
|
474
|
+ if ($this->request['first']) {
|
|
|
|
475
|
+ $position = Arr::last($item['position']);
|
|
|
|
476
|
+ return $position > 0 && $position <= $this->request['first'];
|
|
|
|
477
|
+ }
|
|
|
|
478
|
+ //核心词
|
|
|
|
479
|
+ if ($this->request['g']) {
|
|
|
|
480
|
+ return $item['g'] == $this->request['g'];
|
|
|
|
481
|
+ }
|
|
|
|
482
|
+ return true;
|
|
|
|
483
|
+ })->values();
|
|
|
|
484
|
+
|
|
|
|
485
|
+ if($export){
|
|
|
|
486
|
+ return $list->toArray();
|
|
|
|
487
|
+ }
|
|
|
|
488
|
+ $data = [
|
|
|
|
489
|
+ "list" => $list->forPage($page, 100)->toArray(),
|
|
|
|
490
|
+ "total" => $list->count(),
|
|
|
|
491
|
+ "page" => $page,
|
|
|
|
492
|
+ "total_page" => ceil($list->count() / 100),
|
|
|
|
493
|
+ "size" => 100
|
|
|
|
494
|
+ ];
|
|
|
|
495
|
+ return $data;
|
|
|
|
496
|
+ }
|
|
|
|
497
|
+
|
|
|
|
498
|
+ /**
|
|
|
|
499
|
+ * 获取复制站点项目
|
|
|
|
500
|
+ * @author zbj
|
|
|
|
501
|
+ * @date 2023/5/12
|
|
|
|
502
|
+ */
|
|
|
|
503
|
+ public function getExtendProjects($api_no = null)
|
|
|
|
504
|
+ {
|
|
|
|
505
|
+ $key = 'extend_projects_list';
|
|
|
|
506
|
+ $data = Cache::get($key);
|
|
|
|
507
|
+ if (!$data) {
|
|
|
|
508
|
+ $api_url = 'http://api.quanqiusou.cn/google-rank/api/extend_projects.php';
|
|
|
|
509
|
+ try {
|
|
|
|
510
|
+ $data = HttpUtils::get($api_url, []);
|
|
|
|
511
|
+ if ($data) {
|
|
|
|
512
|
+ $data = Arr::s2a($data);
|
|
|
|
513
|
+ Cache::put($key, $data, 4 * 3600);
|
|
|
|
514
|
+ }
|
|
|
|
515
|
+ } catch (\Exception | GuzzleException $e) {
|
|
|
|
516
|
+ errorLog('复制站点项目获取失败', [], $e);
|
|
|
|
517
|
+ return false;
|
|
|
|
518
|
+ }
|
|
|
|
519
|
+ }
|
|
|
|
520
|
+ if ($api_no !== null) {
|
|
|
|
521
|
+ $data = collect($data)->where('apino', $api_no)->first();
|
|
|
|
522
|
+ return $data ?: [];
|
|
|
|
523
|
+ }
|
|
|
|
524
|
+ return $data;
|
|
|
|
525
|
+ }
|
|
|
|
526
|
+
|
|
|
|
527
|
+ /**
|
|
|
|
528
|
+ * 获取AI站点项目
|
|
|
|
529
|
+ * @author zbj
|
|
|
|
530
|
+ * @date 2023/5/12
|
|
|
|
531
|
+ */
|
|
|
|
532
|
+ public function getAiProjects($domain = null)
|
|
|
|
533
|
+ {
|
|
|
|
534
|
+ $key = 'ai_projects_list';
|
|
|
|
535
|
+ $data = Cache::get($key);
|
|
|
|
536
|
+ if (!$data) {
|
|
|
|
537
|
+ $api_url = 'https://demosite5.globalso.com/api/domain';
|
|
|
|
538
|
+ try {
|
|
|
|
539
|
+ $data = HttpUtils::get($api_url, []);
|
|
|
|
540
|
+ if ($data) {
|
|
|
|
541
|
+ $data = Arr::s2a($data);
|
|
|
|
542
|
+ Cache::put($key, $data, 4 * 3600);
|
|
|
|
543
|
+ }
|
|
|
|
544
|
+ } catch (\Exception | GuzzleException $e) {
|
|
|
|
545
|
+ errorLog('AI站点项目获取失败', [], $e);
|
|
|
|
546
|
+ return false;
|
|
|
|
547
|
+ }
|
|
|
|
548
|
+ }
|
|
|
|
549
|
+ if ($domain !== null) {
|
|
|
|
550
|
+ $domain = parse_url($domain);
|
|
|
|
551
|
+ $data = collect($data['data'])->where('bind_domain', $domain['host'] ?? $domain['path'])->first();
|
|
|
|
552
|
+ return $data ?: [];
|
|
|
|
553
|
+ }
|
|
|
|
554
|
+ return $data;
|
|
|
|
555
|
+ }
|
|
|
|
556
|
+
|
|
|
|
557
|
+ /**
|
|
|
|
558
|
+ * 获取复制项目标识
|
|
|
|
559
|
+ * @author zbj
|
|
|
|
560
|
+ * @date 2023/5/15
|
|
|
|
561
|
+ */
|
|
|
|
562
|
+ protected function getExtFlag($ext_projects, $domain, $api_no)
|
|
|
|
563
|
+ {
|
|
|
|
564
|
+ //复制站点标识
|
|
|
|
565
|
+ $flg_ext = 0;
|
|
|
|
566
|
+ if ($ext_projects) {
|
|
|
|
567
|
+ $ext_urls = array_column($ext_projects, 'ext');
|
|
|
|
568
|
+ $api_nos = array_column($ext_projects, 'apino');
|
|
|
|
569
|
+ if (in_array($api_no, $api_nos)) {
|
|
|
|
570
|
+ $flg_ext = 1;
|
|
|
|
571
|
+ }
|
|
|
|
572
|
+ if (in_array($domain, $ext_urls)) {
|
|
|
|
573
|
+ $flg_ext = 2;
|
|
|
|
574
|
+ }
|
|
|
|
575
|
+ }
|
|
|
|
576
|
+ return $flg_ext;
|
|
|
|
577
|
+ }
|
|
|
|
578
|
+
|
|
|
|
579
|
+ /**
|
|
|
|
580
|
+ * 获取AI项目标识
|
|
|
|
581
|
+ * @author zbj
|
|
|
|
582
|
+ * @date 2023/5/15
|
|
|
|
583
|
+ */
|
|
|
|
584
|
+ protected function getAiFlag($ai_projects, $domain)
|
|
|
|
585
|
+ {
|
|
|
|
586
|
+ $flg_ai = 0;
|
|
|
|
587
|
+ foreach ($ai_projects as $ai_project) {
|
|
|
|
588
|
+ if ($ai_project['bind_domain'] == $domain) {
|
|
|
|
589
|
+ $flg_ai = 1;
|
|
|
|
590
|
+ }
|
|
|
|
591
|
+ }
|
|
|
|
592
|
+ return $flg_ai;
|
|
|
|
593
|
+ }
|
|
|
|
594
|
+} |