diff --git a/app/Builders/AnswerList.php b/app/Builders/AnswerList.php index 4633f7b6..7e47e5b4 100644 --- a/app/Builders/AnswerList.php +++ b/app/Builders/AnswerList.php @@ -1,4 +1,9 @@ findUsers(); + $limit = 1000; - if ($users->count() == 0) return; + $totalCount = $this->countUsers(); + + if ($totalCount == 0) return; + + $page = ceil($totalCount / $limit); $handler = new UserSearcher(); @@ -86,9 +96,20 @@ class UserIndexTask extends Task $index->beginRebuild(); - foreach ($users as $user) { - $document = $documenter->setDocument($user); - $index->add($document); + for ($i = 0; $i < $page; $i++) { + + $offset = $i * $limit; + + $users = $this->findUsers($limit, $offset); + + if ($users->count() == 0) break; + + foreach ($users as $user) { + $document = $documenter->setDocument($user); + $index->add($document); + } + + echo "------ fetch users: {$limit},{$offset} ------" . PHP_EOL; } $index->endRebuild(); @@ -111,15 +132,22 @@ class UserIndexTask extends Task } /** - * 查找课程 - * + * @param int $limit + * @param int $offset * @return ResultsetInterface|Resultset|UserModel[] */ - protected function findUsers() + protected function findUsers($limit, $offset) { return UserModel::query() - ->where('deleted = 0') + ->limit($limit, $offset) ->execute(); } + protected function countUsers() + { + $userRepo = new UserRepo(); + + return $userRepo->countUsers(); + } + } diff --git a/app/Console/Tasks/VodEventTask.php b/app/Console/Tasks/VodEventTask.php index d752c46a..48ef62e7 100644 --- a/app/Console/Tasks/VodEventTask.php +++ b/app/Console/Tasks/VodEventTask.php @@ -1,4 +1,9 @@ update(['attrs' => $attrs]); return; @@ -77,7 +81,6 @@ class VodEventTask extends Task $vodService->createTransVideoTask($fileId); } - $attrs['file']['id'] = $fileId; $attrs['file']['status'] = ChapterModel::FS_TRANSLATING; $attrs['duration'] = (int)$duration; @@ -106,7 +109,6 @@ class VodEventTask extends Task * 获取不到处理结果视为失败 */ if (empty($processResult)) { - $attrs['file']['id'] = $fileId; $attrs['file']['status'] = ChapterModel::FS_FAILED; $chapter->update(['attrs' => $attrs]); return; diff --git a/app/Exceptions/BadRequest.php b/app/Exceptions/BadRequest.php index cf863209..3abf4466 100644 --- a/app/Exceptions/BadRequest.php +++ b/app/Exceptions/BadRequest.php @@ -1,4 +1,9 @@ model) { case CourseModel::MODEL_VOD: $vod = $contentService->getChapterVod($chapter->id); - $playUrls = $contentService->getPlayUrls($chapter->id); + $cosPlayUrls = $contentService->getCosPlayUrls($chapter->id); + $remotePlayUrls = $contentService->getRemotePlayUrls($chapter->id); + $remoteDuration = $contentService->getRemoteDuration($chapter->id); $this->view->setVar('vod', $vod); - $this->view->setVar('play_urls', $playUrls); + $this->view->setVar('cos_play_urls', $cosPlayUrls); + $this->view->setVar('remote_play_urls', $remotePlayUrls); + $this->view->setVar('remote_duration', $remoteDuration); break; case CourseModel::MODEL_LIVE: $live = $contentService->getChapterLive($chapter->id); diff --git a/app/Http/Admin/Controllers/CommentController.php b/app/Http/Admin/Controllers/CommentController.php index 57872dfa..0ba876c5 100644 --- a/app/Http/Admin/Controllers/CommentController.php +++ b/app/Http/Admin/Controllers/CommentController.php @@ -1,4 +1,9 @@ setShared('view', function () { + $dependencyInjector->setShared('view', function () { $view = new MyView(); $view->setViewsDir(__DIR__ . '/Views'); $view->registerEngines([ @@ -26,7 +31,7 @@ class Module implements ModuleDefinitionInterface return $view; }); - $di->setShared('auth', function () { + $dependencyInjector->setShared('auth', function () { return new AdminAuth(); }); } diff --git a/app/Http/Admin/Services/AlipayTest.php b/app/Http/Admin/Services/AlipayTest.php index dfc9269f..8a4db95b 100644 --- a/app/Http/Admin/Services/AlipayTest.php +++ b/app/Http/Admin/Services/AlipayTest.php @@ -1,4 +1,9 @@ findChapterOffline($chapterId); } - public function getPlayUrls($chapterId) + public function getCosPlayUrls($chapterId) { $service = new ChapterVodService(); - return $service->getPlayUrls($chapterId); + return $service->getCosPlayUrls($chapterId); + } + + public function getRemotePlayUrls($chapterId) + { + $service = new ChapterVodService(); + + return $service->getRemotePlayUrls($chapterId); + } + + public function getRemoteDuration($chapterId) + { + $chapterRepo = new ChapterRepo(); + + $chapter = $chapterRepo->findById($chapterId); + + $duration = $chapter->attrs['duration'] ?? 0; + + $result = ['hours' => 0, 'minutes' => 0, 'seconds' => 0]; + + if ($duration == 0) return $result; + + $result['hours'] = floor($duration / 3600); + $result['minutes'] = floor(($duration - $result['hours'] * 3600) / 60); + $result['seconds'] = $duration % 60; + + return $result; } public function updateChapterContent($chapterId) @@ -84,6 +115,17 @@ class ChapterContent extends Service { $post = $this->request->getPost(); + if (isset($post['file_id'])) { + $this->updateCosChapterVod($chapter); + } elseif (isset($post['file_remote'])) { + $this->updateRemoteChapterVod($chapter); + } + } + + protected function updateCosChapterVod(ChapterModel $chapter) + { + $post = $this->request->getPost(); + $validator = new ChapterVodValidator(); $fileId = $validator->checkFileId($post['file_id']); @@ -119,6 +161,54 @@ class ChapterContent extends Service $this->updateCourseVodAttrs($vod->course_id); } + protected function updateRemoteChapterVod(ChapterModel $chapter) + { + $post = $this->request->getPost(); + + $validator = new ChapterVodValidator(); + + $hours = $post['file_remote']['duration']['hours'] ?? 0; + $minutes = $post['file_remote']['duration']['minutes'] ?? 0; + $seconds = $post['file_remote']['duration']['seconds'] ?? 0; + + $duration = 3600 * $hours + 60 * $minutes + $seconds; + + $validator->checkDuration($duration); + + $odUrl = $post['file_remote']['od']['url'] ?? ''; + $hdUrl = $post['file_remote']['hd']['url'] ?? ''; + $sdUrl = $post['file_remote']['sd']['url'] ?? ''; + + $fileRemote = []; + + $attrs = $chapter->attrs; + + if (!empty($odUrl)) { + $fileRemote['od']['url'] = $validator->checkFileUrl($odUrl); + $attrs['file']['status'] = ChapterModel::FS_UPLOADED; + $attrs['duration'] = $duration; + } + + if (!empty($hdUrl)) { + $fileRemote['hd']['url'] = $validator->checkFileUrl($hdUrl); + } + + if (!empty($sdUrl)) { + $fileRemote['sd']['url'] = $validator->checkFileUrl($sdUrl); + } + + $chapterRepo = new ChapterRepo(); + + $vod = $chapterRepo->findChapterVod($chapter->id); + $vod->file_remote = $fileRemote; + $vod->update(); + + $chapter->attrs = $attrs; + $chapter->update(); + + $this->updateCourseVodAttrs($vod->course_id); + } + protected function updateChapterLive(ChapterModel $chapter) { $post = $this->request->getPost(); diff --git a/app/Http/Admin/Services/Comment.php b/app/Http/Admin/Services/Comment.php index 3f0c59dc..c3bc2aa5 100644 --- a/app/Http/Admin/Services/Comment.php +++ b/app/Http/Admin/Services/Comment.php @@ -1,4 +1,9 @@ course_id = $course->id; $imGroup->name = $course->title; $imGroup->about = $course->summary; - $imGroup->published = 1; if ($imGroup->create() === false) { throw new \RuntimeException('Create ImGroup Failed'); @@ -611,6 +615,10 @@ class Course extends Service $data['name'] = $course->title; } + if ($course->published != $group->published) { + $data['published'] = $course->published; + } + if ($course->teacher_id > 0 && $group->owner_id == 0) { $groupUser = new ImGroupUserModel(); diff --git a/app/Http/Admin/Services/FlashSale.php b/app/Http/Admin/Services/FlashSale.php index e8dea649..3a90363b 100644 --- a/app/Http/Admin/Services/FlashSale.php +++ b/app/Http/Admin/Services/FlashSale.php @@ -1,4 +1,9 @@ {{ item.like_count }}
格式 | -时长 | -分辨率 | -码率 | -大小 | -操作 | -
---|---|---|---|---|---|
{{ item.format }} | -{{ item.duration|duration }} | -{{ item.width }} x {{ item.height }} | -{{ item.rate }}kbps | -{{ item.size }}M | -- 预览 - 复制 - | -