From 01932654f544a668b45dc3ccf3be20c32ec6f1c3 Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Wed, 20 May 2020 20:21:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Caches/IndexSlideList.php | 2 +- app/Http/Admin/Services/Slide.php | 4 +- app/Http/Admin/Views/slide/edit.volt | 10 +- app/Http/Web/Controllers/CourseController.php | 109 ++++++------------ app/Http/Web/Controllers/TopicController.php | 15 +-- app/Http/Web/Services/CourseQuery.php | 27 +++++ app/Http/Web/Services/Index.php | 3 + app/Http/Web/Views/course/chapters.volt | 0 app/Http/Web/Views/course/list.volt | 5 +- app/Http/Web/Views/course/show.volt | 58 ++++++++++ .../Web/Views/course/widget_recommended.volt | 18 +++ app/Http/Web/Views/course/widget_related.volt | 18 +++ app/Http/Web/Views/course/widget_teacher.volt | 14 +++ app/Http/Web/Views/course/widget_topic.volt | 8 ++ app/Http/Web/Views/index/index.volt | 2 +- app/Models/Course.php | 5 +- app/Models/Slide.php | 27 ++++- app/Repos/Course.php | 2 +- app/Services/Frontend/Course/CourseInfo.php | 11 +- 19 files changed, 230 insertions(+), 108 deletions(-) create mode 100644 app/Http/Web/Views/course/chapters.volt create mode 100644 app/Http/Web/Views/course/show.volt create mode 100644 app/Http/Web/Views/course/widget_recommended.volt create mode 100644 app/Http/Web/Views/course/widget_related.volt create mode 100644 app/Http/Web/Views/course/widget_teacher.volt create mode 100644 app/Http/Web/Views/course/widget_topic.volt diff --git a/app/Caches/IndexSlideList.php b/app/Caches/IndexSlideList.php index 1c5b41b2..b98e5b34 100644 --- a/app/Caches/IndexSlideList.php +++ b/app/Caches/IndexSlideList.php @@ -47,7 +47,7 @@ class IndexSlideList extends Cache 'id' => $slide->id, 'title' => $slide->title, 'cover' => $slide->cover, - 'bg_color' => $slide->bg_color, + 'style' => $slide->style, 'target' => $slide->target, 'content' => $slide->content, ]; diff --git a/app/Http/Admin/Services/Slide.php b/app/Http/Admin/Services/Slide.php index 37c4d252..2ddc0a01 100644 --- a/app/Http/Admin/Services/Slide.php +++ b/app/Http/Admin/Services/Slide.php @@ -87,8 +87,8 @@ class Slide extends Service $data['cover'] = $validator->checkCover($post['cover']); } - if (isset($post['bg_color'])) { - $data['bg_color'] = $validator->checkBgColor($post['bg_color']); + if (isset($post['style']['bg_color'])) { + $data['style']['bg_color'] = $validator->checkBgColor($post['style']['bg_color']); } if (isset($post['content'])) { diff --git a/app/Http/Admin/Views/slide/edit.volt b/app/Http/Admin/Views/slide/edit.volt index 8d3f913e..2b865374 100644 --- a/app/Http/Admin/Views/slide/edit.volt +++ b/app/Http/Admin/Views/slide/edit.volt @@ -32,10 +32,10 @@
- +
-
+
@@ -92,11 +92,11 @@ var $ = layui.jquery; var colorPicker = layui.colorpicker; colorPicker.render({ - elem: '#bg-color', - color: '{{ slide.bg_color }}', + elem: '#style-bg-color', + color: '{{ slide.style['bg_color'] }}', predefine: true, change: function (color) { - $('input[name=bg_color]').val(color); + $('input[name="style[bg_color]"]').val(color); } }); }); diff --git a/app/Http/Web/Controllers/CourseController.php b/app/Http/Web/Controllers/CourseController.php index e387bbef..56aea8bd 100644 --- a/app/Http/Web/Controllers/CourseController.php +++ b/app/Http/Web/Controllers/CourseController.php @@ -26,18 +26,18 @@ class CourseController extends Controller */ public function listAction() { - $courseListService = new CourseListService(); + $service = new CourseListService(); - $pager = $courseListService->handle(); + $pager = $service->handle(); - $courseQueryService = new CourseQueryService(); + $service = new CourseQueryService(); - $topCategories = $courseQueryService->handleTopCategories(); - $subCategories = $courseQueryService->handleSubCategories(); + $topCategories = $service->handleTopCategories(); + $subCategories = $service->handleSubCategories(); - $models = $courseQueryService->handleModels(); - $levels = $courseQueryService->handleLevels(); - $sorts = $courseQueryService->handleSorts(); + $models = $service->handleModels(); + $levels = $service->handleLevels(); + $sorts = $service->handleSorts(); $this->view->setVar('top_categories', $topCategories); $this->view->setVar('sub_categories', $subCategories); @@ -52,83 +52,46 @@ class CourseController extends Controller */ public function showAction($id) { - $courseInfoService = new CourseInfoService(); + $service = new CourseInfoService(); - $course = $courseInfoService->handle($id); + $course = $service->handle($id); - $this->view->setVar('course', $course); - } + $service = new CourseQueryService(); - /** - * @Get("/{id:[0-9]+}/teachers", name="web.course.teachers") - */ - public function teachersAction($id) - { - $service = new CourseTeacherListService(); + $categoryPaths = $service->handleCategoryPaths($course['category_id']); - $teachers = $service->handle($id); - - return $this->jsonSuccess(['teachers' => $teachers]); - } - - /** - * @Get("/{id:[0-9]+}/chapters", name="web.course.chapters") - */ - public function chaptersAction($id) - { $service = new CourseChapterListService(); $chapters = $service->handle($id); - return $this->jsonSuccess(['chapters' => $chapters]); - } - - /** - * @Get("/{id:[0-9]+}/packages", name="web.course.packages") - */ - public function packagesAction($id) - { $service = new CoursePackageListService(); $packages = $service->handle($id); - return $this->jsonSuccess(['packages' => $packages]); - } + $service = new CourseTeacherListService(); - /** - * @Get("/{id:[0-9]+}/recommended", name="web.course.recommended") - */ - public function recommendedAction($id) - { - $service = new CourseRecommendedListService(); + $teachers = $service->handle($id); - $courses = $service->handle($id); - - return $this->jsonSuccess(['courses' => $courses]); - } - - /** - * @Get("/{id:[0-9]+}/related", name="web.course.related") - */ - public function relatedAction($id) - { - $service = new CourseRelatedListService(); - - $courses = $service->handle($id); - - return $this->jsonSuccess(['courses' => $courses]); - } - - /** - * @Get("/{id:[0-9]+}/topics", name="web.course.topics") - */ - public function topicsAction($id) - { $service = new CourseTopicListService(); $topics = $service->handle($id); - return $this->jsonSuccess(['topics' => $topics]); + $service = new CourseRecommendedListService(); + + $recommendedCourses = $service->handle($id); + + $service = new CourseRelatedListService(); + + $relatedCourses = $service->handle($id); + + $this->view->setVar('course', $course); + $this->view->setVar('chapters', $chapters); + $this->view->setVar('packages', $packages); + $this->view->setVar('teachers', $teachers); + $this->view->setVar('topics', $topics); + $this->view->setVar('recommended_courses', $recommendedCourses); + $this->view->setVar('related_courses', $relatedCourses); + $this->view->setVar('category_paths', $categoryPaths); } /** @@ -136,9 +99,9 @@ class CourseController extends Controller */ public function consultsAction($id) { - $consultListService = new CourseConsultListService(); + $service = new CourseConsultListService(); - $pager = $consultListService->handle($id); + $pager = $service->handle($id); return $this->jsonPaginate($pager); } @@ -148,9 +111,9 @@ class CourseController extends Controller */ public function reviewsAction($id) { - $reviewListService = new CourseReviewListService(); + $service = new CourseReviewListService(); - $pager = $reviewListService->handle($id); + $pager = $service->handle($id); return $this->jsonPaginate($pager); } @@ -160,9 +123,9 @@ class CourseController extends Controller */ public function favoriteAction($id) { - $favoriteService = new CourseFavoriteService(); + $service = new CourseFavoriteService(); - $favoriteService->handle($id); + $service->handle($id); return $this->jsonSuccess(['msg' => '收藏课程成功']); } diff --git a/app/Http/Web/Controllers/TopicController.php b/app/Http/Web/Controllers/TopicController.php index 63c7a8f8..17c6da33 100644 --- a/app/Http/Web/Controllers/TopicController.php +++ b/app/Http/Web/Controllers/TopicController.php @@ -12,27 +12,20 @@ class TopicController extends Controller { /** - * @Get("/{id:[0-9]+}/info", name="web.topic.info") + * @Get("/{id:[0-9]+}", name="web.topic.show") */ - public function infoAction($id) + public function showAction($id) { $service = new TopicInfoService(); $topic = $service->handle($id); - return $this->jsonSuccess(['topic' => $topic]); - } - - /** - * @Get("/{id:[0-9]+}/courses", name="web.topic.courses") - */ - public function coursesAction($id) - { $service = new TopicCourseListService(); $courses = $service->handle($id); - return $this->jsonSuccess(['courses' => $courses]); + $this->view->setVar('topic', $topic); + $this->view->setVar('courses', $courses); } } diff --git a/app/Http/Web/Services/CourseQuery.php b/app/Http/Web/Services/CourseQuery.php index e19881a3..e1f816ed 100644 --- a/app/Http/Web/Services/CourseQuery.php +++ b/app/Http/Web/Services/CourseQuery.php @@ -2,6 +2,7 @@ namespace App\Http\Web\Services; +use App\Caches\Category as CategoryCache; use App\Models\Course as CourseModel; use App\Services\Category as CategoryService; @@ -183,6 +184,32 @@ class CourseQuery extends Service return $result; } + public function handleCategoryPaths($categoryId) + { + $result = []; + + $cache = new CategoryCache(); + + $subCategory = $cache->get($categoryId); + $topCategory = $cache->get($subCategory->parent_id); + + $topParams = ['tc' => $topCategory->id]; + + $result['top'] = [ + 'name' => $topCategory->name, + 'url' => $this->baseUrl . $this->buildQueryParams($topParams), + ]; + + $subParams = ['tc' => $topCategory->id, 'sc' => $subCategory->id]; + + $result['sub'] = [ + 'name' => $subCategory->name, + 'url' => $this->baseUrl . $this->buildQueryParams($subParams), + ]; + + return $result; + } + protected function getQueryParams() { $query = $this->request->getQuery(); diff --git a/app/Http/Web/Services/Index.php b/app/Http/Web/Services/Index.php index 38c68ada..bb5f9511 100644 --- a/app/Http/Web/Services/Index.php +++ b/app/Http/Web/Services/Index.php @@ -24,6 +24,9 @@ class Index extends Service if (!$slides) return []; foreach ($slides as $key => $slide) { + + $slides[$key]['style'] = SlideModel::htmlStyle($slide['style']); + switch ($slide['target']) { case SlideModel::TARGET_COURSE: $slides[$key]['url'] = $this->url->get([ diff --git a/app/Http/Web/Views/course/chapters.volt b/app/Http/Web/Views/course/chapters.volt new file mode 100644 index 00000000..e69de29b diff --git a/app/Http/Web/Views/course/list.volt b/app/Http/Web/Views/course/list.volt index 84d20c57..bab0c1dd 100644 --- a/app/Http/Web/Views/course/list.volt +++ b/app/Http/Web/Views/course/list.volt @@ -42,7 +42,10 @@
- + {% for sort in sorts %} + {% set class = request.get('sort','trim','score') == sort.id ? 'layui-badge active' : 'layui-badge' %} + {{ sort.name }} + {% endfor %}
diff --git a/app/Http/Web/Views/course/show.volt b/app/Http/Web/Views/course/show.volt new file mode 100644 index 00000000..c6dce620 --- /dev/null +++ b/app/Http/Web/Views/course/show.volt @@ -0,0 +1,58 @@ +{% extends 'templates/base.volt' %} + +{% block content %} + + + +
+
+
+
+ +
+
+
+
    +
  • 详情
  • +
  • 目录
  • +
  • 评价
  • +
+
+
+
{{ course.details }}
+
+
+ {{ partial('course/chapters', {'chapters':chapters}) }} +
+
内容3
+
+
+
+
+ {% if teachers %} + {{ partial('course/widget_teacher', {'teachers':teachers}) }} + {% endif %} + + {% if topics %} + {{ partial('course/widget_topic', {'topics':topics}) }} + {% endif %} + + {% if recommended_courses %} + {{ partial('course/widget_recommended', {'courses':recommended_courses}) }} + {% endif %} + + {% if related_courses %} + {{ partial('course/widget_related', {'courses':related_courses}) }} + {% endif %} +
+
+ +{% endblock %} \ No newline at end of file diff --git a/app/Http/Web/Views/course/widget_recommended.volt b/app/Http/Web/Views/course/widget_recommended.volt new file mode 100644 index 00000000..0d047020 --- /dev/null +++ b/app/Http/Web/Views/course/widget_recommended.volt @@ -0,0 +1,18 @@ +
+
推荐课程
+
+ {% for course in courses %} +
+
+
+
{{ course.title }}
+
+ + + +
+
+
+ {% endfor %} +
+
\ No newline at end of file diff --git a/app/Http/Web/Views/course/widget_related.volt b/app/Http/Web/Views/course/widget_related.volt new file mode 100644 index 00000000..72253d0f --- /dev/null +++ b/app/Http/Web/Views/course/widget_related.volt @@ -0,0 +1,18 @@ +
+
相关课程
+
+ {% for course in courses %} +
+
+
+
{{ course.title }}
+
+ + + +
+
+
+ {% endfor %} +
+
\ No newline at end of file diff --git a/app/Http/Web/Views/course/widget_teacher.volt b/app/Http/Web/Views/course/widget_teacher.volt new file mode 100644 index 00000000..ff80970f --- /dev/null +++ b/app/Http/Web/Views/course/widget_teacher.volt @@ -0,0 +1,14 @@ +
+
授课教师
+
+ {% for teacher in teachers %} +
+
+
+
{{ teacher.name }}
+
{{ teacher.title }}
+
+
+ {% endfor %} +
+
\ No newline at end of file diff --git a/app/Http/Web/Views/course/widget_topic.volt b/app/Http/Web/Views/course/widget_topic.volt new file mode 100644 index 00000000..d0f5409c --- /dev/null +++ b/app/Http/Web/Views/course/widget_topic.volt @@ -0,0 +1,8 @@ +
+
热门专题
+
+ {% for topic in topics %} + {{ topic.title }} + {% endfor %} +
+
\ No newline at end of file diff --git a/app/Http/Web/Views/index/index.volt b/app/Http/Web/Views/index/index.volt index 7bb3a77d..6ec05166 100644 --- a/app/Http/Web/Views/index/index.volt +++ b/app/Http/Web/Views/index/index.volt @@ -31,7 +31,7 @@