|
...
|
...
|
@@ -28,16 +28,16 @@ class ProjectFilePDF extends Command |
|
|
|
*/
|
|
|
|
protected $description = '网站项目数据,生成PDF文件';
|
|
|
|
|
|
|
|
protected ProjectAssociation $AiccWechat;
|
|
|
|
protected $ProjectAssociation;
|
|
|
|
|
|
|
|
protected DataFile $DataFile;
|
|
|
|
protected $DataFile;
|
|
|
|
|
|
|
|
protected $time;
|
|
|
|
|
|
|
|
// 最大支持5个进程
|
|
|
|
public int $maxRunNumber = 50;
|
|
|
|
protected $fileController;
|
|
|
|
|
|
|
|
public FileController $fileController;
|
|
|
|
// 最大支持5个进程
|
|
|
|
public $maxRunNumber = 50;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new command instance.
|
|
...
|
...
|
@@ -46,43 +46,48 @@ class ProjectFilePDF extends Command |
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->AiccWechat = new ProjectAssociation();
|
|
|
|
$this->DataFile = new DataFile();
|
|
|
|
$this->time = date("Y-m");
|
|
|
|
$this->fileController = new FileController();
|
|
|
|
$this->ProjectAssociation = new ProjectAssociation();
|
|
|
|
$this->DataFile = new DataFile();
|
|
|
|
$this->time = date("Y-m");
|
|
|
|
$this->fileController = new FileController();
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function start(): int
|
|
|
|
{
|
|
|
|
$status = 1; # 1 - 正常, 0 - 禁用
|
|
|
|
$is_pdf = 0; # 0 - 未生成 1 - 已生成 2 - 其它问题
|
|
|
|
$lists = $this->DataFile::query()->where('status', $status)
|
|
|
|
->where('project_id', '!=', 0)
|
|
|
|
->where('friend_id', '!=', 0)
|
|
|
|
->where('user_id', '!=', 0)
|
|
|
|
->where('is_pdf', $is_pdf)->where('created_at', 'like', $this->time . '%')->first();
|
|
|
|
# 0 - 未生成
|
|
|
|
# 1 - 已生成
|
|
|
|
# 2 - 其它问题
|
|
|
|
$is_pdf = 0;
|
|
|
|
$lists = $this->ProjectAssociation::query()->where('is_pdf', $is_pdf)
|
|
|
|
->where('project_id', '!=', 0)
|
|
|
|
->where('friend_id', '!=', 0)
|
|
|
|
->where('user_id', '!=', 0)
|
|
|
|
->where('created_at', 'like', $this->time . '%')->first();
|
|
|
|
|
|
|
|
if (is_null($lists)) {
|
|
|
|
$this->debug_echo('没有任务,等待中');
|
|
|
|
sleep(60);
|
|
|
|
sleep(30);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
$key = $this->signature . '-' . $lists->id;
|
|
|
|
$count = redis_get($key);
|
|
|
|
$item = $lists->getOriginal();
|
|
|
|
$project_id = $item->project_id;
|
|
|
|
$user_id = $item->user_id;
|
|
|
|
$friend_id = $item->friend_id;
|
|
|
|
$key = $this->signature . '-' . $lists->id;
|
|
|
|
$count = redis_get($key);
|
|
|
|
|
|
|
|
$project_id = $lists->project_id;
|
|
|
|
$user_id = $lists->user_id;
|
|
|
|
$friend_id = $lists->friend_id;
|
|
|
|
// todo 根据项目查询数据
|
|
|
|
$project_data = [];
|
|
|
|
$html = $this->html($project_data);
|
|
|
|
$filename = hash('md5', $this->time . '-' . $project_id . '-' . $friend_id . '-' . $user_id);
|
|
|
|
$file_path = $this->savePDF($html, $filename);
|
|
|
|
|
|
|
|
$file_path = $this->savePDF($html, $filename);
|
|
|
|
if (empty($file_path)) {
|
|
|
|
$this->debug_echo('pdf生成失败!');
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
$isRes = $this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]);
|
|
|
|
$file_path = json_encode($file_path['data']);
|
|
|
|
$isRes = $this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]);
|
|
|
|
if (!$isRes) {
|
|
|
|
if ($count == 2) {
|
|
|
|
$lists->is_pdf = 2;
|
|
...
|
...
|
@@ -99,6 +104,66 @@ class ProjectFilePDF extends Command |
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
// public function handle()
|
|
|
|
// {
|
|
|
|
// # 0 - 未生成
|
|
|
|
// # 1 - 已生成
|
|
|
|
// # 2 - 其它问题
|
|
|
|
// $is_pdf = 0;
|
|
|
|
// $lists = $this->ProjectAssociation::query()->where('is_pdf', $is_pdf)
|
|
|
|
// ->where('project_id', '!=', 0)
|
|
|
|
// ->where('friend_id', '!=', 0)
|
|
|
|
// ->where('user_id', '!=', 0)
|
|
|
|
// ->where('created_at', 'like', $this->time . '%')->first();
|
|
|
|
//
|
|
|
|
// if (is_null($lists)) {
|
|
|
|
// $this->error('没有任务,等待中');
|
|
|
|
// sleep(60);
|
|
|
|
// return 0;
|
|
|
|
// }
|
|
|
|
// $key = $this->signature . '-' . $lists->id;
|
|
|
|
// $count = redis_get($key);
|
|
|
|
// $project_id = $lists->project_id;
|
|
|
|
// $user_id = $lists->user_id;
|
|
|
|
// $friend_id = $lists->friend_id;
|
|
|
|
// // todo 根据项目查询数据
|
|
|
|
// $project_data = [];
|
|
|
|
// $html = $this->html($project_data);
|
|
|
|
// $filename = hash('md5', $this->time . '-' . $project_id . '-' . $friend_id . '-' . $user_id);
|
|
|
|
//
|
|
|
|
// $file_path = $this->savePDF($html, $filename);
|
|
|
|
// if (empty($file_path)) {
|
|
|
|
// $this->debug_echo('pdf生成失败!');
|
|
|
|
// return 0;
|
|
|
|
// }
|
|
|
|
// $file_path = $file_path['data'];
|
|
|
|
// $isRes = $this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]);
|
|
|
|
// if (!$isRes) {
|
|
|
|
// if ($count == 2) {
|
|
|
|
// $lists->status = 2;
|
|
|
|
// $lists->save();
|
|
|
|
// $this->error('项目文件数据保存失败! - 其他原因 - ' . $key);
|
|
|
|
// } else {
|
|
|
|
// redis_add($key, $count + 1);
|
|
|
|
// $this->error('项目文件数据保存失败! - ' . $key);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// $lists->status = 1;
|
|
|
|
// $lists->save();
|
|
|
|
// $this->info('项目文件数据保存成功!');
|
|
|
|
// return 0;
|
|
|
|
// }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $html
|
|
|
|
* @param $filename
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function savePDF($html, $filename)
|
|
|
|
{
|
|
|
|
|
|
...
|
...
|
@@ -127,15 +192,14 @@ class ProjectFilePDF extends Command |
|
|
|
$dompdf->render();
|
|
|
|
|
|
|
|
// 获取PDF内容
|
|
|
|
$pdfContent = $dompdf->output();
|
|
|
|
$pdfContent = $dompdf->output();
|
|
|
|
$this->fileController->path = '/V6/PDF';
|
|
|
|
|
|
|
|
// 将PDF内容保存到文件
|
|
|
|
@file_put_contents($savePath, $pdfContent);
|
|
|
|
|
|
|
|
// 创建一个文件实例
|
|
|
|
$file = new File($savePath);
|
|
|
|
|
|
|
|
return $this->fileController->single($file);
|
|
|
|
return $this->fileController->api_upload_single($file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -148,7 +212,7 @@ class ProjectFilePDF extends Command |
|
|
|
$html = '<html>';
|
|
|
|
$html .= '<body style="font-family:arial">';
|
|
|
|
$html .= '<h1>Hello, World!</h1>';
|
|
|
|
$html .= '<p>中文内容</p>';
|
|
|
|
$html .= '<p>中文内容ffffff</p>';
|
|
|
|
$html .= '</body>';
|
|
|
|
$html .= '</html>';
|
|
|
|
return $html;
|
...
|
...
|
|