作者 刘锟

Merge remote-tracking branch 'origin/master' into akun

  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :SyncImage.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2024/9/11 10:39
  8 + */
  9 +
  10 +namespace App\Console\Commands\Sync;
  11 +
  12 +use App\Models\File\Image;
  13 +use App\Models\File\ImageSetting;
  14 +use App\Services\UpyunService;
  15 +use Illuminate\Console\Command;
  16 +use Qcloud\Cos\Client;
  17 +
  18 +class SyncImage extends Command
  19 +{
  20 + /**
  21 + * The name and signature of the console command.
  22 + *
  23 + * @var string
  24 + */
  25 + protected $signature = 'sync_shuiying_image';
  26 +
  27 + /**
  28 + * The console command description.
  29 + *
  30 + * @var string
  31 + */
  32 + protected $description = '同步图片与文件';
  33 +
  34 +
  35 +// public function handle(){
  36 +// $str = $this->getProjectConfig(501);
  37 +// $imageModel = new Image();
  38 +// $lists = $imageModel->list(['project_id'=>501]);
  39 +// $domain = 'http://globalso-v6-1309677403.cos.ap-hongkong.myqcloud.com';//cos域名
  40 +// foreach ($lists as $k => $v){
  41 +// if($v['path'] == '/upload/p/501/image_product/2024-09/6569ac3a212aa39368.png'){
  42 +// continue;
  43 +// }
  44 +// $url = $domain . $v['path'].'?'.$str;
  45 +// echo date('Y-m-d H:i:s') . '水印路径:'. $url .',主键id:'. $v['id'] . PHP_EOL;
  46 +// $this->coverOriginalImage($url,$v['path']);
  47 +// }
  48 +// return true;
  49 +// }
  50 +
  51 + public function handle(){
  52 + $data = [];
  53 + $domain = 'https://ecdn6-nc.globalso.com/';
  54 + $imageModel = new Image();
  55 + $lists = $imageModel->list(['project_id'=>501]);
  56 + foreach ($lists as $k => $v){
  57 + if($v['path'] == '/upload/p/501/image_product/2024-09/6569ac3a212aa39368.png'){
  58 + continue;
  59 + }
  60 + $url = $domain . $v['path'];
  61 + echo date('Y-m-d H:i:s') . '刷新路径:'. $url .',主键id:'. $v['id'] . PHP_EOL;
  62 + $data[] = $url;
  63 + }
  64 + $yunService = new UpyunService();
  65 + return $yunService->preheatPush($data);
  66 + }
  67 +
  68 + /**
  69 + * @remark :添加水印后保存图片(覆盖/非覆盖的文件未存入数据库)
  70 + * @name :uploadImages
  71 + * @author :lyh
  72 + * @method :post
  73 + * @time :2024/8/19 17:06
  74 + */
  75 + public function coverOriginalImage($url,$cdnUrl){
  76 + // 获取水印后的图片内容
  77 + $imageContent = file_get_contents($url);
  78 + // 使用 COS SDK 将图片重新上传并覆盖原图
  79 + $cos = config('filesystems.disks.cos');
  80 + $cosClient = new Client([
  81 + 'region' => $cos['region'],
  82 + 'credentials' => [
  83 + 'secretId' => $cos['credentials']['secretId'],
  84 + 'secretKey' => $cos['credentials']['secretKey'],
  85 + ],
  86 + ]);
  87 + // 上传并覆盖原图
  88 + $cosClient->putObject([
  89 + 'Bucket' => $cos['bucket'],
  90 + 'Key' => $cdnUrl, // 去掉域名部分,得到存储桶内的路径
  91 + 'Body' => $imageContent,
  92 + ]);
  93 + return $cos['cdn'].$cdnUrl;
  94 + }
  95 +
  96 + /**
  97 + * @remark :获取图片配置
  98 + * @name :getProjectConfig
  99 + * @author :lyh
  100 + * @method :post
  101 + * @time :2024/8/24 11:03
  102 + */
  103 + public function getProjectConfig($project_id = 0){
  104 + $str = '';
  105 + $imageSettingModel = new ImageSetting();
  106 + $settingInfo = $imageSettingModel->read(['project_id'=>$project_id]);
  107 + if($settingInfo !== false){
  108 + if($settingInfo['status'] == 1 && !empty($settingInfo['image_data'])){
  109 + $image_data = json_decode($settingInfo['image_data'],true);
  110 + foreach ($image_data as $k => $v){
  111 + if (str_starts_with($v, "image/")) {
  112 + $v = 'image/'.urlSafeBase64Encode(substr($v, strlen("image/")));
  113 + }
  114 + $image_data[$k] = $v;
  115 + }
  116 + $str = 'watermark/1/'.implode('/',$image_data);
  117 + return $str;
  118 + }
  119 + if($settingInfo['status'] == 2 && !empty($settingInfo['str_data'])){
  120 + $str_data = json_decode($settingInfo['str_data'],true);
  121 + foreach ($str_data as $k => $v){
  122 + $arr = explode('/',$v);
  123 + if ($arr[0] == 'text') {
  124 + $arr[1] = urlSafeBase64Encode($arr[1]);
  125 + $v = implode('/',$arr);
  126 + }
  127 + if ($arr[0] == 'font') {
  128 + $arr[1] = urlSafeBase64Encode($arr[1]);
  129 + $v = implode('/',$arr);
  130 + }
  131 + if ($arr[0] == 'fill') {
  132 + $arr[1] = urlSafeBase64Encode($arr[1]);
  133 + $v = implode('/',$arr);
  134 + }
  135 + $str_data[$k] = $v;
  136 + }
  137 + $str = 'watermark/2/'.implode('/',$str_data);
  138 + return $str;
  139 + }
  140 + }
  141 + return $str;
  142 + }
  143 +}
