GeneratePage.php
2.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
<?php
/**
* @remark :
* @name :GeneratePage.php
* @author :lyh
* @method :post
* @time :2025/2/10 17:00
*/
namespace App\Console\Commands\Project;
use App\Helper\Translate;
use App\Models\Com\NoticeLog;
use App\Models\Product\Keyword;
use App\Models\RouteMap\RouteMap;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
class GeneratePage extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'generate_page';
/**
* The console command description.
*
* @var string
*/
protected $description = '通知生成页面';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* @return bool
*/
public function handle()
{
$noticeModel = new NoticeLog();
while (true){
$noticeInfo = $noticeModel->read(['status'=>0,'type'=>$noticeModel::GENERATE_PAGE]);
if (empty($noticeInfo)) {
sleep(10);
continue;
}
try {
$this->output(' taskID: ' . $noticeInfo['id'] . ' start');
$notice_data = json_decode($noticeInfo['data'],true);
$c_url = $notice_data['c_url'];
$c_params = json_encode($notice_data['c_params']);
$re = http_post($c_url, $c_params, [], true);
if (isset($re['status']) && $re['status'] == 200) {
$noticeModel->edit(['status'=>1],['id'=>$noticeInfo['id']]);
$this->output($c_url . ' | 请求成功');
} else {
$noticeModel->edit(['status'=>2],['id'=>$noticeInfo['id']]);
$this->output($c_url . ' | ' . (json_encode($re,true) ?? '未返回失败原因'));
}
$this->output(' taskID: ' . $noticeInfo['id'] . ' end');
} catch (\Exception $e) {
$noticeModel->edit(['status'=>3],['id'=>$noticeInfo['id']]);
@file_put_contents(storage_path('logs/lyh/lyh_error.log'), var_export('通知C端生成任务:'.date('Y-m-d H:i:s') . ' taskID: ' . $noticeInfo['id'] . ', error: ' . $e->getMessage() . PHP_EOL) . PHP_EOL, FILE_APPEND);
$this->output(' taskID: ' . $noticeInfo['id'] . ', error: ' . $e->getMessage());
}
sleep(2);
}
return true;
}
/**
* 输出message
* @param $message
*/
public function output($message)
{
echo date('Y-m-d H:i:s') . ' ' . $message . PHP_EOL;
}
}