2020-09-12 17:22:43 +08:00
|
|
|
<?php
|
|
|
|
namespace catchAdmin\system\controller;
|
|
|
|
|
2020-10-12 14:00:40 +08:00
|
|
|
use catchAdmin\permissions\model\Permissions;
|
2020-09-12 17:22:43 +08:00
|
|
|
use catcher\base\CatchController;
|
|
|
|
use catcher\CatchResponse;
|
|
|
|
use catcher\CatchAdmin;
|
|
|
|
use catcher\library\InstallCatchModule;
|
|
|
|
use catcher\library\InstallLocalModule;
|
2020-09-12 18:35:31 +08:00
|
|
|
use think\response\Json;
|
2020-09-12 17:22:43 +08:00
|
|
|
|
|
|
|
class Module extends CatchController
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 模块列表
|
|
|
|
*
|
2020-09-12 18:35:31 +08:00
|
|
|
* @return Json
|
2020-09-12 17:22:43 +08:00
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
$modules = [];
|
|
|
|
|
|
|
|
foreach(CatchAdmin::getModulesDirectory() as $d) {
|
|
|
|
$modules[] = json_decode(file_get_contents($d . 'module.json'), true);
|
|
|
|
}
|
|
|
|
|
2020-10-12 14:00:40 +08:00
|
|
|
$hasModules = array_unique(Permissions::whereIn('id', request()->user()->getPermissionsBy())->column('module'));
|
|
|
|
|
2020-09-12 18:35:31 +08:00
|
|
|
$orders = array_column($modules, 'order');
|
|
|
|
|
|
|
|
array_multisort($orders, SORT_DESC, $modules);
|
2020-09-12 17:22:43 +08:00
|
|
|
|
2020-10-12 14:00:40 +08:00
|
|
|
foreach ($modules as $k => $module) {
|
|
|
|
if (!in_array($module['alias'], $hasModules)) {
|
|
|
|
unset($modules[$k]);
|
|
|
|
}
|
|
|
|
}
|
2020-09-12 17:22:43 +08:00
|
|
|
|
2020-10-12 14:00:40 +08:00
|
|
|
return CatchResponse::success(array_values($modules));
|
|
|
|
}
|
2020-09-12 17:22:43 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 禁用/启用模块
|
|
|
|
*
|
|
|
|
* @param string $module
|
2020-09-12 18:35:31 +08:00
|
|
|
* @return Json
|
|
|
|
* @throws \think\db\exception\DbException
|
|
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
|
|
* @throws \think\db\exception\DataNotFoundException
|
2020-09-12 17:22:43 +08:00
|
|
|
*/
|
2020-09-12 18:35:31 +08:00
|
|
|
public function disOrEnable(string $module)
|
2020-09-12 17:22:43 +08:00
|
|
|
{
|
|
|
|
$moduleInfo = CatchAdmin::getModuleInfo(CatchAdmin::directory() . $module);
|
|
|
|
|
|
|
|
$install = new InstallLocalModule($module);
|
|
|
|
if (!$moduleInfo['enable']) {
|
|
|
|
$install->findModuleInPermissions() ? $install->enableModule() : $install->done();
|
|
|
|
} else {
|
|
|
|
$install->disableModule();
|
|
|
|
}
|
|
|
|
|
|
|
|
return CatchResponse::success();
|
|
|
|
}
|
2020-09-22 11:14:51 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 缓存
|
|
|
|
*
|
|
|
|
* @time 2020年09月21日
|
|
|
|
* @return Json
|
|
|
|
*/
|
|
|
|
public function cache()
|
|
|
|
{
|
|
|
|
return CatchResponse::success(CatchAdmin::cacheServices());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 清理缓存
|
|
|
|
*
|
|
|
|
* @time 2020年09月21日
|
|
|
|
* @return Json
|
|
|
|
*/
|
|
|
|
public function clear()
|
|
|
|
{
|
|
|
|
return !file_exists(CatchAdmin::getCacheServicesFile()) ?
|
|
|
|
CatchResponse::fail('模块没有缓存') :
|
|
|
|
CatchResponse::success(unlink(CatchAdmin::getCacheServicesFile()));
|
|
|
|
}
|
2020-09-12 17:22:43 +08:00
|
|
|
}
|