作者 刘锟

合并分支 'akun' 到 'master'

Akun



查看合并请求 !2778
@@ -8,6 +8,7 @@ use App\Models\Project\Project; @@ -8,6 +8,7 @@ use App\Models\Project\Project;
8 use App\Services\ProjectServer; 8 use App\Services\ProjectServer;
9 use Illuminate\Console\Command; 9 use Illuminate\Console\Command;
10 use Illuminate\Support\Facades\DB; 10 use Illuminate\Support\Facades\DB;
  11 +use Illuminate\Support\Facades\Redis;
11 12
12 class ThumbProjectImage extends Command 13 class ThumbProjectImage extends Command
13 { 14 {
@@ -16,7 +17,7 @@ class ThumbProjectImage extends Command @@ -16,7 +17,7 @@ class ThumbProjectImage extends Command
16 * 17 *
17 * @var string 18 * @var string
18 */ 19 */
19 - protected $signature = 'thumb_project_image {project_id}'; 20 + protected $signature = 'thumb_project_image';
20 21
21 /** 22 /**
22 * The console command description. 23 * The console command description.
@@ -27,79 +28,49 @@ class ThumbProjectImage extends Command @@ -27,79 +28,49 @@ class ThumbProjectImage extends Command
27 28
28 public function handle() 29 public function handle()
29 { 30 {
30 - $project_id = $this->argument('project_id');  
31 -  
32 - if ($project_id > 0) {  
33 - //指定项目  
34 - $this->output('project_id:' . $project_id . ' | start');  
35 -  
36 - $project_info = ProjectServer::useProject($project_id);  
37 -  
38 - if ($project_info) {  
39 - $thumb_w = $project_info->deploy_build->thumb_w ?? 0;  
40 - Product::select(['id', 'project_id', 'thumb'])->chunk(100, function ($products) use ($thumb_w) {  
41 - foreach ($products as $product) {  
42 - $thumb = $product->thumb;  
43 - if (isset($thumb['url']) && $thumb['url']) {  
44 - $new_thumb = thumbImageByUrl($thumb['url'], $thumb_w);  
45 - if ($new_thumb != $thumb['url']) {  
46 - $thumb['url'] = $new_thumb;  
47 - $json_thumb = Arr::a2s($thumb);  
48 - if (strlen($json_thumb) <= 500) {  
49 - $product->timestamps = false;  
50 - $product->thumb = $json_thumb;  
51 - $product->save();  
52 -  
53 - $this->output('project_id:' . $product->project_id . ',product_id:' . $product->id . ' | success');  
54 - }  
55 - }  
56 - }  
57 - }  
58 - });  
59 -  
60 - DB::disconnect('custom_mysql');  
61 - } 31 + while (true) {
  32 + $this->start_thumb();
  33 + }
  34 + }
62 35
63 - $this->output('project_id:' . $project_id . ' | end');  
64 - } else {  
65 - //所有项目  
66 - $projectModel = new Project();  
67 - $list = $projectModel->list(['delete_status' => 0, 'is_upgrade' => 0, 'type' => ['in', [1, 2, 3, 4, 6]]], 'id', ['id'], 'asc');  
68 - foreach ($list as $k => $v) {  
69 - $project_id = $v['id']; 36 + public function start_thumb()
  37 + {
  38 + $key = 'thumb_project_image';
  39 + $project_id = Redis::rpop($key);
  40 + if (empty($project_id)) {
  41 + sleep(60);
  42 + return true;
  43 + }
70 44
71 - $this->output('project_id:' . $project_id . ' | start'); 45 + $this->output('project_id:' . $project_id . ' | start');
72 46
73 - $project_info = ProjectServer::useProject($project_id); 47 + $project_info = ProjectServer::useProject($project_id);
74 48
75 - if ($project_info) {  
76 - $thumb_w = $project_info->deploy_build->thumb_w ?? 0;  
77 - Product::select(['id', 'project_id', 'thumb'])->chunk(100, function ($products) use ($thumb_w) {  
78 - foreach ($products as $product) {  
79 - $thumb = $product->thumb;  
80 - if (isset($thumb['url']) && $thumb['url']) {  
81 - $new_thumb = thumbImageByUrl($thumb['url'], $thumb_w);  
82 - if ($new_thumb != $thumb['url']) {  
83 - $thumb['url'] = $new_thumb;  
84 - $json_thumb = Arr::a2s($thumb);  
85 - if (strlen($json_thumb) <= 500) {  
86 - $product->timestamps = false;  
87 - $product->thumb = $json_thumb;  
88 - $product->save(); 49 + if ($project_info) {
  50 + $thumb_w = $project_info->deploy_build->thumb_w ?? 0;
  51 + Product::select(['id', 'project_id', 'gallery'])->chunk(100, function ($products) use ($thumb_w) {
  52 + foreach ($products as $product) {
  53 + $thumb = $product['gallery'][0] ?? [];
  54 + if (isset($thumb['url']) && $thumb['url']) {
  55 + $thumb['url'] = thumbImageByUrl($thumb['url'], $thumb_w);
  56 + $json_thumb = Arr::a2s($thumb);
  57 + if (strlen($json_thumb) <= 500) {
  58 + $product->timestamps = false;
  59 + $product->thumb = $json_thumb;
  60 + $product->save();
89 61
90 - $this->output('project_id:' . $product->project_id . ',product_id:' . $product->id . ' | success');  
91 - }  
92 - }  
93 - } 62 + $this->output('project_id:' . $product->project_id . ',product_id:' . $product->id . ' | success');
94 } 63 }
95 - });  
96 -  
97 - DB::disconnect('custom_mysql'); 64 + }
98 } 65 }
  66 + });
99 67
100 - $this->output('project_id:' . $project_id . ' | end');  
101 - } 68 + DB::disconnect('custom_mysql');
102 } 69 }
  70 +
  71 + $this->output('project_id:' . $project_id . ' | end');
  72 +
  73 + return true;
103 } 74 }
104 75
105 76
@@ -1486,10 +1486,6 @@ function thumbImageByUrl($url, $width = 360) @@ -1486,10 +1486,6 @@ function thumbImageByUrl($url, $width = 360)
1486 return $url; 1486 return $url;
1487 } 1487 }
1488 1488
1489 - if (strpos($url, '_thumb') !== false) {  
1490 - return $url;  
1491 - }  
1492 -  
1493 //获取图片完整访问地址 1489 //获取图片完整访问地址
1494 $url_complete = getImageUrl($url, 0, 0, 0);//先用v6-file地址 1490 $url_complete = getImageUrl($url, 0, 0, 0);//先用v6-file地址
1495 if (strpos($url_complete, 'v6-file') !== false) { 1491 if (strpos($url_complete, 'v6-file') !== false) {