ExternalLinkMake.php
3.7 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
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2025/9/15
* Time: 10:09
*/
namespace App\Console\Commands\Product;
use App\Models\Domain\DomainInfo;
use App\Models\Product\Keyword;
use App\Models\Project\Project;
use App\Models\RankData\RankDataLog;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
/**
* Class ExternalLinkMake
* @package App\Console\Commands\Product
*/
class ExternalLinkMake extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'external_link_make';
/**
* The console command description.
*
* @var string
*/
protected $description = '统计不达标项目,500条 聚合页, 作为外链提交';
/**
* @return bool
*/
public function handle()
{
$date = date('Y-m-d H:i:s', strtotime('-75 day'));
$projects = Project::where(['type' => 2, 'delete_status' => 0, 'site_status' => 0, 'extend_type' => 0, 'is_remain_today' => 0])->get();
foreach ($projects as $project) {
if ($project->id <= 1)
continue;
$this->output('项目开始: ' . $project->id);
$log = DB::table('gl_project_external_link_make')->where(['project_id' => $project->id])->first();
if ($log) {
$this->output('项目已推送过: ' . $project->id . ', 跳过');
continue;
}
$yesterday = RankDataLog::where(['project_id' => $project->id, 'date' => date('Y-m-d', '-1 day')])->first();
if (FALSE == empty($yesterday) && $yesterday->is_compliance == 1){
$this->output('项目昨日达标: ' . $project->id . ', 跳过');
continue;
}
if(empty($project->deploy_optimize['start_date']) || $project->deploy_optimize['start_date'] > $date){
$this->output('项目推广不到75天: ' . $project->id . ', 推广开始时间:' . $project->deploy_optimize['start_date']);
continue;
}
$domain = DomainInfo::where(['project_id' => $project->id, 'status' => DomainInfo::STATUS_ONE])->first();
if (empty($domain)) {
$this->output('项目未找到域名: ' . $project->id);
continue;
}
$host = 'https://' . $domain->domain . '/';
ProjectServer::useProject($project->id);
$keywords = Keyword::select(['id', 'title', 'route', 'seo_title'])->where('route', '<>', null)->orderBy('id', 'desc')->limit(500)->get();
$updated_at = $created_at = date('Y-m-d H:i:s');
$data = [];
foreach ($keywords as $keyword) {
$data[] = [
'project_id' => $project->id,
'keyword_id' => $keyword->id,
'keyword' => $keyword->title,
'route' => $keyword->route,
'seo_title' => $keyword->seo_title,
'external_link' => $host . $keyword->route . '/{' . $keyword->seo_title . '}',
'updated_at' => $updated_at,
'created_at' => $created_at
];
}
DB::table('gl_project_external_link_make')->insert($data);
DB::disconnect('custom_mysql');
}
return true;
}
/**
* 输出message
* @param $message
*/
public function output($message)
{
$message = date('Y-m-d H:i:s') . ' ' . $message . PHP_EOL;
file_put_contents(storage_path('logs/external_link_make.log'), $message, FILE_APPEND);
echo $message;
}
}