作者 赵彬吉
@@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
9 9
10 namespace App\Console\Commands\Test; 10 namespace App\Console\Commands\Test;
11 11
  12 +use App\Models\News\News;
12 use App\Services\CosService; 13 use App\Services\CosService;
13 use Illuminate\Console\Command; 14 use Illuminate\Console\Command;
14 use App\Models\Project\Project; 15 use App\Models\Project\Project;
@@ -36,16 +37,28 @@ class HandleNewsText extends Command @@ -36,16 +37,28 @@ class HandleNewsText extends Command
36 * 37 *
37 * @return void 38 * @return void
38 */ 39 */
  40 + protected $project_id = 0;
39 public function handle() 41 public function handle()
40 { 42 {
41 $projectModel = new Project(); 43 $projectModel = new Project();
42 - $list = $projectModel->list(['delete_status'=>0,'type'=>['!=',0],'id'=>1618]); 44 + $list = $projectModel->list(['delete_status'=>0,'type'=>['!=',0]]);
43 $data = []; 45 $data = [];
44 foreach ($list as $v){ 46 foreach ($list as $v){
  47 + $this->project_id = $v['id'];
45 echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL; 48 echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;
46 ProjectServer::useProject($v['id']); 49 ProjectServer::useProject($v['id']);
  50 + DB::connection('custom_mysql')->statement('DROP TABLE IF EXISTS gl_news_copy');
47 DB::connection('custom_mysql')->statement('CREATE TABLE gl_news_copy LIKE gl_news'); 51 DB::connection('custom_mysql')->statement('CREATE TABLE gl_news_copy LIKE gl_news');
48 DB::connection('custom_mysql')->statement('INSERT INTO gl_news_copy SELECT * FROM gl_news'); 52 DB::connection('custom_mysql')->statement('INSERT INTO gl_news_copy SELECT * FROM gl_news');
  53 + $newsModel = new News();
  54 + $news_list = $newsModel->list(['status'=>['!=',2]],'id',['id','text']);
  55 + if(!empty($news_list)){
  56 + foreach ($news_list as $key => $values){
  57 + echo date('Y-m-d H:i:s') . '处理的数据id:'.$values['id'] . PHP_EOL;
  58 + $text = $this->handleText($values['text']);
  59 + $newsModel->edit(['text'=>$text],['id'=>$values['id']]);
  60 + }
  61 + }
49 DB::disconnect('custom_mysql'); 62 DB::disconnect('custom_mysql');
50 } 63 }
51 echo date('Y-m-d H:i:s') . 'end' . PHP_EOL; 64 echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
@@ -63,7 +76,7 @@ class HandleNewsText extends Command @@ -63,7 +76,7 @@ class HandleNewsText extends Command
63 $matches = []; 76 $matches = [];
64 preg_match_all($pattern, $text, $matches); 77 preg_match_all($pattern, $text, $matches);
65 $text = $this->saveBase64Images($matches[1],$text); 78 $text = $this->saveBase64Images($matches[1],$text);
66 - return $this->success($text); 79 + return ($text);
67 } 80 }
68 81
69 /** 82 /**
@@ -77,12 +90,13 @@ class HandleNewsText extends Command @@ -77,12 +90,13 @@ class HandleNewsText extends Command
77 { 90 {
78 foreach ($imageSources as $src) { 91 foreach ($imageSources as $src) {
79 if (preg_match('/^data:image\/(png|jpg|jpeg|gif);base64,/', $src, $match)) { 92 if (preg_match('/^data:image\/(png|jpg|jpeg|gif);base64,/', $src, $match)) {
  93 + echo date('Y-m-d H:i:s') . '当前数据包含base64图片流。' . PHP_EOL;
80 $imageType = $match[1]; // Image type (png, jpg, etc.) 94 $imageType = $match[1]; // Image type (png, jpg, etc.)
81 $imageUrl = $this->manager_uploads($src,$imageType); 95 $imageUrl = $this->manager_uploads($src,$imageType);
82 $text = str_replace($src, $imageUrl, $text); 96 $text = str_replace($src, $imageUrl, $text);
83 } 97 }
84 } 98 }
85 - return $this->success($text); 99 + return ($text);
86 } 100 }
87 /** 101 /**
88 * @remark :自调用 102 * @remark :自调用
@@ -93,9 +107,9 @@ class HandleNewsText extends Command @@ -93,9 +107,9 @@ class HandleNewsText extends Command
93 */ 107 */
94 public function manager_uploads($files,$type = 'png'){ 108 public function manager_uploads($files,$type = 'png'){
95 $this->uploads = config('upload.default_image'); 109 $this->uploads = config('upload.default_image');
96 - $path = $this->uploads['path_b'].'/'.($this->user['project_id'] ?? 1618).'/image_news/'.date('Y-m'); 110 + $path = $this->uploads['path_b'].'/'.($this->project_id).'/image_news/'.date('Y-m');
97 $cosService = new CosService(); 111 $cosService = new CosService();
98 - $fileName = md5(uniqid() . '_' . time() . '.' . ($this->user['project_id'] ?? 1618).rand(1,10000)) . '.' .$type; 112 + $fileName = md5(uniqid() . '_' . time() . '.' . ($this->project_id).rand(1,10000)) . '.' .$type;
99 return getImageUrl($cosService->uploadFile($files,$path,$fileName)); 113 return getImageUrl($cosService->uploadFile($files,$path,$fileName));
100 } 114 }
101 } 115 }
@@ -254,9 +254,9 @@ class NewsLogic extends BaseLogic @@ -254,9 +254,9 @@ class NewsLogic extends BaseLogic
254 */ 254 */
255 public function manager_uploads($files,$type = 'png'){ 255 public function manager_uploads($files,$type = 'png'){
256 $this->uploads = config('upload.default_image'); 256 $this->uploads = config('upload.default_image');
257 - $path = $this->uploads['path_b'].'/'.($this->user['project_id'] ?? 1618).'/image_news/'.date('Y-m'); 257 + $path = $this->uploads['path_b'].'/'.($this->user['project_id']).'/image_news/'.date('Y-m');
258 $cosService = new CosService(); 258 $cosService = new CosService();
259 - $fileName = md5(uniqid() . '_' . time() . '.' . ($this->user['project_id'] ?? 1618).rand(1,10000)) . '.' .$type; 259 + $fileName = md5(uniqid() . '_' . time() . '.' . ($this->user['project_id']).rand(1,10000)) . '.' .$type;
260 return getImageUrl($cosService->uploadFile($files,$path,$fileName)); 260 return getImageUrl($cosService->uploadFile($files,$path,$fileName));
261 } 261 }
262 /** 262 /**