|
...
|
...
|
@@ -12,6 +12,8 @@ use Illuminate\Http\File; |
|
|
|
|
|
|
|
class ProjectFilePDF extends Command
|
|
|
|
{
|
|
|
|
use CmdSignal;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
...
|
...
|
@@ -26,12 +28,17 @@ class ProjectFilePDF extends Command |
|
|
|
*/
|
|
|
|
protected $description = '网站项目数据,生成PDF文件';
|
|
|
|
|
|
|
|
protected $AiccWechat;
|
|
|
|
protected ProjectAssociation $AiccWechat;
|
|
|
|
|
|
|
|
protected $DataFile;
|
|
|
|
protected DataFile $DataFile;
|
|
|
|
|
|
|
|
protected $time;
|
|
|
|
|
|
|
|
// 最大支持5个进程
|
|
|
|
public int $maxRunNumber = 50;
|
|
|
|
|
|
|
|
public FileController $fileController;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new command instance.
|
|
|
|
*
|
|
...
|
...
|
@@ -42,40 +49,27 @@ class ProjectFilePDF extends Command |
|
|
|
$this->AiccWechat = new ProjectAssociation();
|
|
|
|
$this->DataFile = new DataFile();
|
|
|
|
$this->time = date("Y-m");
|
|
|
|
$this->fileController = new FileController();
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
public function start(): int
|
|
|
|
{
|
|
|
|
$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完成');
|
|
|
|
$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();
|
|
|
|
if (is_null($lists)) {
|
|
|
|
$this->debug_echo('没有任务,等待中');
|
|
|
|
sleep(60);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 数据生成并保存
|
|
|
|
* @param array $items
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function dataPush(array $items)
|
|
|
|
{
|
|
|
|
foreach ($items as $item) {
|
|
|
|
$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;
|
|
...
|
...
|
@@ -84,28 +78,25 @@ class ProjectFilePDF extends Command |
|
|
|
$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]);
|
|
|
|
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]);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
# 详细数据
|
|
|
|
$items = $data['items'];
|
|
|
|
# 总分页
|
|
|
|
$totalPage = $data['totalPage'];
|
|
|
|
# 当前页
|
|
|
|
$currentPage = $data['currentPage'];
|
|
|
|
return compact('total', 'items', 'totalPage', 'currentPage');
|
|
|
|
$lists->is_pdf = 1;
|
|
|
|
$lists->save();
|
|
|
|
$this->debug_echo('项目文件数据保存成功!');
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function savePDF($html, $filename)
|
|
...
|
...
|
@@ -138,16 +129,13 @@ class ProjectFilePDF extends Command |
|
|
|
// 获取PDF内容
|
|
|
|
$pdfContent = $dompdf->output();
|
|
|
|
|
|
|
|
$fileController = new FileController();
|
|
|
|
|
|
|
|
// 将PDF内容保存到文件
|
|
|
|
@file_put_contents($savePath, $pdfContent);
|
|
|
|
|
|
|
|
// 创建一个文件实例
|
|
|
|
$file = new File($savePath);
|
|
|
|
var_dump($file->getFilename());
|
|
|
|
exit();
|
|
|
|
return $fileController->single($file);
|
|
|
|
|
|
|
|
return $this->fileController->single($file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
...
|
...
|
|