作者 lyh

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

  1 +<?php
  2 +
  3 +namespace App\Console\Commands\Project;
  4 +
  5 +use App\Helper\Arr;
  6 +use App\Models\Product\Product;
  7 +use App\Services\ProjectServer;
  8 +use Illuminate\Console\Command;
  9 +use Illuminate\Support\Facades\DB;
  10 +
  11 +class ThumbProjectImage extends Command
  12 +{
  13 + /**
  14 + * The name and signature of the console command.
  15 + *
  16 + * @var string
  17 + */
  18 + protected $signature = 'thumb_project_image {project_id}';
  19 +
  20 + /**
  21 + * The console command description.
  22 + *
  23 + * @var string
  24 + */
  25 + protected $description = '处理项目产品缩略图';
  26 +
  27 + public function handle()
  28 + {
  29 + $project_id = $this->argument('project_id');
  30 +
  31 + if ($project_id > 0) {
  32 + //指定项目
  33 + ProjectServer::useProject($project_id);
  34 +
  35 + Product::select(['id', 'thumb'])->chunk(100, function ($products) {
  36 + foreach ($products as $product) {
  37 + $thumb = $product->thumb;
  38 + if (isset($thumb['url']) && $thumb['url']) {
  39 + $thumb['url'] = thumbImageByUrl($thumb['url']);
  40 + $product->thumb = Arr::a2s($thumb);
  41 + $product->save();
  42 + }
  43 + }
  44 + });
  45 +
  46 + DB::disconnect('custom_mysql');
  47 +
  48 + $this->output('project_id:' . $project_id . ' | success');
  49 + } else {
  50 + //TODO:所有项目
  51 + }
  52 + }
  53 +
  54 +
  55 + /**
  56 + * 输出处理日志
  57 + * @param $message
  58 + * @return bool
  59 + */
  60 + public function output($message)
  61 + {
  62 + echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL;
  63 + return true;
  64 + }
  65 +}
@@ -13,6 +13,7 @@ use GuzzleHttp\Client; @@ -13,6 +13,7 @@ use GuzzleHttp\Client;
13 use GuzzleHttp\Exception\GuzzleException; 13 use GuzzleHttp\Exception\GuzzleException;
14 use Illuminate\Support\Carbon; 14 use Illuminate\Support\Carbon;
15 use Illuminate\Support\Facades\Cache; 15 use Illuminate\Support\Facades\Cache;
  16 +use Illuminate\Support\Facades\Log;
