appLibrary = new \app\admin\library\project\App; } /** * 获取已经安装的应用列表 * @return void */ public function getInstalledApp(){ $appList = $this->appLibrary->getInstallAppList(); $this->success("获取成功",$appList); } /** * 获取最新版本信息 * @return void */ public function newest(){ $newestVersion = $this->getNewestVersion(); if(!$newestVersion){ $this->error("获取版本信息失败"); } $this->success("获取成功",$newestVersion); } /** * 更新数据库文件 * @return void */ public function sql(){ $appTag = input('tag'); $license_token = input('license_token'); if(!$license_token){ $this->error("请登录授权账户后再更新"); } $versionData = $this->getNewestVersion(); if(!$versionData){ $this->error("获取更新文件失败"); } try { $client = \app\common\library\Client::getClient(); $response = $client->request("POST",'api/license/app/sql',[ 'form_params'=>[ 'token'=>$license_token, 'app_tag'=>$appTag, 'new_version'=>$versionData['version_new_no'], 'old_version'=>Cookie::get($appTag.'_old_app_version_no') ] ]); $body = $response->getBody(); $data = $body->getContents(); } catch (\Exception $e) { $this->error("请求失败"); } $data = json_decode($data,true); if(!$data || !isset($data['data'])){ $this->error("获取数据库数据失败"); } if($data['data']){ $result = $this->appLibrary->runsql($data['data']); if($result !== true){ return $this->error($result); } } $this->appLibrary->refreshAppVersion($appTag,$versionData['version_new_no']); $this->success("操作成功"); } /** * 检查应用是否已经安装 * @return void */ public function isInstall(){ $appTag = input('tag'); if(!$this->appLibrary->isInstall($appTag)){ $this->error("未安装"); } $this->success("已安装"); } /** * 下载更新文件 * @return void */ public function download(){ set_time_limit(0); ini_set('memory_limit', '512M'); $appTag = input('tag'); $license_token = input('license_token'); if(!$license_token){ $this->error("请在【系统】-【系统升级】中登录授权账户后再操作"); } $data = $this->getNewestVersion(); if(!$data){ $this->error("获取更新文件失败"); } if($data['package_url'] == 'un_login'){ $this->error("请在【系统】-【系统升级】中登录授权账户后再操作"); } //判断版本号 if(version_compare($data['version_new_no'],$this->appLibrary->getAppVersion($appTag))<=0){ $this->error("当前已是最新版"); } if(!$data['package_url'] || $data['package_url'] == 'un_auth'){ $this->error("暂无更新权限,请联系客服开通"); } Cookie::set($appTag.'_old_app_version_no',$this->appLibrary->getAppVersion($appTag),60000); $result = $this->appLibrary->download($data['package_url'],$this->getFilePath('zip_file',$appTag)); if($result !== true){ return $this->error($result); } return $this->success("操作成功"); } /** * 解压文件 * @return void */ public function unzip(){ $appTag = input('tag'); $result = $this->appLibrary->unzip($this->getFilePath('zip_file',$appTag),$this->getFilePath('root',$appTag)); if($result !== true){ return $this->error($result); } return $this->success("操作成功"); } /** * 获取文件地址 * @param $type * @return string|void */ protected function getFilePath($type,$appTag){ if($type == 'root'){ return $_SERVER['DOCUMENT_ROOT'] . '/../'; } if($type == 'zip_file'){ return $_SERVER['DOCUMENT_ROOT'] . '/../runtime/app/'.$appTag.'.zip'; } } /** * 远程获取最新版本信息 * @return false * @throws \GuzzleHttp\Exception\GuzzleException */ public function getNewestVersion(){ $license_token = input('license_token'); $appTag = input('tag'); try { $client = \app\common\library\Client::getClient(); $response = $client->request("POST",'api/license/app/newest',[ 'form_params'=>[ 'token'=>$license_token, 'app_tag'=>$appTag ] ]); $body = $response->getBody(); $data = $body->getContents(); } catch (\Exception $e) { return false; } $data = json_decode($data,true); if(!$data || !isset($data['data'])){ return false; } $data['data']['version_now'] = $this->appLibrary->getAppVersion($appTag); return $data['data']; } }