UpgradeController.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. Doo::loadModelAt('aconfig', 'admin');
  3. /**
  4. * MainController
  5. * Feel free to delete the methods and replace them with your own code.
  6. *
  7. * @author NoNZero
  8. */
  9. class UpgradeController extends DooController
  10. {
  11. private $data, $modelconfig, $onoff = array('on', 'off');
  12. public function __construct()
  13. {
  14. $this->data['rootUrl'] = Doo::conf()->APP_URL;
  15. $this->modelconfig = new AConfig();
  16. }
  17. public function getWebVersion()
  18. {
  19. exit(json_encode(array('version' => DOO::conf()->ver), JSON_UNESCAPED_UNICODE));
  20. }
  21. public function getVersionAndStatus()
  22. {
  23. header("Access-Control-Allow-Origin: *");
  24. $onoff = $this->modelconfig->getOne(array('select' => 'onoff', 'asArray' => TRUE))['onoff'];
  25. exit(json_encode(array('version' => DOO::conf()->ver, 'onoff' => $onoff), JSON_UNESCAPED_UNICODE));
  26. }
  27. public function getSoftwareVersion()
  28. {
  29. echo json_encode(array('status' => 'TRUE', 'msg' => ''), JSON_UNESCAPED_UNICODE);
  30. }
  31. public function setOnOff()
  32. {
  33. echo json_encode(array('status' => 'TRUE', 'msg' => ''), JSON_UNESCAPED_UNICODE);
  34. }
  35. public function getSwitchStatus()
  36. {
  37. $onoff = $this->modelconfig->getOne(array('select' => 'onoff', 'asArray' => TRUE))['onoff'];
  38. echo json_encode(array('onoff' => $onoff), JSON_UNESCAPED_UNICODE);
  39. die();
  40. }
  41. public function setSwitchStatus()
  42. {
  43. header("Access-Control-Allow-Origin: *");
  44. if (in_array($this->params['onoff'], $this->onoff)) {
  45. if ($this->params['onoff'] == 'on') {
  46. $this->modelconfig->onoff = 0;
  47. $stronoff = $this->modelconfig->update(array('where' => 'conid=1'));
  48. } else {
  49. $this->modelconfig->onoff = 1;
  50. $stronoff = $this->modelconfig->update(array('where' => 'conid=1',));
  51. }
  52. }
  53. echo json_encode(array('onoff' => $stronoff), JSON_UNESCAPED_UNICODE);
  54. die();
  55. }
  56. public function setUpgradeInfo()
  57. {
  58. // error_log(var_dump($_POST, TRUE), 3, '/opt/html/dev/data/sss.txt');
  59. // if (in_array($this->params['onoff'], $this->onoff)) {
  60. // if ($this->params['onoff'] == 'on') {
  61. $this->modelconfig->upgradeinfo = $_POST['json'];
  62. $stronoff = $this->modelconfig->update(array('where' => 'conid=1'));
  63. // }
  64. // }
  65. echo json_encode(array('onoff' => $stronoff), JSON_UNESCAPED_UNICODE);
  66. die();
  67. }
  68. public function fileUpload(){
  69. Doo::loadClass('actmeasure');
  70. Doo::loadClass('change');
  71. Doo::loadClass('Hashids/Hashids');
  72. $actmeasure = new actMeasure();
  73. $change = new Changes();
  74. $__hashids = new Hashids\Hashids('jlzffileid', 8);
  75. $cfuhashids = new Hashids\Hashids('cfileupload', 15);
  76. // session_write_close();
  77. // if(isset($_POST['sessionid'])){
  78. // session_id($_POST['sessionid']);
  79. // setcookie('PHPSESSID',$_POST['sessionid']);
  80. // session_start();
  81. // }
  82. if(!isset($this->params['pmid']) && !is_numeric($this->params['pmid']) && !isset($_POST['uid']) && !isset($_POST['verification'])){
  83. exit(json_encode(array('success' => false, 'msg' => '参数有误')));
  84. }
  85. $pmArray = $actmeasure->getRowByPmid($this->params['pmid']);
  86. if(empty($pmArray)){
  87. exit(json_encode(array('success' => false, 'msg' => '不存在此标段,无法上传')));
  88. }
  89. $verifiction = $cfuhashids->decode($_POST['verification']);
  90. if($verifiction[0] != $this->params['pmid'] || $verifiction[1] != $_POST['uid']){
  91. exit(json_encode(array('success' => false, 'msg' => '用户上传权限验证有误')));
  92. }
  93. Doo::loadClass('extras/Uploader');
  94. $files = array();
  95. $upload_dir = Doo::conf()->SITE_PATH . 'cfiles/';
  96. $uploader = new FileUpload('uploadfile');
  97. $intime = time();
  98. $extPathdir = $upload_dir.date('Y/md/',$intime);
  99. if (!$this->dir_create2($extPathdir)) {
  100. $status = array('success' => FALSE, 'msg' => '文件夹创建失败');
  101. echo json_encode($status, JSON_UNESCAPED_UNICODE);
  102. die();
  103. }
  104. $files['filename'] = $uploader->getFileNameWithoutExt();
  105. $files['fileext'] = $uploader->getExtension();
  106. $files['filesize'] = $uploader->getFileSize();
  107. $filepath = date('Ymdhis',$intime) . rand(100, 999) . '.' . $files['fileext'];
  108. $uploader->newFileName = $filepath;
  109. $files['filepath'] = 'cfiles/'.date('Y/md/',$intime).$filepath;
  110. $result = $uploader->handleUpload($extPathdir);
  111. if (!$result) {
  112. exit(json_encode(array('success' => false, 'msg' => $uploader->getErrorMsg())));
  113. }
  114. $files['pid'] = $pmArray['pid'];
  115. $files['stid'] = $pmArray['stid'];
  116. $files['pmid'] = $pmArray['pmid'];
  117. $files['cid'] = isset($this->params['cid']) && is_numeric($this->params['cid']) ? $this->params['cid'] : 0;
  118. $files['uid'] = $_POST['uid'];
  119. $files['intime'] = $intime;
  120. $result2 = $change->insertChangeAtt($files);
  121. if(empty($result2)){
  122. exit(json_encode(array('success' => false, 'msg' => '添加到数据库发生错误')));
  123. }
  124. $files2 = array();
  125. $files2['id'] = $result2;
  126. //加密下载的id
  127. $fid = $__hashids->encode($result2);
  128. $files2['downurl'] = '/change/file/download/'.$fid;
  129. $files2['filename'] = $files['filename'].'.'.$files['fileext'];
  130. $files2['time'] = date('Y-m-d H:i',$intime);
  131. $files2['size'] = $this->changefilesize($files['filesize']);
  132. echo json_encode(array('success' => true, 'files' => $files2));
  133. }
  134. function dir_create2($path, $mode = 0777)
  135. {
  136. if (is_dir($path))
  137. return TRUE;
  138. $path = $this->dir_path($path);
  139. $parent = dirname($path);
  140. if (!is_dir($parent)){
  141. @mkdir($parent, 0777);
  142. @chmod($parent, 0777);
  143. }
  144. @mkdir($path, 0777);
  145. @chmod($path, 0777);
  146. return is_dir($path);
  147. }
  148. function dir_path($path)
  149. {
  150. $path = str_replace('\\', '/', $path);
  151. if (substr($path, -1) != '/')
  152. $path = $path . '/';
  153. return $path;
  154. }
  155. //字节转换
  156. function changefilesize($value){
  157. $units = array(' B', ' KB', ' MB', ' GB', ' TB');
  158. for ($i = 0; $value >= 1024 && $i < 4; $i++) $value /= 1024;
  159. return round($value, 2).$units[$i];
  160. }
  161. }