作者 刘锟

upload_remote

@@ -324,22 +324,4 @@ class FileController @@ -324,22 +324,4 @@ class FileController
324 $data = ['file_download'=>url('a/download_files?path='.$info['path'])]; 324 $data = ['file_download'=>url('a/download_files?path='.$info['path'])];
325 $this->response('success',Code::SUCCESS,$data); 325 $this->response('success',Code::SUCCESS,$data);
326 } 326 }
327 -  
328 - /**  
329 - * 根据远程图片地址上传  
330 - * @param $file_url  
331 - * @return JsonResponse  
332 - * @author Akun  
333 - * @date 2023/09/21 9:40  
334 - */  
335 - public function upRemoteUrl($file_url){  
336 - $ext = explode('.',$file_url);  
337 - $fileName = uniqid().rand(10000,99999).'.'.end($ext);  
338 -  
339 - //同步数据到cos  
340 - $cosService = new CosService();  
341 - $cosService->uploadRemote($file_url,$this->path,$fileName);  
342 -  
343 - return $this->response('资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName));  
344 - }  
345 } 327 }
@@ -8,6 +8,7 @@ use App\Http\Logic\Bside\BaseLogic; @@ -8,6 +8,7 @@ use App\Http\Logic\Bside\BaseLogic;
8 use App\Models\News\News; 8 use App\Models\News\News;
9 use App\Models\News\NewsCategory as NewsCategoryModel; 9 use App\Models\News\NewsCategory as NewsCategoryModel;
10 use App\Models\RouteMap\RouteMap; 10 use App\Models\RouteMap\RouteMap;
  11 +use App\Services\CosService;
11 use Illuminate\Support\Facades\DB; 12 use Illuminate\Support\Facades\DB;
12 use mysql_xdevapi\Exception; 13 use mysql_xdevapi\Exception;
13 14
@@ -275,15 +276,15 @@ class NewsLogic extends BaseLogic @@ -275,15 +276,15 @@ class NewsLogic extends BaseLogic
275 $category_id = $newsCategoryLogic->importNewsCategory($project_id, $user_id, $data[2]); 276 $category_id = $newsCategoryLogic->importNewsCategory($project_id, $user_id, $data[2]);
276 } 277 }
277 278
278 - $news = $this->model->read(['name'=>$data[0]]);  
279 - if(!$news){ 279 + $news = $this->model->read(['name' => $data[0]]);
  280 + if (!$news) {
280 $id = $this->model->addReturnId( 281 $id = $this->model->addReturnId(
281 [ 282 [
282 'name' => $data[0], 283 'name' => $data[0],
283 'category_id' => $category_id, 284 'category_id' => $category_id,
284 'text' => $data[4], 285 'text' => $data[4],
285 'remark' => $data[3], 286 'remark' => $data[3],
286 - 'image' => '',//TODO: 远程图片下载本地 287 + 'image' => CosService::uploadRemote($project_id, 'image_news', $data[5]),
287 'seo_title' => $data[6], 288 'seo_title' => $data[6],
288 'seo_keywords' => $data[7], 289 'seo_keywords' => $data[7],
289 'seo_description' => $data[8], 290 'seo_description' => $data[8],
@@ -293,7 +294,7 @@ class NewsLogic extends BaseLogic @@ -293,7 +294,7 @@ class NewsLogic extends BaseLogic
293 ] 294 ]
294 ); 295 );
295 //更新路由 296 //更新路由
296 - $route = RouteMap::setRoute($data[0], RouteMap::SOURCE_NEWS, $id, $project_id); 297 + $route = RouteMap::setRoute($data[1] ?: $data[0], RouteMap::SOURCE_NEWS, $id, $project_id);
297 $this->edit(['url' => $route], ['id' => $id]); 298 $this->edit(['url' => $route], ['id' => $id]);
298 299
299 return true; 300 return true;
@@ -64,15 +64,21 @@ class CosService @@ -64,15 +64,21 @@ class CosService
64 64
65 /** 65 /**
66 * 根据远程图片地址上传 66 * 根据远程图片地址上传
  67 + * @param $project_id
  68 + * @param $image_type
67 * @param $file_url 69 * @param $file_url
68 - * @param $path  
69 - * @param $filename  
70 * @return string 70 * @return string
71 * @author Akun 71 * @author Akun
72 * @date 2023/09/21 9:39 72 * @date 2023/09/21 9:39
73 */ 73 */
74 - public function uploadRemote($file_url,$path,$filename) 74 + public static function uploadRemote($project_id,$image_type,$file_url)
75 { 75 {
  76 + $ext = explode('.',$file_url);
  77 +
  78 + $filename = uniqid().rand(10000,99999).'.'.end($ext);
  79 +
  80 + $uploads = config('upload.default_file');
  81 + $path = $uploads['path_b'].'/'.$project_id.'/'.$image_type.'/'.date('Y-m');
76 $cos = config('filesystems.disks.cos'); 82 $cos = config('filesystems.disks.cos');
77 $cosClient = new Client([ 83 $cosClient = new Client([
78 'region' => $cos['region'], 84 'region' => $cos['region'],
@@ -363,6 +363,4 @@ Route::group([], function () { @@ -363,6 +363,4 @@ Route::group([], function () {
363 Route::any('/qrcode', [\App\Http\Controllers\Bside\LoginController::class, 'qrcode'])->name('qrcode'); 363 Route::any('/qrcode', [\App\Http\Controllers\Bside\LoginController::class, 'qrcode'])->name('qrcode');
364 Route::any('/globalSo_v6_login', [\App\Http\Controllers\Bside\LoginController::class, 'globalSo_v6_login'])->name('globalSo_v6_login'); 364 Route::any('/globalSo_v6_login', [\App\Http\Controllers\Bside\LoginController::class, 'globalSo_v6_login'])->name('globalSo_v6_login');
365 Route::any('/getWechatLoginInfo', [\App\Http\Controllers\Bside\LoginController::class, 'getWechatLoginInfo'])->name('getWechatLoginInfo'); 365 Route::any('/getWechatLoginInfo', [\App\Http\Controllers\Bside\LoginController::class, 'getWechatLoginInfo'])->name('getWechatLoginInfo');
366 -  
367 - Route::post('/upload_remote', [\App\Http\Controllers\File\FileController::class, 'upRemoteUrl'])->name('remote_file_upload');  
368 }); 366 });