mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-07-13 11:59:11 +08:00
增加后台刷新首页缓存小工具
This commit is contained in:
parent
906e458ed0
commit
9337c3824b
@ -2,14 +2,9 @@
|
|||||||
|
|
||||||
namespace App\Console\Tasks;
|
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\Http\Admin\Services\Setting as SettingService;
|
||||||
use App\Library\Utils\Password as PasswordUtil;
|
use App\Library\Utils\Password as PasswordUtil;
|
||||||
|
use App\Services\Utils\IndexCourseCache as IndexCourseCacheUtil;
|
||||||
use App\Validators\Account as AccountValidator;
|
use App\Validators\Account as AccountValidator;
|
||||||
|
|
||||||
class MaintainTask extends Task
|
class MaintainTask extends Task
|
||||||
@ -25,39 +20,9 @@ class MaintainTask extends Task
|
|||||||
{
|
{
|
||||||
$section = $params[0] ?? null;
|
$section = $params[0] ?? null;
|
||||||
|
|
||||||
$site = $this->getSettings('site');
|
$util = new IndexCourseCacheUtil();
|
||||||
|
|
||||||
$type = $site['index_tpl_type'] ?: 'full';
|
$util->rebuild($section);
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
echo 'rebuild index course cache success' . PHP_EOL;
|
echo 'rebuild index course cache success' . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
30
app/Http/Admin/Controllers/UtilController.php
Normal file
30
app/Http/Admin/Controllers/UtilController.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Admin\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Admin\Services\Util as UtilService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @RoutePrefix("/admin/util")
|
||||||
|
*/
|
||||||
|
class UtilController extends Controller
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Route("/index/cache", name="admin.util.index_cache")
|
||||||
|
*/
|
||||||
|
public function indexCacheAction()
|
||||||
|
{
|
||||||
|
$service = new UtilService();
|
||||||
|
|
||||||
|
if ($this->request->isPost()) {
|
||||||
|
|
||||||
|
$service->handleIndexCache();
|
||||||
|
|
||||||
|
return $this->jsonSuccess(['msg' => '更新缓存成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->view->pick('util/index_cache');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -14,6 +14,7 @@ class AuthNode extends Service
|
|||||||
$nodes[] = $this->getFinanceNodes();
|
$nodes[] = $this->getFinanceNodes();
|
||||||
$nodes[] = $this->getUserNodes();
|
$nodes[] = $this->getUserNodes();
|
||||||
$nodes[] = $this->getSettingNodes();
|
$nodes[] = $this->getSettingNodes();
|
||||||
|
$nodes[] = $this->getUtilNodes();
|
||||||
|
|
||||||
return $nodes;
|
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',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
40
app/Http/Admin/Services/Util.php
Normal file
40
app/Http/Admin/Services/Util.php
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Admin\Services;
|
||||||
|
|
||||||
|
use App\Caches\IndexSlideList as IndexSlideListCache;
|
||||||
|
use App\Services\Utils\IndexCourseCache as IndexCourseCacheUtil;
|
||||||
|
|
||||||
|
class Util extends Service
|
||||||
|
{
|
||||||
|
|
||||||
|
public function handleIndexCache()
|
||||||
|
{
|
||||||
|
$items = $this->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');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
89
app/Http/Admin/Views/util/index_cache.volt
Normal file
89
app/Http/Admin/Views/util/index_cache.volt
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
{% extends 'templates/main.volt' %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<form class="layui-form kg-form" method="POST" action="{{ url({'for':'admin.util.index_cache'}) }}">
|
||||||
|
<fieldset class="layui-elem-field layui-field-title">
|
||||||
|
<legend>首页缓存</legend>
|
||||||
|
</fieldset>
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<label class="layui-form-label">轮播图</label>
|
||||||
|
<div class="layui-input-block">
|
||||||
|
<input type="radio" name="items[slide]" value="1" title="是">
|
||||||
|
<input type="radio" name="items[slide]" value="0" title="否" checked="checked">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<label class="layui-form-label">推荐课程</label>
|
||||||
|
<div class="layui-input-block">
|
||||||
|
<input type="radio" name="items[featured_course]" value="1" title="是">
|
||||||
|
<input type="radio" name="items[featured_course]" value="0" title="否" checked="checked">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<label class="layui-form-label">新上课程</label>
|
||||||
|
<div class="layui-input-block">
|
||||||
|
<input type="radio" name="items[new_course]" value="1" title="是">
|
||||||
|
<input type="radio" name="items[new_course]" value="0" title="否" checked="checked">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<label class="layui-form-label">免费课程</label>
|
||||||
|
<div class="layui-input-block">
|
||||||
|
<input type="radio" name="items[free_course]" value="1" title="是">
|
||||||
|
<input type="radio" name="items[free_course]" value="0" title="否" checked="checked">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<label class="layui-form-label">会员课程</label>
|
||||||
|
<div class="layui-input-block">
|
||||||
|
<input type="radio" name="items[vip_course]" value="1" title="是">
|
||||||
|
<input type="radio" name="items[vip_course]" value="0" title="否" checked="checked">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<label class="layui-form-label"></label>
|
||||||
|
<div class="layui-input-block">
|
||||||
|
<button class="layui-btn" lay-submit="true" lay-filter="go">刷新</button>
|
||||||
|
<button type="button" class="kg-back layui-btn layui-btn-primary">返回</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block inline_js %}
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
layui.use(['jquery', 'form', 'layer'], function () {
|
||||||
|
|
||||||
|
var $ = layui.jquery;
|
||||||
|
var form = layui.form;
|
||||||
|
var layer = layui.layer;
|
||||||
|
|
||||||
|
form.on('submit(back_verify)', function (data) {
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
url: data.form.action,
|
||||||
|
data: data.field,
|
||||||
|
success: function (res) {
|
||||||
|
if (res.code === 0) {
|
||||||
|
$('#back-verify-btn').remove();
|
||||||
|
$('#back-verify-tips').removeClass('layui-hide');
|
||||||
|
}
|
||||||
|
layer.msg(res.msg, {icon: 1});
|
||||||
|
},
|
||||||
|
error: function (xhr) {
|
||||||
|
var json = JSON.parse(xhr.responseText);
|
||||||
|
layer.msg(json.msg, {icon: 2});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{% endblock %}
|
53
app/Services/Utils/IndexCourseCache.php
Normal file
53
app/Services/Utils/IndexCourseCache.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Utils;
|
||||||
|
|
||||||
|
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\Services\Service;
|
||||||
|
|
||||||
|
class IndexCourseCache extends Service
|
||||||
|
{
|
||||||
|
|
||||||
|
public function rebuild($section = null)
|
||||||
|
{
|
||||||
|
$site = $this->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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user