H5.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace app\shop\controller;
  11. use app\model\system\H5 as H5Model;
  12. use app\model\web\Config;
  13. use app\model\system\Upgrade;
  14. use app\model\web\DiyView as DiyViewModel;
  15. class H5 extends BaseShop
  16. {
  17. /**
  18. * 刷新前端代码
  19. */
  20. public function refreshH5()
  21. {
  22. if (request()->isAjax()) {
  23. $h5 = new H5Model();
  24. $res = $h5->refresh();
  25. $this->h5DomainName(); // 修改H5域名
  26. return $res;
  27. } else {
  28. $refresh_time = 0;
  29. if (file_exists('h5/refresh.log')) {
  30. $refresh_time = file_get_contents('h5/refresh.log');
  31. }
  32. $config_model = new Config();
  33. $config = $config_model->getH5DomainName($this->site_id);
  34. $this->assign('config', $config[ 'data' ][ 'value' ]);
  35. $this->assign('refresh_time', $refresh_time);
  36. $this->assign("root_url", __ROOT__);
  37. // 检测授权
  38. $upgrade_model = new Upgrade();
  39. $auth_info = $upgrade_model->authInfo();
  40. $this->assign('is_auth', ( $auth_info[ 'code' ] == 0 ));
  41. return $this->fetch('h5/refresh_h5');
  42. }
  43. }
  44. /**
  45. * h5域名配置
  46. */
  47. public function h5DomainName()
  48. {
  49. $config_model = new Config();
  50. $domain_name = input("domain", "");
  51. $deploy_way = input("deploy_way", "default");
  52. if ($deploy_way == 'default') {
  53. $domain_name = __ROOT__ . '/h5';
  54. }
  55. $result = $config_model->seth5DomainName([
  56. 'domain_name_h5' => $domain_name,
  57. 'deploy_way' => $deploy_way
  58. ]);
  59. return $result;
  60. }
  61. /**
  62. * 独立部署版下载
  63. */
  64. public function downloadSeparate()
  65. {
  66. if (strstr(ROOT_URL, 'niuteam.cn') === false) {
  67. $domain_name = input("domain", "");
  68. $h5 = new H5Model();
  69. $res = $h5->downloadH5Separate($domain_name);
  70. if (isset($res[ 'code' ]) && $res[ 'code' ] != 0) {
  71. $this->error($res[ 'message' ]);
  72. } else {
  73. $config_model = new Config();
  74. $config_model->seth5DomainName([
  75. 'domain_name_h5' => $domain_name,
  76. 'deploy_way' => 'separate'
  77. ]);
  78. }
  79. }
  80. }
  81. /**
  82. * 下载uniapp源码,混入所选模板代码
  83. * @return array|bool|int|mixed|void
  84. */
  85. public function downloadUniapp()
  86. {
  87. if (strstr(ROOT_URL, 'niuteam.cn') === false) {
  88. $app_info = config('info');
  89. $upgrade_model = new Upgrade();
  90. $res = $upgrade_model->downloadUniapp($app_info[ 'version_no' ]);
  91. if ($res[ 'code' ] == 0) {
  92. $filename = "upload/{$app_info['version_no']}_uniapp.zip";
  93. $res = file_put_contents($filename, base64_decode($res[ 'data' ]));
  94. $zip = new \ZipArchive();
  95. $zip->open($filename, \ZipArchive::CREATE);
  96. $zip->extractTo('upload/temp/standard_uniapp'); // 将压缩包解压到指定目录
  97. $zip->close();
  98. $diy_view = new DiyViewModel();
  99. // 混入当前所选模板的代码,进行编译
  100. $diy_view->compileUniApp([
  101. 'site_id' => $this->site_id
  102. ]);
  103. header("Content-Type: application/zip");
  104. header("Content-Transfer-Encoding: Binary");
  105. header("Content-Length: " . filesize($filename));
  106. header("Content-Disposition: attachment; filename=\"" . basename($filename) . "\"");
  107. readfile($filename);
  108. @unlink($filename);
  109. } else {
  110. $this->error($res[ 'message' ]);
  111. }
  112. }
  113. }
  114. }