正在显示
1 个修改的文件
包含
74 行增加
和
0 行删除
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * @remark : | ||
| 4 | + * @name :SyncProjectFile.php | ||
| 5 | + * @author :lyh | ||
| 6 | + * @method :post | ||
| 7 | + * @time :2024/6/18 14:53 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +namespace App\Console\Commands\Test; | ||
| 11 | + | ||
| 12 | +use App\Models\File\ErrorFile; | ||
| 13 | +use App\Models\File\File; | ||
| 14 | +use Illuminate\Console\Command; | ||
| 15 | + | ||
| 16 | +class SyncProjectFile extends Command | ||
| 17 | +{ | ||
| 18 | + /** | ||
| 19 | + * The name and signature of the console command. | ||
| 20 | + * | ||
| 21 | + * @var string | ||
| 22 | + */ | ||
| 23 | + protected $signature = 'sync_project_file {project_id}'; | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * The console command description. | ||
| 27 | + * | ||
| 28 | + * @var string | ||
| 29 | + */ | ||
| 30 | + protected $description = '同步图片与文件'; | ||
| 31 | + | ||
| 32 | + | ||
| 33 | + public function handle(){ | ||
| 34 | + $project_id = $this->argument('project_id'); | ||
| 35 | + $fileModel = new File(); | ||
| 36 | + $lists = $fileModel->list(['project_id'=>$project_id]);//未同步成功的图片及文件 | ||
| 37 | + foreach ($lists as $k => $v){ | ||
| 38 | + if(strpos($v['path'], '/181/') !== false ){ | ||
| 39 | + $code = $this->synchronizationFiles($v['path']); | ||
| 40 | + }else{ | ||
| 41 | + $code = $this->synchronizationFile($v['path']); | ||
| 42 | + } | ||
| 43 | + if((int)$code == 200){ | ||
| 44 | + echo date('Y-m-d H:i:s') . '编辑的path为:'. $v['path'] .',主键id:'. $v['id'] . PHP_EOL; | ||
| 45 | + } | ||
| 46 | + } | ||
| 47 | + echo date('Y-m-d H:i:s') . '编辑的end为:' . PHP_EOL; | ||
| 48 | + return true; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + /** | ||
| 52 | + * @remark :指定同步文件到獨立177服務器 | ||
| 53 | + * @name :synchronizationFile | ||
| 54 | + * @author :lyh | ||
| 55 | + * @method :post | ||
| 56 | + * @time :2024/4/8 11:10 | ||
| 57 | + */ | ||
| 58 | + public function synchronizationFile($path_name){ | ||
| 59 | + //同步到大文件 | ||
| 60 | + $file_path = config('filesystems.disks.cos')['cdn1'].$path_name; | ||
| 61 | + $directoryPath = pathinfo($path_name, PATHINFO_DIRNAME); | ||
| 62 | + $cmd = 'curl -F "file_path='.$file_path.'" -F "save_path=/www/wwwroot/cos'.$directoryPath.'" https://v6-file.globalso.com/upload.php'; | ||
| 63 | + return shell_exec($cmd); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + | ||
| 67 | + public function synchronizationFiles($path_name){ | ||
| 68 | + //同步到大文件 | ||
| 69 | + $file_path = config('filesystems.disks.s3')['cdn'].$path_name; | ||
| 70 | + $directoryPath = pathinfo($path_name, PATHINFO_DIRNAME); | ||
| 71 | + $cmd = 'curl -F "file_path='.$file_path.'" -F "save_path=/www/wwwroot/cos'.$directoryPath.'" https://v6-file.globalso.com/upload.php'; | ||
| 72 | + return shell_exec($cmd); | ||
| 73 | + } | ||
| 74 | +} |
-
请 注册 或 登录 后发表评论