1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-22 11:41:27 +08:00
koogua a7f197c01b !6 develop->master 1.1.0
* 更新版本号
* 完善后台今日统计,增加权限白名单,增加后台首页菜单,调整后台登录页样式
* Merge branch 'koogua/I1XFCF' of https://gitee.com/koogua/course-tencen…
* 前台学习资料部分完成
* !2 后台运营统计合并
* 后台学习资料部分完成
* Merge branch 'master' into develop
* Merge branch 'master' of https://github.com/xiaochong0302/course-tencent-cloud
* 1.增加changelog.md
* 1.简化部分路由地址
* Merge pull request #2 from xiaochong0302/dependabot/composer/symfony/h…
* Bump symfony/http-foundation from 4.3.4 to 5.1.6
2020-10-08 18:44:06 +08:00

126 lines
3.5 KiB
PHP

<?php
namespace App\Services\Logic\Chapter;
use App\Models\Chapter as ChapterModel;
use App\Models\ChapterLive as ChapterLiveModel;
use App\Models\Course as CourseModel;
use App\Repos\Chapter as ChapterRepo;
use App\Services\ChapterVod as ChapterVodService;
use App\Services\Live as LiveService;
use App\Services\Logic\ChapterTrait;
use App\Services\Logic\CourseTrait;
use App\Services\Logic\Service;
class BasicInfo extends Service
{
use CourseTrait;
use ChapterTrait;
public function handle($id)
{
$chapter = $this->checkChapter($id);
$course = $this->checkCourse($chapter->course_id);
$result = $this->handleBasicInfo($chapter);
$result['course'] = $this->handleCourseInfo($course);
return $result;
}
public function handleBasicInfo(ChapterModel $chapter)
{
$result = [];
switch ($chapter->model) {
case CourseModel::MODEL_VOD:
$result = $this->formatChapterVod($chapter);
break;
case CourseModel::MODEL_LIVE:
$result = $this->formatChapterLive($chapter);
break;
case CourseModel::MODEL_READ:
$result = $this->formatChapterRead($chapter);
break;
}
return $result;
}
public function handleCourseInfo(CourseModel $course)
{
return [
'id' => $course->id,
'title' => $course->title,
'cover' => $course->cover,
];
}
protected function formatChapterVod(ChapterModel $chapter)
{
$chapterVodService = new ChapterVodService();
$playUrls = $chapterVodService->getPlayUrls($chapter->id);
return [
'id' => $chapter->id,
'title' => $chapter->title,
'summary' => $chapter->summary,
'model' => $chapter->model,
'play_urls' => $playUrls,
'resource_count' => $chapter->resource_count,
'user_count' => $chapter->user_count,
'like_count' => $chapter->like_count,
];
}
protected function formatChapterLive(ChapterModel $chapter)
{
$liveService = new LiveService();
$streamName = ChapterLiveModel::generateStreamName($chapter->id);
$playUrls = $liveService->getPullUrls($streamName);
$chapterRepo = new ChapterRepo();
$live = $chapterRepo->findChapterLive($chapter->id);
return [
'id' => $chapter->id,
'title' => $chapter->title,
'summary' => $chapter->summary,
'model' => $chapter->model,
'play_urls' => $playUrls,
'start_time' => $live->start_time,
'end_time' => $live->end_time,
'status' => $live->status,
'resource_count' => $chapter->resource_count,
'user_count' => $chapter->user_count,
'like_count' => $chapter->like_count,
];
}
protected function formatChapterRead(ChapterModel $chapter)
{
$chapterRepo = new ChapterRepo();
$read = $chapterRepo->findChapterRead($chapter->id);
return [
'id' => $chapter->id,
'title' => $chapter->title,
'summary' => $chapter->summary,
'model' => $chapter->model,
'content' => $read->content,
'resource_count' => $chapter->resource_count,
'user_count' => $chapter->user_count,
'like_count' => $chapter->like_count,
];
}
}