From def5b3605abb3dcc99eb256c9d3b759e934d1a19 Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Fri, 11 Sep 2020 20:00:31 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E5=8F=AF=E4=BB=A5=E5=88=87?= =?UTF-8?q?=E6=8D=A2"=E7=AE=80=E6=B4=81"=E5=92=8C=E2=80=9C=E4=B8=B0?= =?UTF-8?q?=E5=AF=8C=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Caches/IndexFreeCourseList.php | 4 +- app/Caches/IndexNewCourseList.php | 4 +- app/Caches/IndexSimpleFreeCourseList.php | 70 +++++++++++++++++++ app/Caches/IndexSimpleNewCourseList.php | 69 ++++++++++++++++++ app/Caches/IndexSimpleVipCourseList.php | 70 +++++++++++++++++++ app/Caches/IndexVipCourseList.php | 4 +- app/Http/Admin/Views/setting/site.volt | 7 ++ .../Desktop/Controllers/IndexController.php | 36 ++++++++-- app/Http/Desktop/Services/Index.php | 44 +++++++++--- .../Views/index/{index.volt => full.volt} | 0 app/Http/Desktop/Views/index/simple.volt | 60 ++++++++++++++++ bootstrap/ConsoleErrorHandler.php | 19 ++++- bootstrap/Kernel.php | 3 + .../20200827112717_insert_setting_data.php | 15 ++++ public/static/desktop/css/common.css | 4 ++ 15 files changed, 385 insertions(+), 24 deletions(-) create mode 100644 app/Caches/IndexSimpleFreeCourseList.php create mode 100644 app/Caches/IndexSimpleNewCourseList.php create mode 100644 app/Caches/IndexSimpleVipCourseList.php rename app/Http/Desktop/Views/index/{index.volt => full.volt} (100%) create mode 100644 app/Http/Desktop/Views/index/simple.volt diff --git a/app/Caches/IndexFreeCourseList.php b/app/Caches/IndexFreeCourseList.php index b6c69d67..2783b4ce 100644 --- a/app/Caches/IndexFreeCourseList.php +++ b/app/Caches/IndexFreeCourseList.php @@ -30,7 +30,7 @@ class IndexFreeCourseList extends Cache { $categoryLimit = 5; - $courseLimit = 10; + $courseLimit = 8; $categories = $this->findCategories($categoryLimit); @@ -100,7 +100,7 @@ class IndexFreeCourseList extends Cache * @param int $limit * @return ResultsetInterface|Resultset|CourseModel[] */ - protected function findCategoryCourses($categoryId, $limit = 10) + protected function findCategoryCourses($categoryId, $limit = 8) { $categoryService = new CategoryService(); diff --git a/app/Caches/IndexNewCourseList.php b/app/Caches/IndexNewCourseList.php index 7cb627cf..9a2a89b6 100644 --- a/app/Caches/IndexNewCourseList.php +++ b/app/Caches/IndexNewCourseList.php @@ -30,7 +30,7 @@ class IndexNewCourseList extends Cache { $categoryLimit = 5; - $courseLimit = 10; + $courseLimit = 8; $categories = $this->findCategories($categoryLimit); @@ -100,7 +100,7 @@ class IndexNewCourseList extends Cache * @param int $limit * @return ResultsetInterface|Resultset|CourseModel[] */ - protected function findCategoryCourses($categoryId, $limit = 10) + protected function findCategoryCourses($categoryId, $limit = 8) { $categoryService = new CategoryService(); diff --git a/app/Caches/IndexSimpleFreeCourseList.php b/app/Caches/IndexSimpleFreeCourseList.php new file mode 100644 index 00000000..a91174a4 --- /dev/null +++ b/app/Caches/IndexSimpleFreeCourseList.php @@ -0,0 +1,70 @@ +lifetime; + } + + public function getKey($id = null) + { + return 'index_simple_free_course_list'; + } + + public function getContent($id = null) + { + $limit = 8; + + $courses = $this->findCourses($limit); + + if ($courses->count() == 0) { + return []; + } + + $result = []; + + foreach ($courses as $course) { + $result[] = [ + 'id' => $course->id, + 'title' => $course->title, + 'cover' => $course->cover, + 'market_price' => $course->market_price, + 'vip_price' => $course->vip_price, + 'model' => $course->model, + 'level' => $course->level, + 'user_count' => $course->user_count, + 'lesson_count' => $course->lesson_count, + ]; + } + + return $result; + } + + /** + * @param int $limit + * @return ResultsetInterface|Resultset|CourseModel[] + */ + protected function findCourses($limit = 8) + { + return CourseModel::query() + ->where('published = 1') + ->andWhere('market_price = 0') + ->orderBy('score DESC') + ->limit($limit) + ->execute(); + } + +} diff --git a/app/Caches/IndexSimpleNewCourseList.php b/app/Caches/IndexSimpleNewCourseList.php new file mode 100644 index 00000000..4d9dcd89 --- /dev/null +++ b/app/Caches/IndexSimpleNewCourseList.php @@ -0,0 +1,69 @@ +lifetime; + } + + public function getKey($id = null) + { + return 'index_simple_new_course_list'; + } + + public function getContent($id = null) + { + $limit = 8; + + $courses = $this->findCourses($limit); + + if ($courses->count() == 0) { + return []; + } + + $result = []; + + foreach ($courses as $course) { + $result[] = [ + 'id' => $course->id, + 'title' => $course->title, + 'cover' => $course->cover, + 'market_price' => $course->market_price, + 'vip_price' => $course->vip_price, + 'model' => $course->model, + 'level' => $course->level, + 'user_count' => $course->user_count, + 'lesson_count' => $course->lesson_count, + ]; + } + + return $result; + } + + /** + * @param int $limit + * @return ResultsetInterface|Resultset|CourseModel[] + */ + protected function findCourses($limit = 8) + { + return CourseModel::query() + ->where('published = 1') + ->orderBy('id DESC') + ->limit($limit) + ->execute(); + } + +} diff --git a/app/Caches/IndexSimpleVipCourseList.php b/app/Caches/IndexSimpleVipCourseList.php new file mode 100644 index 00000000..bfb10e59 --- /dev/null +++ b/app/Caches/IndexSimpleVipCourseList.php @@ -0,0 +1,70 @@ +lifetime; + } + + public function getKey($id = null) + { + return 'index_simple_vip_course_list'; + } + + public function getContent($id = null) + { + $limit = 8; + + $courses = $this->findCourses($limit); + + if ($courses->count() == 0) { + return []; + } + + $result = []; + + foreach ($courses as $course) { + $result[] = [ + 'id' => $course->id, + 'title' => $course->title, + 'cover' => $course->cover, + 'market_price' => $course->market_price, + 'vip_price' => $course->vip_price, + 'model' => $course->model, + 'level' => $course->level, + 'user_count' => $course->user_count, + 'lesson_count' => $course->lesson_count, + ]; + } + + return $result; + } + + /** + * @param int $limit + * @return ResultsetInterface|Resultset|CourseModel[] + */ + protected function findCourses($limit = 8) + { + return CourseModel::query() + ->where('published = 1') + ->andWhere('vip_price >= 0') + ->orderBy('score DESC') + ->limit($limit) + ->execute(); + } + +} diff --git a/app/Caches/IndexVipCourseList.php b/app/Caches/IndexVipCourseList.php index ab869db0..36fe1d0a 100644 --- a/app/Caches/IndexVipCourseList.php +++ b/app/Caches/IndexVipCourseList.php @@ -30,7 +30,7 @@ class IndexVipCourseList extends Cache { $categoryLimit = 5; - $courseLimit = 10; + $courseLimit = 8; $categories = $this->findCategories($categoryLimit); @@ -100,7 +100,7 @@ class IndexVipCourseList extends Cache * @param int $limit * @return ResultsetInterface|Resultset|CourseModel[] */ - protected function findCategoryCourses($categoryId, $limit = 10) + protected function findCategoryCourses($categoryId, $limit = 8) { $categoryService = new CategoryService(); diff --git a/app/Http/Admin/Views/setting/site.volt b/app/Http/Admin/Views/setting/site.volt index a8e1ffb1..4443f487 100644 --- a/app/Http/Admin/Views/setting/site.volt +++ b/app/Http/Admin/Views/setting/site.volt @@ -23,6 +23,13 @@ +
+ +
+ + +
+
diff --git a/app/Http/Desktop/Controllers/IndexController.php b/app/Http/Desktop/Controllers/IndexController.php index 96324570..5fe3a0a5 100644 --- a/app/Http/Desktop/Controllers/IndexController.php +++ b/app/Http/Desktop/Controllers/IndexController.php @@ -15,13 +15,37 @@ class IndexController extends Controller $this->seo->setKeywords($this->siteInfo['keywords']); $this->seo->setDescription($this->siteInfo['description']); - $indexService = new IndexService(); + $template = $this->siteInfo['index_template'] ?? 'full'; - $this->view->setVar('lives', $indexService->getLives()); - $this->view->setVar('carousels', $indexService->getCarousels()); - $this->view->setVar('new_courses', $indexService->getNewCourses()); - $this->view->setVar('free_courses', $indexService->getFreeCourses()); - $this->view->setVar('vip_courses', $indexService->getVipCourses()); + if ($template == 'full') { + $this->fullIndex(); + } else { + $this->simpleIndex(); + } + } + + protected function fullIndex() + { + $service = new IndexService(); + + $this->view->pick('index/full'); + $this->view->setVar('lives', $service->getLives()); + $this->view->setVar('carousels', $service->getCarousels()); + $this->view->setVar('new_courses', $service->getNewCourses()); + $this->view->setVar('free_courses', $service->getFreeCourses()); + $this->view->setVar('vip_courses', $service->getVipCourses()); + } + + protected function simpleIndex() + { + $service = new IndexService(); + + $this->view->pick('index/simple'); + $this->view->setVar('lives', $service->getLives()); + $this->view->setVar('carousels', $service->getCarousels()); + $this->view->setVar('new_courses', $service->getSimpleNewCourses()); + $this->view->setVar('free_courses', $service->getSimpleFreeCourses()); + $this->view->setVar('vip_courses', $service->getSimpleVipCourses()); } } diff --git a/app/Http/Desktop/Services/Index.php b/app/Http/Desktop/Services/Index.php index 71e93eb2..b5b41615 100644 --- a/app/Http/Desktop/Services/Index.php +++ b/app/Http/Desktop/Services/Index.php @@ -2,11 +2,14 @@ namespace App\Http\Desktop\Services; -use App\Caches\IndexCarouselList as IndexCarouselListCache; -use App\Caches\IndexFreeCourseList as IndexFreeCourseListCache; -use App\Caches\IndexLiveList as IndexLiveListCache; -use App\Caches\IndexNewCourseList as IndexNewCourseListCache; -use App\Caches\IndexVipCourseList as IndexVipCourseListCache; +use App\Caches\IndexCarouselList; +use App\Caches\IndexFreeCourseList; +use App\Caches\IndexLiveList; +use App\Caches\IndexNewCourseList; +use App\Caches\IndexSimpleFreeCourseList; +use App\Caches\IndexSimpleNewCourseList; +use App\Caches\IndexSimpleVipCourseList; +use App\Caches\IndexVipCourseList; use App\Models\Carousel as CarouselModel; class Index extends Service @@ -14,7 +17,7 @@ class Index extends Service public function getCarousels() { - $cache = new IndexCarouselListCache(); + $cache = new IndexCarouselList(); /** * @var array $carousels @@ -53,14 +56,14 @@ class Index extends Service public function getLives() { - $cache = new IndexLiveListCache(); + $cache = new IndexLiveList(); return $cache->get(); } public function getNewCourses() { - $cache = new IndexNewCourseListCache(); + $cache = new IndexNewCourseList(); $courses = $cache->get(); @@ -69,7 +72,7 @@ class Index extends Service public function getFreeCourses() { - $cache = new IndexFreeCourseListCache(); + $cache = new IndexFreeCourseList(); $courses = $cache->get(); @@ -78,13 +81,34 @@ class Index extends Service public function getVipCourses() { - $cache = new IndexVipCourseListCache(); + $cache = new IndexVipCourseList(); $courses = $cache->get(); return $this->handleCategoryCourses($courses); } + public function getSimpleNewCourses() + { + $cache = new IndexSimpleNewCourseList(); + + return $cache->get(); + } + + public function getSimpleFreeCourses() + { + $cache = new IndexSimpleFreeCourseList(); + + return $cache->get(); + } + + public function getSimpleVipCourses() + { + $cache = new IndexSimpleVipCourseList(); + + return $cache->get(); + } + protected function handleCategoryCourses($items, $limit = 8) { if (count($items) == 0) { diff --git a/app/Http/Desktop/Views/index/index.volt b/app/Http/Desktop/Views/index/full.volt similarity index 100% rename from app/Http/Desktop/Views/index/index.volt rename to app/Http/Desktop/Views/index/full.volt diff --git a/app/Http/Desktop/Views/index/simple.volt b/app/Http/Desktop/Views/index/simple.volt new file mode 100644 index 00000000..f9353a1b --- /dev/null +++ b/app/Http/Desktop/Views/index/simple.volt @@ -0,0 +1,60 @@ +{% extends 'templates/main.volt' %} + +{% block content %} + + {{ partial('macros/course') }} + + {%- macro show_courses(courses) %} +
+
+ {% for course in courses %} +
+ {{ course_card(course) }} +
+ {% endfor %} +
+
+ {%- endmacro %} + + + +
+
新上课程
+
+ {{ show_courses(new_courses) }} +
+
+ +
+
免费课程
+
+ {{ show_courses(free_courses) }} +
+
+ +
+
会员课程
+
+ {{ show_courses(vip_courses) }} +
+
+ +{% endblock %} + +{% block include_js %} + + {{ js_include('desktop/js/index.js') }} + +{% endblock %} \ No newline at end of file diff --git a/bootstrap/ConsoleErrorHandler.php b/bootstrap/ConsoleErrorHandler.php index c159338a..c6a25826 100644 --- a/bootstrap/ConsoleErrorHandler.php +++ b/bootstrap/ConsoleErrorHandler.php @@ -3,6 +3,8 @@ namespace Bootstrap; use App\Library\Logger as AppLogger; +use Phalcon\Config as PhConfig; +use Phalcon\Logger\Adapter\File as PhLogger; use Phalcon\Mvc\User\Component; class ConsoleErrorHandler extends Component @@ -25,17 +27,30 @@ class ConsoleErrorHandler extends Component */ public function handleException($e) { - $content = sprintf('%s(%d): %s', $e->getFile(), $e->getLine(), $e->getMessage()); + $config = $this->getConfig(); $logger = $this->getLogger(); + $content = sprintf('%s(%d): %s', $e->getFile(), $e->getLine(), $e->getMessage()); + $logger->error($content); - if ($this->config->env == ENV_DEV) { + if ($config->get('env') == ENV_DEV) { echo $content; } } + /** + * @return PhConfig + */ + protected function getConfig() + { + return $this->getDI()->get('config'); + } + + /** + * @return PhLogger + */ protected function getLogger() { $logger = new AppLogger(); diff --git a/bootstrap/Kernel.php b/bootstrap/Kernel.php index 31bd9845..5e1bea07 100644 --- a/bootstrap/Kernel.php +++ b/bootstrap/Kernel.php @@ -24,6 +24,9 @@ abstract class Kernel */ protected $loader; + /** + * @var array + */ protected $configs = []; public function getApp() diff --git a/db/migrations/20200827112717_insert_setting_data.php b/db/migrations/20200827112717_insert_setting_data.php index f20635f1..ba5edecc 100644 --- a/db/migrations/20200827112717_insert_setting_data.php +++ b/db/migrations/20200827112717_insert_setting_data.php @@ -230,6 +230,16 @@ final class InsertSettingData extends AbstractMigration 'item_key' => 'enabled', 'item_value' => '1', ], + [ + 'section' => 'pay.wxpay', + 'item_key' => 'mp_app_id', + 'item_value' => '', + ], + [ + 'section' => 'pay.wxpay', + 'item_key' => 'mini_app_id', + 'item_value' => '', + ], [ 'section' => 'pay.wxpay', 'item_key' => 'app_id', @@ -300,6 +310,11 @@ final class InsertSettingData extends AbstractMigration 'item_key' => 'closed_tips', 'item_value' => '站点维护中,请稍后再访问。', ], + [ + 'section' => 'site', + 'item_key' => 'index_template', + 'item_value' => 'simple', + ], [ 'section' => 'site', 'item_key' => 'copyright', diff --git a/public/static/desktop/css/common.css b/public/static/desktop/css/common.css index 7454b7f8..9e44a1d9 100644 --- a/public/static/desktop/css/common.css +++ b/public/static/desktop/css/common.css @@ -202,6 +202,10 @@ body { line-height: 40px; } +.index-wrap { + padding-bottom: 15px; +} + .index-wrap .layui-tab { margin-bottom: 0; }