作者 lyh

Merge branch 'develop' of http://47.244.231.31:8099/zhl/globalso-v6 into develop

@@ -73,7 +73,7 @@ class ProjectImport extends Command @@ -73,7 +73,7 @@ class ProjectImport extends Command
73 $project = ProjectServer::useProject($task->project_id); 73 $project = ProjectServer::useProject($task->project_id);
74 if ($project) { 74 if ($project) {
75 foreach ($line_of_text as $k => $v) { 75 foreach ($line_of_text as $k => $v) {
76 - if ($k > 0 && $v) { 76 + if ($k > 0 && $v[0]) {
77 $total_count += 1; 77 $total_count += 1;
78 if ($task->type == ImportTask::TYPE_NEWS) { 78 if ($task->type == ImportTask::TYPE_NEWS) {
79 if ((new NewsLogic())->importNews($task->project_id, $task->user_id, $v)) { 79 if ((new NewsLogic())->importNews($task->project_id, $task->user_id, $v)) {
@@ -316,22 +316,4 @@ class FileController @@ -316,22 +316,4 @@ class FileController
316 $data = ['file_download'=>url('a/download_files?path='.$info['path'])]; 316 $data = ['file_download'=>url('a/download_files?path='.$info['path'])];
317 $this->response('success',Code::SUCCESS,$data); 317 $this->response('success',Code::SUCCESS,$data);
318 } 318 }
319 -  
320 - /**  
321 - * 根据远程图片地址上传  
322 - * @param $file_url  
323 - * @return JsonResponse  
324 - * @author Akun  
325 - * @date 2023/09/21 9:40  
326 - */  
327 - public function upRemoteUrl($file_url){  
328 - $ext = explode('.',$file_url);  
329 - $fileName = uniqid().rand(10000,99999).'.'.end($ext);  
330 -  
331 - //同步数据到cos  
332 - $cosService = new CosService();  
333 - $cosService->uploadRemote($file_url,$this->path,$fileName);  
334 -  
335 - return $this->response('资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName));  
336 - }  
337 } 319 }
@@ -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
@@ -269,31 +270,31 @@ class NewsLogic extends BaseLogic @@ -269,31 +270,31 @@ class NewsLogic extends BaseLogic
269 public function importNews($project_id, $user_id, $data) 270 public function importNews($project_id, $user_id, $data)
270 { 271 {
271 $category_id = ''; 272 $category_id = '';
272 - if (!empty($data[2])) { 273 + if ($data[2]) {
273 //处理分类 274 //处理分类
274 $newsCategoryLogic = new NewsCategoryLogic(); 275 $newsCategoryLogic = new NewsCategoryLogic();
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 - 'remark' => $data[3],  
286 - 'image' => '',//TODO: 远程图片下载本地  
287 - 'seo_title' => $data[6],  
288 - 'seo_keywords' => $data[7],  
289 - 'seo_description' => $data[8], 285 + 'text' => $data[4] ?? '',
  286 + 'remark' => $data[3] ?? '',
  287 + 'image' => $data['5'] ? CosService::uploadRemote($project_id, 'image_news', $data[5]) : '',
  288 + 'seo_title' => $data[6] ?? '',
  289 + 'seo_keywords' => $data[7] ?? '',
  290 + 'seo_description' => $data[8] ?? '',
290 'project_id' => $project_id, 291 'project_id' => $project_id,
291 'operator_id' => $user_id, 292 'operator_id' => $user_id,
292 'create_id' => $user_id 293 'create_id' => $user_id
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;
@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 2
3 namespace App\Services; 3 namespace App\Services;
4 4
  5 +use App\Utils\LogUtils;
5 use Qcloud\Cos\Client; 6 use Qcloud\Cos\Client;
6 /** 7 /**
7 * @remark :对象存储cos 8 * @remark :对象存储cos
@@ -64,15 +65,21 @@ class CosService @@ -64,15 +65,21 @@ class CosService
64 65
65 /** 66 /**
66 * 根据远程图片地址上传 67 * 根据远程图片地址上传
  68 + * @param $project_id
  69 + * @param $image_type
67 * @param $file_url 70 * @param $file_url
68 - * @param $path  
69 - * @param $filename  
70 * @return string 71 * @return string
71 * @author Akun 72 * @author Akun
72 * @date 2023/09/21 9:39 73 * @date 2023/09/21 9:39
73 */ 74 */
74 - public function uploadRemote($file_url,$path,$filename) 75 + public static function uploadRemote($project_id,$image_type,$file_url)
75 { 76 {
  77 + $ext = explode('.',$file_url);
  78 +
  79 + $filename = uniqid().rand(10000,99999).'.'.end($ext);
  80 +
  81 + $uploads = config('upload.default_file');
  82 + $path = $uploads['path_b'].'/'.$project_id.'/'.$image_type.'/'.date('Y-m');
76 $cos = config('filesystems.disks.cos'); 83 $cos = config('filesystems.disks.cos');
77 $cosClient = new Client([ 84 $cosClient = new Client([
78 'region' => $cos['region'], 85 'region' => $cos['region'],
@@ -82,11 +89,16 @@ class CosService @@ -82,11 +89,16 @@ class CosService
82 ], 89 ],
83 ]); 90 ]);
84 $key = $path.'/'.$filename; 91 $key = $path.'/'.$filename;
85 - $cosClient->putObject([  
86 - 'Bucket' => $cos['bucket'],  
87 - 'Key' => $key,  
88 - 'Body' => fopen($file_url, 'r'),  
89 - ]); 92 + try {
  93 + $cosClient->putObject([
  94 + 'Bucket' => $cos['bucket'],
  95 + 'Key' => $key,
  96 + 'Body' => fopen($file_url, 'r'),
  97 + ]);
  98 + }catch (\Exception $e){
  99 + LogUtils::error('uploadRemote error', $e->getMessage());
  100 + }
  101 +
90 return $key; 102 return $key;
91 } 103 }
92 104
@@ -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 });