作者 刘锟

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

<?php
/**
* @remark :
* @name :SyncImage.php
* @author :lyh
* @method :post
* @time :2024/9/11 10:39
*/
namespace App\Console\Commands\Sync;
use App\Models\File\Image;
use App\Models\File\ImageSetting;
use App\Services\UpyunService;
use Illuminate\Console\Command;
use Qcloud\Cos\Client;
class SyncImage extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'sync_shuiying_image';
/**
* The console command description.
*
* @var string
*/
protected $description = '同步图片与文件';
// public function handle(){
// $str = $this->getProjectConfig(501);
// $imageModel = new Image();
// $lists = $imageModel->list(['project_id'=>501]);
// $domain = 'http://globalso-v6-1309677403.cos.ap-hongkong.myqcloud.com';//cos域名
// foreach ($lists as $k => $v){
// if($v['path'] == '/upload/p/501/image_product/2024-09/6569ac3a212aa39368.png'){
// continue;
// }
// $url = $domain . $v['path'].'?'.$str;
// echo date('Y-m-d H:i:s') . '水印路径:'. $url .',主键id:'. $v['id'] . PHP_EOL;
// $this->coverOriginalImage($url,$v['path']);
// }
// return true;
// }
public function handle(){
$data = [];
$domain = 'https://ecdn6-nc.globalso.com/';
$imageModel = new Image();
$lists = $imageModel->list(['project_id'=>501]);
foreach ($lists as $k => $v){
if($v['path'] == '/upload/p/501/image_product/2024-09/6569ac3a212aa39368.png'){
continue;
}
$url = $domain . $v['path'];
echo date('Y-m-d H:i:s') . '刷新路径:'. $url .',主键id:'. $v['id'] . PHP_EOL;
$data[] = $url;
}
$yunService = new UpyunService();
return $yunService->preheatPush($data);
}
/**
* @remark :添加水印后保存图片(覆盖/非覆盖的文件未存入数据库)
* @name :uploadImages
* @author :lyh
* @method :post
* @time :2024/8/19 17:06
*/
public function coverOriginalImage($url,$cdnUrl){
// 获取水印后的图片内容
$imageContent = file_get_contents($url);
// 使用 COS SDK 将图片重新上传并覆盖原图
$cos = config('filesystems.disks.cos');
$cosClient = new Client([
'region' => $cos['region'],
'credentials' => [
'secretId' => $cos['credentials']['secretId'],
'secretKey' => $cos['credentials']['secretKey'],
],
]);
// 上传并覆盖原图
$cosClient->putObject([
'Bucket' => $cos['bucket'],
'Key' => $cdnUrl, // 去掉域名部分,得到存储桶内的路径
'Body' => $imageContent,
]);
return $cos['cdn'].$cdnUrl;
}
/**
* @remark :获取图片配置
* @name :getProjectConfig
* @author :lyh
* @method :post
* @time :2024/8/24 11:03
*/
public function getProjectConfig($project_id = 0){
$str = '';
$imageSettingModel = new ImageSetting();
$settingInfo = $imageSettingModel->read(['project_id'=>$project_id]);
if($settingInfo !== false){
if($settingInfo['status'] == 1 && !empty($settingInfo['image_data'])){
$image_data = json_decode($settingInfo['image_data'],true);
foreach ($image_data as $k => $v){
if (str_starts_with($v, "image/")) {
$v = 'image/'.urlSafeBase64Encode(substr($v, strlen("image/")));
}
$image_data[$k] = $v;
}
$str = 'watermark/1/'.implode('/',$image_data);
return $str;
}
if($settingInfo['status'] == 2 && !empty($settingInfo['str_data'])){
$str_data = json_decode($settingInfo['str_data'],true);
foreach ($str_data as $k => $v){
$arr = explode('/',$v);
if ($arr[0] == 'text') {
$arr[1] = urlSafeBase64Encode($arr[1]);
$v = implode('/',$arr);
}
if ($arr[0] == 'font') {
$arr[1] = urlSafeBase64Encode($arr[1]);
$v = implode('/',$arr);
}
if ($arr[0] == 'fill') {
$arr[1] = urlSafeBase64Encode($arr[1]);
$v = implode('/',$arr);
}
$str_data[$k] = $v;
}
$str = 'watermark/2/'.implode('/',$str_data);
return $str;
}
}
return $str;
}
}
... ...
... ... @@ -56,7 +56,7 @@ class MessagePush extends Base
$model->friend_id = $friend_id;
$model->type = self::TYPE_INQUIRY;
$model->ref_ids = $id;
$model->content = '[' . date('H:i', strtotime($submit_at)) . '] 您的站点收到来自【' . $country . '】的询盘信息,请登录全球搜后台进行查看!';
$model->content = '[' . date('H:i', strtotime($submit_at)) . '] 您的全球搜网站收到来自【' . $country . '】的询盘信息,请登录后台或APP进行查看!';
}else{
//定时发送时间
$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
$model->type = self::TYPE_INQUIRY;
$model->ref_ids = $id;
$model->send_time = $send_time;
$model->content = '[09:00] 您的站点收到来自【' . $country . '】的询盘信息,请登录全球搜后台进行查看!';
$model->content = '[09:00] 您的全球搜网站收到来自【' . $country . '】的询盘信息,请登录后台或APP进行查看!';
}else{
$ref_ids = explode(',', $model->ref_ids);
$ref_ids[] = $id;
... ... @@ -82,7 +82,7 @@ class MessagePush extends Base
}else{
$country = implode(',', $countries);
}
$model->content = '[09:00] 您的站点收到来自【' . $country . '】'.$count.'条询盘信息,请登录全球搜后台进行查看!';
$model->content = '[09:00] 您的全球搜网站收到来自【' . $country . '】'.$count.'条询盘信息,请登录后台或APP进行查看!';
}
}
$model->save();
... ...
... ... @@ -295,14 +295,14 @@ class SyncSubmitTaskService
//过滤内容关键字
if ($config['filter_contents']){
foreach ($config['filter_contents'] as $filter_content) {
if (Str::contains($data['data']['message'], $filter_content)) {
if (Str::contains(strtolower($data['data']['message']), strtolower($filter_content))) {
throw new InquiryFilterException('过滤内容:' . $filter_content);
}
}
}
//是否允许包含链接
if(!$config['is_allow_link']){
if (Str::contains($data['data']['message'], ['http://', 'https://', 'www.'])) {
if (Str::contains(strtolower($data['data']['message']), ['http://', 'https://', 'www.'])) {
throw new InquiryFilterException('不允许包含链接');
}
}
... ... @@ -326,7 +326,7 @@ class SyncSubmitTaskService
//过滤邮箱
if($config['filter_emails'] && !empty($data['data']['email'])){
foreach ($config['filter_emails'] as $filter_email){
if(Str::contains($data['data']['email'], $filter_email)){
if(Str::contains(strtolower($data['data']['email']), strtolower($filter_email))){
throw new InquiryFilterException( '过滤邮箱:' . $filter_email);
}
}
... ... @@ -334,7 +334,7 @@ class SyncSubmitTaskService
//过滤电话
if($config['filter_mobiles'] && !empty($data['data']['phone'])){
foreach ($config['filter_mobiles'] as $filter_mobile){
if(Str::contains($data['data']['phone'], $filter_mobile)){
if(Str::contains(strtolower($data['data']['phone']), strtolower($filter_mobile))){
throw new InquiryFilterException( '过滤电话:' . $filter_mobile);
}
}
... ... @@ -342,7 +342,7 @@ class SyncSubmitTaskService
//过滤姓名
if($config['filter_names'] && !empty($data['data']['name'])){
foreach ($config['filter_names'] as $filter_name){
if( Str::contains($data['data']['name'], $filter_name)){
if( Str::contains(strtolower($data['data']['name']), strtolower($filter_name))){
throw new InquiryFilterException( '过滤姓名:' . $filter_name);
}
}
... ...