16 use Illuminate\Support\Facades\Redis; 17 use Illuminate\Support\Facades\Redis;
17 18
18 define('HTTP_OPENAI_URL', 'http://openai.waimaoq.com/'); 19 define('HTTP_OPENAI_URL', 'http://openai.waimaoq.com/');
@@ -28,7 +29,7 @@ define('HTTP_OPENAI_URL', 'http://openai.waimaoq.com/'); @@ -28,7 +29,7 @@ define('HTTP_OPENAI_URL', 'http://openai.waimaoq.com/');
28 if (!function_exists('generateRoute')) { 29 if (!function_exists('generateRoute')) {
29 function generateRoute($string) 30 function generateRoute($string)
30 { 31 {
31 - if(is_array($string)){ 32 + if (is_array($string)) {
32 $string = $string[0]; 33 $string = $string[0];
33 } 34 }
34 $sign = str_replace(".", "", trim(strtolower(preg_replace('/[^\w.]+/', '-', trim($string))), '-')); 35 $sign = str_replace(".", "", trim(strtolower(preg_replace('/[^\w.]+/', '-', trim($string))), '-'));
@@ -61,7 +62,7 @@ if (!function_exists('http_post')) { @@ -61,7 +62,7 @@ if (!function_exists('http_post')) {
61 * @param type $url 62 * @param type $url
62 * @param type $post_data 63 * @param type $post_data
63 */ 64 */
64 - function http_post($url, $post_data, $header = [],$is_json = true,$timeout = 60) 65 + function http_post($url, $post_data, $header = [], $is_json = true, $timeout = 60)
65 { 66 {
66 if (empty($header)) { 67 if (empty($header)) {
67 $header = array( 68 $header = array(
@@ -87,7 +88,7 @@ if (!function_exists('http_post')) { @@ -87,7 +88,7 @@ if (!function_exists('http_post')) {
87 @file_put_contents(storage_path('logs/lyh_error.log'), var_export($error_message, true) . PHP_EOL, FILE_APPEND); 88 @file_put_contents(storage_path('logs/lyh_error.log'), var_export($error_message, true) . PHP_EOL, FILE_APPEND);
88 } 89 }
89 curl_close($ch); 90 curl_close($ch);
90 - if($is_json){ 91 + if ($is_json) {
91 return json_decode($res, true); 92 return json_decode($res, true);
92 } 93 }
93 return trim($res); 94 return trim($res);
@@ -130,7 +131,7 @@ if (!function_exists('http_get')) { @@ -130,7 +131,7 @@ if (!function_exists('http_get')) {
130 131
131 132
132 if (!function_exists('curl_get')) { 133 if (!function_exists('curl_get')) {
133 - function curl_get($url,$is_array=true) 134 + function curl_get($url, $is_array = true)
134 { 135 {
135 $header = array( 136 $header = array(
136 'Expect:', 137 'Expect:',
@@ -161,7 +162,8 @@ if (!function_exists('curl_get')) { @@ -161,7 +162,8 @@ if (!function_exists('curl_get')) {
161 * @method :post 162 * @method :post
162 * @time :2024/6/5 10:38 163 * @time :2024/6/5 10:38
163 */ 164 */
164 -function contains_russian($text) { 165 +function contains_russian($text)
  166 +{
165 // 使用正则表达式检查是否包含俄语字符 167 // 使用正则表达式检查是否包含俄语字符
166 return preg_match('/[\x{0400}-\x{04FF}]/u', $text) > 0; 168 return preg_match('/[\x{0400}-\x{04FF}]/u', $text) > 0;
167 169
@@ -176,7 +178,8 @@ if (!function_exists('curl_c')) { @@ -176,7 +178,8 @@ if (!function_exists('curl_c')) {
176 * @author Akun 178 * @author Akun
177 * @date 2023/11/22 11:33 179 * @date 2023/11/22 11:33
178 */ 180 */
179 - function curl_c($url,$is_array=true,$replace=[]){ 181 + function curl_c($url, $is_array = true, $replace = [])
  182 + {
180 $header = array( 183 $header = array(
181 'Expect:', 184 'Expect:',
182 'Content-Type: application/json; charset=utf-8' 185 'Content-Type: application/json; charset=utf-8'
@@ -195,16 +198,16 @@ if (!function_exists('curl_c')) { @@ -195,16 +198,16 @@ if (!function_exists('curl_c')) {
195 curl_setopt($ch, CURLOPT_SSLVERSION, 'all'); 198 curl_setopt($ch, CURLOPT_SSLVERSION, 'all');
196 curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 199 curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
197 $content = curl_exec($ch); 200 $content = curl_exec($ch);
198 - $http_code = curl_getinfo($ch,CURLINFO_HTTP_CODE); 201 + $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
199 curl_close($ch); 202 curl_close($ch);
200 - if($http_code == 200){  
201 - if(!empty($replace)){  
202 - foreach ($replace as $k=>$v){  
203 - $content = str_replace($k,$v,$content); 203 + if ($http_code == 200) {
  204 + if (!empty($replace)) {
  205 + foreach ($replace as $k => $v) {
  206 + $content = str_replace($k, $v, $content);
204 } 207 }
205 } 208 }
206 return $is_array ? json_decode($content, true) : $content; 209 return $is_array ? json_decode($content, true) : $content;
207 - }else{ 210 + } else {
208 return false; 211 return false;
209 } 212 }
210 } 213 }
@@ -218,7 +221,8 @@ if (!function_exists('curl_code')) { @@ -218,7 +221,8 @@ if (!function_exists('curl_code')) {
218 * @author Akun 221 * @author Akun
219 * @date 2023/11/22 11:33 222 * @date 2023/11/22 11:33
220 */ 223 */
221 - function curl_code($url,$is_array=true){ 224 + function curl_code($url, $is_array = true)
  225 + {
222 $header = array( 226 $header = array(
223 'Expect:', 227 'Expect:',
224 'Content-Type: application/json; charset=utf-8' 228 'Content-Type: application/json; charset=utf-8'
@@ -237,11 +241,11 @@ if (!function_exists('curl_code')) { @@ -237,11 +241,11 @@ if (!function_exists('curl_code')) {
237 curl_setopt($ch, CURLOPT_SSLVERSION, 'all'); 241 curl_setopt($ch, CURLOPT_SSLVERSION, 'all');
238 curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 242 curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
239 $content = curl_exec($ch); 243 $content = curl_exec($ch);
240 - $http_code = curl_getinfo($ch,CURLINFO_HTTP_CODE); 244 + $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
241 curl_close($ch); 245 curl_close($ch);
242 - if($http_code == 200){ 246 + if ($http_code == 200) {
243 return $is_array ? json_decode($content, true) : $content; 247 return $is_array ? json_decode($content, true) : $content;
244 - }else{ 248 + } else {
245 return $http_code; 249 return $http_code;
246 } 250 }
247 } 251 }
@@ -274,7 +278,7 @@ if (!function_exists('_get_all_sub')) { @@ -274,7 +278,7 @@ if (!function_exists('_get_all_sub')) {
274 * @param int 278 * @param int
275 * @return array 279 * @return array
276 */ 280 */
277 - function _get_all_sub($my_id,$id_Arr) 281 + function _get_all_sub($my_id, $id_Arr)
278 { 282 {
279 $new_arr[] = $my_id; 283 $new_arr[] = $my_id;
280 foreach ($id_Arr as $v) { 284 foreach ($id_Arr as $v) {
@@ -659,34 +663,35 @@ if (!function_exists('getImageUrl')) { @@ -659,34 +663,35 @@ if (!function_exists('getImageUrl')) {
659 * @method :post 663 * @method :post
660 * @time :2023/7/20 16:46 664 * @time :2023/7/20 16:46
661 */ 665 */
662 - function getImageUrl($path,$storage_type = 0,$location = 0,$image_cdn = 1){  
663 - if(is_array($path)){  
664 - $url =[];  
665 - foreach ($path as $v){  
666 - $url[] = getImageUrl($v,$storage_type,$location);  
667 - }  
668 - }else{  
669 - if(empty($path)){ 666 + function getImageUrl($path, $storage_type = 0, $location = 0, $image_cdn = 1)
  667 + {
  668 + if (is_array($path)) {
  669 + $url = [];
  670 + foreach ($path as $v) {
  671 + $url[] = getImageUrl($v, $storage_type, $location);
  672 + }
  673 + } else {
  674 + if (empty($path)) {
670 return ''; 675 return '';
671 } 676 }
672 - if((strpos($path,'https://')!== false) || (strpos($path,'http://') !== false)){ 677 + if ((strpos($path, 'https://') !== false) || (strpos($path, 'http://') !== false)) {
673 return $path; 678 return $path;
674 } 679 }
675 - if(substr($path,0,2) == '//'){  
676 - return 'https:'.$path; 680 + if (substr($path, 0, 2) == '//') {
  681 + return 'https:' . $path;
677 } 682 }
678 - if($location == 0){ 683 + if ($location == 0) {
679 $cos = config('filesystems.disks.cos'); 684 $cos = config('filesystems.disks.cos');
680 - if($image_cdn == 0){//v6链接 685 + if ($image_cdn == 0) {//v6链接
681 $cosCdn = $cos['cdn2']; 686 $cosCdn = $cos['cdn2'];
682 - }else{ 687 + } else {
683 $cosCdn = ($storage_type == 0) ? $cos['cdn'] : $cos['cdn1']; 688 $cosCdn = ($storage_type == 0) ? $cos['cdn'] : $cos['cdn1'];
684 } 689 }
685 - $url = $cosCdn.$path;  
686 - }else{ 690 + $url = $cosCdn . $path;
  691 + } else {
687 $s3 = config('filesystems.disks.s3'); 692 $s3 = config('filesystems.disks.s3');
688 $cdn = $s3['cdn']; 693 $cdn = $s3['cdn'];
689 - $url = $cdn.$path; 694 + $url = $cdn . $path;
690 } 695 }
691 } 696 }
692 return $url; 697 return $url;
@@ -701,36 +706,37 @@ if (!function_exists('getFileUrl')) { @@ -701,36 +706,37 @@ if (!function_exists('getFileUrl')) {
701 * @method :post 706 * @method :post
702 * @time :2023/7/20 16:46 707 * @time :2023/7/20 16:46
703 */ 708 */
704 - function getFileUrl($path,$storage_type = 0,$location = 0,$file_cdn = 0){  
705 - if(is_array($path)){  
706 - $url =[];  
707 - foreach ($path as $v){  
708 - $url[] = getFileUrl($v,$storage_type,$location,$file_cdn);  
709 - }  
710 - }else{  
711 - if(empty($path)){ 709 + function getFileUrl($path, $storage_type = 0, $location = 0, $file_cdn = 0)
  710 + {
  711 + if (is_array($path)) {
  712 + $url = [];
  713 + foreach ($path as $v) {
  714 + $url[] = getFileUrl($v, $storage_type, $location, $file_cdn);
  715 + }
  716 + } else {
  717 + if (empty($path)) {
712 return ''; 718 return '';
713 } 719 }
714 - if((strpos($path,'https://')!== false) || (strpos($path,'http://') !== false)){ 720 + if ((strpos($path, 'https://') !== false) || (strpos($path, 'http://') !== false)) {
715 return $path; 721 return $path;
716 } 722 }
717 - if(substr($path,0,2) == '//'){  
718 - return 'https:'.$path; 723 + if (substr($path, 0, 2) == '//') {
  724 + return 'https:' . $path;
719 } 725 }
720 $file_type = pathinfo($path, PATHINFO_EXTENSION); 726 $file_type = pathinfo($path, PATHINFO_EXTENSION);
721 $fileTypeArr = ['zip', 'pdf', 'mp4', 'doc', 'docx', 'm4v', 'xlsx']; 727 $fileTypeArr = ['zip', 'pdf', 'mp4', 'doc', 'docx', 'm4v', 'xlsx'];
722 - if(in_array(strtolower($file_type),$fileTypeArr) && ($file_cdn == 0)){ 728 + if (in_array(strtolower($file_type), $fileTypeArr) && ($file_cdn == 0)) {
723 $cdn2 = config('filesystems.disks.cos')['cdn2']; 729 $cdn2 = config('filesystems.disks.cos')['cdn2'];
724 - return $cdn2.$path; 730 + return $cdn2 . $path;
725 } 731 }
726 - if($location == 0){ 732 + if ($location == 0) {
727 $cos = config('filesystems.disks.cos'); 733 $cos = config('filesystems.disks.cos');
728 $cosCdn = ($storage_type == 0) ? $cos['cdn'] : $cos['cdn1']; 734 $cosCdn = ($storage_type == 0) ? $cos['cdn'] : $cos['cdn1'];
729 - return $cosCdn.$path;  
730 - }else{ 735 + return $cosCdn . $path;
  736 + } else {
731 $s3 = config('filesystems.disks.s3'); 737 $s3 = config('filesystems.disks.s3');
732 $cdn = $s3['cdn']; 738 $cdn = $s3['cdn'];
733 - return $cdn.$path; 739 + return $cdn . $path;
734 } 740 }
735 } 741 }
736 return $url; 742 return $url;
@@ -744,7 +750,8 @@ if (!function_exists('getFileUrl')) { @@ -744,7 +750,8 @@ if (!function_exists('getFileUrl')) {
744 * @method :post 750 * @method :post
745 * @time :2023/6/28 17:39 751 * @time :2023/6/28 17:39
746 */ 752 */
747 -function characterTruncation($string,$pattern){ 753 +function characterTruncation($string, $pattern)
  754 +{
748 preg_match($pattern, $string, $matches); 755 preg_match($pattern, $string, $matches);
749 if (isset($matches[0])) { 756 if (isset($matches[0])) {
750 $result = $matches[0]; 757 $result = $matches[0];
@@ -761,7 +768,8 @@ function characterTruncation($string,$pattern){ @@ -761,7 +768,8 @@ function characterTruncation($string,$pattern){
761 * @method :post 768 * @method :post
762 * @time :2024/5/14 16:24 769 * @time :2024/5/14 16:24
763 */ 770 */
764 -function characterTruncationStr($string,$startStr,$endStr){ 771 +function characterTruncationStr($string, $startStr, $endStr)
  772 +{
765 $start = strpos($string, $startStr); 773 $start = strpos($string, $startStr);
766 $end = strpos($string, $endStr) + strlen($endStr); 774 $end = strpos($string, $endStr) + strlen($endStr);
767 return substr($string, $start, $end - $start); 775 return substr($string, $start, $end - $start);
@@ -798,7 +806,7 @@ if (!function_exists('str_replace_url')) { @@ -798,7 +806,7 @@ if (!function_exists('str_replace_url')) {
798 $cosCdn1 = $cos['cdn1']; 806 $cosCdn1 = $cos['cdn1'];
799 $cosCdn2 = $cos['cdn2']; 807 $cosCdn2 = $cos['cdn2'];
800 $cosCdn3 = config('filesystems.disks.s3')['cdn']; 808 $cosCdn3 = config('filesystems.disks.s3')['cdn'];
801 - if($url && ((strpos($url,$cosCdn) !== false) || (strpos($url,$cosCdn1) !== false) || (strpos($url,$cosCdn2) !== false) || (strpos($url,$cosCdn3) !== false))){ 809 + if ($url && ((strpos($url, $cosCdn) !== false) || (strpos($url, $cosCdn1) !== false) || (strpos($url, $cosCdn2) !== false) || (strpos($url, $cosCdn3) !== false))) {
802 // 外部URL无需解析 810 // 外部URL无需解析
803 // 使用 parse_url 函数来解析 URL 811 // 使用 parse_url 函数来解析 URL
804 $urlParts = parse_url($url); 812 $urlParts = parse_url($url);
@@ -812,7 +820,7 @@ if (!function_exists('str_replace_url')) { @@ -812,7 +820,7 @@ if (!function_exists('str_replace_url')) {
812 } 820 }
813 } 821 }
814 822
815 -if(!function_exists('curlGet')){ 823 +if (!function_exists('curlGet')) {
816 /** 824 /**
817 * @remark :忽略证书curl请求 825 * @remark :忽略证书curl请求
818 * @name :curlGet 826 * @name :curlGet
@@ -820,7 +828,8 @@ if(!function_exists('curlGet')){ @@ -820,7 +828,8 @@ if(!function_exists('curlGet')){
820 * @method :post 828 * @method :post
821 * @time :2023/9/12 10:10 829 * @time :2023/9/12 10:10
822 */ 830 */
823 - function curlGet($url){ 831 + function curlGet($url)
  832 + {
824 $ch1 = curl_init(); 833 $ch1 = curl_init();
825 $timeout = 60; 834 $timeout = 60;
826 curl_setopt($ch1, CURLOPT_URL, $url); 835 curl_setopt($ch1, CURLOPT_URL, $url);
@@ -852,15 +861,15 @@ function ends_with($string, $suffix) @@ -852,15 +861,15 @@ function ends_with($string, $suffix)
852 * @method :post 861 * @method :post
853 * @time :2025/6/21 9:57 862 * @time :2025/6/21 9:57
854 */ 863 */
855 -function getCustomRouteMap($module_route,$route = '',$is_upgrade = 0) 864 +function getCustomRouteMap($module_route, $route = '', $is_upgrade = 0)
856 { 865 {
857 - if($is_upgrade == 0){ 866 + if ($is_upgrade == 0) {
858 return $route; 867 return $route;
859 } 868 }
860 - if($module_route == $route){ 869 + if ($module_route == $route) {
861 $resultRoute = $route; 870 $resultRoute = $route;
862 - }else{  
863 - $resultRoute = $module_route.'_catalog/'.$route; 871 + } else {
  872 + $resultRoute = $module_route . '_catalog/' . $route;
864 } 873 }
865 return $resultRoute; 874 return $resultRoute;
866 } 875 }
@@ -872,48 +881,53 @@ function getCustomRouteMap($module_route,$route = '',$is_upgrade = 0) @@ -872,48 +881,53 @@ function getCustomRouteMap($module_route,$route = '',$is_upgrade = 0)
872 * @method :post 881 * @method :post
873 * @time :2023/11/10 14:29 882 * @time :2023/11/10 14:29
874 */ 883 */
875 -function getRouteMap($source,$source_id,$is_upgrade = 0, $returnModel = false){ 884 +function getRouteMap($source, $source_id, $is_upgrade = 0, $returnModel = false)
  885 +{
876 $route = ''; 886 $route = '';
877 $routeMapModel = new RouteMap(); 887 $routeMapModel = new RouteMap();
878 - $info = $routeMapModel->read(['source'=>$source,'source_id'=>$source_id]);  
879 - if($info !== false){  
880 - if($is_upgrade == 1){  
881 - if($source == $routeMapModel::SOURCE_NEWS_CATE){  
882 - if($info['route'] != 'news'){  
883 - return $routeMapModel::PATH_NEWS_CATE.'/'.$info['route']; 888 + $info = $routeMapModel->read(['source' => $source, 'source_id' => $source_id]);
  889 + if ($info !== false) {
  890 + if ($is_upgrade == 1) {
  891 + if ($source == $routeMapModel::SOURCE_NEWS_CATE) {
  892 + if ($info['route'] != 'news') {
  893 + return $routeMapModel::PATH_NEWS_CATE . '/' . $info['route'];
884 } 894 }
885 - }elseif ($source == $routeMapModel::SOURCE_BLOG_CATE){  
886 - if($info['route'] != 'blog'){  
887 - return $routeMapModel::PATH_BLOG_CATE.'/'.$info['route']; 895 + } elseif ($source == $routeMapModel::SOURCE_BLOG_CATE) {
  896 + if ($info['route'] != 'blog') {
  897 + return $routeMapModel::PATH_BLOG_CATE . '/' . $info['route'];
888 } 898 }
889 } 899 }
890 $route = $info['route']; 900 $route = $info['route'];
891 return $route; 901 return $route;
892 } 902 }
893 - if(!empty($info['path'])){  
894 - if($info['path'] == 'blog'){  
895 - $info['path'] = $info['path'].'s'; 903 + if (!empty($info['path'])) {
  904 + if ($info['path'] == 'blog') {
  905 + $info['path'] = $info['path'] . 's';
896 } 906 }
897 - $route = $info['path'].'/'.$info['route'];  
898 - }else{ 907 + $route = $info['path'] . '/' . $info['route'];
  908 + } else {
899 $route = $info['route']; 909 $route = $info['route'];
900 } 910 }
901 } 911 }
902 - if($returnModel && ($info !== false)){ 912 + if ($returnModel && ($info !== false)) {
903 return $info; 913 return $info;
904 } 914 }
905 return $route; 915 return $route;
906 } 916 }
907 917
908 -function redis_get($key){ 918 +function redis_get($key)
  919 +{
909 return Redis::connection()->client()->get($key); 920 return Redis::connection()->client()->get($key);
910 } 921 }
911 -function redis_del(...$key){ 922 +
  923 +function redis_del(...$key)
  924 +{
912 return Redis::connection()->client()->del(...$key); 925 return Redis::connection()->client()->del(...$key);
913 } 926 }
914 927
915 -function redis_set($key,$val,$ttl=3600){  
916 - return Redis::connection()->client()->set($key,$val,$ttl); 928 +function redis_set($key, $val, $ttl = 3600)
  929 +{
  930 + return Redis::connection()->client()->set($key, $val, $ttl);
917 } 931 }
918 932
919 /** 933 /**
@@ -925,7 +939,8 @@ function redis_set($key,$val,$ttl=3600){ @@ -925,7 +939,8 @@ function redis_set($key,$val,$ttl=3600){
925 * @author:dc 939 * @author:dc
926 * @time 2023/10/25 9:48 940 * @time 2023/10/25 9:48
927 */ 941 */
928 -function redis_add($key,$val,$ttl=3600){ 942 +function redis_add($key, $val, $ttl = 3600)
  943 +{
929 return Redis::connection()->client()->eval( 944 return Redis::connection()->client()->eval(
930 "return redis.call('exists',KEYS[1])<1 and redis.call('setex',KEYS[1],ARGV[2],ARGV[1])", [$key, $val, $ttl], 1 945 "return redis.call('exists',KEYS[1])<1 and redis.call('setex',KEYS[1],ARGV[2],ARGV[1])", [$key, $val, $ttl], 1
931 ); 946 );
@@ -937,11 +952,12 @@ function redis_add($key,$val,$ttl=3600){ @@ -937,11 +952,12 @@ function redis_add($key,$val,$ttl=3600){
937 * @param $project_id 952 * @param $project_id
938 * @param $domain 953 * @param $domain
939 * @param $is_complete 954 * @param $is_complete
940 - * @author Akun  
941 * @return bool 955 * @return bool
942 * @date 2023/12/08 14:17 956 * @date 2023/12/08 14:17
  957 + * @author Akun
943 */ 958 */
944 -function check_remote_url_down($url,$project_id,$domain,$is_complete=0){ 959 +function check_remote_url_down($url, $project_id, $domain, $is_complete = 0)
  960 +{
945 961
946 if (!$url) { 962 if (!$url) {
947 return ''; 963 return '';
@@ -950,24 +966,24 @@ function check_remote_url_down($url,$project_id,$domain,$is_complete=0){ @@ -950,24 +966,24 @@ function check_remote_url_down($url,$project_id,$domain,$is_complete=0){
950 $arr = parse_url($url); 966 $arr = parse_url($url);
951 $scheme = $arr['scheme'] ?? ''; 967 $scheme = $arr['scheme'] ?? '';
952 $host = $arr['host'] ?? ''; 968 $host = $arr['host'] ?? '';
953 - $host_arr = explode('.',$host); 969 + $host_arr = explode('.', $host);
954 $path = $arr['path'] ?? ''; 970 $path = $arr['path'] ?? '';
955 971
956 - if(strpos($host_arr[0], 'cdn') !== false){ 972 + if (strpos($host_arr[0], 'cdn') !== false) {
957 return $url; 973 return $url;
958 } 974 }
959 975
960 - if($host_arr[0] == 'file' && $host_arr[1] == 'globalso'){ 976 + if ($host_arr[0] == 'file' && $host_arr[1] == 'globalso') {
961 return $url; 977 return $url;
962 } 978 }
963 979
964 //475项目特殊处理 980 //475项目特殊处理
965 - if($project_id == 475 && $host == 'www.ebuyplc.com'){ 981 + if ($project_id == 475 && $host == 'www.ebuyplc.com') {
966 $host = 'g934.goodao.net'; 982 $host = 'g934.goodao.net';
967 } 983 }
968 984
969 - if($path && substr($path,0,1) != '/'){  
970 - $path = '/'.$path; 985 + if ($path && substr($path, 0, 1) != '/') {
  986 + $path = '/' . $path;
971 } 987 }
972 988
973 if ( 989 if (
@@ -978,13 +994,13 @@ function check_remote_url_down($url,$project_id,$domain,$is_complete=0){ @@ -978,13 +994,13 @@ function check_remote_url_down($url,$project_id,$domain,$is_complete=0){
978 ) { 994 ) {
979 $url_complete = ($scheme ?: 'https') . '://' . ($host ?: $domain) . $path; 995 $url_complete = ($scheme ?: 'https') . '://' . ($host ?: $domain) . $path;
980 996
981 - $new_url = CosService::uploadRemote($project_id,'image_product',$url_complete);  
982 - if($new_url){ 997 + $new_url = CosService::uploadRemote($project_id, 'image_product', $url_complete);
  998 + if ($new_url) {
983 return $is_complete ? getImageUrl($new_url) : $new_url; 999 return $is_complete ? getImageUrl($new_url) : $new_url;
984 - }else{ 1000 + } else {
985 return false; 1001 return false;
986 } 1002 }
987 - }else{ 1003 + } else {
988 return false; 1004 return false;
989 } 1005 }
990 } 1006 }
@@ -994,10 +1010,11 @@ function check_remote_url_down($url,$project_id,$domain,$is_complete=0){ @@ -994,10 +1010,11 @@ function check_remote_url_down($url,$project_id,$domain,$is_complete=0){
994 * @author zbj 1010 * @author zbj
995 * @date 2024/3/29 1011 * @date 2024/3/29
996 */ 1012 */
997 -function textareaToArr($content, $separator = ','){  
998 - return array_values(array_filter(array_unique(array_map(function ($v){ 1013 +function textareaToArr($content, $separator = ',')
  1014 +{
  1015 + return array_values(array_filter(array_unique(array_map(function ($v) {
999 return trim($v); 1016 return trim($v);
1000 - },explode($separator, $content))))); 1017 + }, explode($separator, $content)))));
1001 } 1018 }
1002 1019
1003 /** 1020 /**
@@ -1007,7 +1024,8 @@ function textareaToArr($content, $separator = ','){ @@ -1007,7 +1024,8 @@ function textareaToArr($content, $separator = ','){
1007 * @method :post 1024 * @method :post
1008 * @time :2024/6/26 10:46 1025 * @time :2024/6/26 10:46
1009 */ 1026 */
1010 -function ip_to_unique_string($ip) { 1027 +function ip_to_unique_string($ip)
  1028 +{
1011 // 将IP地址转换为数值表示 1029 // 将IP地址转换为数值表示
1012 $ip_number = ip2long($ip); 1030 $ip_number = ip2long($ip);
1013 // 使用哈希函数生成唯一数值 1031 // 使用哈希函数生成唯一数值
@@ -1021,7 +1039,8 @@ function ip_to_unique_string($ip) { @@ -1021,7 +1039,8 @@ function ip_to_unique_string($ip) {
1021 return strtolower($unique_string); 1039 return strtolower($unique_string);
1022 } 1040 }
1023 1041
1024 -function base62_encode($num) { 1042 +function base62_encode($num)
  1043 +{
1025 $characters = '23456789abcdefghijkmnpqrstuvwxyz'; 1044 $characters = '23456789abcdefghijkmnpqrstuvwxyz';
1026 $base = strlen($characters); 1045 $base = strlen($characters);
1027 $result = ''; 1046 $result = '';
@@ -1039,8 +1058,9 @@ function base62_encode($num) { @@ -1039,8 +1058,9 @@ function base62_encode($num) {
1039 * @method :post 1058 * @method :post
1040 * @time :2024/8/19 14:21 1059 * @time :2024/8/19 14:21
1041 */ 1060 */
1042 -function urlSafeBase64Encode($data = '') {  
1043 - if(empty($data)){ 1061 +function urlSafeBase64Encode($data = '')
  1062 +{
  1063 + if (empty($data)) {
1044 return $data; 1064 return $data;
1045 } 1065 }
1046 // 1. 使用标准的 BASE64 编码 1066 // 1. 使用标准的 BASE64 编码
@@ -1061,7 +1081,8 @@ function urlSafeBase64Encode($data = '') { @@ -1061,7 +1081,8 @@ function urlSafeBase64Encode($data = '') {
1061 * @method :post 1081 * @method :post
1062 * @time :2024/9/14 16:45 1082 * @time :2024/9/14 16:45
1063 */ 1083 */
1064 -function generateRandomString($length) { 1084 +function generateRandomString($length)
  1085 +{
1065 return substr(str_shuffle(str_repeat($x = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($length / strlen($x)))), 1, $length); 1086 return substr(str_shuffle(str_repeat($x = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($length / strlen($x)))), 1, $length);
1066 } 1087 }
1067 1088
@@ -1080,26 +1101,26 @@ if (!function_exists('check_domain_record')) { @@ -1080,26 +1101,26 @@ if (!function_exists('check_domain_record')) {
1080 $is_record = false; 1101 $is_record = false;
1081 1102
1082 //获取域名解析记录 1103 //获取域名解析记录
1083 - $records = dns_get_record($domain,DNS_A);  
1084 - if(count($records) == 1 && ($records[0]['host'] == $server_info['domain'] || $records[0]['ip'] == $server_info['ip'])){ 1104 + $records = dns_get_record($domain, DNS_A);
  1105 + if (count($records) == 1 && ($records[0]['host'] == $server_info['domain'] || $records[0]['ip'] == $server_info['ip'])) {
1085 $is_record = true; 1106 $is_record = true;
1086 } 1107 }
1087 1108
1088 - if(!$is_record){ 1109 + if (!$is_record) {
1089 //解析不正确,再判断是否开启cnd 1110 //解析不正确,再判断是否开启cnd
1090 $top_domain = getTopDomain($domain); 1111 $top_domain = getTopDomain($domain);
1091 $cnd = curlGet('http://sitebak.globalso.com/get_records?domain=' . $top_domain); 1112 $cnd = curlGet('http://sitebak.globalso.com/get_records?domain=' . $top_domain);
1092 if (isset($cnd['data']) && $cnd['data']) { 1113 if (isset($cnd['data']) && $cnd['data']) {
1093 - if($domain == $top_domain || substr($domain,0,4) == 'www.'){ 1114 + if ($domain == $top_domain || substr($domain, 0, 4) == 'www.') {
1094 $check_domain = $domain; 1115 $check_domain = $domain;
1095 - }else{  
1096 - $check_domain = '*.'.$top_domain; 1116 + } else {
  1117 + $check_domain = '*.' . $top_domain;
1097 } 1118 }
1098 foreach ($cnd['data'] as $vc) { 1119 foreach ($cnd['data'] as $vc) {
1099 if ($vc['name'] == $check_domain && $vc['type'] == 'A' && $vc['content'] == $server_info['ip']) { 1120 if ($vc['name'] == $check_domain && $vc['type'] == 'A' && $vc['content'] == $server_info['ip']) {
1100 $is_record = true; 1121 $is_record = true;
1101 break; 1122 break;
1102 - }elseif ($vc['name'] == $check_domain && $vc['type'] == 'CNAME' && $vc['content'] == $server_info['domain']){ 1123 + } elseif ($vc['name'] == $check_domain && $vc['type'] == 'CNAME' && $vc['content'] == $server_info['domain']) {
1103 $is_record = true; 1124 $is_record = true;
1104 break; 1125 break;
1105 } 1126 }
@@ -1108,8 +1129,8 @@ if (!function_exists('check_domain_record')) { @@ -1108,8 +1129,8 @@ if (!function_exists('check_domain_record')) {
1108 } 1129 }
1109 1130
1110 return $is_record; 1131 return $is_record;
1111 - }catch (\Exception $e){  
1112 - errorLog('dns_get_record',['domain'=>$domain],$e); 1132 + } catch (\Exception $e) {
  1133 + errorLog('dns_get_record', ['domain' => $domain], $e);
1113 return false; 1134 return false;
1114 } 1135 }
1115 } 1136 }
@@ -1123,7 +1144,8 @@ if (!function_exists('check_curl_status')) { @@ -1123,7 +1144,8 @@ if (!function_exists('check_curl_status')) {
1123 * @author Akun 1144 * @author Akun
1124 * @date 2024/12/12 15:52 1145 * @date 2024/12/12 15:52
1125 */ 1146 */
1126 - function check_curl_status($url){ 1147 + function check_curl_status($url)
  1148 + {
1127 $header = array( 1149 $header = array(
1128 'Expect:', 1150 'Expect:',
1129 'Content-Type: application/json; charset=utf-8' 1151 'Content-Type: application/json; charset=utf-8'
@@ -1142,7 +1164,7 @@ if (!function_exists('check_curl_status')) { @@ -1142,7 +1164,7 @@ if (!function_exists('check_curl_status')) {
1142 curl_setopt($ch, CURLOPT_SSLVERSION, 'all'); 1164 curl_setopt($ch, CURLOPT_SSLVERSION, 'all');
1143 curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 1165 curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
1144 curl_exec($ch); 1166 curl_exec($ch);
1145 - $http_code = curl_getinfo($ch,CURLINFO_HTTP_CODE); 1167 + $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
1146 curl_close($ch); 1168 curl_close($ch);
1147 1169
1148 return $http_code; 1170 return $http_code;
@@ -1154,7 +1176,8 @@ if (!function_exists('check_curl_status')) { @@ -1154,7 +1176,8 @@ if (!function_exists('check_curl_status')) {
1154 * @author zbj 1176 * @author zbj
1155 * @date 2024/10/25 1177 * @date 2024/10/25
1156 */ 1178 */
1157 -function email_desensitize($email){ 1179 +function email_desensitize($email)
  1180 +{
1158 $parts = explode('@', $email); 1181 $parts = explode('@', $email);
1159 $username = $parts[0] ?? ''; 1182 $username = $parts[0] ?? '';
1160 $domain = $parts[1] ?? ''; 1183 $domain = $parts[1] ?? '';
@@ -1168,7 +1191,8 @@ function email_desensitize($email){ @@ -1168,7 +1191,8 @@ function email_desensitize($email){
1168 * @author zbj 1191 * @author zbj
1169 * @date 2024/10/25 1192 * @date 2024/10/25
1170 */ 1193 */
1171 -function getRandByRatio($proArr){ 1194 +function getRandByRatio($proArr)
  1195 +{
1172 $result = ''; 1196 $result = '';
1173 $proSum = array_sum($proArr); 1197 $proSum = array_sum($proArr);
1174 foreach ($proArr as $key => $proCur) { 1198 foreach ($proArr as $key => $proCur) {
@@ -1206,7 +1230,7 @@ function getPrefixKeyword($project_id, $type, $num) @@ -1206,7 +1230,7 @@ function getPrefixKeyword($project_id, $type, $num)
1206 $keyword = array_slice($fix_keyword, 0, $num); 1230 $keyword = array_slice($fix_keyword, 0, $num);
1207 $str = implode(", ", $keyword); 1231 $str = implode(", ", $keyword);
1208 1232
1209 - foreach ($keyword as $k=>$v){ 1233 + foreach ($keyword as $k => $v) {
1210 $tmp = rtrim($v, 's'); 1234 $tmp = rtrim($v, 's');
1211 if (substr_count($str, $tmp) > 1) { 1235 if (substr_count($str, $tmp) > 1) {
1212 unset($keyword[$k]); 1236 unset($keyword[$k]);
@@ -1224,16 +1248,17 @@ function getPrefixKeyword($project_id, $type, $num) @@ -1224,16 +1248,17 @@ function getPrefixKeyword($project_id, $type, $num)
1224 * @method :post 1248 * @method :post
1225 * @time :2025/2/11 14:58 1249 * @time :2025/2/11 14:58
1226 */ 1250 */
1227 -function getDeployOptimize($project_id){ 1251 +function getDeployOptimize($project_id)
  1252 +{
1228 $cache_key = 'project_deploy_optimize_info_' . $project_id; 1253 $cache_key = 'project_deploy_optimize_info_' . $project_id;
1229 $info = Cache::get($cache_key); 1254 $info = Cache::get($cache_key);
1230 - if(!$info){ 1255 + if (!$info) {
1231 $projectOptimizeModel = new DeployOptimize(); 1256 $projectOptimizeModel = new DeployOptimize();
1232 $info = $projectOptimizeModel->read(['project_id' => $project_id], ['id', 'company_en_name', 'company_en_description', 'keyword_prefix', 'keyword_suffix', 'special']); 1257 $info = $projectOptimizeModel->read(['project_id' => $project_id], ['id', 'company_en_name', 'company_en_description', 'keyword_prefix', 'keyword_suffix', 'special']);
1233 $projectKeywordModel = new ProjectKeyword(); 1258 $projectKeywordModel = new ProjectKeyword();
1234 - $keywordInfo = $projectKeywordModel->read(['project_id'=>$project_id]); 1259 + $keywordInfo = $projectKeywordModel->read(['project_id' => $project_id]);
1235 $info['main_keyword'] = ''; 1260 $info['main_keyword'] = '';
1236 - if(!empty($keywordInfo['main_keyword'])){ 1261 + if (!empty($keywordInfo['main_keyword'])) {
1237 $info['main_keyword'] = $keywordInfo['main_keyword']; 1262 $info['main_keyword'] = $keywordInfo['main_keyword'];
1238 } 1263 }
1239 Cache::put($cache_key, $info, 600); 1264 Cache::put($cache_key, $info, 600);
@@ -1249,7 +1274,8 @@ function getDeployOptimize($project_id){ @@ -1249,7 +1274,8 @@ function getDeployOptimize($project_id){
1249 * @method :post 1274 * @method :post
1250 * @time :2025/4/1 9:41 1275 * @time :2025/4/1 9:41
1251 */ 1276 */
1252 -function paginateArray($array, $page = 1, $pageSize = 20) { 1277 +function paginateArray($array, $page = 1, $pageSize = 20)
  1278 +{
1253 $totalItems = count($array); 1279 $totalItems = count($array);
1254 $totalPages = ceil($totalItems / $pageSize); 1280 $totalPages = ceil($totalItems / $pageSize);
1255 // 确保页码有效 1281 // 确保页码有效
@@ -1272,8 +1298,9 @@ function paginateArray($array, $page = 1, $pageSize = 20) { @@ -1272,8 +1298,9 @@ function paginateArray($array, $page = 1, $pageSize = 20) {
1272 * @method :post 1298 * @method :post
1273 * @time :2025/4/3 16:19 1299 * @time :2025/4/3 16:19
1274 */ 1300 */
1275 -function getDomain($url) {  
1276 - if(empty($url)){ 1301 +function getDomain($url)
  1302 +{
  1303 + if (empty($url)) {
1277 return $url; 1304 return $url;
1278 } 1305 }
1279 $parsedUrl = parse_url($url); 1306 $parsedUrl = parse_url($url);
@@ -1394,12 +1421,13 @@ function analysisRoute($pathInfo) @@ -1394,12 +1421,13 @@ function analysisRoute($pathInfo)
1394 return $router; 1421 return $router;
1395 } 1422 }
1396 1423
1397 -function getTopDomain ($url) { 1424 +function getTopDomain($url)
  1425 +{
1398 $url = strtolower($url); //首先转成小写 1426 $url = strtolower($url); //首先转成小写
1399 $url = mb_ereg_replace('^( | )+', '', trim($url)); 1427 $url = mb_ereg_replace('^( | )+', '', trim($url));
1400 $url = mb_ereg_replace('( | )+$', '', $url); 1428 $url = mb_ereg_replace('( | )+$', '', $url);
1401 if (!preg_match('/^(http:\/\/|https)/', $url)) { 1429 if (!preg_match('/^(http:\/\/|https)/', $url)) {
1402 - $url = "https://".$url; 1430 + $url = "https://" . $url;
1403 } 1431 }
1404 $hosts = parse_url($url); 1432 $hosts = parse_url($url);
1405 $host = $hosts['host'] ?? ''; 1433 $host = $hosts['host'] ?? '';
@@ -1413,10 +1441,10 @@ function getTopDomain ($url) { @@ -1413,10 +1441,10 @@ function getTopDomain ($url) {
1413 $preg = '/[\w].+\.(com|net|org|gov|edu|co|ne)\.[\w]/'; 1441 $preg = '/[\w].+\.(com|net|org|gov|edu|co|ne)\.[\w]/';
1414 if (($n > 2) && preg_match($preg, $host)) { 1442 if (($n > 2) && preg_match($preg, $host)) {
1415 //双后缀取后3位 1443 //双后缀取后3位
1416 - $host = $data[$n - 3].'.'.$data[$n - 2].'.'.$data[$n - 1]; 1444 + $host = $data[$n - 3] . '.' . $data[$n - 2] . '.' . $data[$n - 1];
1417 } else { 1445 } else {
1418 //非双后缀取后两位 1446 //非双后缀取后两位
1419 - $host = $data[$n - 2].'.'.$data[$n - 1]; 1447 + $host = $data[$n - 2] . '.' . $data[$n - 1];
1420 } 1448 }
1421 return $host; 1449 return $host;
1422 } 1450 }
@@ -1440,3 +1468,55 @@ function diffInHours($startTime, $endTime) @@ -1440,3 +1468,55 @@ function diffInHours($startTime, $endTime)
1440 return round($hours, 1); 1468 return round($hours, 1);
1441 } 1469 }
1442 1470
  1471 +/**
  1472 + * 通过图片地址压缩图片
  1473 + * @param $url
  1474 + * @param int $width
  1475 + * @return string
  1476 + * @author Akun
  1477 + * @date 2025/09/01 15:18
  1478 + */
  1479 +function thumbImageByUrl($url, $width = 360)
  1480 +{
  1481 + if (empty($url)) {
  1482 + return $url;
  1483 + }
  1484 +
  1485 + if (strpos($url, '_thumb') !== false) {
  1486 + return $url;
  1487 + }
  1488 +
  1489 + //获取图片完整访问地址
  1490 + $url = getImageUrl($url);
  1491 +
  1492 + //获取与原图存储路径相同的压缩路径
  1493 + $path = parse_url($url, PHP_URL_PATH);
  1494 + $path_arr = explode('.', $path);
  1495 + if (count($path_arr) != 2) {
  1496 + return $url;
  1497 + }
  1498 + $path_arr[0] = $path_arr[0] . '_thumbW' . $width;
  1499 + $key = implode('.', $path_arr);
  1500 +
  1501 + try {
  1502 + $img = \Intervention\Image\Facades\Image::make($url);
  1503 +
  1504 + //宽度按设定,高度自动调整
  1505 + $img->resize($width, null, function ($constraint) {
  1506 + $constraint->aspectRatio();
  1507 + $constraint->upsize();
  1508 + });
  1509 +
  1510 + //获取处理后的图片二进制资源
  1511 + $resource = $img->stream()->__toString();
  1512 +
  1513 + //上传存储桶
  1514 + $thumb_url = CosService::uploadRemote('', '', '', $key, $resource);
  1515 +
  1516 + $url = $thumb_url ? $thumb_url : $url;
  1517 + } catch (\Exception $e) {
  1518 + Log::channel('thumb_img')->error($e->getMessage(), [$url, $width]);
  1519 + }
  1520 +
  1521 + return $url;
  1522 +}
@@ -356,7 +356,12 @@ class ProductLogic extends BaseLogic @@ -356,7 +356,12 @@ class ProductLogic extends BaseLogic
356 $v['url'] = str_replace_url($v['url']); 356 $v['url'] = str_replace_url($v['url']);
357 $param['gallery'][$k] = $v; 357 $param['gallery'][$k] = $v;
358 } 358 }
359 - $param['thumb'] = Arr::a2s($param['gallery'][0] ?? []); 359 + $thumb = $param['gallery'][0] ?? [];
  360 + if(isset($thumb['url']) && $thumb['url']){
  361 + //生成缩略图
  362 + $thumb['url'] = thumbImageByUrl($thumb['url']);
  363 + }
  364 + $param['thumb'] = Arr::a2s($thumb);
360 $param['gallery'] = Arr::a2s($param['gallery'] ?? []); 365 $param['gallery'] = Arr::a2s($param['gallery'] ?? []);
361 }else{ 366 }else{
362 $param['thumb'] = Arr::a2s([]); 367 $param['thumb'] = Arr::a2s([]);
@@ -204,6 +204,12 @@ return [ @@ -204,6 +204,12 @@ return [
204 'level' => 'debug', 204 'level' => 'debug',
205 'days' => 30, 205 'days' => 30,
206 ], 206 ],
  207 + 'thumb_img' => [
  208 + 'driver' => 'daily',
  209 + 'path' => storage_path('logs/thumb_img/laravel.log'),
  210 + 'level' => 'debug',
  211 + 'days' => 14,
  212 + ],
207 ], 213 ],
208 //操作日志 214 //操作日志
209 'operator_log' =>[ 215 'operator_log' =>[