SystemUpgradeclient.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\admin\controller\system;
  3. use app\admin\controller\AuthController;
  4. use crmeb\services\JsonService as Json;
  5. use crmeb\services\UpgradeService as uService;
  6. use think\facade\Db;
  7. /**
  8. * 在线升级控制器
  9. * Class SystemUpgradeclient
  10. * @package app\admin\controller\system
  11. *
  12. */
  13. class SystemUpgradeclient extends AuthController
  14. {
  15. protected $serverweb = array('version' => '1.0', 'version_code' => 0);//本站点信息
  16. public function initialize()
  17. {
  18. parent::initialize();
  19. //屏蔽所有错误避免操作文件夹发生错误提示
  20. ini_set('display_errors', 0);
  21. error_reporting(0);
  22. self::snyweninfo();//更新站点信息
  23. $this->assign(['auth' => self::isauth(), 'app' => uService::isWritable(app()->getRootPath()), 'extend' => uService::isWritable(EXTEND_PATH), 'public' => uService::isWritable(app()->getRootPath() . 'public')]);
  24. }
  25. //同步更新站点信息
  26. public function snyweninfo()
  27. {
  28. $this->serverweb['ip'] = $this->request->ip();
  29. $this->serverweb['host'] = $this->request->host();
  30. $this->serverweb['https'] = !empty($this->request->domain()) ? $this->request->domain() : sys_config('site_url');
  31. $this->serverweb['webname'] = sys_config('site_name');
  32. $local = uService::getVersion();
  33. if ($local['code'] == 200 && isset($local['msg']['version']) && isset($local['msg']['version_code'])) {
  34. $this->serverweb['version'] = uService::replace($local['msg']['version']);
  35. $this->serverweb['version_code'] = (int)uService::replace($local['msg']['version_code']);
  36. }
  37. uService::snyweninfo($this->serverweb);
  38. }
  39. //是否授权
  40. public function isauth()
  41. {
  42. return uService::isauth();
  43. }
  44. public function index()
  45. {
  46. $server = uService::start();
  47. $version = $this->serverweb['version'];
  48. $version_code = $this->serverweb['version_code'];
  49. $this->assign(compact('server', 'version', 'version_code'));
  50. return $this->fetch();
  51. }
  52. public function get_list()
  53. {
  54. $list = uService::request_post(uService::$isList, ['page' => input('post.page/d'), 'limit' => input('post.limit/d')]);
  55. if (is_array($list) && isset($list['code']) && isset($list['data']) && $list['code'] == 200) {
  56. $list = $list['data'];
  57. } else {
  58. $list = [];
  59. }
  60. Json::successful('ok', ['list' => $list, 'page' => input('post.page/d') + 1]);
  61. }
  62. public function get_new_version_conte()
  63. {
  64. $post = $this->request->post();
  65. if (!isset($post['id'])) Json::fail('缺少参数ID');
  66. $versionInfo = uService::request_post(uService::$NewVersionCount, ['id' => $post['id']]);
  67. if (isset($versionInfo['code']) && isset($versionInfo['data']['count']) && $versionInfo['code'] == 200) {
  68. return Json::successful(['count' => $versionInfo['data']['count']]);
  69. } else {
  70. return Json::fail('服务器异常');
  71. }
  72. }
  73. }