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