From 5039b7891dcb0c212985a5182139af5d06a04f1e Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Fri, 10 Jul 2020 18:46:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=BC=B9=E5=B9=95=E9=83=A8?= =?UTF-8?q?=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Builders/DanmuList.php | 99 ++++++++++++++ .../Web/Controllers/ChapterController.php | 13 ++ app/Http/Web/Views/chapter/show_vod.volt | 11 +- app/Models/Danmu.php | 61 +++++++-- app/Repos/Danmu.php | 39 ++++++ app/Services/Frontend/Chapter/ChapterInfo.php | 20 ++- app/Services/Frontend/Chapter/DanmuList.php | 67 +++++++++ app/Services/Frontend/Danmu/DanmuCreate.php | 4 +- app/Services/Frontend/Help/HelpList.php | 7 +- public/static/web/js/live.player.js | 53 ++++--- public/static/web/js/vod.player.js | 129 +++++++++++------- 11 files changed, 408 insertions(+), 95 deletions(-) create mode 100644 app/Builders/DanmuList.php create mode 100644 app/Services/Frontend/Chapter/DanmuList.php diff --git a/app/Builders/DanmuList.php b/app/Builders/DanmuList.php new file mode 100644 index 00000000..270514b4 --- /dev/null +++ b/app/Builders/DanmuList.php @@ -0,0 +1,99 @@ +getCourses($danmus); + + foreach ($danmus as $key => $danmu) { + $danmus[$key]['course'] = $courses[$danmu['course_id']] ?? new \stdClass(); + } + + return $danmus; + } + + public function handleChapters(array $danmus) + { + $chapters = $this->getChapters($danmus); + + foreach ($danmus as $key => $danmu) { + $danmus[$key]['chapter'] = $chapters[$danmu['chapter_id']] ?? new \stdClass(); + } + + return $danmus; + } + + public function handleUsers(array $danmus) + { + $users = $this->getUsers($danmus); + + foreach ($danmus as $key => $danmu) { + $danmus[$key]['user'] = $users[$danmu['user_id']] ?? new \stdClass(); + } + + return $danmus; + } + + public function getCourses(array $danmus) + { + $ids = kg_array_column($danmus, 'course_id'); + + $courseRepo = new CourseRepo(); + + $courses = $courseRepo->findByIds($ids, ['id', 'title']); + + $result = []; + + foreach ($courses->toArray() as $course) { + $result[$course['id']] = $course; + } + + return $result; + } + + public function getChapters(array $danmus) + { + $ids = kg_array_column($danmus, 'chapter_id'); + + $chapterRepo = new ChapterRepo(); + + $chapters = $chapterRepo->findByIds($ids, ['id', 'title']); + + $result = []; + + foreach ($chapters->toArray() as $chapter) { + $result[$chapter['id']] = $chapter; + } + + return $result; + } + + public function getUsers(array $danmus) + { + $ids = kg_array_column($danmus, 'user_id'); + + $userRepo = new UserRepo(); + + $users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); + + $baseUrl = kg_ci_base_url(); + + $result = []; + + foreach ($users->toArray() as $user) { + $user['avatar'] = $baseUrl . $user['avatar']; + $result[$user['id']] = $user; + } + + return $result; + } + +} diff --git a/app/Http/Web/Controllers/ChapterController.php b/app/Http/Web/Controllers/ChapterController.php index 30e405bb..8b3c4393 100644 --- a/app/Http/Web/Controllers/ChapterController.php +++ b/app/Http/Web/Controllers/ChapterController.php @@ -5,6 +5,7 @@ namespace App\Http\Web\Controllers; use App\Services\Frontend\Chapter\AgreeVote as ChapterAgreeVoteService; use App\Services\Frontend\Chapter\ChapterInfo as ChapterInfoService; use App\Services\Frontend\Chapter\CommentList as ChapterCommentListService; +use App\Services\Frontend\Chapter\DanmuList as ChapterDanmuListService; use App\Services\Frontend\Chapter\Learning as ChapterLearningService; use App\Services\Frontend\Chapter\OpposeVote as ChapterOpposeVoteService; use App\Services\Frontend\Course\ChapterList as CourseChapterListService; @@ -53,6 +54,18 @@ class ChapterController extends Controller $this->view->setVar('chapters', $chapters); } + /** + * @Get("/{id:[0-9]+}/danmu", name="web.chapter.danmu") + */ + public function danmuAction($id) + { + $service = new ChapterDanmuListService(); + + $items = $service->handle($id); + + return $this->jsonSuccess(['items' => $items]); + } + /** * @Get("/{id:[0-9]+}/comments", name="web.chapter.comments") */ diff --git a/app/Http/Web/Views/chapter/show_vod.volt b/app/Http/Web/Views/chapter/show_vod.volt index 04454ddd..62de09ae 100644 --- a/app/Http/Web/Views/chapter/show_vod.volt +++ b/app/Http/Web/Views/chapter/show_vod.volt @@ -3,6 +3,7 @@ {% block content %} {% set learning_url = url({'for':'web.chapter.learning','id':chapter.id}) %} + {% set danmu_url = url({'for':'web.chapter.danmu','id':chapter.id}) %}