|
...
|
...
|
@@ -12,8 +12,6 @@ use Illuminate\Http\File; |
|
|
|
|
|
|
|
class ProjectFilePDF extends Command
|
|
|
|
{
|
|
|
|
use CmdSignal;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
...
|
...
|
@@ -34,11 +32,6 @@ class ProjectFilePDF extends Command |
|
|
|
|
|
|
|
protected $time;
|
|
|
|
|
|
|
|
// 最大支持5个进程
|
|
|
|
public $maxRunNumber = 50;
|
|
|
|
|
|
|
|
public $fileController;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new command instance.
|
|
|
|
*
|
|
...
|
...
|
@@ -46,100 +39,73 @@ 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->AiccWechat = new ProjectAssociation();
|
|
|
|
$this->DataFile = new DataFile();
|
|
|
|
$this->time = date("Y-m");
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
$data = $this->get_data();
|
|
|
|
# 详细数据
|
|
|
|
$items = $data['items'];
|
|
|
|
# 总分页
|
|
|
|
$totalPage = $data['totalPage'];
|
|
|
|
$this->dataPush($items);
|
|
|
|
if ($totalPage > 1) {
|
|
|
|
for ($page = 2; $page <= $totalPage; $page++) {
|
|
|
|
$da = $this->get_data();
|
|
|
|
$this->dataPush($da['items']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->info('生成pdf完成');
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// public function handle()
|
|
|
|
// {
|
|
|
|
// $status = 0; # 0 - 未生成 1 - 已生成 2 - 其它问题1
|
|
|
|
// $lists = $this->DataFile::query()->where('status', $status)
|
|
|
|
// ->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->error('pdf生成失败!');
|
|
|
|
// return 0;
|
|
|
|
// }
|
|
|
|
// $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;
|
|
|
|
// $lists->save();
|
|
|
|
// $this->error('项目文件数据保存失败! - 其他原因 - ' . $key);
|
|
|
|
// } else {
|
|
|
|
// redis_add($key, $count + 1);
|
|
|
|
// $this->error('项目文件数据保存失败! - ' . $key);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// $lists->is_pdf = 1;
|
|
|
|
// $lists->save();
|
|
|
|
// $this->error('项目文件数据保存成功!');
|
|
|
|
// return 0;
|
|
|
|
// }
|
|
|
|
|
|
|
|
public function start(): int
|
|
|
|
/**
|
|
|
|
* 数据生成并保存
|
|
|
|
* @param array $items
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function dataPush(array $items)
|
|
|
|
{
|
|
|
|
$status = 0; # 0 - 未生成 1 - 已生成 2 - 其它问题
|
|
|
|
$lists = $this->DataFile::query()->where('status', $status)
|
|
|
|
->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);
|
|
|
|
return 0;
|
|
|
|
foreach ($items as $item) {
|
|
|
|
$project_id = $item->project_id;
|
|
|
|
$user_id = $item->user_id;
|
|
|
|
$friend_id = $item->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);
|
|
|
|
var_dump($file_path);
|
|
|
|
$this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]);
|
|
|
|
}
|
|
|
|
$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生成失败!');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function get_data($page = 1, $perPage = 20)
|
|
|
|
{
|
|
|
|
$data = $this->AiccWechat->allData($page, $perPage);
|
|
|
|
# 总条数
|
|
|
|
$total = $data['total'];
|
|
|
|
if (empty($total)) {
|
|
|
|
$this->error('暂无绑定AICC微信数据');
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
$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;
|
|
|
|
$lists->save();
|
|
|
|
$this->debug_echo('项目文件数据保存失败! - 其他原因 - ' . $key);
|
|
|
|
} else {
|
|
|
|
redis_add($key, $count + 1);
|
|
|
|
$this->debug_echo('项目文件数据保存失败! - ' . $key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$lists->is_pdf = 1;
|
|
|
|
$lists->save();
|
|
|
|
$this->debug_echo('项目文件数据保存成功!');
|
|
|
|
return 0;
|
|
|
|
# 详细数据
|
|
|
|
$items = $data['items'];
|
|
|
|
# 总分页
|
|
|
|
$totalPage = $data['totalPage'];
|
|
|
|
# 当前页
|
|
|
|
$currentPage = $data['currentPage'];
|
|
|
|
return compact('total', 'items', 'totalPage', 'currentPage');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function savePDF($html, $filename)
|
|
...
|
...
|
@@ -172,15 +138,16 @@ class ProjectFilePDF extends Command |
|
|
|
// 获取PDF内容
|
|
|
|
$pdfContent = $dompdf->output();
|
|
|
|
|
|
|
|
$fileController = new FileController();
|
|
|
|
|
|
|
|
// 将PDF内容保存到文件
|
|
|
|
@file_put_contents($savePath, $pdfContent);
|
|
|
|
|
|
|
|
// 创建一个文件实例
|
|
|
|
$file = new File($savePath);
|
|
|
|
// var_dump($file->getExtension());
|
|
|
|
// exit();
|
|
|
|
|
|
|
|
echo $this->fileController->single($file);
|
|
|
|
var_dump($file->getFilename());
|
|
|
|
exit();
|
|
|
|
return $fileController->single($file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
...
|
...
|
|