systemUpgrade.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  1. <?php
  2. namespace app\common\services;
  3. use app\common\helpers\Cache;
  4. use app\common\models\UniAccount;
  5. use Illuminate\Filesystem\Filesystem;
  6. use vierbergenlars\SemVer\version;
  7. class systemUpgrade
  8. {
  9. public $update;
  10. public $filesystem;
  11. public $downloadUrl;
  12. private $key;
  13. private $secret;
  14. public function __construct($key = '', $secret = '')
  15. {
  16. $this->key = $key;
  17. $this->secret = $secret;
  18. $this->update = new AutoUpdate();
  19. $this->filesystem = app(Filesystem::class);
  20. $this->downloadUrl = 'https://downloads.yunzmall.com';
  21. }
  22. /**
  23. * 删除非法文件
  24. */
  25. public function deleteFile()
  26. {
  27. //file-删除指定文件,file-空 删除目录下所有文件
  28. $files = [
  29. [
  30. 'path' => base_path('config'),
  31. 'ext' => ['php'],
  32. 'file' => [
  33. base_path('database/migrations/main-menu.php'),
  34. base_path('database/migrations/notice-template.php'),
  35. base_path('database/migrations/notice.php'),
  36. base_path('database/migrations/observer.php'),
  37. base_path('database/migrations/widget.php'),
  38. ]
  39. ],
  40. [
  41. 'path' => base_path('database/migrations'),
  42. 'ext' => ['php'],
  43. 'file' => [
  44. base_path('database/migrations/2018_10_18_150312_add_unique_to_yz_member_income.php')
  45. ]
  46. ],
  47. [
  48. 'path' => base_path('plugins/store-cashier/migrations'),
  49. 'ext' => ['php'],
  50. 'file' => [
  51. base_path('plugins/store-cashier/migrations/2018_11_26_174034_fix_address_store.php'),
  52. base_path('plugins/store-cashier/migrations/2017_08_03_170658_create_ims_yz_cashier_goods_table.php')
  53. ]
  54. ],
  55. [
  56. 'path' => base_path('plugins/supplier/migrations'),
  57. 'ext' => ['php'],
  58. 'file' => [
  59. base_path('plugins/supplier/migrations/2018_11_26_155528_update_ims_yz_order_and_goods.php')
  60. ]
  61. ],
  62. [
  63. 'path' => base_path(),
  64. 'file' => [
  65. base_path('manifest.xml'),
  66. base_path('map.json')
  67. ]
  68. ],
  69. [
  70. 'path' => base_path('vendor/james-heinrich/getid3/demos'),
  71. ],
  72. [
  73. 'path' => base_path('storage/app/auto-update/shop/vendor/james-heinrich/getid3/demos'),
  74. ]
  75. ];
  76. foreach ($files as $rows) {
  77. if (!is_dir($rows['path'])) {
  78. continue;
  79. }
  80. $scan_file = $this->filesystem->files($rows['path']);
  81. if (!empty($scan_file)) {
  82. foreach ($scan_file as $item) {
  83. if (!empty($rows['file'])) {
  84. foreach ($rows['file'] as $val) {
  85. if ($val == $item) {
  86. @unlink($item);
  87. }
  88. }
  89. } else {
  90. $file_info = pathinfo($item);
  91. if (!in_array($file_info['extension'], $rows['ext'])) {
  92. @unlink($item);
  93. }
  94. }
  95. }
  96. }
  97. }
  98. }
  99. /**
  100. * 执行迁移文件
  101. */
  102. public function runMigrate()
  103. {
  104. \Log::debug('----CLI----');
  105. $plugins_dir = $this->update->getDirsByPath('plugins', $this->filesystem);
  106. if (!empty($plugins_dir)) {
  107. \Artisan::call('update:version', ['version' => $plugins_dir]);
  108. }
  109. }
  110. /**
  111. * 更新本地前/后端版本号
  112. *
  113. * @param $updateList
  114. */
  115. public function setSystemVersion($updateList, $type = 1)
  116. {
  117. $version = $this->getFrontVersion($updateList);
  118. $str = file_get_contents(base_path('config/') . 'front-version.php');
  119. $str = preg_replace('/"[\d\.]+"/', '"' . $version . '"', $str);
  120. switch ($type) {
  121. case 1:
  122. file_put_contents(base_path('config/') . 'front-version.php', $str);
  123. break;
  124. case 2:
  125. file_put_contents(base_path('config/') . 'backend_version.php', $str);
  126. break;
  127. }
  128. }
  129. /**
  130. * 获取授权系统前端版本号
  131. *
  132. * @param $updateList
  133. * @return mixed
  134. */
  135. public function getFrontVersion($updateList)
  136. {
  137. rsort($updateList);
  138. $version = $updateList[0]['version'];
  139. return $version;
  140. }
  141. /**
  142. * 前端更新文件检测
  143. *
  144. * @param $key
  145. * @param $secret
  146. * @return array|null
  147. */
  148. public function frontendUpgrad($key, $secret)
  149. {
  150. $this->update->setUpdateFile('check_app.json');
  151. $this->update->setCurrentVersion(config('front-version'));
  152. $this->update->setUpdateUrl(config('auto-update.checkUrl')); //Replace with your server update directory
  153. $this->update->setBasicAuth($key, $secret);
  154. $this->update->checkUpdate();
  155. if ($this->update->newVersionAvailable()) {
  156. $list = $this->update->getUpdates();
  157. }
  158. krsort($list);
  159. return $list;
  160. }
  161. /**
  162. * 验证php版本
  163. *
  164. * @param $php_version
  165. * @return bool
  166. */
  167. public function checkPHPVersion($php_version)
  168. {
  169. if (version::lt($php_version, PHP_VERSION)) {
  170. return true;
  171. }
  172. return false;
  173. }
  174. /**
  175. * 迁移数据库信息
  176. */
  177. public function mvenv()
  178. {
  179. $database = config('database');
  180. $databaseSet = $database['connections'][$database['default']];
  181. $DB_HOST = $databaseSet['host'];
  182. $DB_USERNAME = $databaseSet['username'];
  183. $DB_PASSWORD = $databaseSet['password'];
  184. $DB_PORT = $databaseSet['port'];
  185. $DB_DATABASE = $databaseSet['database'];
  186. $DB_PREFIX = $databaseSet['prefix'];
  187. if (config('app.APP_Framework', false) == 'platform' && !empty($DB_HOST)) {
  188. $str = '<?php
  189. $config = array();
  190. $config[\'db\'][\'master\'][\'host\'] = \'' . $DB_HOST . '\';
  191. $config[\'db\'][\'master\'][\'username\'] = \'' . $DB_USERNAME . '\';
  192. $config[\'db\'][\'master\'][\'password\'] = \'' . $DB_PASSWORD . '\';
  193. $config[\'db\'][\'master\'][\'port\'] = \'' . $DB_PORT . '\';
  194. $config[\'db\'][\'master\'][\'database\'] = \'' . $DB_DATABASE . '\';
  195. $config[\'db\'][\'master\'][\'tablepre\'] = \'' . $DB_PREFIX . '\';
  196. $config[\'db\'][\'slave_status\'] = false;
  197. $config[\'db\'][\'slave\'][\'1\'][\'host\'] = \'\';
  198. $config[\'db\'][\'slave\'][\'1\'][\'username\'] = \'\';
  199. $config[\'db\'][\'slave\'][\'1\'][\'password\'] = \'\';
  200. $config[\'db\'][\'slave\'][\'1\'][\'port\'] = \'\';
  201. $config[\'db\'][\'slave\'][\'1\'][\'database\'] = \'\';
  202. $config[\'db\'][\'slave\'][\'1\'][\'tablepre\'] = \'\';
  203. ';
  204. $this->filesystem->put(base_path('database/config.php'), $str);
  205. if (file_exists(base_path('database/config.php'))) {
  206. $str = "APP_ENV=production
  207. APP_KEY=base64:2q7s0Z714xS1L1WNN/8dsB69XDqOb4Qdptgh4X2ZtZU=
  208. APP_DEBUG=true
  209. APP_LOG_LEVEL=debug
  210. APP_Framework=platform
  211. IS_WEB=/admin/shop
  212. ROOT_PATH=''
  213. EXTEND_DIR=''";
  214. $this->filesystem->put(base_path('.env'), $str);
  215. }
  216. }
  217. }
  218. /**
  219. * 下载venddor组件压缩包
  220. */
  221. public function downloadVendorZip()
  222. {
  223. $url = $this->downloadUrl . $this->getSysUpgrade() . '.zip';
  224. $tmp_path = base_path($this->getSysUpgrade() . '_' . date('Y-m-d') . '.zip');
  225. if (file_exists($tmp_path)) {
  226. return;
  227. }
  228. try {
  229. Utils::download($url, $tmp_path);
  230. \Log::debug('----vendor zip 下载ok----');
  231. } catch (\Exception $e) {
  232. \Log::debug('----vendor zip 下载失败----');
  233. }
  234. }
  235. /**
  236. * 解压vendor压缩包
  237. *
  238. * @return bool
  239. */
  240. public function unVendorZip()
  241. {
  242. ini_set("memory_limit", "-1"); //不限制内存
  243. ini_set('max_execution_time', '0');
  244. $path = base_path($this->getSysUpgrade() . '_' . date('Y-m-d') . '.zip');
  245. if (file_exists($path)) {
  246. $zip = new \ZipArchive();
  247. $res = $zip->open($path);
  248. if ($res === true) {
  249. try {
  250. $zip->extractTo(base_path());
  251. } catch (\Exception $e) {
  252. $zip->close();
  253. \Log::debug('----vendor zip 解压失败----');
  254. return false;
  255. }
  256. } else {
  257. $zip->close();
  258. \Log::debug('----vendor zip 下载失败----');
  259. return false;
  260. }
  261. $zip->close();
  262. \Log::debug('----vendor zip 解压ok----');
  263. return true;
  264. }
  265. }
  266. /**
  267. * 删除vendor压缩包
  268. */
  269. public function delVendorZip()
  270. {
  271. $path = base_path($this->getSysUpgrade() . '_' . date('Y-m-d') . '.zip');
  272. if (file_exists($path)) {
  273. @unlink($path);
  274. \Log::debug('----vendor zip 删除ok----');
  275. }
  276. }
  277. /**
  278. * 删除缓存配置文件
  279. */
  280. public function delConfig()
  281. {
  282. $path = base_path('bootstrap/cache/config.php');
  283. if (file_exists($path)) {
  284. @unlink($path);
  285. \Log::debug('----config 删除ok----');
  286. }
  287. }
  288. /**
  289. * 清理视图文件
  290. *
  291. * @param Filesystem|null $filesystem
  292. */
  293. public function clearCache(Filesystem $filesystem = null)
  294. {
  295. \Log::debug('----View Cache Flush----');
  296. if (is_null($filesystem)) {
  297. $filesystem = app(Filesystem::class);
  298. }
  299. $allfiles = $filesystem->allFiles(storage_path('framework/views'));
  300. foreach ($allfiles as $rows) {
  301. @unlink($rows->getPathname());
  302. }
  303. }
  304. /**
  305. * 清理缓存
  306. */
  307. public function createCache()
  308. {
  309. $request = request();
  310. \Artisan::call('config:cache');
  311. \Cache::flush();
  312. app()->instance('request', $request);
  313. }
  314. /**
  315. * 下载vendor组件包重命名
  316. *
  317. * @param bool $res
  318. */
  319. public function renameVendor($res = true)
  320. {
  321. \Log::debug('------renameVendor-------', [$res]);
  322. if ($res) {
  323. rename(base_path('vendor'), base_path('vendor_' . date('Y-m-d')));
  324. } else {
  325. rename(base_path('vendor_' . date('Y-m-d')), base_path('vendor'));
  326. }
  327. }
  328. /**
  329. * 删除本地vendor组件包
  330. *
  331. * @param $path
  332. * @return bool
  333. */
  334. public function delVendor($path)
  335. {
  336. \Log::debug('------delVendor-------');
  337. if (is_dir($path)) {
  338. $p = scandir($path);
  339. if (count($p) > 2) {
  340. foreach ($p as $val) {
  341. if ($val != "." && $val != "..") {
  342. if (is_dir($path . '/' . $val)) {
  343. $this->delVendor($path . '/' . $val . '/');
  344. } else {
  345. unlink($path . '/' . $val);
  346. }
  347. }
  348. }
  349. }
  350. }
  351. return rmdir($path);
  352. }
  353. /**
  354. * 设置更新的系统版本分支
  355. *
  356. * @param $ret
  357. */
  358. public function setSysUpgrade($ret)
  359. {
  360. Cache::put('sys_upgrade', $ret['upgrade'], 60);
  361. }
  362. /**
  363. * 获取系统版本分支
  364. *
  365. * @return mixed|string
  366. */
  367. public function getSysUpgrade()
  368. {
  369. if (Cache::has('sys_upgrade')) {
  370. return Cache::get('sys_upgrade');
  371. }
  372. return 'vendor';
  373. }
  374. /**
  375. * 设置vendor压缩包是否下载成功
  376. * @param $ret
  377. */
  378. public function setVendorZip($ret)
  379. {
  380. Cache::put('sys_vendor_zip', $ret['is_vendor_zip'], 60);
  381. }
  382. /**
  383. * 本地是否存在vendor压缩包
  384. *
  385. * @return false|mixed
  386. */
  387. public function isVendorZip()
  388. {
  389. if (!$this->getComposerStatus()) {
  390. return false;
  391. }
  392. if (Cache::has('sys_vendor_zip')) {
  393. return Cache::get('sys_vendor_zip');
  394. }
  395. return false;
  396. }
  397. /**
  398. * composer是否需要更新
  399. */
  400. public function setComposerStatus()
  401. {
  402. Cache::put('sys_composer_status', 1, 60);
  403. }
  404. /**
  405. * 获取composer状态
  406. *
  407. * @return false|mixed
  408. */
  409. public function getComposerStatus()
  410. {
  411. if (Cache::has('sys_composer_status')) {
  412. return Cache::get('sys_composer_status');
  413. }
  414. return false;
  415. }
  416. /**
  417. * 检查vendor压缩包下载文件是否有效
  418. *
  419. * @return bool
  420. */
  421. public function validateVendorZip()
  422. {
  423. $path = base_path($this->getSysUpgrade() . '_' . date('Y-m-d') . '.zip');
  424. if (file_exists($path) && filesize($path) > 0) {
  425. \Log::debug('--------validateVendorZip------');
  426. return true;
  427. }
  428. \Log::debug('--------no validateVendorZip------');
  429. return false;
  430. }
  431. /**
  432. * 获取本地前端版本
  433. *
  434. * @return \Illuminate\Config\Repository|\Illuminate\Contracts\Foundation\Application|mixed
  435. */
  436. public function getFrontendVersioin()
  437. {
  438. return config('front-version');
  439. }
  440. /**
  441. * 获取本地后端版本
  442. *
  443. * @return \Illuminate\Config\Repository|\Illuminate\Contracts\Foundation\Application|mixed
  444. */
  445. public function getBackendVersion()
  446. {
  447. return config('version');
  448. }
  449. /**
  450. * 授权数据
  451. *
  452. * @param $autoUpdate
  453. * @return mixed
  454. */
  455. public function OriginData($autoUpdate)
  456. {
  457. $autoUpdate->setUpdateFile('system_check.json');
  458. $res = $autoUpdate->remoteSystemVersion();
  459. return $res;
  460. }
  461. /**
  462. * 版本比较
  463. *
  464. * @param $autoUpdate
  465. * @return array
  466. */
  467. public function compareVersion($params)
  468. {
  469. $originBackendVersion = '未知';
  470. $originFrontendVersion = '未知';
  471. $hasUpgradeFile = 0;
  472. if (isset($params->result)) {
  473. $originBackendVersion = $params->result->backendVersion;
  474. $originFrontendVersion = $params->result->frontendVersion;
  475. }
  476. $localFrontendVersion = $this->getFrontendVersioin();
  477. $localBackendVersion = $this->getBackendVersion();
  478. if (version::eq($localFrontendVersion, $originFrontendVersion)) {
  479. $originFrontendVersion = '已经和本地版本一致';
  480. }
  481. if (version::eq($localBackendVersion, $originBackendVersion)) {
  482. $originBackendVersion = '已经和本地版本一致';
  483. }
  484. if ($originBackendVersion == '已经和本地版本一致' && $originFrontendVersion == '已经和本地版本一致') {
  485. $hasUpgradeFile = 1;
  486. }
  487. return [
  488. 'localBackendVersion' => $localBackendVersion,
  489. 'localFrontendVersion' => $localFrontendVersion,
  490. 'originBackendVersion' => $originBackendVersion,
  491. 'originFrontendVersion' => $originFrontendVersion,
  492. 'hasUpgradeFile' => $hasUpgradeFile
  493. ];
  494. }
  495. /**
  496. * 域名信息
  497. *
  498. * @param $params
  499. * @return array
  500. */
  501. public function domainInfo($params)
  502. {
  503. $domainStatus = 0;
  504. $currentDomain = rtrim(request()->getHost(), '/');
  505. $originDomain = '未知';
  506. if (isset($params->result)) {
  507. $originDomain = $params->result->authDomain;
  508. }
  509. if (strpos($currentDomain, $originDomain) !== false) {
  510. $domainStatus = 1;
  511. }
  512. switch ($domainStatus) {
  513. case 0:
  514. $domainStatusTxt = '不一致';
  515. break;
  516. case 1:
  517. $domainStatusTxt = '已授权';
  518. break;
  519. default:
  520. $domainStatusTxt = '未知';
  521. }
  522. return [
  523. 'originDomain' => $originDomain,
  524. 'domainStatus' => $domainStatus,
  525. 'domainStatusTxt' => $domainStatusTxt,
  526. 'currentDomain' => $currentDomain
  527. ];
  528. }
  529. /**
  530. * 授权插件信息
  531. *
  532. * @param $params
  533. * @return array
  534. */
  535. public function originPlugins($params)
  536. {
  537. $originAuthPlugins = '未知';
  538. $originAllPlugins = [];
  539. $tmp_authPlugins = [];
  540. $tmp_allPlugins = [];
  541. $noAuthPlugins = []; //未授权插件
  542. if (isset($params->result)) {
  543. $originAuthPlugins = $params->result->authPlugins;
  544. $originAllPlugins = $params->result->allPlugins;
  545. }
  546. foreach ($originAuthPlugins as $items) {
  547. $tmp_authPlugins[] = $items->name;
  548. }
  549. foreach ($originAllPlugins as $rows) {
  550. $tmp_allPlugins[] = $rows->name;
  551. }
  552. $noAuthPlugins = array_diff($tmp_allPlugins, $tmp_authPlugins);
  553. if (is_array($originAuthPlugins)) {
  554. $originAuthPlugins = count($originAuthPlugins);
  555. }
  556. return [
  557. 'originAuthPlugins' => $originAuthPlugins,
  558. 'noAuthPlugins' => $noAuthPlugins
  559. ];
  560. }
  561. /**
  562. * 本地安装插件
  563. *
  564. * @return array
  565. */
  566. public function localPlugins()
  567. {
  568. $localPlugins = [];
  569. $resource = opendir(base_path('plugins'));
  570. while ($file_name = @readdir($resource)) {
  571. if ($file_name == '.' || $file_name == '..')
  572. continue;
  573. $plugin_path = base_path('plugins') . '/' . $file_name;
  574. if (is_dir($plugin_path)) {
  575. $localPlugins[] = $file_name;
  576. }
  577. }
  578. closedir($resource);
  579. return $localPlugins;
  580. }
  581. /**
  582. * 插件信息
  583. *
  584. * @param $params
  585. * @return array
  586. */
  587. public function pluginsInfo($params)
  588. {
  589. //忽略
  590. $filter_plugins = ['wechat'];
  591. //未授权安装插件
  592. $localNoAuthPlugins = [];
  593. $originPlugins = $this->originPlugins($params);
  594. $localPlugins = $this->localPlugins();
  595. if (!empty($originPlugins['noAuthPlugins'])) {
  596. $localNoAuthPlugins = array_intersect($originPlugins['noAuthPlugins'], $localPlugins);
  597. $localNoAuthPlugins = array_diff($localNoAuthPlugins, $filter_plugins);
  598. }
  599. return [
  600. 'localInstallPlugins' => count($localPlugins),
  601. 'originAuthPlugins' => $originPlugins['originAuthPlugins'],
  602. 'localNoAuthPlugins' => count($localNoAuthPlugins)
  603. ];
  604. }
  605. /**
  606. * 商城是否允许更新
  607. *
  608. * @param $domainInfo
  609. * @param $pluginsInfo
  610. * @return int[]
  611. */
  612. public function systemStatus($domainInfo, $pluginsInfo)
  613. {
  614. $buttonStatus = 0; // 0-禁止更新;1-允许更新
  615. if ($domainInfo['domainStatus'] == 1 && $pluginsInfo['localNoAuthPlugins'] == 0) {
  616. $buttonStatus = 1;
  617. }
  618. return ['status' => $buttonStatus];
  619. }
  620. /**
  621. * 系统版本检测
  622. *
  623. * @param $autoUpdate
  624. * @return array|string[]
  625. */
  626. public function systemCheck($autoUpdate)
  627. {
  628. $data = [
  629. 'local_backend_version' => '未知',
  630. 'local_frontend_version' => '未知',
  631. 'origin_backend_version' => '未知',
  632. 'origin_frontend_version' => '未知',
  633. 'origin_domain' => '未知',
  634. 'current_domain' => '未知',
  635. 'domain_status_txt' => '未知',
  636. 'origin_plugins_count' => '未知',
  637. 'local_plugins_count' => '未知',
  638. 'no_auth_plugins' => '未知',
  639. 'upgrade_status' => '未知',
  640. 'service_time' => '未知'
  641. ];
  642. $res = $this->OriginData($autoUpdate);
  643. $origin = json_decode($res);
  644. if (!isset($origin->result)) {
  645. return $data;
  646. }
  647. $ver = $this->compareVersion($origin);
  648. $domainInfo = $this->domainInfo($origin);
  649. $pluginsInfo = $this->pluginsInfo($origin);
  650. $upgrade = $this->systemStatus($domainInfo, $pluginsInfo);
  651. $data = [
  652. 'local_backend_version' => $ver['localBackendVersion'],
  653. 'local_frontend_version' => $ver['localFrontendVersion'],
  654. 'origin_backend_version' => $ver['originBackendVersion'],
  655. 'origin_frontend_version' => $ver['originFrontendVersion'],
  656. 'hasUpgradeFile' => $ver['hasUpgradeFile'],
  657. 'origin_domain' => $domainInfo['originDomain'],
  658. 'current_domain' => $domainInfo['currentDomain'],
  659. 'domain_status_txt' => $domainInfo['domainStatusTxt'],
  660. 'origin_plugins_count' => $pluginsInfo['originAuthPlugins'],
  661. 'local_plugins_count' => $pluginsInfo['localInstallPlugins'],
  662. 'no_auth_plugins' => $pluginsInfo['localNoAuthPlugins'],
  663. 'upgrade_status' => $upgrade['status'],
  664. 'service_time' => $origin->result->remainingTime
  665. ];
  666. return $data;
  667. }
  668. /**
  669. * 更新日志
  670. *
  671. * @param $autoUpdate
  672. * @param $page
  673. * @return mixed
  674. */
  675. public function showLog($autoUpdate, $page)
  676. {
  677. $autoUpdate->setUpdateFile('show_log.json');
  678. $res = $autoUpdate->showLog($page);
  679. return $res;
  680. }
  681. /**
  682. * 企业管理前端更新
  683. *
  684. * @return void
  685. */
  686. public function business($version)
  687. {
  688. ini_set("memory_limit", "-1");
  689. ini_set('max_execution_time', '0');
  690. if (!file_exists(base_path('config/business_version.php')) || is_null($version)) {
  691. return false;
  692. }
  693. //验证
  694. if (version::lt(config('business_version'), $version) && $this->filesystem->isDirectory(base_path('plugins/business-pc'))) {
  695. //下载
  696. $path = base_path('business/business_font.zip');
  697. if (!file_exists($path)) {
  698. $url = $this->downloadUrl . '/company_backend/business_font.zip';
  699. try {
  700. Utils::download($url, $path);
  701. \Log::debug('----business zip 下载ok----');
  702. } catch (\Exception $e) {
  703. \Log::debug('----business zip 下载失败----');
  704. return;
  705. }
  706. }
  707. //删除本地文件
  708. if (file_exists($path)) {
  709. $this->filesystem->deleteDirectory(base_path('business/business_font'));
  710. \Log::debug('----business dir delete----');
  711. }
  712. //解压
  713. if (file_exists($path)) {
  714. $zip = new \ZipArchive();
  715. $res = $zip->open($path);
  716. if ($res === true) {
  717. try {
  718. $zip->extractTo(base_path('business'));
  719. } catch (\Exception $e) {
  720. $zip->close();
  721. \Log::debug('----business zip 解压失败----');
  722. return false;
  723. }
  724. } else {
  725. $zip->close();
  726. \Log::debug('----business zip 解压下载失败----');
  727. return false;
  728. }
  729. $zip->close();
  730. \Log::debug('----business zip 解压ok----');
  731. }
  732. //更新版本
  733. $str = file_get_contents(base_path('config/') . 'business_version.php');
  734. $str = preg_replace('/"[\d\.]+"/', '"' . $version . '"', $str);
  735. file_put_contents(base_path('config/') . 'business_version.php', $str);
  736. //删除压缩文件
  737. if (file_exists($path)) {
  738. @unlink($path);
  739. \Log::debug('----business zip 删除ok----');
  740. }
  741. }
  742. }
  743. }