From e13797acc71a4b2bbbbe589d9757c3da4cfff674 Mon Sep 17 00:00:00 2001 From: zengyyh Date: Wed, 6 Nov 2024 01:31:38 +0800 Subject: [PATCH] 1 --- app/api/controller/Course.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/api/controller/Course.php b/app/api/controller/Course.php index f24bdccd..63435362 100644 --- a/app/api/controller/Course.php +++ b/app/api/controller/Course.php @@ -29,13 +29,21 @@ class Course extends Controller ->when($courseCategoryId, function ($query) use ($courseCategoryId) { return $query->where('course_category_id', $courseCategoryId)->where('status', 1); })->paginate($pageSize); - + if(empty($list)){ return $this->renderError("没有课程"); } + $image_ids = array_column(($list->toArray())['data'], 'image_id'); + $video_ids = array_column(($list->toArray())['data'], 'video_id'); + $images= array_unique(array_merge($image_ids,$video_ids)); + $image = UploadFile::withoutGlobalScope()->whereIn('file_id',$images)->select(); + + + $list_image = array_column($image->toArray(), null ,'file_id'); + foreach($list as $value){ - $value['image_url'] = UploadFile::withoutGlobalScope()->where('file_id', '=',$value['image_id'])->find(); - $value['video_url'] = UploadFile::withoutGlobalScope()->where('file_id', '=',$value['video_id'])->find(); + $value['image_url'] = $list_image[$value['image_id']] ?? []; + $value['video_url'] = $list_image[$value['video_id']] ?? []; } return $this->renderSuccess(compact('list'));