作者 lyh

Merge branch 'master' of http://47.244.231.31:8099/zhl/globalso-v6 into lyh-server

@@ -4,10 +4,10 @@ namespace App\Console\Commands\Project; @@ -4,10 +4,10 @@ namespace App\Console\Commands\Project;
4 4
5 use App\Helper\Arr; 5 use App\Helper\Arr;
6 use App\Models\Product\Product; 6 use App\Models\Product\Product;
7 -use App\Models\Project\Project;  
8 use App\Services\ProjectServer; 7 use App\Services\ProjectServer;
9 use Illuminate\Console\Command; 8 use Illuminate\Console\Command;
10 use Illuminate\Support\Facades\DB; 9 use Illuminate\Support\Facades\DB;
  10 +use Illuminate\Support\Facades\Redis;
11 11
12 class ThumbProjectImage extends Command 12 class ThumbProjectImage extends Command
13 { 13 {
@@ -16,7 +16,7 @@ class ThumbProjectImage extends Command @@ -16,7 +16,7 @@ class ThumbProjectImage extends Command
16 * 16 *
17 * @var string 17 * @var string
18 */ 18 */
19 - protected $signature = 'thumb_project_image {project_id}'; 19 + protected $signature = 'thumb_project_image';
20 20
21 /** 21 /**
22 * The console command description. 22 * The console command description.
@@ -27,68 +27,38 @@ class ThumbProjectImage extends Command @@ -27,68 +27,38 @@ class ThumbProjectImage extends Command
27 27
28 public function handle() 28 public function handle()
29 { 29 {
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 - } 30 + while (true) {
  31 + $this->start_thumb();
55 } 32 }
56 } 33 }
57 - }  
58 - });  
59 34
60 - DB::disconnect('custom_mysql'); 35 + public function start_thumb()
  36 + {
  37 + $key = 'thumb_project_image';
  38 + $project_id = Redis::rpop($key);
  39 + if (empty($project_id)) {
  40 + sleep(60);
  41 + return true;
61 } 42 }
62 43
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'];  
70 -  
71 $this->output('project_id:' . $project_id . ' | start'); 44 $this->output('project_id:' . $project_id . ' | start');
72 45
73 $project_info = ProjectServer::useProject($project_id); 46 $project_info = ProjectServer::useProject($project_id);
74 47
75 if ($project_info) { 48 if ($project_info) {
76 $thumb_w = $project_info->deploy_build->thumb_w ?? 0; 49 $thumb_w = $project_info->deploy_build->thumb_w ?? 0;
77 - Product::select(['id', 'project_id', 'thumb'])->chunk(100, function ($products) use ($thumb_w) { 50 + Product::select(['id', 'project_id', 'gallery'])->chunk(100, function ($products) use ($thumb_w) {
78 foreach ($products as $product) { 51 foreach ($products as $product) {
79 - $thumb = $product->thumb; 52 + $thumb = $product['gallery'][0] ?? [];
80 if (isset($thumb['url']) && $thumb['url']) { 53 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; 54 + $thumb['url'] = thumbImageByUrl($thumb['url'], $thumb_w);
84 $json_thumb = Arr::a2s($thumb); 55 $json_thumb = Arr::a2s($thumb);
85 if (strlen($json_thumb) <= 500) { 56 if (strlen($json_thumb) <= 500) {
86 $product->timestamps = false; 57 $product->timestamps = false;
87 $product->thumb = $json_thumb; 58 $product->thumb = $json_thumb;
88 $product->save(); 59 $product->save();
89 60
90 - $this->output('project_id:' . $product->project_id . ',product_id:' . $product->id . ' | success');  
91 - } 61 + $this->output('project_id:' . $product->project_id . ',product_id:' . $product->id . ',thumb:' . $thumb_w . ' | success');
92 } 62 }
93 } 63 }
94 } 64 }
@@ -98,8 +68,8 @@ class ThumbProjectImage extends Command @@ -98,8 +68,8 @@ class ThumbProjectImage extends Command
98 } 68 }
99 69
100 $this->output('project_id:' . $project_id . ' | end'); 70 $this->output('project_id:' . $project_id . ' | end');
101 - }  
102 - } 71 +
  72 + return true;
103 } 73 }
104 74
105 75
@@ -1468,7 +1468,8 @@ function diffInHours($startTime, $endTime) @@ -1468,7 +1468,8 @@ function diffInHours($startTime, $endTime)
1468 return round($hours, 1); 1468 return round($hours, 1);
1469 } 1469 }
1470 1470
1471 -/** 1471 +if (!function_exists('thumbImageByUrl')) {
  1472 + /**
1472 * 通过图片地址压缩图片 1473 * 通过图片地址压缩图片
1473 * @param $url 1474 * @param $url
1474 * @param int $width 1475 * @param int $width
@@ -1476,8 +1477,8 @@ function diffInHours($startTime, $endTime) @@ -1476,8 +1477,8 @@ function diffInHours($startTime, $endTime)
1476 * @author Akun 1477 * @author Akun
1477 * @date 2025/09/01 15:18 1478 * @date 2025/09/01 15:18
1478 */ 1479 */
1479 -function thumbImageByUrl($url, $width = 360)  
1480 -{ 1480 + function thumbImageByUrl($url, $width = 360)
  1481 + {
1481 if (empty($url)) { 1482 if (empty($url)) {
1482 return $url; 1483 return $url;
1483 } 1484 }
@@ -1486,10 +1487,6 @@ function thumbImageByUrl($url, $width = 360) @@ -1486,10 +1487,6 @@ function thumbImageByUrl($url, $width = 360)
1486 return $url; 1487 return $url;
1487 } 1488 }
1488 1489
1489 - if (strpos($url, '_thumb') !== false) {  
1490 - return $url;  
1491 - }  
1492 -  
1493 //获取图片完整访问地址 1490 //获取图片完整访问地址
1494 $url_complete = getImageUrl($url, 0, 0, 0);//先用v6-file地址 1491 $url_complete = getImageUrl($url, 0, 0, 0);//先用v6-file地址
1495 if (strpos($url_complete, 'v6-file') !== false) { 1492 if (strpos($url_complete, 'v6-file') !== false) {
@@ -1526,10 +1523,11 @@ function thumbImageByUrl($url, $width = 360) @@ -1526,10 +1523,11 @@ function thumbImageByUrl($url, $width = 360)
1526 1523
1527 $url = $thumb_url ? $thumb_url : $url; 1524 $url = $thumb_url ? $thumb_url : $url;
1528 } catch (\Exception $e) { 1525 } catch (\Exception $e) {
1529 - Log::channel('thumb_img')->error($e->getMessage(), [$url, $width]); 1526 + Log::channel('thumb_img')->error($e->getMessage(), [$url_complete, $width]);
1530 } 1527 }
1531 1528
1532 return $url; 1529 return $url;
  1530 + }
1533 } 1531 }
1534 1532
1535 if (!function_exists('checkRemoteFileExists')) { 1533 if (!function_exists('checkRemoteFileExists')) {
@@ -59,6 +59,7 @@ use Illuminate\Support\Facades\Cache; @@ -59,6 +59,7 @@ use Illuminate\Support\Facades\Cache;
59 use Illuminate\Support\Facades\DB; 59 use Illuminate\Support\Facades\DB;
60 use Illuminate\Support\Facades\Http; 60 use Illuminate\Support\Facades\Http;
61 use Illuminate\Support\Facades\Log as LogInfo; 61 use Illuminate\Support\Facades\Log as LogInfo;
  62 +use Illuminate\Support\Facades\Redis;
62 63
63 /** 64 /**
64 * Class ProjectLogic 65 * Class ProjectLogic
@@ -528,6 +529,13 @@ class ProjectLogic extends BaseLogic @@ -528,6 +529,13 @@ class ProjectLogic extends BaseLogic
528 protected function saveProjectDeployBuild($deploy_build){ 529 protected function saveProjectDeployBuild($deploy_build){
529 $deployBuildModel = new DeployBuild(); 530 $deployBuildModel = new DeployBuild();
530 $deploy_build['configuration'] = Arr::a2s(!empty($deploy_build['configuration']) ? $deploy_build['configuration'] : []); 531 $deploy_build['configuration'] = Arr::a2s(!empty($deploy_build['configuration']) ? $deploy_build['configuration'] : []);
  532 +
  533 + //如果更改了缩略图压缩大小,同步写入处理缩略图任务队列
  534 + $old_thumb_info = $deployBuildModel->read(['id'=>$deploy_build['id']],['thumb_w']);
  535 + if(isset($old_thumb_info['thumb_w']) && $old_thumb_info['thumb_w'] != $deploy_build['thumb_w']){
  536 + Redis::lpush('thumb_project_image',$deploy_build['project_id']);
  537 + }
  538 +
531 $deployBuildModel->edit($deploy_build,['id'=>$deploy_build['id']]); 539 $deployBuildModel->edit($deploy_build,['id'=>$deploy_build['id']]);
532 return $this->success(); 540 return $this->success();
533 } 541 }