ProductFileUpload.php
2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/**
* @remark :
* @name :ProductFileUpload.php
* @author :lyh
* @method :post
* @time :2024/6/18 15:43
*/
namespace App\Console\Commands\Test;
use App\Models\File\File;
use App\Models\Product\Product;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class ProductFileUpload extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'files_upload {project_id}';
/**
* The console command description.
*
* @var string
*/
protected $description = '重新上传文件获取文件后缀';
/**
* @remark :
* @name :handle
* @author :lyh
* @method :post
* @time :2024/6/18 15:46
*/
public function handle(){
$project_id = $this->argument('project_id');
ProjectServer::useProject($project_id);
$productModel = new Product();
$lists = $productModel->list(['status'=>1,'id'=>['<=',106]]);
foreach ($lists as $k => $v){
if(!empty($v['files']) && !empty($v['files']['url'])){
$url = str_replace_url($v['files']['url']);
//获取当前图片的原名称
$files = new File();
$fileInfo = $files->read(['path'=>$url,'project_id'=>$project_id]);
if($fileInfo === false){
continue;
}
$newName = $fileInfo['name'];
$code = $this->synchronizationFile($url,$newName);
if((int)$code == 200){
echo date('Y-m-d H:i:s') . '编辑的path为:'. $url .',主键id:'. $v['id'] . PHP_EOL;
$v['files']['url'] = preg_replace('#/[^/]*$#', '/', $url).$newName;
$productModel->edit(['files'=>json_encode($v['files'])],['id'=>$v['id']]);
}
}
}
DB::disconnect('custom_mysql');
}
/**
* @remark :指定同步文件到獨立177服務器
* @name :synchronizationFile
* @author :lyh
* @method :post
* @time :2024/4/8 11:10
*/
public function synchronizationFile($path_name,$newName){
//同步到大文件
$file_path = config('filesystems.disks.cos')['cdn1'].$path_name;
echo date('Y-m-d H:i:s') . '编辑的path为:'. $file_path. PHP_EOL;
$directoryPath = pathinfo($path_name, PATHINFO_DIRNAME);
$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';
return shell_exec($cmd);
}
}