作者 lyh

gx

@@ -10,6 +10,7 @@ use App\Jobs\CopyProjectJob; @@ -10,6 +10,7 @@ use App\Jobs\CopyProjectJob;
10 use App\Jobs\SyncImageFileJob; 10 use App\Jobs\SyncImageFileJob;
11 use App\Models\File\ErrorFile; 11 use App\Models\File\ErrorFile;
12 use App\Models\File\Image as ImageModel; 12 use App\Models\File\Image as ImageModel;
  13 +use App\Models\File\ImageSetting;
13 use App\Models\File\WatermarkImage; 14 use App\Models\File\WatermarkImage;
14 use App\Models\Project\Project; 15 use App\Models\Project\Project;
15 use App\Services\AmazonS3Service; 16 use App\Services\AmazonS3Service;
@@ -339,8 +340,9 @@ class ImageController extends Controller @@ -339,8 +340,9 @@ class ImageController extends Controller
339 $this->saveMysql($imageModel,$file->getSize(),$image_type,$fileName,$hash,$this->upload_location,$file->getMimeType(),$name); 340 $this->saveMysql($imageModel,$file->getSize(),$image_type,$fileName,$hash,$this->upload_location,$file->getMimeType(),$name);
340 //同步数据到cos 341 //同步数据到cos
341 if($this->upload_location == 0){ 342 if($this->upload_location == 0){
  343 + $watermarkOptions = $this->getProjectConfig($this->cache['project_id'] ?? 0);
342 $cosService = new CosService(); 344 $cosService = new CosService();
343 - $cosService->uploadFile($file,$this->path,$fileName); 345 + $cosService->uploadFile($file,$this->path,$fileName,$watermarkOptions);
344 }else{ 346 }else{
345 //TODO::上传亚马逊 347 //TODO::上传亚马逊
346 $amazonS3Service = new AmazonS3Service(); 348 $amazonS3Service = new AmazonS3Service();
@@ -356,6 +358,27 @@ class ImageController extends Controller @@ -356,6 +358,27 @@ class ImageController extends Controller
356 } 358 }
357 359
358 /** 360 /**
  361 + * @remark :获取图片配置
  362 + * @name :getProjectConfig
  363 + * @author :lyh
  364 + * @method :post
  365 + * @time :2024/8/24 11:03
  366 + */
  367 + public function getProjectConfig($project_id = 0){
  368 + $imageSettingModel = new ImageSetting();
  369 + $settingInfo = $imageSettingModel->read(['project_id'=>$project_id]);
  370 + if($settingInfo !== false){
  371 + if($settingInfo['status'] == 1 && !empty($settingInfo['image_data'])){
  372 + return json_decode($settingInfo['image_data'],true);
  373 + }
  374 + if($settingInfo['status'] == 2 && !empty($settingInfo['str_data'])){
  375 + return json_decode($settingInfo['str_data'],true);
  376 + }
  377 + }
  378 + return null;
  379 + }
  380 +
  381 + /**
359 * @param $filename 382 * @param $filename
360 * @remark :下载 383 * @remark :下载
361 * @name :download 384 * @name :download
@@ -606,4 +629,90 @@ class ImageController extends Controller @@ -606,4 +629,90 @@ class ImageController extends Controller
606 ]; 629 ];
607 return $watermarkImageModel->addReturnId($data); 630 return $watermarkImageModel->addReturnId($data);
608 } 631 }
  632 +
  633 + /**
  634 + * @remark :设置请求参数
  635 + * @name :setInputParam
  636 + * @author :lyh
  637 + * @method :post
  638 + * @time :2024/8/24 10:31
  639 + */
  640 + public function saveInputParam(){
  641 + $this->request->validate([
  642 + 'data'=>['required'],
  643 + 'is_image'=>['required'],
  644 + ],[
  645 + 'data.required'=>'数据',
  646 + 'is_image.required'=>'请设置文本水印还是图片水印',
  647 + ]);
  648 + $data = $this->param['data'];
  649 + $is_image = $this->param['is_image'];
  650 + $imageSetting = new ImageSetting();
  651 + $info = $imageSetting->read(['project_id'=>$this->cache['project_id']]);
  652 + $domain = 'http://globalso-v6-1309677403.cos.ap-hongkong.myqcloud.com';//cos域名
  653 + if($is_image){
  654 + $param = [
  655 + 'image/'.$this->urlSafeBase64Encode($domain.$data['image'] ?? ''),//图片
  656 + 'gravity/'.($data['gravity'] ?? 'SouthEast'),
  657 + 'dx/'.($data['dx'] ?? 0),
  658 + 'dy/'. ($data['dy'] ?? 0),
  659 + 'batch/'.($data['batch'] ?? 0),//平铺水印功能
  660 + 'dissolve/'.($data['dissolve'] ?? 50),//透明度
  661 + 'degree/'.($data['degree'] ?? 0),//旋转角度设置,取值范围为0 - 360,默认0
  662 + ];
  663 + if($info === false){
  664 + $imageSetting->add(['image_data'=>json_encode($param,true),'project_id'=>$this->cache['project_id']]);
  665 + }else{
  666 + $imageSetting->edit(['image_data'=>json_encode($param,true)],['project_id'=>$this->cache['project_id']]);
  667 + }
  668 + }else{
  669 + $param = [
  670 + 'text/'.$this->urlSafeBase64Encode($data['text'] ?? ''),//文字水印名称
  671 + 'gravity/'.($data['gravity'] ?? 'SouthEast'),
  672 + 'dx/'.($data['dx'] ?? 10),
  673 + 'dy/'. ($data['dy'] ?? 10),
  674 + 'font/'.$this->urlSafeBase64Encode($data['font'] ?? 'tahoma.ttf'),//默认宋体
  675 + 'fontsize/'.($data['fontsize'] ?? 24),//水印文字字体大小,单位为磅,缺省值13
  676 + 'fill/'.$this->urlSafeBase64Encode($data['fill'] ?? '#3D3D3D'),//颜色
  677 + 'dissolve/'.($data['dissolve'] ?? 50),//透明度
  678 + 'degree/'.($data['degree'] ?? 0),//文字水印的旋转角度设置,取值范围为0 - 360,默认0
  679 + 'batch/'.($data['batch'] ?? 0),//平铺水印功能
  680 + 'shadow/'.($data['shadow'] ?? 0),//文字阴影效果,有效值为[0,100],默认为0,表示无阴影
  681 + ];
  682 + if($info === false){
  683 + $imageSetting->add(['str_data'=>json_encode($param,true),'project_id'=>$this->cache['project_id']]);
  684 + }else{
  685 + $imageSetting->edit(['str_data'=>json_encode($param,true)],['project_id'=>$this->cache['project_id']]);
  686 + }
  687 + }
  688 + $this->response('success');
  689 + }
  690 +
  691 + /**
  692 + * @remark :修改水印配置状态
  693 + * @name :editStatus
  694 + * @author :lyh
  695 + * @method :post
  696 + * @time :2024/8/24 11:14
  697 + */
  698 + public function editStatus(){
  699 + $this->request->validate([
  700 + 'status'=>'required',
  701 + ],[
  702 + 'status.required'=>'状态',
  703 + ]);
  704 + $imageSetting = new ImageSetting();
  705 + $info = $imageSetting->read(['project_id'=>$this->cache['project_id']]);
  706 + if($info === false){
  707 + $this->response('请先设置水印',Code::SYSTEM_ERROR);
  708 + }
  709 + if($info['status'] == 1 && !empty($info['image_data'])){
  710 + $this->response('请先设置水印',Code::SYSTEM_ERROR);
  711 + }
  712 + if($info['status'] == 2 && !empty($info['str_data'])){
  713 + $this->response('请先设置水印',Code::SYSTEM_ERROR);
  714 + }
  715 + $imageSetting->edit(['status'=>$this->param['status']],['project_id'=>$this->cache['project_id']]);
  716 + $this->response('success');
  717 + }