@@ -56,7 +56,7 @@ class MessagePush extends Base @@ -56,7 +56,7 @@ class MessagePush extends Base
56 $model->friend_id = $friend_id; 56 $model->friend_id = $friend_id;
57 $model->type = self::TYPE_INQUIRY; 57 $model->type = self::TYPE_INQUIRY;
58 $model->ref_ids = $id; 58 $model->ref_ids = $id;
59 - $model->content = '[' . date('H:i', strtotime($submit_at)) . '] 您的站点收到来自【' . $country . '】的询盘信息,请登录全球搜后台进行查看!'; 59 + $model->content = '[' . date('H:i', strtotime($submit_at)) . '] 您的全球搜网站收到来自【' . $country . '】的询盘信息,请登录后台或APP进行查看!';
60 }else{ 60 }else{
61 //定时发送时间 61 //定时发送时间
62 $send_time = $hour >= 9 ? date('Y-m-d 09:00:00', strtotime('+1 day')) : date('Y-m-d 09:00:00'); 62 $send_time = $hour >= 9 ? date('Y-m-d 09:00:00', strtotime('+1 day')) : date('Y-m-d 09:00:00');
@@ -69,7 +69,7 @@ class MessagePush extends Base @@ -69,7 +69,7 @@ class MessagePush extends Base
69 $model->type = self::TYPE_INQUIRY; 69 $model->type = self::TYPE_INQUIRY;
70 $model->ref_ids = $id; 70 $model->ref_ids = $id;
71 $model->send_time = $send_time; 71 $model->send_time = $send_time;
72 - $model->content = '[09:00] 您的站点收到来自【' . $country . '】的询盘信息,请登录全球搜后台进行查看!'; 72 + $model->content = '[09:00] 您的全球搜网站收到来自【' . $country . '】的询盘信息,请登录后台或APP进行查看!';
73 }else{ 73 }else{
74 $ref_ids = explode(',', $model->ref_ids); 74 $ref_ids = explode(',', $model->ref_ids);
75 $ref_ids[] = $id; 75 $ref_ids[] = $id;
@@ -82,7 +82,7 @@ class MessagePush extends Base @@ -82,7 +82,7 @@ class MessagePush extends Base
82 }else{ 82 }else{
83 $country = implode(',', $countries); 83 $country = implode(',', $countries);
84 } 84 }
85 - $model->content = '[09:00] 您的站点收到来自【' . $country . '】'.$count.'条询盘信息,请登录全球搜后台进行查看!'; 85 + $model->content = '[09:00] 您的全球搜网站收到来自【' . $country . '】'.$count.'条询盘信息,请登录后台或APP进行查看!';
86 } 86 }
87 } 87 }
88 $model->save(); 88 $model->save();
@@ -295,14 +295,14 @@ class SyncSubmitTaskService @@ -295,14 +295,14 @@ class SyncSubmitTaskService
295 //过滤内容关键字 295 //过滤内容关键字
296 if ($config['filter_contents']){ 296 if ($config['filter_contents']){
297 foreach ($config['filter_contents'] as $filter_content) { 297 foreach ($config['filter_contents'] as $filter_content) {
298 - if (Str::contains($data['data']['message'], $filter_content)) { 298 + if (Str::contains(strtolower($data['data']['message']), strtolower($filter_content))) {
299 throw new InquiryFilterException('过滤内容:' . $filter_content); 299 throw new InquiryFilterException('过滤内容:' . $filter_content);
300 } 300 }
301 } 301 }
302 } 302 }
303 //是否允许包含链接 303 //是否允许包含链接
304 if(!$config['is_allow_link']){ 304 if(!$config['is_allow_link']){
305 - if (Str::contains($data['data']['message'], ['http://', 'https://', 'www.'])) { 305 + if (Str::contains(strtolower($data['data']['message']), ['http://', 'https://', 'www.'])) {
306 throw new InquiryFilterException('不允许包含链接'); 306 throw new InquiryFilterException('不允许包含链接');
307 } 307 }
308 } 308 }
@@ -326,7 +326,7 @@ class SyncSubmitTaskService @@ -326,7 +326,7 @@ class SyncSubmitTaskService
326 //过滤邮箱 326 //过滤邮箱
327 if($config['filter_emails'] && !empty($data['data']['email'])){ 327 if($config['filter_emails'] && !empty($data['data']['email'])){
328 foreach ($config['filter_emails'] as $filter_email){ 328 foreach ($config['filter_emails'] as $filter_email){
329 - if(Str::contains($data['data']['email'], $filter_email)){ 329 + if(Str::contains(strtolower($data['data']['email']), strtolower($filter_email))){
330 throw new InquiryFilterException( '过滤邮箱:' . $filter_email); 330 throw new InquiryFilterException( '过滤邮箱:' . $filter_email);
331 } 331 }
332 } 332 }
@@ -334,7 +334,7 @@ class SyncSubmitTaskService @@ -334,7 +334,7 @@ class SyncSubmitTaskService
334 //过滤电话 334 //过滤电话
335 if($config['filter_mobiles'] && !empty($data['data']['phone'])){ 335 if($config['filter_mobiles'] && !empty($data['data']['phone'])){
336 foreach ($config['filter_mobiles'] as $filter_mobile){ 336 foreach ($config['filter_mobiles'] as $filter_mobile){
337 - if(Str::contains($data['data']['phone'], $filter_mobile)){ 337 + if(Str::contains(strtolower($data['data']['phone']), strtolower($filter_mobile))){
338 throw new InquiryFilterException( '过滤电话:' . $filter_mobile); 338 throw new InquiryFilterException( '过滤电话:' . $filter_mobile);
339 } 339 }
340 } 340 }
@@ -342,7 +342,7 @@ class SyncSubmitTaskService @@ -342,7 +342,7 @@ class SyncSubmitTaskService
342 //过滤姓名 342 //过滤姓名
343 if($config['filter_names'] && !empty($data['data']['name'])){ 343 if($config['filter_names'] && !empty($data['data']['name'])){
344 foreach ($config['filter_names'] as $filter_name){ 344 foreach ($config['filter_names'] as $filter_name){
345 - if( Str::contains($data['data']['name'], $filter_name)){ 345 + if( Str::contains(strtolower($data['data']['name']), strtolower($filter_name))){
346 throw new InquiryFilterException( '过滤姓名:' . $filter_name); 346 throw new InquiryFilterException( '过滤姓名:' . $filter_name);
347 } 347 }
348 } 348 }