123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- <?php
- // +----------------------------------------------------------------------
- // | ThinkAdmin
- // +----------------------------------------------------------------------
- // | 版权所有 2014~2020 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
- // +----------------------------------------------------------------------
- // | 官方网站: https://thinkadmin.top
- // +----------------------------------------------------------------------
- // | 开源协议 ( https://mit-license.org )
- // +----------------------------------------------------------------------
- // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
- // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
- // +----------------------------------------------------------------------
- namespace app\admin\controller\api;
- use think\admin\Controller;
- use think\admin\service\AdminService;
- use think\admin\service\SystemService;
- use think\exception\HttpResponseException;
- /**
- * 通用插件管理
- * Class Plugs
- * @package app\admin\controller\api
- */
- class Plugs extends Controller
- {
- /**
- * 系统图标选择器
- */
- public function icon()
- {
- $this->title = '图标选择器';
- $this->field = input('field', 'icon');
- $this->fetch(realpath(__DIR__ . '/../../view/api/icon.html'));
- }
- /**
- * 网站压缩发布
- * @login true
- */
- public function push()
- {
- try {
- if (AdminService::instance()->isSuper()) {
- SystemService::instance()->pushRuntime();
- $this->success('网站缓存加速成功!');
- } else {
- $this->error('只有超级管理员才能操作!');
- }
- } catch (HttpResponseException $exception) {
- throw $exception;
- } catch (\Exception $exception) {
- $this->error($exception->getMessage());
- }
- }
- /**
- * 清理运行缓存
- * @login true
- */
- public function clear()
- {
- try {
- if (AdminService::instance()->isSuper()) {
- SystemService::instance()->clearRuntime();
- $this->success('清理网站缓存成功!');
- } else {
- $this->error('只有超级管理员才能操作!');
- }
- } catch (HttpResponseException $exception) {
- throw $exception;
- } catch (\Exception $exception) {
- $this->error($exception->getMessage());
- }
- }
- /**
- * 数据变更日志
- * @login true
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function oplog()
- {
- if (AdminService::instance()->isSuper()) {
- $data = $this->_vali([
- 'state.in:0,1' => '状态值范围错误!',
- 'state.require' => '状态值不能为空!',
- ]);
- sysconf('base.oplog_state', $data['state']);
- $this->success('数据变更日志切换成功!');
- } else {
- $this->error('只有超级管理员才能操作!');
- }
- }
- /**
- * 当前运行模式
- * @login true
- */
- public function debug()
- {
- if (AdminService::instance()->isSuper()) {
- if (input('state')) {
- SystemService::instance()->productMode(true);
- $this->success('已切换为生产模式!');
- } else {
- SystemService::instance()->productMode(false);
- $this->success('已切换为开发模式!');
- }
- } else {
- $this->error('只有超级管理员才能操作!');
- }
- }
- /**
- * 优化数据库
- * @login true
- */
- public function optimize()
- {
- if (AdminService::instance()->isSuper()) {
- $this->_queue('优化数据库所有数据表', 'xadmin:database optimize', 0, [], 0, 0);
- } else {
- $this->error('只有超级管理员才能操作!');
- }
- }
- /**
- * 清理系统配置
- * @login true
- */
- public function clearConfig()
- {
- if (AdminService::instance()->isSuper()) try {
- $this->app->db->transaction(function () {
- [$tmpdata, $alldata] = [[], []];
- foreach ($this->app->db->name('SystemConfig')->cursor() as $item) {
- $tmpdata[$item['type']][$item['name']] = $item['value'];
- ksort($tmpdata[$item['type']]);
- }
- ksort($tmpdata);
- foreach ($tmpdata as $type => $items) foreach ($items as $name => $value) {
- $alldata[] = ['type' => $type, 'name' => $name, 'value' => $value];
- }
- $this->app->db->name('SystemConfig')->whereRaw('1=1')->delete();
- $this->app->db->name('SystemConfig')->insertAll($alldata);
- });
- $this->app->cache->delete('SystemConfig');
- $GLOBALS['oplogs'] = [];
- $this->success('清理系统配置成功!');
- } catch (HttpResponseException $exception) {
- throw $exception;
- } catch (\Exception $exception) {
- $this->error($exception->getMessage());
- } else {
- $this->error('只有超级管理员才能操作!');
- }
- }
- }
|