|
@@ -12,6 +12,8 @@ use Illuminate\Http\File; |
|
@@ -12,6 +12,8 @@ use Illuminate\Http\File; |
|
12
|
|
12
|
|
|
13
|
class ProjectFilePDF extends Command
|
13
|
class ProjectFilePDF extends Command
|
|
14
|
{
|
14
|
{
|
|
|
|
15
|
+ use CmdSignal;
|
|
|
|
16
|
+
|
|
15
|
/**
|
17
|
/**
|
|
16
|
* The name and signature of the console command.
|
18
|
* The name and signature of the console command.
|
|
17
|
*
|
19
|
*
|
|
@@ -26,12 +28,17 @@ class ProjectFilePDF extends Command |
|
@@ -26,12 +28,17 @@ class ProjectFilePDF extends Command |
|
26
|
*/
|
28
|
*/
|
|
27
|
protected $description = '网站项目数据,生成PDF文件';
|
29
|
protected $description = '网站项目数据,生成PDF文件';
|
|
28
|
|
30
|
|
|
29
|
- protected $AiccWechat;
|
31
|
+ protected ProjectAssociation $AiccWechat;
|
|
30
|
|
32
|
|
|
31
|
- protected $DataFile;
|
33
|
+ protected DataFile $DataFile;
|
|
32
|
|
34
|
|
|
33
|
protected $time;
|
35
|
protected $time;
|
|
34
|
|
36
|
|
|
|
|
37
|
+ // 最大支持5个进程
|
|
|
|
38
|
+ public int $maxRunNumber = 50;
|
|
|
|
39
|
+
|
|
|
|
40
|
+ public FileController $fileController;
|
|
|
|
41
|
+
|
|
35
|
/**
|
42
|
/**
|
|
36
|
* Create a new command instance.
|
43
|
* Create a new command instance.
|
|
37
|
*
|
44
|
*
|
|
@@ -42,40 +49,27 @@ class ProjectFilePDF extends Command |
|
@@ -42,40 +49,27 @@ class ProjectFilePDF extends Command |
|
42
|
$this->AiccWechat = new ProjectAssociation();
|
49
|
$this->AiccWechat = new ProjectAssociation();
|
|
43
|
$this->DataFile = new DataFile();
|
50
|
$this->DataFile = new DataFile();
|
|
44
|
$this->time = date("Y-m");
|
51
|
$this->time = date("Y-m");
|
|
|
|
52
|
+ $this->fileController = new FileController();
|
|
45
|
parent::__construct();
|
53
|
parent::__construct();
|
|
46
|
}
|
54
|
}
|
|
47
|
|
55
|
|
|
48
|
- /**
|
|
|
|
49
|
- * Execute the console command.
|
|
|
|
50
|
- *
|
|
|
|
51
|
- * @return int
|
|
|
|
52
|
- */
|
|
|
|
53
|
- public function handle()
|
56
|
+ public function start(): int
|
|
54
|
{
|
57
|
{
|
|
55
|
- $data = $this->get_data();
|
|
|
|
56
|
- # 详细数据
|
|
|
|
57
|
- $items = $data['items'];
|
|
|
|
58
|
- # 总分页
|
|
|
|
59
|
- $totalPage = $data['totalPage'];
|
|
|
|
60
|
- $this->dataPush($items);
|
|
|
|
61
|
- if ($totalPage > 1) {
|
|
|
|
62
|
- for ($page = 2; $page <= $totalPage; $page++) {
|
|
|
|
63
|
- $da = $this->get_data();
|
|
|
|
64
|
- $this->dataPush($da['items']);
|
|
|
|
65
|
- }
|
|
|
|
66
|
- }
|
|
|
|
67
|
- $this->info('生成pdf完成');
|
58
|
+ $status = 1; # 1 - 正常, 0 - 禁用
|
|
|
|
59
|
+ $is_pdf = 0; # 0 - 未生成 1 - 已生成 2 - 其它问题
|
|
|
|
60
|
+ $lists = $this->DataFile::query()->where('status', $status)
|
|
|
|
61
|
+ ->where('project_id', '!=', 0)
|
|
|
|
62
|
+ ->where('friend_id', '!=', 0)
|
|
|
|
63
|
+ ->where('user_id', '!=', 0)
|
|
|
|
64
|
+ ->where('is_pdf', $is_pdf)->where('created_at', 'like', $this->time . '%')->first();
|
|
|
|
65
|
+ if (is_null($lists)) {
|
|
|
|
66
|
+ $this->debug_echo('没有任务,等待中');
|
|
|
|
67
|
+ sleep(60);
|
|
68
|
return 0;
|
68
|
return 0;
|
|
69
|
}
|
69
|
}
|
|
70
|
-
|
|
|
|
71
|
- /**
|
|
|
|
72
|
- * 数据生成并保存
|
|
|
|
73
|
- * @param array $items
|
|
|
|
74
|
- * @return void
|
|
|
|
75
|
- */
|
|
|
|
76
|
- public function dataPush(array $items)
|
|
|
|
77
|
- {
|
|
|
|
78
|
- foreach ($items as $item) {
|
70
|
+ $key = $this->signature . '-' . $lists->id;
|
|
|
|
71
|
+ $count = redis_get($key);
|
|
|
|
72
|
+ $item = $lists->getOriginal();
|
|
79
|
$project_id = $item->project_id;
|
73
|
$project_id = $item->project_id;
|
|
80
|
$user_id = $item->user_id;
|
74
|
$user_id = $item->user_id;
|
|
81
|
$friend_id = $item->friend_id;
|
75
|
$friend_id = $item->friend_id;
|
|
@@ -84,28 +78,25 @@ class ProjectFilePDF extends Command |
|
@@ -84,28 +78,25 @@ class ProjectFilePDF extends Command |
|
84
|
$html = $this->html($project_data);
|
78
|
$html = $this->html($project_data);
|
|
85
|
$filename = hash('md5', $this->time . '-' . $project_id . '-' . $friend_id . '-' . $user_id);
|
79
|
$filename = hash('md5', $this->time . '-' . $project_id . '-' . $friend_id . '-' . $user_id);
|
|
86
|
$file_path = $this->savePDF($html, $filename);
|
80
|
$file_path = $this->savePDF($html, $filename);
|
|
87
|
- var_dump($file_path);
|
|
|
|
88
|
- $this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]);
|
81
|
+ if (empty($file_path)) {
|
|
|
|
82
|
+ $this->debug_echo('pdf生成失败!');
|
|
|
|
83
|
+ return 0;
|
|
89
|
}
|
84
|
}
|
|
|
|
85
|
+ $isRes = $this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]);
|
|
|
|
86
|
+ if (!$isRes) {
|
|
|
|
87
|
+ if ($count == 2) {
|
|
|
|
88
|
+ $lists->is_pdf = 2;
|
|
|
|
89
|
+ $lists->save();
|
|
|
|
90
|
+ $this->debug_echo('项目文件数据保存失败! - 其他原因 - ' . $key);
|
|
|
|
91
|
+ } else {
|
|
|
|
92
|
+ redis_add($key, $count + 1);
|
|
|
|
93
|
+ $this->debug_echo('项目文件数据保存失败! - ' . $key);
|
|
90
|
}
|
94
|
}
|
|
91
|
-
|
|
|
|
92
|
-
|
|
|
|
93
|
- public function get_data($page = 1, $perPage = 20)
|
|
|
|
94
|
- {
|
|
|
|
95
|
- $data = $this->AiccWechat->allData($page, $perPage);
|
|
|
|
96
|
- # 总条数
|
|
|
|
97
|
- $total = $data['total'];
|
|
|
|
98
|
- if (empty($total)) {
|
|
|
|
99
|
- $this->error('暂无绑定AICC微信数据');
|
|
|
|
100
|
- return 0;
|
|
|
|
101
|
}
|
95
|
}
|
|
102
|
- # 详细数据
|
|
|
|
103
|
- $items = $data['items'];
|
|
|
|
104
|
- # 总分页
|
|
|
|
105
|
- $totalPage = $data['totalPage'];
|
|
|
|
106
|
- # 当前页
|
|
|
|
107
|
- $currentPage = $data['currentPage'];
|
|
|
|
108
|
- return compact('total', 'items', 'totalPage', 'currentPage');
|
96
|
+ $lists->is_pdf = 1;
|
|
|
|
97
|
+ $lists->save();
|
|
|
|
98
|
+ $this->debug_echo('项目文件数据保存成功!');
|
|
|
|
99
|
+ return 0;
|
|
109
|
}
|
100
|
}
|
|
110
|
|
101
|
|
|
111
|
public function savePDF($html, $filename)
|
102
|
public function savePDF($html, $filename)
|
|
@@ -138,16 +129,13 @@ class ProjectFilePDF extends Command |
|
@@ -138,16 +129,13 @@ class ProjectFilePDF extends Command |
|
138
|
// 获取PDF内容
|
129
|
// 获取PDF内容
|
|
139
|
$pdfContent = $dompdf->output();
|
130
|
$pdfContent = $dompdf->output();
|
|
140
|
|
131
|
|
|
141
|
- $fileController = new FileController();
|
|
|
|
142
|
-
|
|
|
|
143
|
// 将PDF内容保存到文件
|
132
|
// 将PDF内容保存到文件
|
|
144
|
@file_put_contents($savePath, $pdfContent);
|
133
|
@file_put_contents($savePath, $pdfContent);
|
|
145
|
|
134
|
|
|
146
|
// 创建一个文件实例
|
135
|
// 创建一个文件实例
|
|
147
|
$file = new File($savePath);
|
136
|
$file = new File($savePath);
|
|
148
|
-var_dump($file->getFilename());
|
|
|
|
149
|
-exit();
|
|
|
|
150
|
- return $fileController->single($file);
|
137
|
+
|
|
|
|
138
|
+ return $this->fileController->single($file);
|
|
151
|
}
|
139
|
}
|
|
152
|
|
140
|
|
|
153
|
/**
|
141
|
/**
|