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