diff --git a/app/admin/controller/Addons.php b/app/admin/controller/Addons.php index e6a1e35..f188fea 100644 --- a/app/admin/controller/Addons.php +++ b/app/admin/controller/Addons.php @@ -3,6 +3,7 @@ namespace app\admin\controller; use app\common\controller\AdminController; use app\common\lib\SqlFile; +use think\Exception; use think\facade\View; use think\facade\Request; use think\facade\Config; @@ -302,28 +303,25 @@ class Addons extends AdminController return json(['code' => 0, 'msg' => '插件卸载成功']); } - - //启用插件 - public function start() - { - $name = input('name'); - $arr = ['status' => 1]; - //$res = get_addons_info($name); - //$res = get_addons_instance($name); - $res = set_addons_info($name,$arr); - return json(['code'=>0,'msg'=>$name.'插件已启用']); - - } - - //暂停插件 - public function shutDown() - { - $name = input('name'); - $arr = ['status' => 0]; - $res = set_addons_info($name,$arr); - return json(['code'=>-1,'msg'=>$name.'插件已禁用']); - - } + + // 启用禁用插件 + public function status(){ + $name = input('name'); + $info = get_addons_info($name); + try{ + $arr = ['status' => $info['status'] ? 0 :1]; + set_addons_info($name,$arr); + if($arr['status']) { + $res = ['code'=>0,'msg'=>'启用成功']; + } else { + $res = ['code'=>0,'msg'=>'已被禁用']; + } + } catch (\Exception $e) { + throw new Exception($e->getMessage()); + } + + return json($res); + } //配置插件 public function config($name) diff --git a/app/admin/controller/Menu.php b/app/admin/controller/Menu.php index b3ed64d..5d19337 100644 --- a/app/admin/controller/Menu.php +++ b/app/admin/controller/Menu.php @@ -2,10 +2,59 @@ namespace app\admin\controller; use app\common\controller\AdminController; +use think\facade\Db; class Menu extends AdminController { public function index(){ return view(); } + + + /** + * 动态菜单并排序 + * @return \think\response\Json + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getMenuNavbar() + { + $pid = empty(input('id')) ? 0 : input('id'); + $data = Db::name('auth_rule')->field('id,title,icon,name,sort')->where(['delete_time'=> 0,'status'=> 1,'ismenu'=>1,'pid'=>$pid])->select(); + $tree = []; + foreach ($data as $k => $v) { + $hasChild = $this->hasChildren($v['id']); + if($hasChild) { + $v['hasChildren'] = 1; + } else { + $v['hasChildren'] = 0; + } + $tree[] = ['id'=>$v['id'],'text'=>$v['title'],'icon'=>$v['icon'],'hasChildren'=>$v['hasChildren'],'href'=>(string) url($v['name']),'sort'=>$v['sort']]; + } + // 排序 + $cmf_arr = array_column($tree, 'sort'); + array_multisort($cmf_arr, SORT_ASC, $tree); + + return json($tree); + } + + /** + * 是否有子菜单 + * @param $pid + * @return bool + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function hasChildren($pid) + { + $data = Db::name('auth_rule')->field('pid')->where(['delete_time'=> 0,'status'=> 1,'ismenu'=>1,'pid'=>$pid])->select()->toArray(); + if(count($data)) { + return true; + } else { + return false; + } + + } } \ No newline at end of file diff --git a/app/admin/controller/Upgrade.php b/app/admin/controller/Upgrade.php index 0a508a1..a65dd4d 100644 --- a/app/admin/controller/Upgrade.php +++ b/app/admin/controller/Upgrade.php @@ -160,10 +160,7 @@ class Upgrade extends AdminController } //把远程文件放入本地 - - //拼接路径 - //$upload_dir = substr($this->upload_dir,-1) == '/' ? $this->upload_dir : $this->upload_dir.'/'; - $upload_dir = Files::getDirPath($this->upload_dir); + $upload_dir = Files::getDirPath($this->upload_dir); //拼接路径 Files::mkdirs($upload_dir); $package_file = $upload_dir.'taoler_'.$version_num.'.zip'; //升级的压缩包文件 @@ -211,15 +208,12 @@ class Upgrade extends AdminController //清理缓存 $this->clearSysCache(); - - //更新版本 - //Db::name('system')->update(['sys_version_num'=>$version_num,'id'=>1]); $value = [ 'version' => $version_num ]; $res = SetArr::name('taoler')->edit($value); - if($res == false){ + if(!$res){ return json(['code'=>-1,'msg'=>'代码更新成功,但版本写入失败']); } @@ -227,9 +221,11 @@ class Upgrade extends AdminController } - /**升级执行 + /** + * 升级执行 * @param string $package_file * @return \think\response\Json + * @throws \Exception */ private function execute_update(string $package_file) { @@ -246,7 +242,16 @@ class Upgrade extends AdminController //$package_name = str_replace('.zip','',$package_file); Log::channel('update')->info('update:{type} {progress} {msg}',['type'=>'success','progress'=>'50%','msg'=>'升级文件解压成功!']); - + + //升级sql操作 + $upSql = $zipPath.'runtime/update.sql'; + if(file_exists($upSql)) { + SqlFile::dbExecute($upSql); + //删除sql语句 + unlink($upSql); + } + + //升级PHP if(is_dir($zipPath)) { //升级前的写入文件权限检查 @@ -288,13 +293,7 @@ class Upgrade extends AdminController } - //升级sql操作 - $upSql = $zipPath.'runtime/update.sql'; - if(file_exists($upSql)) { - SqlFile::dbExecute($upSql); - //删除sql语句 - unlink($upSql); - } + Log::channel('update')->info('update:{type} {progress} {msg}',['type'=>'success','progress'=>'100%','msg'=>'升级成功!']); //更新系统的版本号了 diff --git a/app/admin/view/addons/index.html b/app/admin/view/addons/index.html index 5edaafd..a59796c 100644 --- a/app/admin/view/addons/index.html +++ b/app/admin/view/addons/index.html @@ -15,12 +15,13 @@ +