|
@@ -12,8 +12,6 @@ use Illuminate\Http\File; |
|
@@ -12,8 +12,6 @@ use Illuminate\Http\File; |
|
12
|
|
12
|
|
|
13
|
class ProjectFilePDF extends Command
|
13
|
class ProjectFilePDF extends Command
|
|
14
|
{
|
14
|
{
|
|
15
|
- use CmdSignal;
|
|
|
|
16
|
-
|
|
|
|
17
|
/**
|
15
|
/**
|
|
18
|
* The name and signature of the console command.
|
16
|
* The name and signature of the console command.
|
|
19
|
*
|
17
|
*
|
|
@@ -34,11 +32,6 @@ class ProjectFilePDF extends Command |
|
@@ -34,11 +32,6 @@ class ProjectFilePDF extends Command |
|
34
|
|
32
|
|
|
35
|
protected $time;
|
33
|
protected $time;
|
|
36
|
|
34
|
|
|
37
|
- // 最大支持5个进程
|
|
|
|
38
|
- public $maxRunNumber = 50;
|
|
|
|
39
|
-
|
|
|
|
40
|
- public $fileController;
|
|
|
|
41
|
-
|
|
|
|
42
|
/**
|
35
|
/**
|
|
43
|
* Create a new command instance.
|
36
|
* Create a new command instance.
|
|
44
|
*
|
37
|
*
|
|
@@ -46,100 +39,73 @@ class ProjectFilePDF extends Command |
|
@@ -46,100 +39,73 @@ class ProjectFilePDF extends Command |
|
46
|
*/
|
39
|
*/
|
|
47
|
public function __construct()
|
40
|
public function __construct()
|
|
48
|
{
|
41
|
{
|
|
49
|
- $this->AiccWechat = new ProjectAssociation();
|
|
|
|
50
|
- $this->DataFile = new DataFile();
|
|
|
|
51
|
- $this->time = date("Y-m");
|
|
|
|
52
|
- $this->fileController = new FileController();
|
42
|
+ $this->AiccWechat = new ProjectAssociation();
|
|
|
|
43
|
+ $this->DataFile = new DataFile();
|
|
|
|
44
|
+ $this->time = date("Y-m");
|
|
53
|
parent::__construct();
|
45
|
parent::__construct();
|
|
54
|
}
|
46
|
}
|
|
55
|
|
47
|
|
|
|
|
48
|
+ /**
|
|
|
|
49
|
+ * Execute the console command.
|
|
|
|
50
|
+ *
|
|
|
|
51
|
+ * @return int
|
|
|
|
52
|
+ */
|
|
|
|
53
|
+ public function handle()
|
|
|
|
54
|
+ {
|
|
|
|
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完成');
|
|
|
|
68
|
+ return 0;
|
|
|
|
69
|
+ }
|
|
56
|
|
70
|
|
|
57
|
-// public function handle()
|
|
|
|
58
|
-// {
|
|
|
|
59
|
-// $status = 0; # 0 - 未生成 1 - 已生成 2 - 其它问题1
|
|
|
|
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('created_at', 'like', $this->time . '%')->first();
|
|
|
|
65
|
-// if (is_null($lists)) {
|
|
|
|
66
|
-// $this->error('没有任务,等待中');
|
|
|
|
67
|
-// sleep(60);
|
|
|
|
68
|
-// return 0;
|
|
|
|
69
|
-// }
|
|
|
|
70
|
-// $key = $this->signature . '-' . $lists->id;
|
|
|
|
71
|
-// $count = redis_get($key);
|
|
|
|
72
|
-// $project_id = $lists->project_id;
|
|
|
|
73
|
-// $user_id = $lists->user_id;
|
|
|
|
74
|
-// $friend_id = $lists->friend_id;
|
|
|
|
75
|
-// // todo 根据项目查询数据
|
|
|
|
76
|
-// $project_data = [];
|
|
|
|
77
|
-// $html = $this->html($project_data);
|
|
|
|
78
|
-// $filename = hash('md5', $this->time . '-' . $project_id . '-' . $friend_id . '-' . $user_id);
|
|
|
|
79
|
-// $file_path = $this->savePDF($html, $filename);
|
|
|
|
80
|
-// if (empty($file_path)) {
|
|
|
|
81
|
-// $this->error('pdf生成失败!');
|
|
|
|
82
|
-// return 0;
|
|
|
|
83
|
-// }
|
|
|
|
84
|
-// $isRes = $this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]);
|
|
|
|
85
|
-// if (!$isRes) {
|
|
|
|
86
|
-// if ($count == 2) {
|
|
|
|
87
|
-// $lists->is_pdf = 2;
|
|
|
|
88
|
-// $lists->save();
|
|
|
|
89
|
-// $this->error('项目文件数据保存失败! - 其他原因 - ' . $key);
|
|
|
|
90
|
-// } else {
|
|
|
|
91
|
-// redis_add($key, $count + 1);
|
|
|
|
92
|
-// $this->error('项目文件数据保存失败! - ' . $key);
|
|
|
|
93
|
-// }
|
|
|
|
94
|
-// }
|
|
|
|
95
|
-// $lists->is_pdf = 1;
|
|
|
|
96
|
-// $lists->save();
|
|
|
|
97
|
-// $this->error('项目文件数据保存成功!');
|
|
|
|
98
|
-// return 0;
|
|
|
|
99
|
-// }
|
|
|
|
100
|
-
|
|
|
|
101
|
- public function start(): int
|
71
|
+ /**
|
|
|
|
72
|
+ * 数据生成并保存
|
|
|
|
73
|
+ * @param array $items
|
|
|
|
74
|
+ * @return void
|
|
|
|
75
|
+ */
|
|
|
|
76
|
+ public function dataPush(array $items)
|
|
102
|
{
|
77
|
{
|
|
103
|
- $status = 0; # 0 - 未生成 1 - 已生成 2 - 其它问题
|
|
|
|
104
|
- $lists = $this->DataFile::query()->where('status', $status)
|
|
|
|
105
|
- ->where('project_id', '!=', 0)
|
|
|
|
106
|
- ->where('friend_id', '!=', 0)
|
|
|
|
107
|
- ->where('user_id', '!=', 0)
|
|
|
|
108
|
- ->where('created_at', 'like', $this->time . '%')->first();
|
|
|
|
109
|
- if (is_null($lists)) {
|
|
|
|
110
|
- $this->debug_echo('没有任务,等待中');
|
|
|
|
111
|
- sleep(60);
|
|
|
|
112
|
- return 0;
|
78
|
+ foreach ($items as $item) {
|
|
|
|
79
|
+ $project_id = $item->project_id;
|
|
|
|
80
|
+ $user_id = $item->user_id;
|
|
|
|
81
|
+ $friend_id = $item->friend_id;
|
|
|
|
82
|
+ // todo 根据项目查询数据
|
|
|
|
83
|
+ $project_data = [];
|
|
|
|
84
|
+ $html = $this->html($project_data);
|
|
|
|
85
|
+ $filename = hash('md5', $this->time . '-' . $project_id . '-' . $friend_id . '-' . $user_id);
|
|
|
|
86
|
+ $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]);
|
|
113
|
}
|
89
|
}
|
|
114
|
- $key = $this->signature . '-' . $lists->id;
|
|
|
|
115
|
- $count = redis_get($key);
|
|
|
|
116
|
- $project_id = $lists->project_id;
|
|
|
|
117
|
- $user_id = $lists->user_id;
|
|
|
|
118
|
- $friend_id = $lists->friend_id;
|
|
|
|
119
|
- // todo 根据项目查询数据
|
|
|
|
120
|
- $project_data = [];
|
|
|
|
121
|
- $html = $this->html($project_data);
|
|
|
|
122
|
- $filename = hash('md5', $this->time . '-' . $project_id . '-' . $friend_id . '-' . $user_id);
|
|
|
|
123
|
- $file_path = $this->savePDF($html, $filename);
|
|
|
|
124
|
- if (empty($file_path)) {
|
|
|
|
125
|
- $this->debug_echo('pdf生成失败!');
|
90
|
+ }
|
|
|
|
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微信数据');
|
|
126
|
return 0;
|
100
|
return 0;
|
|
127
|
}
|
101
|
}
|
|
128
|
- $isRes = $this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]);
|
|
|
|
129
|
- if (!$isRes) {
|
|
|
|
130
|
- if ($count == 2) {
|
|
|
|
131
|
- $lists->is_pdf = 2;
|
|
|
|
132
|
- $lists->save();
|
|
|
|
133
|
- $this->debug_echo('项目文件数据保存失败! - 其他原因 - ' . $key);
|
|
|
|
134
|
- } else {
|
|
|
|
135
|
- redis_add($key, $count + 1);
|
|
|
|
136
|
- $this->debug_echo('项目文件数据保存失败! - ' . $key);
|
|
|
|
137
|
- }
|
|
|
|
138
|
- }
|
|
|
|
139
|
- $lists->is_pdf = 1;
|
|
|
|
140
|
- $lists->save();
|
|
|
|
141
|
- $this->debug_echo('项目文件数据保存成功!');
|
|
|
|
142
|
- return 0;
|
102
|
+ # 详细数据
|
|
|
|
103
|
+ $items = $data['items'];
|
|
|
|
104
|
+ # 总分页
|
|
|
|
105
|
+ $totalPage = $data['totalPage'];
|
|
|
|
106
|
+ # 当前页
|
|
|
|
107
|
+ $currentPage = $data['currentPage'];
|
|
|
|
108
|
+ return compact('total', 'items', 'totalPage', 'currentPage');
|
|
143
|
}
|
109
|
}
|
|
144
|
|
110
|
|
|
145
|
public function savePDF($html, $filename)
|
111
|
public function savePDF($html, $filename)
|
|
@@ -172,15 +138,16 @@ class ProjectFilePDF extends Command |
|
@@ -172,15 +138,16 @@ class ProjectFilePDF extends Command |
|
172
|
// 获取PDF内容
|
138
|
// 获取PDF内容
|
|
173
|
$pdfContent = $dompdf->output();
|
139
|
$pdfContent = $dompdf->output();
|
|
174
|
|
140
|
|
|
|
|
141
|
+ $fileController = new FileController();
|
|
|
|
142
|
+
|
|
175
|
// 将PDF内容保存到文件
|
143
|
// 将PDF内容保存到文件
|
|
176
|
@file_put_contents($savePath, $pdfContent);
|
144
|
@file_put_contents($savePath, $pdfContent);
|
|
177
|
|
145
|
|
|
178
|
// 创建一个文件实例
|
146
|
// 创建一个文件实例
|
|
179
|
$file = new File($savePath);
|
147
|
$file = new File($savePath);
|
|
180
|
-// var_dump($file->getExtension());
|
|
|
|
181
|
-// exit();
|
|
|
|
182
|
-
|
|
|
|
183
|
- echo $this->fileController->single($file);
|
148
|
+var_dump($file->getFilename());
|
|
|
|
149
|
+exit();
|
|
|
|
150
|
+ return $fileController->single($file);
|
|
184
|
}
|
151
|
}
|
|
185
|
|
152
|
|
|
186
|
/**
|
153
|
/**
|