AiVideoAutoPublish.php
5.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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
/**
* @remark :
* @name :AiVideoAutoPublish.php
* @author :lyh
* @method :post
* @time :2025/8/1 15:19
*/
namespace App\Console\Commands\Ai;
use App\Models\Product\Product;
use App\Models\Project\DeployOptimize;
use App\Models\Project\Project;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use App\Models\Project\AiVideoTask;
/**
* @remark :ai视频自动发布
* @name :AiVideoAutoPublish
* @author :lyh
* @method :post
* @time :2025/8/1 15:19
*/
class AiVideoAutoPublish extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'ai_video_auto_publish';
/**
* The console command description.
*
* @var string
*/
protected $description = '自动发布AI Video';
public function handle(){
}
/**
* @remark :普通项目--自动发布
* @name :auto_publish
* @author :lyh
* @method :post
* @time :2025/8/1 15:22
*/
public function auto_six_publish(){
$this->output('开始自动发布Video文章');
$projectModel = new Project();
$optimizeModel = new DeployOptimize();
$projectList = $projectModel->list(['is_ai_video'=>1,'project_type'=>0,'delete_status'=>0,'site_status'=>0,'extend_type'=>0],'id',['id']);
foreach ($projectList as $item){
$this->output("项目{$item['id']}开始自动发布");
//获取当前是否开启自动发布aiVideo
$opInfo = $optimizeModel->read(['project_id'=>$item['id']],['is_ai_video_send','send_ai_video_frequency','start_date']);
if($opInfo['is_ai_video_send'] != 1){
$this->output("项目{$item['id']}未开启自动发布" . $opInfo['start_date']);
continue;
}
if(($opInfo['start_date'] > date('Y-m-d')) || empty($opInfo['start_date'])){
$this->output("项目{$item['id']}未到推广时间" . $opInfo['start_date']);
continue;
}
$aiVideoTaskModel = new AiVideoTask();
$next_auto_date = $aiVideoTaskModel->formatQuery(['project_id'=>$item['id'],'next_auto_date'=>['!=',null]])->orderBy('id', 'desc')->value('next_auto_date');
if($next_auto_date && ($next_auto_date > date('Y-m-d'))){
$this->output("项目{$item['id']}未到执行时间" . $next_auto_date);
continue;
}
//获取当前网站的标题
ProjectServer::useProject($item['id']);
$data = $this->getProduct();
DB::disconnect('custom_mysql');
}
}
/**
* @remark :获取产品标题+产品描述
* @name :getProduct
* @author :lyh
* @method :post
* @time :2025/8/1 16:09
*/
public function getProduct(){
$data = [];
$productModel = new Product();
$info = $productModel->formatQuery(['gallery'=>['!=',null]])->select(['title','gallery','intro'])->inRandomOrder()->first();
if(empty($info)){
return $data;
}
$data['title'] = $info['title'];
$data['remark'] = $info['intro'];
$data['images'] = array_walk($info['gallery'], function (&$item) {$item['alt'] = $item['title'];unset($item['title']);});
if(count($data['images']) < 6){
//todo::需要生成图片
}
return $data;
}
/**
* @remark :
* @name :getAiVideoParam
* @author :lyh
* @method :post
* @time :2025/8/1 16:25
*/
public function getAiVideoParam()
{
$project_id = '1';
$domain = 'www.cs-conveyor.com';
try {
$sitemap_url = 'https://' . $domain . '/sitemap_post_tag.xml';
$sitemap_string = file_get_contents($sitemap_url);
$xml = new \SimpleXMLElement($sitemap_string);
$json = json_encode($xml);
$array = json_decode($json, true);
$urls = array_column($array['url'], 'loc');
$num = 0;
if ($num >= 10) {
return false;
}
AGAIN:
$url = $urls[array_rand($urls)];
$dom = file_get_html($url);
$h1 = $dom->find('.layout .global_section h1', 0);
$title = $h1 ? trim($h1->plaintext) : '';
$p = $dom->find('.layout .global_section p', 0);
$content = $p ? trim($p->plaintext) : '';
$img = $dom->find('.layout .global_section img');
$images = [];
foreach ($img as $item) {
if (empty($item->src) || empty($item->alt))
continue;
array_push($images, ['src' => $item->src, 'alt' => $item->alt]);
}
if (empty($title) || empty($content) || empty($images)) {
$num++;
goto AGAIN;
}
} catch (\Exception $e) {
echo 'project_id: ' . $project_id . ', domain: ' . $domain . ', error: ' . $e->getMessage() . PHP_EOL;
}
}
/**
* @remark :日志
* @name :output
* @author :lyh
* @method :post
* @time :2025/8/1 15:28
*/
public function output($message)
{
Log::channel('ai_video')->info($message);
echo date('Y-m-d H:i:s') . ' ' . $message . PHP_EOL;
}
}