609 } 718 }
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :ImageSetting.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2024/8/24 10:07
  8 + */
  9 +
  10 +namespace App\Models\File;
  11 +
  12 +use App\Models\Base;
  13 +
  14 +class ImageSetting extends Base
  15 +{
  16 + protected $table = 'gl_image_setting';
  17 +}
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 namespace App\Services; 3 namespace App\Services;
4 4
5 use App\Exceptions\InquiryFilterException; 5 use App\Exceptions\InquiryFilterException;
  6 +use App\Models\File\ImageSetting;
6 use App\Utils\LogUtils; 7 use App\Utils\LogUtils;
7 use Qcloud\Cos\Client; 8 use Qcloud\Cos\Client;
8 /** 9 /**
@@ -46,7 +47,7 @@ class CosService @@ -46,7 +47,7 @@ class CosService
46 'rules' => [ 47 'rules' => [
47 [ 48 [
48 'fileid' => $filename, // 使用相同的文件名保存 49 'fileid' => $filename, // 使用相同的文件名保存
49 - 'rule' => $watermarkOptions, 50 + 'rule' => 'watermark/1/'.implode('/',$watermarkOptions),
50 ] 51 ]
51 ] 52 ]
52 ]); 53 ]);
@@ -215,6 +216,8 @@ class CosService @@ -215,6 +216,8 @@ class CosService
215 return $url; 216 return $url;
216 } 217 }
217 218
  219 +
  220 +
218 /** 221 /**
219 * @remark :添加水印后保存图片(覆盖/非覆盖的文件未存入数据库) 222 * @remark :添加水印后保存图片(覆盖/非覆盖的文件未存入数据库)
220 * @name :uploadImages 223 * @name :uploadImages
@@ -323,6 +323,8 @@ Route::middleware(['bloginauth'])->group(function () { @@ -323,6 +323,8 @@ Route::middleware(['bloginauth'])->group(function () {
323 Route::post('/setWatermark', [\App\Http\Controllers\File\ImageController::class, 'setWatermark'])->name('images_setWatermark'); 323 Route::post('/setWatermark', [\App\Http\Controllers\File\ImageController::class, 'setWatermark'])->name('images_setWatermark');
324 Route::post('/coverOriginalImage', [\App\Http\Controllers\File\ImageController::class, 'coverOriginalImage'])->name('images_coverOriginalImage'); 324 Route::post('/coverOriginalImage', [\App\Http\Controllers\File\ImageController::class, 'coverOriginalImage'])->name('images_coverOriginalImage');
325 Route::any('/getImageList', [\App\Http\Controllers\File\ImageController::class, 'getImageList'])->name('image_getImageList'); 325 Route::any('/getImageList', [\App\Http\Controllers\File\ImageController::class, 'getImageList'])->name('image_getImageList');
  326 + Route::any('/saveInputParam', [\App\Http\Controllers\File\ImageController::class, 'saveInputParam'])->name('image_saveInputParam');
  327 + Route::any('/editStatus', [\App\Http\Controllers\File\ImageController::class, 'editStatus'])->name('image_editStatus');
326 }); 328 });
327 //文件操作 329 //文件操作
328 Route::prefix('files')->group(function () { 330 Route::prefix('files')->group(function () {