作者 lyh

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

  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :ProductFileUpload.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2024/6/18 15:43
  8 + */
  9 +
  10 +namespace App\Console\Commands\Test;
  11 +
  12 +use App\Models\File\File;
  13 +use App\Models\Product\Product;
  14 +use App\Services\ProjectServer;
  15 +use Illuminate\Console\Command;
  16 +use Illuminate\Support\Facades\DB;
  17 +
  18 +class ProductFileUpload extends Command
  19 +{
  20 + /**
  21 + * The name and signature of the console command.
  22 + *
  23 + * @var string
  24 + */
  25 + protected $signature = 'files_upload {project_id}';
  26 +
  27 + /**
  28 + * The console command description.
  29 + *
  30 + * @var string
  31 + */
  32 + protected $description = '重新上传文件获取文件后缀';
  33 +
  34 + /**
  35 + * @remark :
  36 + * @name :handle
  37 + * @author :lyh
  38 + * @method :post
  39 + * @time :2024/6/18 15:46
  40 + */
  41 + public function handle(){
  42 + $project_id = $this->argument('project_id');
  43 + ProjectServer::useProject($project_id);
  44 + $productModel = new Product();
  45 + $lists = $productModel->list(['status'=>1,'id'=>['<=',106]]);
  46 + foreach ($lists as $k => $v){
  47 + if(!empty($v['files']) && !empty($v['files']['url'])){
  48 + $url = str_replace_url($v['files']['url']);
  49 + //获取当前图片的原名称
  50 + $files = new File();
  51 + $fileInfo = $files->read(['path'=>$url,'project_id'=>$project_id]);
  52 + if($fileInfo === false){
  53 + continue;
  54 + }
  55 + $newName = $fileInfo['name'];
  56 + $code = $this->synchronizationFile($url,$newName);
  57 + if((int)$code == 200){
  58 + echo date('Y-m-d H:i:s') . '编辑的path为:'. $url .',主键id:'. $v['id'] . PHP_EOL;
  59 + $v['files']['url'] = $newName;
  60 + $productModel->edit(['files'=>json_encode($v['files'])],['id'=>$v['id']]);
  61 + }
  62 + }
  63 + }
  64 + DB::disconnect('custom_mysql');
  65 + }
  66 +
  67 + /**
  68 + * @remark :指定同步文件到獨立177服務器
  69 + * @name :synchronizationFile
  70 + * @author :lyh
  71 + * @method :post
  72 + * @time :2024/4/8 11:10
  73 + */
  74 + public function synchronizationFile($path_name,$newName){
  75 + //同步到大文件
  76 + $file_path = config('filesystems.disks.cos')['cdn1'].$path_name;
  77 + echo date('Y-m-d H:i:s') . '编辑的path为:'. $file_path. PHP_EOL;
  78 + $directoryPath = pathinfo($path_name, PATHINFO_DIRNAME);
  79 + $cmd = 'curl -F "file_path='.$file_path.'" -F "save_path=/www/wwwroot/cos'.$directoryPath.'" -F "file_name='.$newName.'" https://v6-file.globalso.com/fileUploads.php';
  80 + return shell_exec($cmd);
  81 + }
  82 +}
@@ -343,11 +343,11 @@ class FileController @@ -343,11 +343,11 @@ class FileController
343 $this->response('指定文件不存在!', Code::USER_ERROR); 343 $this->response('指定文件不存在!', Code::USER_ERROR);
344 } 344 }
345 $fileUrl = getFileUrl($info['path'],$info['is_cos']); 345 $fileUrl = getFileUrl($info['path'],$info['is_cos']);
346 -// $fileName = basename($fileUrl); // 要保存的文件名  
347 // 设置响应头 346 // 设置响应头
348 header('Content-Description: File Transfer'); 347 header('Content-Description: File Transfer');
349 header('Content-Type: application/octet-stream'); 348 header('Content-Type: application/octet-stream');
350 - header('Content-Disposition: attachment; filename="' . !empty($info['name']) ? $info['name'] : '未命名'.basename($info['path']) . '"'); 349 + $name = !empty($info['name']) ? $info['name'] : '未命名'.basename($info['path']);
  350 + header('Content-Disposition: attachment; filename="'.$name.'"');
351 // 下载文件 351 // 下载文件
352 readfile($fileUrl); 352 readfile($fileUrl);
353 } 353 }