diff --git a/app/BaseController.php b/app/BaseController.php index f3d35a3..0de3c8d 100644 --- a/app/BaseController.php +++ b/app/BaseController.php @@ -100,102 +100,6 @@ abstract class BaseController return $v->failException(true)->check($data); } - /** - * 操作错误跳转 - * @param mixed $msg 提示信息 - * @param string $url 跳转的URL地址 - * @param mixed $data 返回的数据 - * @param integer $wait 跳转等待时间 - * @param array $header 发送的Header信息 - * @return void - */ - protected function error($msg = '', string $url = null, $data = '', int $wait = 3, array $header = []): Response - { - if (is_null($url)) { - $url = request()->isAjax() ? '' : 'javascript:history.back(-1);'; - } elseif ($url) { - $url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : app('route')->buildUrl($url); - } - - $result = [ - 'code' => 0, - 'msg' => $msg, - 'data' => $data, - 'url' => $url, - 'wait' => $wait, - ]; - - $type = (request()->isJson() || request()->isAjax()) ? 'json' : 'html'; - if ('html' == strtolower($type)) { - $type = 'jump'; - } - - $response = Response::create($result, $type)->header($header)->options(['jump_template' => app('config')->get('app.dispatch_error_tmpl')]); - - throw new HttpResponseException($response); - } - - /** - * 返回封装后的API数据到客户端 - * @param mixed $data 要返回的数据 - * @param integer $code 返回的code - * @param mixed $msg 提示信息 - * @param string $type 返回数据格式 - * @param array $header 发送的Header信息 - * @return Response - */ - protected function result($data, int $code = 0, $msg = '', string $type = '', array $header = []): Response - { - $result = [ - 'code' => $code, - 'msg' => $msg, - 'time' => time(), - 'data' => $data, - ]; - - $type = $type ?: 'json'; - $response = Response::create($result, $type)->header($header); - - throw new HttpResponseException($response); - } - - /** - * 操作成功跳转 - * @param mixed $msg 提示信息 - * @param string $url 跳转的URL地址 - * @param mixed $data 返回的数据 - * @param integer $wait 跳转等待时间 - * @param array $header 发送的Header信息 - * @return void - */ - protected function success($msg = '', string $url = null, $data = '', int $wait = 3, array $header = []): Response - { - if (is_null($url) && isset($_SERVER["HTTP_REFERER"])) { - $url = $_SERVER["HTTP_REFERER"]; - } elseif ($url) { - $url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : app('route')->buildUrl($url); - } - - $result = [ - 'code' => 1, - 'msg' => $msg, - 'data' => $data, - 'url' => $url, - 'wait' => $wait, - ]; - - $type = (request()->isJson() || request()->isAjax()) ? 'json' : 'html'; - // 把跳转模板的渲染下沉,这样在 response_send 行为里通过getData()获得的数据是一致性的格式 - if ('html' == strtolower($type)) { - $type = 'jump'; - } - - $response = Response::create($result, $type)->header($header)->options(['jump_template' => app('config')->get('app.dispatch_success_tmpl')]); - - throw new HttpResponseException($response); - } - - //显示网站设置 protected function getSystem() { diff --git a/app/admin/controller/addon/Addons.php b/app/admin/controller/addon/Addons.php index bec3001..3e39204 100644 --- a/app/admin/controller/addon/Addons.php +++ b/app/admin/controller/addon/Addons.php @@ -34,12 +34,6 @@ class Addons extends AdminController */ public function index() { -// if(Request::isAjax()) { -// $data = Request::param(); -// if(!isset($data['type'])) $data['type'] = 'onlineAddons'; -// if(!isset($data['selector'])) $data['selector'] = 'all'; -// return $this->getList($data); -// } return View::fetch(); } @@ -101,123 +95,6 @@ class Addons extends AdminController return json(['code' => -1, 'msg' => '未获取到服务器信息']); } - - /** - * 插件动态列表 - * @param $data - * @return Json - */ - public function getList() - { - $data = Request::param(); - if(!isset($data['type'])) $data['type'] = 'onlineAddons'; - if(!isset($data['selector'])) $data['selector'] = 'all'; - $res = []; - //本地插件列表 - $addonsList = Files::getDirName('../addons/'); - $response = HttpHelper::withHost()->get('/v1/addons'); - $addons = $response->toJson(); - switch($data['type']){ - //已安装 - case 'installed': - if($addonsList){ - $res = ['code'=>0,'msg'=>'','count'=>5]; - $res['col'] = [ - ['type' => 'numbers'], - ['field' => 'name','title'=> '插件', 'width'=> 120], - ['field'=> 'title','title'=> '标题', 'width'=> 100], - ['field'=> 'version','title'=> '版本', 'templet' => '
{{d.version}}
', 'width'=> 60], - ['field' => 'author','title'=> '作者', 'width'=> 80], - ['field' => 'description','title'=> '简介', 'minWidth'=> 200], - ['field' => 'install','title'=> '安装', 'width'=> 100], - ['field' => 'ctime','title'=> '到期时间', 'width'=> 100], - ['field' => 'status','title'=> '状态', 'width'=> 95, 'templet' => '#buttonStatus'], - ['title' => '操作', 'width'=> 150, 'align'=>'center', 'toolbar'=> '#addons-installed-tool'] - ]; - - // $data数据 - foreach($addonsList as $v){ - $info_file = '../addons/'.$v.'/info.ini'; - $info = parse_ini_file($info_file); - $info['show'] = $info['status'] ? '启用' : '禁用'; - $info['install'] = $info['status'] ? '是' : '否'; - $res['data'][] = $info; - } - - } else { - $res = ['code'=>-1,'msg'=>'没有安装任何插件']; - } - break; - //在线全部 - case 'onlineAddons': - if($response->ok()) { - - $res['code'] = 0; - $res['msg'] = ''; - $res['count'] = count($addons->data); - $res['col'] = [ - ['type' => 'numbers'], - ['field' => 'title','title'=> '插件', 'width'=> 200], - ['field' => 'description','title'=> '简介', 'minWidth'=> 200], - ['field' => 'author','title'=> '作者', 'width'=> 100], - ['field' => 'price','title'=> '价格(元)','width'=> 85], - ['field' => 'downloads','title'=> '下载', 'width'=> 70], - ['field' => 'version','title'=> '版本', 'templet' => '
{{d.version}} {{# if(d.have_newversion == 1){ }}{{# } }}
','width'=> 75], - ['field' => 'status','title'=> '在线', 'width'=> 70], - ['title' => '操作', 'width'=> 150, 'align'=>'center', 'toolbar'=> '#addons-tool'] - ]; - - // $data数据 与本地文件对比 - foreach($addons->data as $v){ - switch ($data['selector']) { - case 'free': - if($v->price == 0) { - if(in_array($v->name,$addonsList)) { - $info = get_addons_info($v->name); - //已安装 - $v->isInstall = 1; - //判断是否有新版本 - if($v->version > $info['version']) $v->have_newversion = 1; - $v->price = $v->price ? $v->price : '免费'; - } - $res['data'][] = $v; - } - break; - case 'pay': - if($v->price > 0) { - if(in_array($v->name,$addonsList)) { - $info = get_addons_info($v->name); - //已安装 - $v->isInstall = 1; - //判断是否有新版本 - if($v->version > $info['version']) $v->have_newversion = 1; - $v->price = $v->price ? $v->price : '免费'; - } - $res['data'][] = $v; - } - break; - case 'all': - if(in_array($v->name,$addonsList)) { - $info = get_addons_info($v->name); - //已安装 - $v->isInstall = 1; - //判断是否有新版本 - if($v->version > $info['version']) $v->have_newversion = 1; - $v->price = $v->price ? $v->price : '免费'; - } - $res['data'][] = $v; - break; - } - }; - - } else { - $res = ['code' => -1, 'msg' => '未获取到服务器信息']; - } - break; - } - return json($res); - } - /** * 安装&升级, * @param array $data @@ -423,10 +300,10 @@ class Addons extends AdminController } // 写入版本号 set_addons_info($data['name'],['version' =>$data['version']]); + return $installRes; } catch (\Exception $e) { return json(['code' => -1, 'msg' => $e->getMessage()]); } - return $res; } /** @@ -667,4 +544,20 @@ class Addons extends AdminController } + /** + * 检测已安装插件是否有新的插件版本 + * @param string $addons_name + * @param string $local_version + * @return bool + */ + public function checkHasNewVer(string $addons_name, string $local_version) :bool + { + // 在线插件 + $response = HttpHelper::withHost()->get('/v1/checkNewVersion', ['name' => $addons_name, 'version' => $local_version]); + $addons = $response->toJson(); + if($addons->code === 0) return true; + return false; + } + + } diff --git a/config/taoler.php b/config/taoler.php index 47098d2..6ad2362 100644 --- a/config/taoler.php +++ b/config/taoler.php @@ -16,7 +16,7 @@ return [ // 应用名,此项不可更改 'appname' => 'TaoLer', // 版本配置 - 'version' => '2.2.8', + 'version' => '2.2.9', // 加盐 'salt' => 'taoler', // 数据库备份目录