From 9974430f18f263cadb7336c7c4acee145a290729 Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Sat, 26 Dec 2020 17:44:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=90=8E=E5=8F=B0=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E9=A6=96=E9=A1=B5=E7=BC=93=E5=AD=98=E5=B0=8F=E5=B7=A5?= =?UTF-8?q?=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Tasks/MaintainTask.php | 41 +-------- app/Http/Admin/Controllers/UtilController.php | 30 +++++++ app/Http/Admin/Services/AuthNode.php | 24 +++++ app/Http/Admin/Services/Util.php | 40 +++++++++ app/Http/Admin/Views/util/index_cache.volt | 89 +++++++++++++++++++ app/Services/Utils/IndexCourseCache.php | 53 +++++++++++ 6 files changed, 239 insertions(+), 38 deletions(-) create mode 100644 app/Http/Admin/Controllers/UtilController.php create mode 100644 app/Http/Admin/Services/Util.php create mode 100644 app/Http/Admin/Views/util/index_cache.volt create mode 100644 app/Services/Utils/IndexCourseCache.php diff --git a/app/Console/Tasks/MaintainTask.php b/app/Console/Tasks/MaintainTask.php index 7f6d5898..bb915d46 100644 --- a/app/Console/Tasks/MaintainTask.php +++ b/app/Console/Tasks/MaintainTask.php @@ -2,14 +2,9 @@ namespace App\Console\Tasks; -use App\Caches\IndexFreeCourseList as IndexFreeCourseListCache; -use App\Caches\IndexNewCourseList as IndexNewCourseListCache; -use App\Caches\IndexSimpleFreeCourseList as IndexSimpleFreeCourseListCache; -use App\Caches\IndexSimpleNewCourseList as IndexSimpleNewCourseListCache; -use App\Caches\IndexSimpleVipCourseList as IndexSimpleVipCourseListCache; -use App\Caches\IndexVipCourseList as IndexVipCourseListCache; use App\Http\Admin\Services\Setting as SettingService; use App\Library\Utils\Password as PasswordUtil; +use App\Services\Utils\IndexCourseCache as IndexCourseCacheUtil; use App\Validators\Account as AccountValidator; class MaintainTask extends Task @@ -25,39 +20,9 @@ class MaintainTask extends Task { $section = $params[0] ?? null; - $site = $this->getSettings('site'); + $util = new IndexCourseCacheUtil(); - $type = $site['index_tpl_type'] ?: 'full'; - - if (!$section || $section == 'new_course') { - if ($type == 'full') { - $cache = new IndexNewCourseListCache(); - $cache->rebuild(); - } else { - $cache = new IndexSimpleNewCourseListCache(); - $cache->rebuild(); - } - } - - if (!$section || $section == 'free_course') { - if ($type == 'full') { - $cache = new IndexFreeCourseListCache(); - $cache->rebuild(); - } else { - $cache = new IndexSimpleFreeCourseListCache(); - $cache->rebuild(); - } - } - - if (!$section || $section == 'vip_course') { - if ($type == 'full') { - $cache = new IndexVipCourseListCache(); - $cache->rebuild(); - } else { - $cache = new IndexSimpleVipCourseListCache(); - $cache->rebuild(); - } - } + $util->rebuild($section); echo 'rebuild index course cache success' . PHP_EOL; } diff --git a/app/Http/Admin/Controllers/UtilController.php b/app/Http/Admin/Controllers/UtilController.php new file mode 100644 index 00000000..89dc1386 --- /dev/null +++ b/app/Http/Admin/Controllers/UtilController.php @@ -0,0 +1,30 @@ +request->isPost()) { + + $service->handleIndexCache(); + + return $this->jsonSuccess(['msg' => '更新缓存成功']); + } + + $this->view->pick('util/index_cache'); + } + +} diff --git a/app/Http/Admin/Services/AuthNode.php b/app/Http/Admin/Services/AuthNode.php index db2ec7d8..073058bc 100644 --- a/app/Http/Admin/Services/AuthNode.php +++ b/app/Http/Admin/Services/AuthNode.php @@ -14,6 +14,7 @@ class AuthNode extends Service $nodes[] = $this->getFinanceNodes(); $nodes[] = $this->getUserNodes(); $nodes[] = $this->getSettingNodes(); + $nodes[] = $this->getUtilNodes(); return $nodes; } @@ -768,4 +769,27 @@ class AuthNode extends Service ]; } + protected function getUtilNodes() + { + return [ + 'id' => '6', + 'title' => '实用工具', + 'children' => [ + [ + 'id' => '6-1', + 'title' => '常用工具', + 'type' => 'menu', + 'children' => [ + [ + 'id' => '6-1-1', + 'title' => '首页缓存', + 'type' => 'menu', + 'route' => 'admin.util.index_cache', + ], + ], + ], + ], + ]; + } + } diff --git a/app/Http/Admin/Services/Util.php b/app/Http/Admin/Services/Util.php new file mode 100644 index 00000000..42806b70 --- /dev/null +++ b/app/Http/Admin/Services/Util.php @@ -0,0 +1,40 @@ +request->getPost('items'); + + if ($items['slide'] == 1) { + $cache = new IndexSlideListCache(); + $cache->rebuild(); + } + + $util = new IndexCourseCacheUtil(); + + if ($items['featured_course'] == 1) { + $util->rebuild('featured_course'); + } + + if ($items['new_course'] == 1) { + $util->rebuild('new_course'); + } + + if ($items['free_course'] == 1) { + $util->rebuild('free_course'); + } + + if ($items['vip_course'] == 1) { + $util->rebuild('vip_course'); + } + + } + +} diff --git a/app/Http/Admin/Views/util/index_cache.volt b/app/Http/Admin/Views/util/index_cache.volt new file mode 100644 index 00000000..75278348 --- /dev/null +++ b/app/Http/Admin/Views/util/index_cache.volt @@ -0,0 +1,89 @@ +{% extends 'templates/main.volt' %} + +{% block content %} + +
+
+ 首页缓存 +
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+ +{% endblock %} + +{% block inline_js %} + + + +{% endblock %} \ No newline at end of file diff --git a/app/Services/Utils/IndexCourseCache.php b/app/Services/Utils/IndexCourseCache.php new file mode 100644 index 00000000..26e279cd --- /dev/null +++ b/app/Services/Utils/IndexCourseCache.php @@ -0,0 +1,53 @@ +getSettings('site'); + + $type = $site['index_tpl_type'] ?: 'full'; + + if (!$section || $section == 'new_course') { + if ($type == 'full') { + $cache = new IndexNewCourseListCache(); + $cache->rebuild(); + } else { + $cache = new IndexSimpleNewCourseListCache(); + $cache->rebuild(); + } + } + + if (!$section || $section == 'free_course') { + if ($type == 'full') { + $cache = new IndexFreeCourseListCache(); + $cache->rebuild(); + } else { + $cache = new IndexSimpleFreeCourseListCache(); + $cache->rebuild(); + } + } + + if (!$section || $section == 'vip_course') { + if ($type == 'full') { + $cache = new IndexVipCourseListCache(); + $cache->rebuild(); + } else { + $cache = new IndexSimpleVipCourseListCache(); + $cache->rebuild(); + } + } + } + +} \ No newline at end of file