diff --git a/app/Builders/CommentList.php b/app/Builders/CommentList.php deleted file mode 100644 index 8f3b2a4f..00000000 --- a/app/Builders/CommentList.php +++ /dev/null @@ -1,99 +0,0 @@ -getCourses($comments); - - foreach ($comments as $key => $comment) { - $comments[$key]['course'] = $courses[$comment['course_id']] ?? new \stdClass(); - } - - return $comments; - } - - public function handleChapters(array $comments) - { - $chapters = $this->getChapters($comments); - - foreach ($comments as $key => $comment) { - $comments[$key]['chapter'] = $chapters[$comment['chapter_id']] ?? new \stdClass(); - } - - return $comments; - } - - public function handleUsers(array $comments) - { - $users = $this->getUsers($comments); - - foreach ($comments as $key => $comment) { - $comments[$key]['user'] = $users[$comment['user_id']] ?? new \stdClass(); - } - - return $comments; - } - - public function getCourses(array $comments) - { - $ids = kg_array_column($comments, '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 $comments) - { - $ids = kg_array_column($comments, '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 $comments) - { - $ids = kg_array_column($comments, '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/Caches/ChapterCounter.php b/app/Caches/ChapterCounter.php index 3ed88699..d6370b18 100644 --- a/app/Caches/ChapterCounter.php +++ b/app/Caches/ChapterCounter.php @@ -29,8 +29,7 @@ class ChapterCounter extends Counter return [ 'user_count' => $chapter->user_count, - 'lesson_count' => $chapter->lesson_count, - 'comment_count' => $chapter->comment_count, + 'consult_count' => $chapter->consult_count, 'like_count' => $chapter->like_count, ]; } diff --git a/app/Caches/CommentCounter.php b/app/Caches/CommentCounter.php deleted file mode 100644 index daa5e6d4..00000000 --- a/app/Caches/CommentCounter.php +++ /dev/null @@ -1,36 +0,0 @@ -lifetime; - } - - public function getKey($id = null) - { - return "comment_counter:{$id}"; - } - - public function getContent($id = null) - { - $commentRepo = new CommentRepo(); - - $comment = $commentRepo->findById($id); - - if (!$comment) return null; - - return [ - 'reply_count' => $comment->reply_count, - 'like_count' => $comment->like_count, - ]; - } - -} diff --git a/app/Caches/CourseRecommendedList.php b/app/Caches/CourseRecommendedList.php index 5943fbea..fdd8fe45 100644 --- a/app/Caches/CourseRecommendedList.php +++ b/app/Caches/CourseRecommendedList.php @@ -65,7 +65,7 @@ class CourseRecommendedList extends Cache public function findCourses($limit = 5) { return CourseModel::query() - ->where('published = 1 AND deleted = 0 AND market_price > 0') + ->where('published = 1 AND market_price > 0') ->orderBy('RAND()') ->limit($limit) ->execute(); diff --git a/app/Caches/CourseTopicList.php b/app/Caches/CourseTopicList.php index 18d2f914..84e1f36c 100644 --- a/app/Caches/CourseTopicList.php +++ b/app/Caches/CourseTopicList.php @@ -58,7 +58,7 @@ class CourseTopicList extends Cache public function findTopics($limit = 5) { return TopicModel::query() - ->where('published = 1 AND deleted = 0') + ->where('published = 1') ->orderBy('RAND()') ->limit($limit) ->execute(); diff --git a/app/Caches/IndexSlideList.php b/app/Caches/IndexSlideList.php index b98e5b34..75a138d1 100644 --- a/app/Caches/IndexSlideList.php +++ b/app/Caches/IndexSlideList.php @@ -63,7 +63,7 @@ class IndexSlideList extends Cache public function findSlides($limit = 5) { return SlideModel::query() - ->where('published = 1 AND deleted = 0') + ->where('published = 1') ->orderBy('priority ASC') ->limit($limit) ->execute(); diff --git a/app/Caches/MaxImChatGroupId.php b/app/Caches/MaxImGroupId.php similarity index 91% rename from app/Caches/MaxImChatGroupId.php rename to app/Caches/MaxImGroupId.php index ae73f162..346206b4 100644 --- a/app/Caches/MaxImChatGroupId.php +++ b/app/Caches/MaxImGroupId.php @@ -16,7 +16,7 @@ class MaxImGroupId extends Cache public function getKey($id = null) { - return 'max_im_chat_group_id'; + return 'max_im_group_id'; } public function getContent($id = null) diff --git a/app/Console/Tasks/CleanSessionTask.php b/app/Console/Tasks/CleanSessionTask.php new file mode 100644 index 00000000..a7140a1b --- /dev/null +++ b/app/Console/Tasks/CleanSessionTask.php @@ -0,0 +1,55 @@ +cache = $this->getDI()->get('cache'); + + $this->redis = $this->cache->getRedis(); + + $keys = $this->querySessionKeys(10000); + + if (count($keys) == 0) return; + + $config = $this->getDI()->get('config'); + + $lifetime = $config->session->lifetime; + + foreach ($keys as $key) { + $ttl = $this->redis->ttl($key); + $content = $this->redis->get($key); + if (empty($content) && $ttl < $lifetime * 0.5) { + $this->redis->del($key); + } + } + } + + /** + * 查找待清理会话 + * + * @param int $limit + * @return array + */ + protected function querySessionKeys($limit) + { + return $this->cache->queryKeys('_PHCR', $limit); + } + +} diff --git a/app/Console/Tasks/SyncCommentCounterTask.php b/app/Console/Tasks/SyncCommentCounterTask.php deleted file mode 100644 index 9c9cf7ac..00000000 --- a/app/Console/Tasks/SyncCommentCounterTask.php +++ /dev/null @@ -1,89 +0,0 @@ -cache = $this->getDI()->get('cache'); - - $this->redis = $this->cache->getRedis(); - - $this->rebuild(); - } - - protected function rebuild() - { - $key = $this->getCacheKey(); - - $commentIds = $this->redis->sRandMember($key, 500); - - if (!$commentIds) return; - - $commentRepo = new CommentRepo(); - - $comments = $commentRepo->findByIds($commentIds); - - if ($comments->count() == 0) { - return; - } - - $counterCache = new CommentCounterCache(); - - $allowRecount = $this->allowRecount(); - - foreach ($comments as $comment) { - - if ($allowRecount) { - - $comment->reply_count = $commentRepo->countReplies($comment->id); - $comment->like_count = $commentRepo->countLikes($comment->id); - $comment->update(); - - $counterCache->rebuild($comment->id); - - } else { - - $counter = $counterCache->get($comment->id); - - if ($counter) { - $comment->reply_count = $counter['reply_count']; - $comment->like_count = $counter['like_count']; - $comment->update(); - } - } - } - - $this->redis->sRem($key, ...$commentIds); - } - - protected function getCacheKey() - { - $syncer = new CommentCounterSyncer(); - - return $syncer->getSyncKey(); - } - - protected function allowRecount() - { - return date('H') % 4 == 0; - } - -} diff --git a/app/Http/Admin/Controllers/CommentController.php b/app/Http/Admin/Controllers/CommentController.php deleted file mode 100644 index 03d5b392..00000000 --- a/app/Http/Admin/Controllers/CommentController.php +++ /dev/null @@ -1,121 +0,0 @@ -request->getQuery('course_id', 'int', 0); - $chapterId = $this->request->getQuery('chapter_id', 'int', 0); - - $commentService = new CommentService(); - - $pager = $commentService->getComments(); - - $chapter = null; - - if ($chapterId > 0) { - $chapter = $commentService->getChapter($chapterId); - $courseId = $chapter->course_id; - } - - $course = null; - - if ($courseId > 0) { - $course = $commentService->getCourse($courseId); - } - - $this->view->setVar('pager', $pager); - $this->view->setVar('course', $course); - $this->view->setVar('chapter', $chapter); - } - - /** - * @Get("/{id:[0-9]+}/edit", name="admin.comment.edit") - */ - public function editAction($id) - { - $commentService = new CommentService(); - - $comment = $commentService->getComment($id); - - $this->view->setVar('comment', $comment); - } - - /** - * @Post("/{id:[0-9]+}/update", name="admin.comment.update") - */ - public function updateAction($id) - { - $commentService = new CommentService(); - - $commentService->update($id); - - $location = $this->request->getHTTPReferer(); - - $content = [ - 'location' => $location, - 'msg' => '更新评论成功', - ]; - - return $this->jsonSuccess($content); - } - - /** - * @Post("/{id:[0-9]+}/delete", name="admin.comment.delete") - */ - public function deleteAction($id) - { - $commentService = new CommentService(); - - $commentService->deleteComment($id); - - $location = $this->request->getHTTPReferer(); - - $content = [ - 'location' => $location, - 'msg' => '删除评论成功', - ]; - - return $this->jsonSuccess($content); - } - - - /** - * @Post("/{id:[0-9]+}/restore", name="admin.comment.restore") - */ - public function restoreAction($id) - { - $commentService = new CommentService(); - - $commentService->restoreComment($id); - - $location = $this->request->getHTTPReferer(); - - $content = [ - 'location' => $location, - 'msg' => '还原评论成功', - ]; - - return $this->jsonSuccess($content); - } - -} diff --git a/app/Http/Admin/Services/AuthNode.php b/app/Http/Admin/Services/AuthNode.php index 1f000edf..077ef889 100644 --- a/app/Http/Admin/Services/AuthNode.php +++ b/app/Http/Admin/Services/AuthNode.php @@ -325,37 +325,6 @@ class AuthNode extends Service ], ], ], - [ - 'id' => '2-4', - 'title' => '评论管理', - 'type' => 'menu', - 'children' => [ - [ - 'id' => '2-4-1', - 'title' => '评论列表', - 'type' => 'menu', - 'route' => 'admin.comment.list', - ], - [ - 'id' => '2-4-2', - 'title' => '搜索评论', - 'type' => 'menu', - 'route' => 'admin.comment.search', - ], - [ - 'id' => '2-4-3', - 'title' => '编辑评论', - 'type' => 'button', - 'route' => 'admin.comment.edit', - ], - [ - 'id' => '2-4-4', - 'title' => '删除评论', - 'type' => 'button', - 'route' => 'admin.comment.delete', - ], - ], - ], [ 'id' => '2-5', 'title' => '轮播管理', diff --git a/app/Http/Admin/Services/Category.php b/app/Http/Admin/Services/Category.php index 8f4f71d5..1cb123fa 100644 --- a/app/Http/Admin/Services/Category.php +++ b/app/Http/Admin/Services/Category.php @@ -36,7 +36,7 @@ class Category extends Service return $categoryRepo->findAll([ 'parent_id' => 0, - 'deleted' => 0, + 'published' => 1, ]); } diff --git a/app/Http/Admin/Services/Comment.php b/app/Http/Admin/Services/Comment.php deleted file mode 100644 index 24106c36..00000000 --- a/app/Http/Admin/Services/Comment.php +++ /dev/null @@ -1,151 +0,0 @@ -getParams(); - - $params['deleted'] = $params['deleted'] ?? 0; - - $sort = $pagerQuery->getSort(); - $page = $pagerQuery->getPage(); - $limit = $pagerQuery->getLimit(); - - $commentRepo = new CommentRepo(); - - $pager = $commentRepo->paginate($params, $sort, $page, $limit); - - return $this->handleComments($pager); - } - - public function getCourse($courseId) - { - $courseRepo = new CourseRepo(); - - return $courseRepo->findById($courseId); - } - - public function getChapter($chapterId) - { - $chapterRepo = new ChapterRepo(); - - return $chapterRepo->findById($chapterId); - } - - public function getComment($id) - { - return $this->findOrFail($id); - } - - public function updateComment($id) - { - $comment = $this->findOrFail($id); - - $post = $this->request->getPost(); - - $validator = new CommentValidator(); - - $data = []; - - if (isset($post['content'])) { - $data['content'] = $validator->checkContent($post['content']); - } - - if (isset($post['published'])) { - $data['published'] = $validator->checkPublishStatus($post['published']); - } - - $comment->update($data); - - return $comment; - } - - public function deleteComment($id) - { - $comment = $this->findOrFail($id); - - $comment->deleted = 1; - - $comment->update(); - - $chapterRepo = new ChapterRepo(); - - $chapter = $chapterRepo->findById($comment->chapter_id); - - $chapter->comment_count -= 1; - - $chapter->update(); - - $courseRepo = new CourseRepo(); - - $course = $courseRepo->findById($comment->course_id); - - $course->comment_count -= 1; - - $course->update(); - } - - public function restoreComment($id) - { - $comment = $this->findOrFail($id); - - $comment->deleted = 0; - - $comment->update(); - - $chapterRepo = new ChapterRepo(); - - $chapter = $chapterRepo->findById($comment->chapter_id); - - $chapter->comment_count += 1; - - $chapter->update(); - - $courseRepo = new CourseRepo(); - - $course = $courseRepo->findById($comment->course_id); - - $course->comment_count += 1; - - $course->update(); - } - - private function findOrFail($id) - { - $validator = new CommentValidator(); - - return $validator->checkComment($id); - } - - private function handleComments($pager) - { - if ($pager->total_items > 0) { - - $builder = new CommentListBuilder(); - - $pipeA = $pager->items->toArray(); - $pipeB = $builder->handleCourses($pipeA); - $pipeC = $builder->handleChapters($pipeB); - $pipeD = $builder->handleUsers($pipeC); - $pipeE = $builder->objects($pipeD); - - $pager->items = $pipeE; - } - - return $pager; - } - -} diff --git a/app/Http/Admin/Services/Nav.php b/app/Http/Admin/Services/Nav.php index 8fcd451d..0ab819bc 100644 --- a/app/Http/Admin/Services/Nav.php +++ b/app/Http/Admin/Services/Nav.php @@ -35,19 +35,17 @@ class Nav extends Service return $navRepo->findAll([ 'parent_id' => 0, 'position' => 'top', - 'deleted' => 0, + 'published' => 1, ]); } public function getChildNavs($parentId) { - $deleted = $this->request->getQuery('deleted', 'int', 0); - $navRepo = new NavRepo(); return $navRepo->findAll([ 'parent_id' => $parentId, - 'deleted' => $deleted, + 'published' => 1, ]); } diff --git a/app/Http/Admin/Views/comment/edit.volt b/app/Http/Admin/Views/comment/edit.volt deleted file mode 100644 index 72e7cac3..00000000 --- a/app/Http/Admin/Views/comment/edit.volt +++ /dev/null @@ -1,30 +0,0 @@ -
- 编辑评论 -
- -
- -
- -
- -
-
- -
- -
- - -
-
- -
- -
- - -
-
- -
\ No newline at end of file diff --git a/app/Http/Admin/Views/comment/list.volt b/app/Http/Admin/Views/comment/list.volt deleted file mode 100644 index a470689a..00000000 --- a/app/Http/Admin/Views/comment/list.volt +++ /dev/null @@ -1,73 +0,0 @@ -
-
- - 返回 - {% if course %} - {{ course.title }} - {% endif %} - {% if chapter %} - {{ chapter.title }} - {% endif %} - 评论管理 - -
-
- - 搜索评论 - -
-
- - - - - - - - - - - - - - - - - - - - {% for item in pager.items %} - - - - - - - - {% endfor %} - -
评论用户时间发布操作
-

课程:{{ item.course.title }}

- {% if item.chapter %} -

章节:{{ item.chapter.title }}

- {% endif %} -

评论:{{ substr(item.content,0,30) }}

-
-

昵称:{{ item.user.name }}

-

编号:{{ item.user.id }}

-
{{ date('Y-m-d H:i:s',item.create_time) }} -
- - -
-
- -{{ partial('partials/pager') }} \ No newline at end of file diff --git a/app/Http/Admin/Views/comment/search.volt b/app/Http/Admin/Views/comment/search.volt deleted file mode 100644 index aed87846..00000000 --- a/app/Http/Admin/Views/comment/search.volt +++ /dev/null @@ -1,67 +0,0 @@ -
- 搜索评论 -
- -
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- - -
-
- -
- -
- - -
-
- -
- -
- - -
-
- -
- - \ No newline at end of file diff --git a/app/Http/Web/Controllers/CommentController.php b/app/Http/Web/Controllers/CommentController.php deleted file mode 100644 index fa81303e..00000000 --- a/app/Http/Web/Controllers/CommentController.php +++ /dev/null @@ -1,81 +0,0 @@ -handle($id); - - return $this->jsonSuccess(['comment' => $comment]); - } - - /** - * @Post("/create", name="web.comment.create") - */ - public function createAction() - { - $service = new CommentCreateService(); - - $comment = $service->handle(); - - $service = new CommentInfoService(); - - $comment = $service->handle($comment->id); - - return $this->jsonSuccess(['comment' => $comment]); - } - - /** - * @Post("/{id:[0-9]+}/update", name="web.comment.update") - */ - public function updateAction($id) - { - $service = new CommentUpdateService(); - - $comment = $service->handle($id); - - return $this->jsonSuccess(['comment' => $comment]); - } - - /** - * @Post("/{id:[0-9]+}/delete", name="web.comment.delete") - */ - public function deleteAction($id) - { - $service = new CommentDeleteService(); - - $service->handle($id); - - return $this->jsonSuccess(); - } - - /** - * @Post("/{id:[0-9]+}/like", name="web.comment.like") - */ - public function likeAction($id) - { - $service = new CommentLikeService(); - - $service->handle($id); - - return $this->jsonSuccess(); - } - -} diff --git a/app/Http/Web/Controllers/ConsultController.php b/app/Http/Web/Controllers/ConsultController.php index 9581e5b8..107859a4 100644 --- a/app/Http/Web/Controllers/ConsultController.php +++ b/app/Http/Web/Controllers/ConsultController.php @@ -14,6 +14,16 @@ use App\Services\Frontend\Consult\ConsultUpdate as ConsultUpdateService; class ConsultController extends Controller { + /** + * @Get("/add", name="web.consult.add") + */ + public function addAction() + { + $chapterId = $this->request->getQuery('chapter_id'); + + $this->view->setVar('chapter_id', $chapterId); + } + /** * @Get("/{id:[0-9]+}/info", name="web.consult.info") */ @@ -39,7 +49,12 @@ class ConsultController extends Controller $consult = $service->handle($consult->id); - return $this->jsonSuccess(['consult' => $consult]); + $content = [ + 'consult' => $consult, + 'msg' => '提交课程咨询成功', + ]; + + return $this->jsonSuccess($content); } /** @@ -51,7 +66,12 @@ class ConsultController extends Controller $consult = $service->handle($id); - return $this->jsonSuccess(['consult' => $consult]); + $content = [ + 'consult' => $consult, + 'msg' => '更新课程咨询成功', + ]; + + return $this->jsonSuccess($content); } /** @@ -63,7 +83,9 @@ class ConsultController extends Controller $service->handle($id); - return $this->jsonSuccess(); + $content = ['msg' => '删除课程咨询成功']; + + return $this->jsonSuccess($content); } /** diff --git a/app/Http/Web/Controllers/CourseController.php b/app/Http/Web/Controllers/CourseController.php index cdbc4066..60037d7c 100644 --- a/app/Http/Web/Controllers/CourseController.php +++ b/app/Http/Web/Controllers/CourseController.php @@ -5,7 +5,6 @@ namespace App\Http\Web\Controllers; use App\Http\Web\Services\CourseQuery as CourseQueryService; use App\Services\Frontend\Course\ChapterList as CourseChapterListService; use App\Services\Frontend\Course\ConsultList as CourseConsultListService; -use App\Services\Frontend\Course\CourseBasic as CourseBasicService; use App\Services\Frontend\Course\CourseInfo as CourseInfoService; use App\Services\Frontend\Course\CourseList as CourseListService; use App\Services\Frontend\Course\Favorite as CourseFavoriteService; @@ -59,7 +58,7 @@ class CourseController extends Controller $pager->target = 'course-list'; $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); - $this->view->pick('course/ajax_pager'); + $this->view->pick('course/pager'); $this->view->setVar('pager', $pager); } @@ -98,7 +97,7 @@ class CourseController extends Controller $teachers = $service->handle($id); $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); - $this->view->pick('course/ajax_teachers'); + $this->view->pick('course/teachers'); $this->view->setVar('teachers', $teachers); } @@ -112,7 +111,7 @@ class CourseController extends Controller $chapters = $service->handle($id); $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); - $this->view->pick('course/ajax_chapters'); + $this->view->pick('course/chapters'); $this->view->setVar('chapters', $chapters); } @@ -126,7 +125,7 @@ class CourseController extends Controller $packages = $service->handle($id); $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); - $this->view->pick('course/ajax_packages'); + $this->view->pick('course/packages'); $this->view->setVar('packages', $packages); } @@ -142,7 +141,7 @@ class CourseController extends Controller $pager->target = 'tab-consults'; $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); - $this->view->pick('course/ajax_consults'); + $this->view->pick('course/consults'); $this->view->setVar('pager', $pager); } @@ -158,7 +157,7 @@ class CourseController extends Controller $pager->target = 'tab-reviews'; $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); - $this->view->pick('course/ajax_reviews'); + $this->view->pick('course/reviews'); $this->view->setVar('pager', $pager); } @@ -172,7 +171,7 @@ class CourseController extends Controller $courses = $service->handle($id); $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); - $this->view->pick('course/ajax_recommended'); + $this->view->pick('course/recommended'); $this->view->setVar('courses', $courses); } @@ -186,7 +185,7 @@ class CourseController extends Controller $courses = $service->handle($id); $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); - $this->view->pick('course/ajax_related'); + $this->view->pick('course/related'); $this->view->setVar('courses', $courses); } @@ -200,23 +199,10 @@ class CourseController extends Controller $topics = $service->handle($id); $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); - $this->view->pick('course/ajax_topics'); + $this->view->pick('course/topics'); $this->view->setVar('topics', $topics); } - /** - * @Get("/{id:[0-9]+}/rating", name="web.course.rating") - */ - public function ratingAction($id) - { - $service = new CourseBasicService(); - - $course = $service->handle($id); - - $this->view->pick('course/rating'); - $this->view->setVar('course', $course); - } - /** * @Post("/{id:[0-9]+}/favorite", name="web.course.favorite") */ diff --git a/app/Http/Web/Controllers/ReviewController.php b/app/Http/Web/Controllers/ReviewController.php index 64e875b1..c33fa4d3 100644 --- a/app/Http/Web/Controllers/ReviewController.php +++ b/app/Http/Web/Controllers/ReviewController.php @@ -14,6 +14,16 @@ use App\Services\Frontend\Review\ReviewUpdate as ReviewUpdateService; class ReviewController extends Controller { + /** + * @Get("/add", name="web.review.add") + */ + public function addAction() + { + $courseId = $this->request->getQuery('course_id'); + + $this->view->setVar('course_id', $courseId); + } + /** * @Get("/{id:[0-9]+}/info", name="web.review.info") */ @@ -73,7 +83,9 @@ class ReviewController extends Controller $service->handle($id); - return $this->jsonSuccess(); + $content = ['msg' => '删除课程评价成功']; + + return $this->jsonSuccess($content); } /** diff --git a/app/Http/Web/Controllers/TeacherController.php b/app/Http/Web/Controllers/TeacherController.php index 153cc44f..e443084c 100644 --- a/app/Http/Web/Controllers/TeacherController.php +++ b/app/Http/Web/Controllers/TeacherController.php @@ -31,7 +31,7 @@ class TeacherController extends Controller $pager->target = 'teacher-list'; $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); - $this->view->pick('teacher/ajax_pager'); + $this->view->pick('teacher/pager'); $this->view->setVar('pager', $pager); } diff --git a/app/Http/Web/Controllers/UserController.php b/app/Http/Web/Controllers/UserController.php index c1eb0ac4..479030c2 100644 --- a/app/Http/Web/Controllers/UserController.php +++ b/app/Http/Web/Controllers/UserController.php @@ -38,7 +38,7 @@ class UserController extends Controller $pager->target = 'tab-courses'; $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); - $this->view->pick('user/ajax_courses'); + $this->view->pick('user/courses'); $this->view->setVar('pager', $pager); } @@ -54,7 +54,7 @@ class UserController extends Controller $pager->target = 'tab-favorites'; $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); - $this->view->pick('user/ajax_favorites'); + $this->view->pick('user/favorites'); $this->view->setVar('pager', $pager); } @@ -70,7 +70,7 @@ class UserController extends Controller $pager->target = 'tab-friends'; $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); - $this->view->pick('user/ajax_friends'); + $this->view->pick('user/friends'); $this->view->setVar('pager', $pager); } diff --git a/app/Http/Web/Views/chapter/vod.volt b/app/Http/Web/Views/chapter/vod.volt index c866f18b..146b0e63 100644 --- a/app/Http/Web/Views/chapter/vod.volt +++ b/app/Http/Web/Views/chapter/vod.volt @@ -7,6 +7,7 @@ {% set danmu_url = url({'for':'web.chapter.danmu','id':chapter.id}) %} {% set like_url = url({'for':'web.chapter.like','id':chapter.id}) %} {% set qrcode_url = url({'for':'web.qrcode_img'},{'text':chapter_full_url}) %} + {% set consult_url = url({'for':'web.consult.add'},{'chapter_id':chapter.id}) %}
diff --git a/app/Http/Web/Views/course/ajax_pager.volt b/app/Http/Web/Views/course/pager.volt similarity index 100% rename from app/Http/Web/Views/course/ajax_pager.volt rename to app/Http/Web/Views/course/pager.volt diff --git a/app/Http/Web/Views/course/ajax_recommended.volt b/app/Http/Web/Views/course/recommended.volt similarity index 100% rename from app/Http/Web/Views/course/ajax_recommended.volt rename to app/Http/Web/Views/course/recommended.volt diff --git a/app/Http/Web/Views/course/ajax_related.volt b/app/Http/Web/Views/course/related.volt similarity index 100% rename from app/Http/Web/Views/course/ajax_related.volt rename to app/Http/Web/Views/course/related.volt diff --git a/app/Http/Web/Views/course/ajax_reviews.volt b/app/Http/Web/Views/course/reviews.volt similarity index 100% rename from app/Http/Web/Views/course/ajax_reviews.volt rename to app/Http/Web/Views/course/reviews.volt diff --git a/app/Http/Web/Views/course/show.volt b/app/Http/Web/Views/course/show.volt index 08a7cfa1..7a7986ce 100644 --- a/app/Http/Web/Views/course/show.volt +++ b/app/Http/Web/Views/course/show.volt @@ -4,6 +4,11 @@ {{ partial('partials/macro_course') }} + {% set favorite_star_class = course.me.favorited ? 'layui-icon-star-fill' : 'layui-icon-star' %} + {% set full_course_url = full_url({'for':'web.course.show','id':course.id}) %} + {% set favorite_url = url({'for':'web.course.favorite','id':course.id}) %} + {% set qrcode_url = url({'for':'web.qrcode_img'},{'text':full_course_url}) %} + -
- {{ partial('course/show_meta') }} -
+ {{ partial('course/show_meta') }}
@@ -95,6 +104,13 @@
+
+ + + + +
+ {% endblock %} {% block include_js %} diff --git a/app/Http/Web/Views/course/show_meta.volt b/app/Http/Web/Views/course/show_meta.volt index 9c1baabf..d00924c4 100644 --- a/app/Http/Web/Views/course/show_meta.volt +++ b/app/Http/Web/Views/course/show_meta.volt @@ -1,53 +1,52 @@ -
- {{ course.title|e }} -
- -
- {% if course.model == 'vod' %} -

课程时长 {{ course.attrs.duration|total_duration }}

- {% elseif course.model == 'live' %} -

直播时间 {{ course.attrs.start_date }} ~ {{ course.attrs.end_date }}

- {% endif %} - {% if course.market_price > 0 %} -

- 学习期限 {{ course.study_expiry }}个月 - 退款期限 {{ course.refund_expiry }}天 -

- {% endif %} -

- {% if course.market_price > 0 %} - 市场价格 {{ '¥%0.2f'|format(course.market_price) }} - {% else %} - 市场价格 免费 - {% endif %} - {% if course.vip_price > 0 %} - 会员价格 {{ '¥%0.2f'|format(course.vip_price) }} - {% else %} - 会员价格 免费 - {% endif %} -

-

- 难度 {{ level_info(course.level) }} - 课时 {{ course.lesson_count }} - 学员 {{ course.user_count }} - 评分 {{ course.rating }} -

- - {% set favorite_url = url({'for':'web.course.favorite','id':course.id}) %} - {% set full_course_url = full_url({'for':'web.course.show','id':course.id}) %} - {% set qrcode_url = url({'for':'web.qrcode_img'},{'text':full_course_url}) %} - -
- - - - +
+
+ {{ course.title|e }}
- - \ No newline at end of file diff --git a/app/Http/Web/Views/course/ajax_teachers.volt b/app/Http/Web/Views/course/teachers.volt similarity index 100% rename from app/Http/Web/Views/course/ajax_teachers.volt rename to app/Http/Web/Views/course/teachers.volt diff --git a/app/Http/Web/Views/course/ajax_topics.volt b/app/Http/Web/Views/course/topics.volt similarity index 100% rename from app/Http/Web/Views/course/ajax_topics.volt rename to app/Http/Web/Views/course/topics.volt diff --git a/app/Http/Web/Views/partials/macro_course.volt b/app/Http/Web/Views/partials/macro_course.volt index 6b567a73..d70caa3e 100644 --- a/app/Http/Web/Views/partials/macro_course.volt +++ b/app/Http/Web/Views/partials/macro_course.volt @@ -20,6 +20,13 @@ {% endif %} {%- endmacro %} +{%- macro star_info(rating) %} + {% set stars = [1,2,3,4,5] %} + {% for val in stars if val <= rating %} + + {% endfor %} +{%- endmacro %} + {%- macro course_card(course) %} {% set course_url = url({'for':'web.course.show','id':course.id}) %}
diff --git a/app/Http/Web/Views/course/rating.volt b/app/Http/Web/Views/review/add.volt similarity index 97% rename from app/Http/Web/Views/course/rating.volt rename to app/Http/Web/Views/review/add.volt index 46e317a8..58bad1fe 100644 --- a/app/Http/Web/Views/course/rating.volt +++ b/app/Http/Web/Views/review/add.volt @@ -30,7 +30,7 @@
- + diff --git a/app/Http/Web/Views/teacher/ajax_pager.volt b/app/Http/Web/Views/teacher/pager.volt similarity index 100% rename from app/Http/Web/Views/teacher/ajax_pager.volt rename to app/Http/Web/Views/teacher/pager.volt diff --git a/app/Http/Web/Views/user/ajax_courses.volt b/app/Http/Web/Views/user/courses.volt similarity index 100% rename from app/Http/Web/Views/user/ajax_courses.volt rename to app/Http/Web/Views/user/courses.volt diff --git a/app/Http/Web/Views/user/ajax_favorites.volt b/app/Http/Web/Views/user/favorites.volt similarity index 100% rename from app/Http/Web/Views/user/ajax_favorites.volt rename to app/Http/Web/Views/user/favorites.volt diff --git a/app/Http/Web/Views/user/ajax_friends.volt b/app/Http/Web/Views/user/friends.volt similarity index 100% rename from app/Http/Web/Views/user/ajax_friends.volt rename to app/Http/Web/Views/user/friends.volt diff --git a/app/Library/Cache/Backend/Redis.php b/app/Library/Cache/Backend/Redis.php index c78ad6f2..57422183 100644 --- a/app/Library/Cache/Backend/Redis.php +++ b/app/Library/Cache/Backend/Redis.php @@ -143,9 +143,10 @@ class Redis extends \Phalcon\Cache\Backend\Redis * {@inheritdoc} * * @param string $prefix + * @param int $limit * @return array */ - public function queryKeys($prefix = null): array + public function queryKeys($prefix = null, $limit = 1000): array { $result = []; @@ -158,6 +159,7 @@ class Redis extends \Phalcon\Cache\Backend\Redis $it = null; while ($keys = $redis->scan($it, $pattern)) { + if (count($result) > $limit) break; $result = array_merge($result, $keys); } diff --git a/app/Listeners/ChapterCounter.php b/app/Listeners/ChapterCounter.php index 4e248227..5933da47 100644 --- a/app/Listeners/ChapterCounter.php +++ b/app/Listeners/ChapterCounter.php @@ -31,16 +31,16 @@ class ChapterCounter extends Listener $this->syncChapterCounter($chapter); } - public function incrCommentCount(Event $event, $source, ChapterModel $chapter) + public function incrConsultCount(Event $event, $source, ChapterModel $chapter) { - $this->counter->hIncrBy($chapter->id, 'comment_count'); + $this->counter->hIncrBy($chapter->id, 'consult_count'); $this->syncChapterCounter($chapter); } - public function decrCommentCount(Event $event, $source, ChapterModel $chapter) + public function decrConsultCount(Event $event, $source, ChapterModel $chapter) { - $this->counter->hDecrBy($chapter->id, 'comment_count'); + $this->counter->hDecrBy($chapter->id, 'consult_count'); $this->syncChapterCounter($chapter); } diff --git a/app/Listeners/CommentCounter.php b/app/Listeners/CommentCounter.php deleted file mode 100644 index 1185e077..00000000 --- a/app/Listeners/CommentCounter.php +++ /dev/null @@ -1,55 +0,0 @@ -counter = new CacheCommentCounter(); - } - - public function incrReplyCount(Event $event, $source, CommentModel $comment) - { - $this->counter->hIncrBy($comment->id, 'reply_count'); - - $this->syncCommentCounter($comment); - } - - public function decrReplyCount(Event $event, $source, CommentModel $comment) - { - $this->counter->hDecrBy($comment->id, 'reply_count'); - - $this->syncCommentCounter($comment); - } - - public function incrLikeCount(Event $event, $source, CommentModel $comment) - { - $this->counter->hIncrBy($comment->id, 'like_count'); - - $this->syncCommentCounter($comment); - } - - public function decrLikeCount(Event $event, $source, CommentModel $comment) - { - $this->counter->hDecrBy($comment->id, 'like_count'); - - $this->syncCommentCounter($comment); - } - - protected function syncCommentCounter(CommentModel $comment) - { - $syncer = new CommentCounterSyncer(); - - $syncer->addItem($comment->id); - } - -} \ No newline at end of file diff --git a/app/Listeners/CourseCounter.php b/app/Listeners/CourseCounter.php index 55efb03f..36febf58 100644 --- a/app/Listeners/CourseCounter.php +++ b/app/Listeners/CourseCounter.php @@ -68,20 +68,6 @@ class CourseCounter extends Listener $this->syncCourseIndex($course); } - public function incrCommentCount(Event $event, $source, CourseModel $course) - { - $this->counter->hIncrBy($course->id, 'comment_count'); - - $this->syncCourseCounter($course); - } - - public function decrCommentCount(Event $event, $source, CourseModel $course) - { - $this->counter->hDecrBy($course->id, 'comment_count'); - - $this->syncCourseCounter($course); - } - public function incrFavoriteCount(Event $event, $source, CourseModel $course) { $this->counter->hIncrBy($course->id, 'favorite_count'); diff --git a/app/Listeners/UserDailyCounter.php b/app/Listeners/UserDailyCounter.php index dc313e83..88cee653 100644 --- a/app/Listeners/UserDailyCounter.php +++ b/app/Listeners/UserDailyCounter.php @@ -21,11 +21,6 @@ class UserDailyCounter extends Listener $this->counter->hIncrBy($user->id, 'favorite_count'); } - public function incrCommentCount(Event $event, $source, UserModel $user) - { - $this->counter->hIncrBy($user->id, 'comment_count'); - } - public function incrDanmuCount(Event $event, $source, UserModel $user) { $this->counter->hIncrBy($user->id, 'danmu_count'); @@ -46,11 +41,6 @@ class UserDailyCounter extends Listener $this->counter->hIncrBy($user->id, 'order_count'); } - public function incrCommentLikeCount(Event $event, $source, UserModel $user) - { - $this->counter->hIncrBy($user->id, 'comment_like_count'); - } - public function incrConsultLikeCount(Event $event, $source, UserModel $user) { $this->counter->hIncrBy($user->id, 'consult_like_count'); diff --git a/app/Models/Comment.php b/app/Models/Comment.php deleted file mode 100644 index 35c5758d..00000000 --- a/app/Models/Comment.php +++ /dev/null @@ -1,132 +0,0 @@ -addBehavior( - new SoftDelete([ - 'field' => 'deleted', - 'value' => 1, - ]) - ); - } - - public function beforeCreate() - { - $this->create_time = time(); - } - - public function beforeUpdate() - { - $this->update_time = time(); - - if ($this->deleted == 1) { - $this->published = 0; - } - } - -} diff --git a/app/Models/CommentLike.php b/app/Models/CommentLike.php deleted file mode 100644 index f3cbc300..00000000 --- a/app/Models/CommentLike.php +++ /dev/null @@ -1,79 +0,0 @@ -addBehavior( - new SoftDelete([ - 'field' => 'deleted', - 'value' => 1, - ]) - ); - } - - public function beforeCreate() - { - $this->create_time = time(); - } - - public function beforeUpdate() - { - $this->update_time = time(); - } - -} diff --git a/app/Models/Consult.php b/app/Models/Consult.php index df708aea..15939fc3 100644 --- a/app/Models/Consult.php +++ b/app/Models/Consult.php @@ -7,6 +7,13 @@ use Phalcon\Mvc\Model\Behavior\SoftDelete; class Consult extends Model { + /** + * 优先级 + */ + const PRIORITY_HIGH = 10; // 高 + const PRIORITY_MIDDLE = 20; // 中 + const PRIORITY_LOW = 30; // 低 + /** * 主键编号 * @@ -21,6 +28,13 @@ class Consult extends Model */ public $course_id; + /** + * 章节编号 + * + * @var int + */ + public $chapter_id; + /** * 用户编号 * diff --git a/app/Models/ImGroup.php b/app/Models/ImGroup.php index 0d5b4005..884afb76 100644 --- a/app/Models/ImGroup.php +++ b/app/Models/ImGroup.php @@ -51,7 +51,14 @@ class ImGroup extends Model public $about; /** - * 状态 + * 发布状态 + * + * @var integer + */ + public $published; + + /** + * 删除状态 * * @var integer */ @@ -109,6 +116,10 @@ class ImGroup extends Model public function beforeUpdate() { $this->update_time = time(); + + if ($this->deleted == 1) { + $this->published = 0; + } } public function afterFetch() diff --git a/app/Repos/Comment.php b/app/Repos/Comment.php deleted file mode 100644 index a1f55c41..00000000 --- a/app/Repos/Comment.php +++ /dev/null @@ -1,111 +0,0 @@ -modelsManager->createBuilder(); - - $builder->from(CommentModel::class); - - $builder->where('1 = 1'); - - if (!empty($where['id'])) { - $builder->andWhere('id = :id:', ['id' => $where['id']]); - } - - if (!empty($where['parent_id'])) { - $builder->andWhere('parent_id = :parent_id:', ['parent_id' => $where['parent_id']]); - } - - if (!empty($where['course_id'])) { - $builder->andWhere('course_id = :course_id:', ['course_id' => $where['course_id']]); - } - - if (!empty($where['chapter_id'])) { - $builder->andWhere('chapter_id = :chapter_id:', ['chapter_id' => $where['chapter_id']]); - } - - if (!empty($where['user_id'])) { - $builder->andWhere('user_id = :user_id:', ['user_id' => $where['user_id']]); - } - - if (isset($where['published'])) { - $builder->andWhere('published = :published:', ['published' => $where['published']]); - } - - if (isset($where['deleted'])) { - $builder->andWhere('deleted = :deleted:', ['deleted' => $where['deleted']]); - } - - switch ($sort) { - default: - $orderBy = 'id DESC'; - break; - } - - $builder->orderBy($orderBy); - - $pager = new PagerQueryBuilder([ - 'builder' => $builder, - 'page' => $page, - 'limit' => $limit, - ]); - - return $pager->paginate(); - } - - /** - * @param int $id - * @return CommentModel|Model|bool - */ - public function findById($id) - { - return CommentModel::findFirst($id); - } - - /** - * @param array $ids - * @param string|array $columns - * @return ResultsetInterface|Resultset|CommentModel[] - */ - public function findByIds($ids, $columns = '*') - { - return CommentModel::query() - ->columns($columns) - ->inWhere('id', $ids) - ->execute(); - } - - public function countComments() - { - return (int)CommentModel::count(['conditions' => 'deleted = 0']); - } - - public function countReplies($commentId) - { - return (int)CommentModel::count([ - 'conditions' => 'parent_id = :parent_id: AND deleted = 0', - 'bind' => ['parent_id' => $commentId], - ]); - } - - public function countLikes($commentId) - { - return (int)CommentLikeModel::count([ - 'conditions' => 'comment_id = :comment_id: AND deleted = 0', - 'bind' => ['comment_id' => $commentId], - ]); - } - -} diff --git a/app/Repos/CommentLike.php b/app/Repos/CommentLike.php deleted file mode 100644 index 8e9bd8be..00000000 --- a/app/Repos/CommentLike.php +++ /dev/null @@ -1,24 +0,0 @@ - 'comment_id = :comment_id: AND user_id = :user_id:', - 'bind' => ['comment_id' => $commentId, 'user_id' => $userId], - ]); - } - -} diff --git a/app/Services/Frontend/Comment/CommentCreate.php b/app/Services/Frontend/Comment/CommentCreate.php deleted file mode 100644 index 3de237c5..00000000 --- a/app/Services/Frontend/Comment/CommentCreate.php +++ /dev/null @@ -1,77 +0,0 @@ -request->getPost(); - - $user = $this->getLoginUser(); - - $chapter = $this->checkChapter($post['chapter_id']); - - $course = $this->checkCourse($chapter->course_id); - - $validator = new UserDailyLimitValidator(); - - $validator->checkCommentLimit($user); - - $validator = new CommentValidator(); - - $data = []; - - $data['content'] = $validator->checkContent($post['content']); - - if (isset($post['parent_id'])) { - $parent = $validator->checkParent($post['parent_id']); - $data['parent_id'] = $parent->id; - } - - $comment = new CommentModel(); - - $data['course_id'] = $course->id; - $data['chapter_id'] = $chapter->id; - $data['user_id'] = $user->id; - - $comment->create($data); - - $this->incrChapterCommentCount($chapter); - - $this->incrCourseCommentCount($course); - - $this->incrUserDailyCommentCount($user); - - return $comment; - } - - protected function incrChapterCommentCount(ChapterModel $chapter) - { - $this->eventsManager->fire('chapterCounter:incrCommentCount', $this, $chapter); - } - - protected function incrCourseCommentCount(CourseModel $course) - { - $this->eventsManager->fire('courseCounter:incrCommentCount', $this, $course); - } - - protected function incrUserDailyCommentCount(UserModel $user) - { - $this->eventsManager->fire('userDailyCounter:incrCommentCount', $this, $user); - } - -} diff --git a/app/Services/Frontend/Comment/CommentDelete.php b/app/Services/Frontend/Comment/CommentDelete.php deleted file mode 100644 index 29e78e8e..00000000 --- a/app/Services/Frontend/Comment/CommentDelete.php +++ /dev/null @@ -1,49 +0,0 @@ -checkComment($id); - - $chapter = $this->checkChapter($comment->chapter_id); - - $course = $this->checkCourse($comment->course_id); - - $user = $this->getLoginUser(); - - $validator = new CommentValidator(); - - $validator->checkOwner($user->id, $comment->user_id); - - $comment->delete(); - - $this->decrChapterCommentCount($chapter); - - $this->decrCourseCommentCount($course); - } - - protected function decrChapterCommentCount(ChapterModel $chapter) - { - $this->eventsManager->fire('chapterCounter:decrCommentCount', $this, $chapter); - } - - protected function decrCourseCommentCount(CourseModel $course) - { - $this->eventsManager->fire('courseCounter:decrCommentCount', $this, $course); - } - -} diff --git a/app/Services/Frontend/Comment/CommentInfo.php b/app/Services/Frontend/Comment/CommentInfo.php deleted file mode 100644 index 62659d1e..00000000 --- a/app/Services/Frontend/Comment/CommentInfo.php +++ /dev/null @@ -1,45 +0,0 @@ -checkComment($id); - - return $this->handleComment($comment); - } - - protected function handleComment(CommentModel $comment) - { - $result = [ - 'id' => $comment->id, - 'content' => $comment->content, - 'like_count' => $comment->like_count, - 'create_time' => $comment->create_time, - 'update_time' => $comment->update_time, - ]; - - $userRepo = new UserRepo(); - - $owner = $userRepo->findById($comment->user_id); - - $result['user'] = [ - 'id' => $owner->id, - 'name' => $owner->name, - 'avatar' => $owner->avatar, - ]; - - return $result; - } - -} diff --git a/app/Services/Frontend/Comment/CommentLike.php b/app/Services/Frontend/Comment/CommentLike.php deleted file mode 100644 index 46e5ca4f..00000000 --- a/app/Services/Frontend/Comment/CommentLike.php +++ /dev/null @@ -1,88 +0,0 @@ -checkComment($id); - - $user = $this->getLoginUser(); - - $validator = new UserDailyLimitValidator(); - - $validator->checkCommentLikeLimit($user); - - $validator = new CommentValidator(); - - $commentLike = $validator->checkIfLiked($comment->id, $user->id); - - if (!$commentLike) { - - $commentLike = new CommentLikeModel(); - - $commentLike->create([ - 'comment_id' => $comment->id, - 'user_id' => $user->id, - ]); - - $this->incrLikeCount($comment); - - } else { - - if ($commentLike->deleted == 0) { - - $commentLike->update(['deleted' => 1]); - - $this->decrLikeCount($comment); - - } else { - - $commentLike->update(['deleted' => 0]); - - $this->incrLikeCount($comment); - } - } - - $this->incrUserDailyCommentLikeCount($user); - - return $comment; - } - - protected function incrLikeCount(CommentModel $comment) - { - $this->getPhEventsManager()->fire('commentCounter:incrLikeCount', $this, $comment); - } - - protected function decrLikeCount(CommentModel $comment) - { - $this->getPhEventsManager()->fire('commentCounter:decrLikeCount', $this, $comment); - } - - protected function incrUserDailyCommentLikeCount(UserModel $user) - { - $this->getPhEventsManager()->fire('userDailyCounter:incrCommentLikeCount', $this, $user); - } - - /** - * @return EventsManager - */ - protected function getPhEventsManager() - { - return $this->getDI()->get('eventsManager'); - } - -} diff --git a/app/Services/Frontend/Comment/CommentUpdate.php b/app/Services/Frontend/Comment/CommentUpdate.php deleted file mode 100644 index a8d1823f..00000000 --- a/app/Services/Frontend/Comment/CommentUpdate.php +++ /dev/null @@ -1,42 +0,0 @@ -request->getPost(); - - $user = $this->getLoginUser(); - - $comment = $this->checkComment($id); - - $validator = new CommentValidator(); - - $validator->checkOwner($user->id, $comment->user_id); - - $data = []; - - $data['content'] = $validator->checkContent($post['content']); - - if (isset($post['mentions'])) { - $data['mentions'] = $validator->checkMentions($post['mentions']); - } - - $comment->update($data); - } - - protected function handleMentions($mentions) - { - - } - -} diff --git a/app/Services/Frontend/CommentTrait.php b/app/Services/Frontend/CommentTrait.php deleted file mode 100644 index 0a98fbc3..00000000 --- a/app/Services/Frontend/CommentTrait.php +++ /dev/null @@ -1,17 +0,0 @@ -checkComment($id); - } - -} diff --git a/app/Services/Frontend/Consult/ConsultCreate.php b/app/Services/Frontend/Consult/ConsultCreate.php index d4a7a59a..94b94a3a 100644 --- a/app/Services/Frontend/Consult/ConsultCreate.php +++ b/app/Services/Frontend/Consult/ConsultCreate.php @@ -2,9 +2,11 @@ namespace App\Services\Frontend\Consult; +use App\Models\Chapter as ChapterModel; use App\Models\Consult as ConsultModel; use App\Models\Course as CourseModel; use App\Models\User as UserModel; +use App\Services\Frontend\ChapterTrait; use App\Services\Frontend\CourseTrait; use App\Services\Frontend\Service as FrontendService; use App\Validators\Consult as ConsultValidator; @@ -13,7 +15,7 @@ use App\Validators\UserDailyLimit as UserDailyLimitValidator; class ConsultCreate extends FrontendService { - use CourseTrait; + use CourseTrait, ChapterTrait; public function handle() { @@ -21,7 +23,9 @@ class ConsultCreate extends FrontendService $user = $this->getLoginUser(); - $course = $this->checkCourseCache($post['course_id']); + $chapter = $this->checkChapter($post['chapter_id']); + + $course = $this->checkCourse($chapter->course_id); $validator = new UserDailyLimitValidator(); @@ -31,26 +35,51 @@ class ConsultCreate extends FrontendService $question = $validator->checkQuestion($post['question']); + $priority = $this->getPriority($course, $user); + $consult = new ConsultModel(); - $consult->course_id = $course->id; - $consult->user_id = $user->id; $consult->question = $question; + $consult->priority = $priority; + $consult->course_id = $course->id; + $consult->chapter_id = $chapter->id; + $consult->user_id = $user->id; $consult->create(); $this->incrCourseConsultCount($course); - + $this->incrChapterConsultCount($chapter); $this->incrUserDailyConsultCount($user); return $consult; } + protected function getPriority(CourseModel $course, UserModel $user) + { + $charge = $course->market_price > 0; + $vip = $user->vip == 1; + + if ($vip && $charge) { + $priority = ConsultModel::PRIORITY_HIGH; + } elseif ($charge) { + $priority = ConsultModel::PRIORITY_MIDDLE; + } else { + $priority = ConsultModel::PRIORITY_LOW; + } + + return $priority; + } + protected function incrCourseConsultCount(CourseModel $course) { $this->eventsManager->fire('courseCounter:incrConsultCount', $this, $course); } + protected function incrChapterConsultCount(ChapterModel $chapter) + { + $this->eventsManager->fire('chapterCounter:incrConsultCount', $this, $chapter); + } + protected function incrUserDailyConsultCount(UserModel $user) { $this->eventsManager->fire('userDailyCounter:incrConsultCount', $this, $user); diff --git a/app/Services/Frontend/Course/ConsultList.php b/app/Services/Frontend/Course/ConsultList.php index f06fbaba..0ec190ef 100644 --- a/app/Services/Frontend/Course/ConsultList.php +++ b/app/Services/Frontend/Course/ConsultList.php @@ -27,7 +27,6 @@ class ConsultList extends FrontendService 'course_id' => $course->id, 'private' => 0, 'published' => 1, - 'deleted' => 0, ]; $consultRepo = new ConsultRepo(); diff --git a/app/Services/Frontend/Course/CourseInfo.php b/app/Services/Frontend/Course/CourseInfo.php index 83b00738..d5ebe858 100644 --- a/app/Services/Frontend/Course/CourseInfo.php +++ b/app/Services/Frontend/Course/CourseInfo.php @@ -4,6 +4,7 @@ namespace App\Services\Frontend\Course; use App\Models\Course as CourseModel; use App\Models\User as UserModel; +use App\Repos\Course as CourseRepo; use App\Repos\CourseFavorite as CourseFavoriteRepo; use App\Services\Frontend\CourseTrait; use App\Services\Frontend\Service as FrontendService; @@ -26,6 +27,17 @@ class CourseInfo extends FrontendService protected function handleCourse(CourseModel $course, UserModel $user) { + $repo = new CourseRepo(); + + $rating = $repo->findCourseRating($course->id); + + $ratings = [ + 'rating' => $rating->rating, + 'rating1' => $rating->rating1, + 'rating2' => $rating->rating2, + 'rating3' => $rating->rating3, + ]; + $result = [ 'id' => $course->id, 'title' => $course->title, @@ -39,7 +51,7 @@ class CourseInfo extends FrontendService 'vip_price' => $course->vip_price, 'study_expiry' => $course->study_expiry, 'refund_expiry' => $course->refund_expiry, - 'rating' => $course->rating, + 'ratings' => $ratings, 'model' => $course->model, 'level' => $course->level, 'attrs' => $course->attrs, @@ -47,7 +59,6 @@ class CourseInfo extends FrontendService 'lesson_count' => $course->lesson_count, 'package_count' => $course->package_count, 'review_count' => $course->review_count, - 'comment_count' => $course->comment_count, 'consult_count' => $course->consult_count, 'favorite_count' => $course->favorite_count, ]; diff --git a/app/Services/Frontend/Course/ReviewList.php b/app/Services/Frontend/Course/ReviewList.php index e5b87331..9c035219 100644 --- a/app/Services/Frontend/Course/ReviewList.php +++ b/app/Services/Frontend/Course/ReviewList.php @@ -26,7 +26,6 @@ class ReviewList extends FrontendService $params = [ 'course_id' => $course->id, 'published' => 1, - 'deleted' => 0, ]; $reviewRepo = new ReviewRepo(); diff --git a/app/Validators/Comment.php b/app/Validators/Comment.php deleted file mode 100644 index 1c20ad6c..00000000 --- a/app/Validators/Comment.php +++ /dev/null @@ -1,94 +0,0 @@ -findById($id); - - if (!$comment) { - throw new BadRequestException('comment.not_found'); - } - - return $comment; - } - - public function checkChapter($chapterId) - { - $chapterRepo = new ChapterRepo(); - - $chapter = $chapterRepo->findById($chapterId); - - if (!$chapter) { - throw new BadRequestException('comment.invalid_chapter_id'); - } - - return $chapter; - } - - public function checkParent($parentId) - { - $commentRepo = new CourseRepo(); - - $parent = $commentRepo->findById($parentId); - - if (!$parent) { - throw new BadRequestException('comment.invalid_parent_id'); - } - - return $parent; - } - - public function checkContent($content) - { - $value = $this->filter->sanitize($content, ['trim', 'string']); - - $length = kg_strlen($value); - - if ($length < 1) { - throw new BadRequestException('comment.content_too_short'); - } - - if ($length > 1000) { - throw new BadRequestException('comment.content_too_long'); - } - - return $value; - } - - public function checkPublishStatus($status) - { - if (!in_array($status, [0, 1])) { - throw new BadRequestException('consult.invalid_publish_status'); - } - - return $status; - } - - public function checkIfLiked($chapterId, $userId) - { - $repo = new CommentLikeRepo(); - - $like = $repo->findCommentLike($chapterId, $userId); - - if ($like) { - if ($like->deleted == 0 && time() - $like->create_time > 5 * 60) { - throw new BadRequestException('comment.has_liked'); - } - } - - return $like; - } - -} diff --git a/app/Validators/Consult.php b/app/Validators/Consult.php index 15f4b815..93ef050e 100644 --- a/app/Validators/Consult.php +++ b/app/Validators/Consult.php @@ -29,6 +29,13 @@ class Consult extends Validator return $validator->checkCourse($id); } + public function checkChapter($id) + { + $validator = new Chapter(); + + return $validator->checkChapter($id); + } + public function checkQuestion($question) { $value = $this->filter->sanitize($question, ['trim', 'string']); diff --git a/app/Validators/UserDailyLimit.php b/app/Validators/UserDailyLimit.php index 2f14c65e..c5e002dc 100644 --- a/app/Validators/UserDailyLimit.php +++ b/app/Validators/UserDailyLimit.php @@ -27,17 +27,6 @@ class UserDailyLimit extends Validator } } - public function checkCommentLimit(UserModel $user) - { - $count = $this->counter->hGet($user->id, 'comment_count'); - - $limit = $user->vip ? 100 : 50; - - if ($count > $limit) { - throw new BadRequestException('user_daily_limit.reach_comment_limit'); - } - } - public function checkDanmuLimit(UserModel $user) { $count = $this->counter->hGet($user->id, 'danmu_count'); @@ -89,17 +78,6 @@ class UserDailyLimit extends Validator } } - public function checkCommentLikeLimit(UserModel $user) - { - $count = $this->counter->hGet($user->id, 'comment_like_count'); - - $limit = $user->vip ? 200 : 100; - - if ($count > $limit) { - throw new BadRequestException('user_daily_limit.reach_like_limit'); - } - } - public function checkConsultLikeLimit(UserModel $user) { $count = $this->counter->hGet($user->id, 'consult_like_count'); diff --git a/config/errors.php b/config/errors.php index 4c5321da..35c5e904 100644 --- a/config/errors.php +++ b/config/errors.php @@ -201,21 +201,12 @@ $error['review.has_liked'] = '你已经点过赞啦'; $error['consult.not_found'] = '咨询不存在'; $error['consult.invalid_private_status'] = '无效的私密状态'; $error['consult.invalid_publish_status'] = '无效的发布状态'; -$error['consult.question_too_short'] = '提问太短(少于5个字符)'; -$error['consult.question_too_long'] = '提问太长(多于1000个字符)'; -$error['consult.answer_too_short'] = '回复太短(少于5个字符)'; -$error['consult.answer_too_long'] = '回复太长(多于1000个字符)'; +$error['consult.question_too_short'] = '问题内容太短(少于5个字符)'; +$error['consult.question_too_long'] = '问题内容太长(多于1000个字符)'; +$error['consult.answer_too_short'] = '回复内容太短(少于5个字符)'; +$error['consult.answer_too_long'] = '回复内容太长(多于1000个字符)'; $error['consult.has_liked'] = '你已经点过赞啦'; -/** - * 评论相关 - */ -$error['comment.not_found'] = '评价不存在'; -$error['comment.invalid_publish_status'] = '无效的发布状态'; -$error['comment.content_too_short'] = '评价太短(少于1个字符)'; -$error['comment.content_too_long'] = '评价太长(多于1000个字符)'; -$error['comment.has_liked'] = '你已经点过赞啦'; - /** * 单页相关 */ diff --git a/config/events.php b/config/events.php index 4df77f01..09383864 100644 --- a/config/events.php +++ b/config/events.php @@ -1,7 +1,6 @@ Pay::class, 'courseCounter' => CourseCounter::class, 'chapterCounter' => ChapterCounter::class, - 'commentCounter' => CommentCounter::class, 'consultCounter' => ConsultCounter::class, 'reviewCounter' => ReviewCounter::class, 'userDailyCounter' => UserDailyCounter::class, diff --git a/public/static/web/css/common.css b/public/static/web/css/common.css index 04aab267..3db71a4e 100644 --- a/public/static/web/css/common.css +++ b/public/static/web/css/common.css @@ -432,38 +432,17 @@ body { } .course-meta .info { - position: relative; float: left; - width: 80%; + width: 400px; } -.course-meta .share { - position: absolute; - top: 0; - right: 0; +.course-meta .rating { + float: right; + padding: 10px 50px 0 0; } -.course-meta .share a { - margin-right: 5px; - color: #999; -} - -.course-meta .share a:hover { - color: #000; -} - -.course-meta .price { - color: red; - font-size: 14px; -} - -.course-meta .free { - color: green; -} - -.course-meta span { - color: #666; - margin: 0 5px; +.course-meta p { + line-height: 30px; } .course-meta .cover img { @@ -471,8 +450,30 @@ body { height: 118px; } -.course-meta p { - line-height: 30px; +.course-meta .info .price { + color: red; + font-size: 14px; +} + +.course-meta .info .free { + color: green; +} + +.course-meta .info span { + color: #666; + margin: 0 5px; +} + +.course-meta .rating span { + margin: 0 3px; +} + +.course-meta .rating .layui-icon { + color: orange; +} + +.course-meta .rating .score { + color: #666; } .layui-tab-title li { diff --git a/public/static/web/js/chapter.vod.js b/public/static/web/js/chapter.vod.js new file mode 100644 index 00000000..d8bc4881 --- /dev/null +++ b/public/static/web/js/chapter.vod.js @@ -0,0 +1,21 @@ +layui.use(['jquery', 'helper'], function () { + + var $ = layui.jquery; + var helper = layui.helper; + + /** + * 咨询 + */ + $('.icon-help').on('click', function () { + var url = $(this).parent().data('url'); + helper.checkLogin(function () { + layer.open({ + type: 2, + title: '课程咨询', + content: [url, 'no'], + area: ['640px', '300px'] + }); + }); + }); + +}); \ No newline at end of file diff --git a/public/static/web/js/course.rating.js b/public/static/web/js/course.rating.js index 5708de77..0bfbe6eb 100644 --- a/public/static/web/js/course.rating.js +++ b/public/static/web/js/course.rating.js @@ -3,12 +3,13 @@ layui.use(['jquery', 'rate'], function () { var $ = layui.jquery; var rate = layui.rate; - $('.cancel-rating').on('click', function () { + $('.btn-cancel').on('click', function () { parent.layer.closeAll(); }); rate.render({ elem: '#rating1', + value: 5, choose: function (value) { $('input[name=rating1]').val(value); } @@ -16,6 +17,7 @@ layui.use(['jquery', 'rate'], function () { rate.render({ elem: '#rating2', + value: 5, choose: function (value) { $('input[name=rating2]').val(value); } @@ -23,6 +25,7 @@ layui.use(['jquery', 'rate'], function () { rate.render({ elem: '#rating3', + value: 5, choose: function (value) { $('input[name=rating3]').val(value); } diff --git a/public/static/web/js/course.show.js b/public/static/web/js/course.show.js index 6d5d2e38..c7bddff0 100644 --- a/public/static/web/js/course.show.js +++ b/public/static/web/js/course.show.js @@ -4,6 +4,9 @@ layui.use(['jquery', 'layer', 'helper'], function () { var layer = layui.layer; var helper = layui.helper; + /** + * 收藏 + */ $('.icon-star').on('click', function () { var $this = $(this); helper.checkLogin(function () { @@ -23,6 +26,9 @@ layui.use(['jquery', 'layer', 'helper'], function () { }); }); + /** + * 打赏 + */ $('.btn-reward').on('click', function () { var url = $(this).data('url'); helper.checkLogin(function () { @@ -30,7 +36,10 @@ layui.use(['jquery', 'layer', 'helper'], function () { }); }); - $('.btn-buy').on('click', function () { + /** + * 购买(课程|套餐) + */ + $('body').on('click', '.btn-buy', function () { var url = $(this).data('url'); helper.checkLogin(function () { window.location.href = url; @@ -47,6 +56,22 @@ layui.use(['jquery', 'layer', 'helper'], function () { }); }); + /** + * 浏览章节 + */ + $('body').on('click', '.view-lesson', function () { + if ($(this).hasClass('deny')) { + return false; + } + var url = $(this).data('url'); + helper.checkLogin(function () { + window.location.href = url; + }); + }); + + /** + * 点赞(咨询|评价) + */ $('body').on('click', '.icon-praise', function () { var $this = $(this); var $likeCount = $this.next();