diff --git a/app/Caches/IndexLiveCourseList.php b/app/Caches/IndexLiveList.php similarity index 97% rename from app/Caches/IndexLiveCourseList.php rename to app/Caches/IndexLiveList.php index da6e38d6..26bc5c30 100644 --- a/app/Caches/IndexLiveCourseList.php +++ b/app/Caches/IndexLiveList.php @@ -11,10 +11,10 @@ use Phalcon\Mvc\Model\Resultset; /** * 直播课程 * - * Class IndexLiveCourseList + * Class IndexLiveList * @package App\Caches */ -class IndexLiveCourseList extends Cache +class IndexLiveList extends Cache { protected $lifetime = 1 * 86400; @@ -26,7 +26,7 @@ class IndexLiveCourseList extends Cache public function getKey($id = null) { - return 'index_live_course_list'; + return 'index_live_list'; } public function getContent($id = null) diff --git a/app/Http/Admin/Services/ChapterContent.php b/app/Http/Admin/Services/ChapterContent.php index 5c23820c..548f337e 100644 --- a/app/Http/Admin/Services/ChapterContent.php +++ b/app/Http/Admin/Services/ChapterContent.php @@ -2,7 +2,7 @@ namespace App\Http\Admin\Services; -use App\Library\Util\Word as WordUtil; +use App\Library\Utils\Word as WordUtil; use App\Models\Chapter as ChapterModel; use App\Models\Course as CourseModel; use App\Repos\Chapter as ChapterRepo; diff --git a/app/Http/Admin/Services/Session.php b/app/Http/Admin/Services/Session.php index 90268ad1..2394908f 100644 --- a/app/Http/Admin/Services/Session.php +++ b/app/Http/Admin/Services/Session.php @@ -21,22 +21,27 @@ class Session extends Service public function login() { + $currentUser = $this->getCurrentUser(); + + if ($currentUser->id > 0) { + $this->response->redirect(['for' => 'web.index']); + } + $post = $this->request->getPost(); $accountValidator = new AccountValidator(); $user = $accountValidator->checkAdminLogin($post['account'], $post['password']); - $setting = new Setting(); - - $captcha = $setting->getSectionSettings('captcha'); - - $captchaValidator = new CaptchaValidator(); + $captchaSettings = $this->getSectionSettings('captcha'); /** * 验证码是一次性的,放到最后检查,减少第三方调用 */ - if ($captcha->enabled) { + if ($captchaSettings['enabled'] == 1) { + + $captchaValidator = new CaptchaValidator(); + $captchaValidator->checkCode($post['ticket'], $post['rand']); } diff --git a/app/Http/Admin/Views/public/live_player.volt b/app/Http/Admin/Views/public/live_player.volt index cbd37f4f..aad6007c 100644 --- a/app/Http/Admin/Views/public/live_player.volt +++ b/app/Http/Admin/Views/public/live_player.volt @@ -1,5 +1,5 @@ - +
diff --git a/app/Http/Web/Controllers/AccountController.php b/app/Http/Web/Controllers/AccountController.php index bfd536e5..50776a8a 100644 --- a/app/Http/Web/Controllers/AccountController.php +++ b/app/Http/Web/Controllers/AccountController.php @@ -3,6 +3,10 @@ namespace App\Http\Web\Controllers; use App\Http\Web\Services\Account as AccountService; +use App\Services\Frontend\Account\EmailUpdate as EmailUpdateService; +use App\Services\Frontend\Account\PasswordReset as PasswordResetService; +use App\Services\Frontend\Account\PasswordUpdate as PasswordUpdateService; +use App\Services\Frontend\Account\PhoneUpdate as PhoneUpdateService; /** * @RoutePrefix("/account") @@ -11,17 +15,52 @@ class AccountController extends Controller { /** - * @Post("/register", name="web.account.register") + * @Route("/login", name="web.account.login") */ - public function registerAction() + public function loginAction() + { + if ($this->request->isPost()) { + + $service = new AccountService(); + + $service->login(); + + $location = $this->request->getHTTPReferer(); + + return $this->jsonSuccess(['location' => $location]); + } + } + + /** + * @Route("/logout", name="web.account.logout") + */ + public function logoutAction() { $service = new AccountService(); - $service->signup(); + $service->logout(); - $location = $this->request->getHTTPReferer(); + $this->response->redirect(['for' => 'web.index']); + } - $this->response->redirect($location); + /** + * @Route("/register", name="web.account.register") + */ + public function registerAction() + { + if ($this->request->isPost()) { + + $service = new AccountService(); + + $service->register(); + + $location = $this->request->getHTTPReferer(); + + return $this->jsonSuccess([ + 'location' => $location, + 'msg' => '注册账户成功', + ]); + } } /** @@ -29,47 +68,59 @@ class AccountController extends Controller */ public function resetPasswordAction() { - $service = new AccountService(); + if ($this->request->isPost()) { - $service->resetPassword(); + $service = new PasswordResetService(); - return $this->jsonSuccess(); + $service->handle(); + + return $this->jsonSuccess(['msg' => '重置密码成功']); + } } /** - * @Post("/phone/update", name="web.account.update_phone") + * @Route("/phone/update", name="web.account.update_phone") */ public function updatePhoneAction() { - $service = new AccountService(); + if ($this->request->isPost()) { - $service->updateMobile(); + $service = new PhoneUpdateService(); - return $this->jsonSuccess(); + $service->handle(); + + return $this->jsonSuccess(['msg' => '更新手机成功']); + } } /** - * @Post("/email/update", name="web.account.update_email") + * @Route("/email/update", name="web.account.update_email") */ public function updateEmailAction() { - $service = new AccountService(); + if ($this->request->isPost()) { - $service->updateMobile(); + $service = new EmailUpdateService(); - return $this->jsonSuccess(); + $service->handle(); + + return $this->jsonSuccess(['msg' => '更新邮箱成功']); + } } /** - * @Post("/password/update", name="web.account.update_password") + * @Route("/password/update", name="web.account.update_password") */ public function updatePasswordAction() { - $service = new AccountService(); + if ($this->request->isPost()) { - $service->updatePassword(); + $service = new PasswordUpdateService(); - return $this->jsonSuccess(); + $service->handle(); + + return $this->jsonSuccess(['msg' => '更新密码成功']); + } } } diff --git a/app/Http/Web/Controllers/CourseController.php b/app/Http/Web/Controllers/CourseController.php index ebbaeb61..80f88380 100644 --- a/app/Http/Web/Controllers/CourseController.php +++ b/app/Http/Web/Controllers/CourseController.php @@ -2,11 +2,13 @@ namespace App\Http\Web\Controllers; -use App\Services\Frontend\Course as CourseService; -use App\Services\Frontend\CourseList as CourseListService; -use App\Services\Frontend\CourseRelated as CourseRelatedService; -use App\Services\Frontend\Favorite as CourseFavoriteService; -use App\Services\Frontend\ReviewCreate as CourseReviewService; +use App\Http\Web\Services\Course as CourseService; +use App\Services\Frontend\Course\ConsultList as CourseConsultListService; +use App\Services\Frontend\Course\CourseFavorite as CourseFavoriteService; +use App\Services\Frontend\Course\CourseInfo as CourseInfoService; +use App\Services\Frontend\Course\CourseList as CourseListService; +use App\Services\Frontend\Course\CourseRelated as CourseRelatedService; +use App\Services\Frontend\Course\ReviewList as CourseReviewListService; /** * @RoutePrefix("/course") @@ -21,10 +23,19 @@ class CourseController extends Controller { $courseListService = new CourseListService(); - $pager = $courseListService->getCourses(); + $pager = $courseListService->handle(); - return $this->jsonSuccess(['pager' => $pager]); + $courseService = new CourseService(); + $topCategories = $courseService->handleTopCategories(); + $subCategories = $courseService->handleSubCategories(); + $levels = $courseService->handleLevels(); + + dd($topCategories, $subCategories, $levels); + + $this->view->setVar('top_categories', $topCategories); + $this->view->setVar('sub_categories', $subCategories); + $this->view->setVar('levels', $levels); $this->view->setVar('pager', $pager); } @@ -33,27 +44,28 @@ class CourseController extends Controller */ public function showAction($id) { - $courseService = new CourseService(); + $courseInfoService = new CourseInfoService(); - $course = $courseService->getCourse($id); + $courseInfo = $courseInfoService->handle($id); - return $this->jsonSuccess(['course' => $course]); + $courseRelatedService = new CourseRelatedService(); - $this->view->setVar('course', $course); + $relatedCourses = $courseRelatedService->handle($id); + + $this->view->setVar('course_info', $courseInfo); + $this->view->setVar('related_courses', $relatedCourses); } /** - * @Get("/{id:[0-9]+}/related", name="web.course.related") + * @Get("/{id:[0-9]+}/consults", name="web.course.consults") */ - public function relatedAction($id) + public function consultsAction($id) { - $relatedService = new CourseRelatedService(); + $consultListService = new CourseConsultListService(); - $courses = $relatedService->getRelated($id); + $pager = $consultListService->handle($id); - return $this->jsonSuccess(['courses' => $courses]); - - $this->view->setVar('course', $course); + $this->view->setVar('pager', $pager); } /** @@ -61,11 +73,9 @@ class CourseController extends Controller */ public function reviewsAction($id) { - $reviewService = new CourseReviewService(); + $reviewListService = new CourseReviewListService(); - $pager = $reviewService->getReviews($id); - - return $this->jsonSuccess(['pager' => $pager]); + $pager = $reviewListService->handle($id); $this->view->setVar('pager', $pager); } @@ -77,9 +87,9 @@ class CourseController extends Controller { $favoriteService = new CourseFavoriteService(); - $favoriteService->saveFavorite($id); + $favoriteService->handle($id); - return $this->response->ajaxSuccess(); + return $this->jsonSuccess(['msg' => '收藏课程成功']); } } diff --git a/app/Http/Web/Controllers/IndexController.php b/app/Http/Web/Controllers/IndexController.php index 3a1453a5..cdf6a988 100644 --- a/app/Http/Web/Controllers/IndexController.php +++ b/app/Http/Web/Controllers/IndexController.php @@ -2,6 +2,8 @@ namespace App\Http\Web\Controllers; +use App\Http\Web\Services\Index as IndexService; + class IndexController extends Controller { @@ -12,6 +14,14 @@ class IndexController extends Controller { $this->siteSeo->setKeywords($this->siteSettings['keywords']); $this->siteSeo->setDescription($this->siteSettings['description']); + + $indexService = new IndexService(); + + $this->view->setVar('slide_list', $indexService->getSlideList()); + $this->view->setVar('live_list', $indexService->getLiveList()); + $this->view->setVar('new_course_list', $indexService->getNewCourseList()); + $this->view->setVar('free_course_list', $indexService->getFreeCourseList()); + $this->view->setVar('vip_course_list', $indexService->getVipCourseList()); } } diff --git a/app/Http/Web/Controllers/SessionController.php b/app/Http/Web/Controllers/SessionController.php deleted file mode 100644 index 92f7ee53..00000000 --- a/app/Http/Web/Controllers/SessionController.php +++ /dev/null @@ -1,39 +0,0 @@ -login(); - - $location = $this->request->getHTTPReferer(); - - $this->response->redirect($location); - } - - /** - * @Get("/logout", name="web.account.logout") - */ - public function logoutAction() - { - $service = new AccountService(); - - $service->logout(); - - $this->response->redirect(['for' => 'web.index']); - } - -} diff --git a/app/Http/Web/Services/Account.php b/app/Http/Web/Services/Account.php new file mode 100644 index 00000000..f9f6d174 --- /dev/null +++ b/app/Http/Web/Services/Account.php @@ -0,0 +1,60 @@ +auth = $this->getDI()->get('auth'); + } + + public function login() + { + $post = $this->request->getPost(); + + $accountValidator = new AccountValidator(); + + $user = $accountValidator->checkUserLogin($post['account'], $post['password']); + + $captchaSettings = $this->getSectionSettings('captcha'); + + /** + * 验证码是一次性的,放到最后检查,减少第三方调用 + */ + if ($captchaSettings['enabled'] == 1) { + + $captchaValidator = new CaptchaValidator(); + + $captchaValidator->checkCode($post['ticket'], $post['rand']); + } + + $this->auth->saveAuthInfo($user); + } + + public function logout() + { + $this->auth->clearAuthInfo(); + } + + public function register() + { + $service = new RegisterService(); + + $user = $service->handle(); + + $this->auth->saveAuthInfo($user); + } + +} diff --git a/app/Http/Web/Services/Course.php b/app/Http/Web/Services/Course.php new file mode 100644 index 00000000..f6b43d8e --- /dev/null +++ b/app/Http/Web/Services/Course.php @@ -0,0 +1,161 @@ +getQueryParams(); + + if (isset($params['tc'])) { + unset($params['tc']); + } + + if (isset($params['sc'])) { + unset($params['sc']); + } + + $baseUrl = $this->url->get(['for' => 'web.course.list']); + + $defaultItem = [ + 'id' => 0, + 'name' => '全部', + 'href' => $baseUrl . $this->buildQueryParams($params), + ]; + + $result = []; + + $result[] = $defaultItem; + + $categoryService = new CategoryService(); + + $topCategories = $categoryService->getChildCategories(0); + + foreach ($topCategories as $key => $category) { + $params['tc'] = $category['id']; + $result[] = [ + 'id' => $category['id'], + 'name' => $category['name'], + 'href' => $baseUrl . $this->buildQueryParams($params), + ]; + } + + return $result; + } + + public function handleSubCategories() + { + $params = $this->getQueryParams(); + + if (empty($params['tc'])) { + return []; + } + + $categoryService = new CategoryService(); + + $subCategories = $categoryService->getChildCategories($params['tc']); + + if (empty($subCategories)) { + return []; + } + + if (isset($params['sc'])) { + unset($params['sc']); + } + + $baseUrl = $this->url->get(['for' => 'web.course.list']); + + $defaultItem = [ + 'id' => 0, + 'name' => '全部', + 'href' => $baseUrl . $this->buildQueryParams($params), + ]; + + $result = []; + + $result[] = $defaultItem; + + foreach ($subCategories as $key => $category) { + $params['sc'] = $category['id']; + $result[] = [ + 'id' => $category['id'], + 'name' => $category['name'], + 'href' => $baseUrl . $this->buildQueryParams($params), + ]; + } + + return $result; + } + + public function handleLevels() + { + $params = $this->getQueryParams(); + + $defaultParams = $params; + + if (isset($defaultParams['level'])) { + unset($defaultParams['level']); + } + + $baseUrl = $this->url->get(['for' => 'web.course.list']); + + $defaultItem = [ + 'id' => 0, + 'name' => '全部', + 'href' => $baseUrl . $this->buildQueryParams($defaultParams), + ]; + + $result = []; + + $result[] = $defaultItem; + + $levels = CourseModel::levelTypes(); + + foreach ($levels as $key => $value) { + $params['sc'] = $key; + $result[] = [ + 'id' => $key, + 'name' => $value, + 'href' => $baseUrl . $this->buildQueryParams($params), + ]; + } + + return $result; + } + + public function handleSorts() + { + } + + protected function getQueryParams() + { + $query = $this->request->getQuery(); + + $params = []; + + if (!empty($query['tc'])) { + $params['tc'] = $query['tc']; + } + + if (!empty($query['sc'])) { + $params['sc'] = $query['sc']; + } + + if (!empty($query['level'])) { + $params['level'] = $query['level']; + } + + return $params; + } + + protected function buildQueryParams($params) + { + return $params ? '?' . http_build_query($params) : ''; + } + +} diff --git a/app/Http/Web/Services/Index.php b/app/Http/Web/Services/Index.php new file mode 100644 index 00000000..2c72da6a --- /dev/null +++ b/app/Http/Web/Services/Index.php @@ -0,0 +1,49 @@ +get(); + } + + public function getLiveList() + { + $cache = new IndexLiveList(); + + return $cache->get(); + } + + public function getNewCourseList() + { + $cache = new IndexNewCourseList(); + + return $cache->get(); + } + + public function getFreeCourseList() + { + $cache = new IndexFreeCourseList(); + + return $cache->get(); + } + + public function getVipCourseList() + { + $cache = new IndexVipCourseList(); + + return $cache->get(); + } + +} diff --git a/app/Http/Web/Views/course/list.volt b/app/Http/Web/Views/course/list.volt new file mode 100644 index 00000000..36b2f5b6 --- /dev/null +++ b/app/Http/Web/Views/course/list.volt @@ -0,0 +1 @@ +{% extends 'templates/base.volt' %} \ 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 61999092..d44e0272 100644 --- a/app/Http/Web/Views/index/index.volt +++ b/app/Http/Web/Views/index/index.volt @@ -2,6 +2,18 @@ {% block content %} -