作者 李美松

优化程序

@@ -5,6 +5,7 @@ namespace App\Console\Commands; @@ -5,6 +5,7 @@ namespace App\Console\Commands;
5 use App\Http\Controllers\File\FileController; 5 use App\Http\Controllers\File\FileController;
6 use App\Models\ProjectAssociation\ProjectAssociation; 6 use App\Models\ProjectAssociation\ProjectAssociation;
7 use App\Models\File\DataFile; 7 use App\Models\File\DataFile;
  8 +use App\Services\CosService;
8 use Dompdf\Dompdf; 9 use Dompdf\Dompdf;
9 use Dompdf\Options; 10 use Dompdf\Options;
10 use Illuminate\Console\Command; 11 use Illuminate\Console\Command;
@@ -36,6 +37,8 @@ class ProjectFilePDF extends Command @@ -36,6 +37,8 @@ class ProjectFilePDF extends Command
36 37
37 protected $fileController; 38 protected $fileController;
38 39
  40 + protected $CosService;
  41 +
39 // 最大支持5个进程 42 // 最大支持5个进程
40 public $maxRunNumber = 50; 43 public $maxRunNumber = 50;
41 44
@@ -50,6 +53,7 @@ class ProjectFilePDF extends Command @@ -50,6 +53,7 @@ class ProjectFilePDF extends Command
50 $this->DataFile = new DataFile(); 53 $this->DataFile = new DataFile();
51 $this->time = date("Y-m"); 54 $this->time = date("Y-m");
52 $this->fileController = new FileController(); 55 $this->fileController = new FileController();
  56 + $this->CosService = new CosService();
53 parent::__construct(); 57 parent::__construct();
54 } 58 }
55 59
@@ -86,8 +90,7 @@ class ProjectFilePDF extends Command @@ -86,8 +90,7 @@ class ProjectFilePDF extends Command
86 $this->debug_echo('pdf生成失败!'); 90 $this->debug_echo('pdf生成失败!');
87 return 0; 91 return 0;
88 } 92 }
89 - $file_path = json_encode($file_path['data']);  
90 - $isRes = $this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]); 93 + $isRes = $this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]);
91 if (!$isRes) { 94 if (!$isRes) {
92 if ($count == 2) { 95 if ($count == 2) {
93 $lists->is_pdf = 2; 96 $lists->is_pdf = 2;
@@ -100,14 +103,15 @@ class ProjectFilePDF extends Command @@ -100,14 +103,15 @@ class ProjectFilePDF extends Command
100 } 103 }
101 $lists->is_pdf = 1; 104 $lists->is_pdf = 1;
102 $lists->save(); 105 $lists->save();
103 - $this->debug_echo('项目文件数据保存成功!'); 106 + $this->info('项目文件数据保存成功!');
104 return 0; 107 return 0;
105 } 108 }
106 109
  110 +
107 /** 111 /**
108 * @param $html 112 * @param $html
109 * @param $filename 113 * @param $filename
110 - * @return array 114 + * @return string
111 */ 115 */
112 public function savePDF($html, $filename) 116 public function savePDF($html, $filename)
113 { 117 {
@@ -137,14 +141,14 @@ class ProjectFilePDF extends Command @@ -137,14 +141,14 @@ class ProjectFilePDF extends Command
137 $dompdf->render(); 141 $dompdf->render();
138 142
139 // 获取PDF内容 143 // 获取PDF内容
140 - $pdfContent = $dompdf->output();  
141 - $this->fileController->path = '/V6/PDF'; 144 + $pdfContent = $dompdf->output();
  145 + $path = '/V6/PDF/' . $this->time;
142 146
143 // 将PDF内容保存到文件 147 // 将PDF内容保存到文件
144 @file_put_contents($savePath, $pdfContent); 148 @file_put_contents($savePath, $pdfContent);
145 // 创建一个文件实例 149 // 创建一个文件实例
146 $file = new File($savePath); 150 $file = new File($savePath);
147 - return $this->fileController->api_upload_single($file); 151 + return $this->CosService->uploadFile($file, $path, $filename . '.pdf');
148 } 152 }
149 153
150 /** 154 /**