作者 lyh

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

... ... @@ -20,7 +20,7 @@ class Kernel extends ConsoleKernel
$schedule->command('template_label')->dailyAt('01:00')->withoutOverlapping(1);//最新模块
$schedule->command('popular_template_label')->dailyAt('01:30')->withoutOverlapping(1);//热门模块
// $schedule->command('inspire')->hourly();
$schedule->command('remain_day')->dailyAt('06:00')->withoutOverlapping(1); // 项目剩余服务时长
$schedule->command('remain_day')->dailyAt('08:30')->withoutOverlapping(1); // 项目剩余服务时长
$schedule->command('rank_data_task')->everyMinute()->withoutOverlapping(1); // 排名数据更新任务
$schedule->command('service_count')->dailyAt('01:00')->withoutOverlapping(1); //服务器使用情况,每天凌晨1点执行一次
$schedule->command('web_traffic_special')->everyMinute()->withoutOverlapping(1); // 特殊引流
... ...
... ... @@ -24,6 +24,7 @@ use App\Models\Sms\SmsLog;
use App\Models\User\DeptUser;
use App\Models\User\ProjectRole;
use App\Models\User\User;
use App\Services\CosService;
use App\Utils\EncryptUtils;
use http\Client\Response;
use Illuminate\Support\Facades\Cache;
... ... @@ -323,4 +324,15 @@ class LoginController extends BaseController
}
return $data;
}
public function ceshi()
{
$cos = new CosService();
$cdnUrl = '/upload/p/1/image_other/2023-11/655d9c70b692e10129.png';
$data = [
'image' => '/upload/m/image_other/2024-06/logo-162-2-1.png',
'gravity' => 'center',
];
return $cos->addFieldImage($cdnUrl, $data,true);
}
}
... ...
... ... @@ -309,7 +309,7 @@ class CustomTemplateLogic extends BaseLogic
$typeSource = $this->getType();
}
//查看当前数据是否还存在
$condition = ['template_id'=>$template_id,'source'=>$typeSource,'common_type'=>$type];
$condition = ['project_id'=>$this->user['project_id'],'template_id'=>$template_id,'source'=>$typeSource,'common_type'=>$type];
$info = $templateComModel->read($condition);
if($info === false){
$data = array_merge($param,$condition);
... ...
... ... @@ -22,7 +22,7 @@ class CosService
* @method :post
* @time :2023/7/19 15:28
*/
public function uploadFile(&$files,$path,$filename, $binary = false)
public function uploadFile(&$files,$path,$filename, $binary = false,$watermarkOptions = null)
{
$cos = config('filesystems.disks.cos');
$cosClient = new Client([
... ... @@ -34,11 +34,25 @@ class CosService
]);
$key = $path.'/'.$filename;
$Body = $binary ? $files : fopen($files->getRealPath(), 'r');
$cosClient->putObject([
$options = [
'Bucket' => $cos['bucket'],
'Key' => $key,
'Body' => $Body,
];
//水印
if ($watermarkOptions) {
$options['Pic-Operations'] = json_encode([
'is_pic_info' => 1,
'rules' => [
[
'fileid' => $filename, // 使用相同的文件名保存
'rule' => $watermarkOptions,
]
]
]);
}
// 上传文件
$cosClient->putObject($options);
return $key;
}
... ... @@ -148,4 +162,152 @@ class CosService
'mime' => $file->getMimeType(),
];
}
/**
* @remark :生成带水印的图片文件
* @name :addFieldImage
* @author :lyh
* @method :post
* @time :2024/8/19 11:01
* gravity/SouthEast:
gravity:表示水印的对齐方式。常见的值有:
NorthWest:左上角
North:顶部中间
NorthEast:右上角
West:左侧中间
Center:中心
East:右侧中间
SouthWest:左下角
South:底部中间
SouthEast:右下角
*/
public function addFieldImage($cdnUrl = '',$data = [],$is_image = false){
$domain = 'http://globalso-v6-1309677403.cos.ap-hongkong.myqcloud.com';//cos域名
$url = $domain . $cdnUrl;
if($is_image){
$param = [
'image/'.$this->urlSafeBase64Encode($domain.$data['image'] ?? ''),//文字水印名称
'gravity/'.($data['gravity'] ?? 'SouthEast'),
'dx/'.($data['dx'] ?? 0),
'dy/'. ($data['dy'] ?? 0),
'batch/'.($data['batch'] ?? 0),//平铺水印功能
'dissolve/'.($data['dissolve'] ?? 50),//透明度
'degree/'.($data['degree'] ?? 0),//文字水印的旋转角度设置,取值范围为0 - 360,默认0
];
$url = $url.'?watermark/1/'.implode('/',$param);
}else{
$param = [
'text/'.$this->urlSafeBase64Encode($data['text'] ?? ''),//文字水印名称
'gravity/'.($data['gravity'] ?? 'SouthEast'),
'dx/'.($data['dx'] ?? 10),
'dy/'. ($data['dy'] ?? 10),
'font/'.$this->urlSafeBase64Encode($data['font'] ?? 'tahoma.ttf'),//默认宋体
'fontsize/'.($data['fontsize'] ?? 24),//水印文字字体大小,单位为磅,缺省值13
'fill/'.$this->urlSafeBase64Encode($data['fill'] ?? '#3D3D3D'),//颜色
'dissolve/'.($data['dissolve'] ?? 50),//透明度
'degree/'.($data['degree'] ?? 0),//文字水印的旋转角度设置,取值范围为0 - 360,默认0
'batch/'.($data['batch'] ?? 0),//平铺水印功能
'shadow/'.($data['shadow'] ?? 0),//文字阴影效果,有效值为[0,100],默认为0,表示无阴影
];
$url = $url.'?watermark/2/'.implode('/',$param);
}
return $url;
}
/**
* @remark :添加水印后保存图片(覆盖)
* @name :uploadImages
* @author :lyh
* @method :post
* @time :2024/8/19 17:06
*/
public function uploadImages($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 :腾讯云安全的base64
* @name :urlSafeBase64Encode
* @author :lyh
* @method :post
* @time :2024/8/19 14:21
*/
public function urlSafeBase64Encode($data = '') {
if(empty($data)){
return $data;
}
// 1. 使用标准的 BASE64 编码
$base64 = base64_encode($data);
// 2. 将加号(+)替换成连接号(-)
$base64 = str_replace('+', '-', $base64);
// 3. 将正斜线(/)替换成下划线(_)
$base64 = str_replace('/', '_', $base64);
// 4. 去掉末尾的等号(=)
$base64 = rtrim($base64, '=');
return $base64;
}
/**
* @remark :处理9宫格数据
* @name :getPosition
* @author :lyh
* @method :post
* @time :2024/8/19 15:16
*/
public function getPosition(){
return [
1=>'gravity/northWest',
2=>'gravity/north',
3=>'gravity/northEast',
4=>'gravity/west',
5=>'gravity/center',
6=>'gravity/east',
7=>'gravity/southWest',
8=>'gravity/south',
9=>'gravity/southEast',
];
}
/**
* @remark :字体
* @name :getFont
* @author :lyh
* @method :post
* @time :2024/8/19 15:47
*/
public function getFont(){
return [
'simfang仿宋.ttf',
'tahoma.ttf',
'simhei黑体.ttf',
'simkai楷体.ttf',
'simsun宋体.ttc',
'STHeiti Light华文黑体.ttc',
'STHeiti Medium.ttc',
'幼圆.TTF',
'ahronbd.ttf',
'arial.ttf',
'ariblk.ttf',
'Helvetica.dfont',
'HelveticaNeue.dfont'
];
}
}
... ...