正在显示
1 个修改的文件
包含
91 行增加
和
0 行删除
app/Console/Commands/Test/SyncTimeFiles.php
0 → 100644
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * @remark : | ||
| 4 | + * @name :SyncTimeFiles.php | ||
| 5 | + * @author :lyh | ||
| 6 | + * @method :post | ||
| 7 | + * @time :2024/8/14 14:23 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +namespace App\Console\Commands\Test; | ||
| 11 | + | ||
| 12 | +use App\Models\File\ErrorFile; | ||
| 13 | +use App\Models\File\File; | ||
| 14 | +use GuzzleHttp\Command\Command; | ||
| 15 | + | ||
| 16 | +class SyncTimeFiles extends Command | ||
| 17 | +{ | ||
| 18 | + /** | ||
| 19 | + * The name and signature of the console command. | ||
| 20 | + * | ||
| 21 | + * @var string | ||
| 22 | + */ | ||
| 23 | + protected $signature = 'sync_videos'; | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * The console command description. | ||
| 27 | + * | ||
| 28 | + * @var string | ||
| 29 | + */ | ||
| 30 | + protected $description = '按时间同步图片与文件'; | ||
| 31 | + | ||
| 32 | + public function handle() | ||
| 33 | + { | ||
| 34 | + $fileModel = new File(); | ||
| 35 | + $start = '2024-08-10 00:00:00'; | ||
| 36 | + $end = date('Y-m-d H:i:s'); | ||
| 37 | + $lists = $fileModel->list(['created_at'=>['between',[$start,$end]]]); | ||
| 38 | + foreach ($lists as $v){ | ||
| 39 | + $path = $v['path']; | ||
| 40 | + $this->param['name'] = basename($path); | ||
| 41 | + $this->param['path'] = str_replace('/'.$this->param['name'],'',$path); | ||
| 42 | + $file_path = $this->getUrl($this->param['path'].'/'.$this->param['name'], 0,0); | ||
| 43 | + $cmd = 'curl -F "file_path='.$file_path.'" -F "save_path=/www/wwwroot/cos'.$this->param['path'].'" https://v6-file.globalso.com/upload.php'; | ||
| 44 | + echo date('Y-m-d H:i:s') . ' | ' . $cmd . PHP_EOL; | ||
| 45 | + $code = shell_exec($cmd); | ||
| 46 | + if(200 != (int)$code){ | ||
| 47 | + echo date('Y-m-d H:i:s') . ' | 错误状态:' . $code . PHP_EOL; | ||
| 48 | +// $errorFileModel = new ErrorFile(); | ||
| 49 | +// $errorFileModel->add(['path'=>$this->param['path'].'/'.$this->param['name']]); | ||
| 50 | + } | ||
| 51 | + return true; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + /** | ||
| 57 | + * @remark :获取图片文件链接 | ||
| 58 | + * @name :getUrl | ||
| 59 | + * @author :lyh | ||
| 60 | + * @method :post | ||
| 61 | + * @time :2024/5/22 11:53 | ||
| 62 | + */ | ||
| 63 | + public function getUrl($path,$storage_type,$location){ | ||
| 64 | + if(is_array($path)){ | ||
| 65 | + $url =[]; | ||
| 66 | + foreach ($path as $v){ | ||
| 67 | + $url[] = $this->getUrl($v,$storage_type,$location); | ||
| 68 | + } | ||
| 69 | + }else{ | ||
| 70 | + if(empty($path)){ | ||
| 71 | + return ''; | ||
| 72 | + } | ||
| 73 | + if((strpos($path,'https://')!== false) || (strpos($path,'http://') !== false)){ | ||
| 74 | + return $path; | ||
| 75 | + } | ||
| 76 | + if(substr($path,0,2) == '//'){ | ||
| 77 | + return 'https:'.$path; | ||
| 78 | + } | ||
| 79 | + if($location == 0){ | ||
| 80 | + $cos = config('filesystems.disks.cos'); | ||
| 81 | + $cosCdn = ($storage_type == 0) ? $cos['cdn'] : $cos['cdn1']; | ||
| 82 | + $url = $cosCdn.$path; | ||
| 83 | + }else{ | ||
| 84 | + $s3 = config('filesystems.disks.s3'); | ||
| 85 | + $cdn = $s3['cdn']; | ||
| 86 | + $url = $cdn.$path; | ||
| 87 | + } | ||
| 88 | + } | ||
| 89 | + return $url; | ||
| 90 | + } | ||
| 91 | +} |
-
请 注册 或 登录 后发表评论