123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- <?php
- Doo::loadModelAt('aconfig', 'admin');
- /**
- * MainController
- * Feel free to delete the methods and replace them with your own code.
- *
- * @author NoNZero
- */
- class UpgradeController extends DooController
- {
- private $data, $modelconfig, $onoff = array('on', 'off');
- public function __construct()
- {
- $this->data['rootUrl'] = Doo::conf()->APP_URL;
- $this->modelconfig = new AConfig();
- }
- public function getWebVersion()
- {
- exit(json_encode(array('version' => DOO::conf()->ver), JSON_UNESCAPED_UNICODE));
- }
- public function getVersionAndStatus()
- {
- header("Access-Control-Allow-Origin: *");
- $onoff = $this->modelconfig->getOne(array('select' => 'onoff', 'asArray' => TRUE))['onoff'];
- exit(json_encode(array('version' => DOO::conf()->ver, 'onoff' => $onoff), JSON_UNESCAPED_UNICODE));
- }
- public function getSoftwareVersion()
- {
- echo json_encode(array('status' => 'TRUE', 'msg' => ''), JSON_UNESCAPED_UNICODE);
- }
- public function setOnOff()
- {
- echo json_encode(array('status' => 'TRUE', 'msg' => ''), JSON_UNESCAPED_UNICODE);
- }
- public function getSwitchStatus()
- {
- $onoff = $this->modelconfig->getOne(array('select' => 'onoff', 'asArray' => TRUE))['onoff'];
- echo json_encode(array('onoff' => $onoff), JSON_UNESCAPED_UNICODE);
- die();
- }
- public function setSwitchStatus()
- {
- header("Access-Control-Allow-Origin: *");
- if (in_array($this->params['onoff'], $this->onoff)) {
- if ($this->params['onoff'] == 'on') {
- $this->modelconfig->onoff = 0;
- $stronoff = $this->modelconfig->update(array('where' => 'conid=1'));
- } else {
- $this->modelconfig->onoff = 1;
- $stronoff = $this->modelconfig->update(array('where' => 'conid=1',));
- }
- }
- echo json_encode(array('onoff' => $stronoff), JSON_UNESCAPED_UNICODE);
- die();
- }
- public function setUpgradeInfo()
- {
- // error_log(var_dump($_POST, TRUE), 3, '/opt/html/dev/data/sss.txt');
- // if (in_array($this->params['onoff'], $this->onoff)) {
- // if ($this->params['onoff'] == 'on') {
- $this->modelconfig->upgradeinfo = $_POST['json'];
- $stronoff = $this->modelconfig->update(array('where' => 'conid=1'));
- // }
- // }
- echo json_encode(array('onoff' => $stronoff), JSON_UNESCAPED_UNICODE);
- die();
- }
- public function fileUpload(){
- Doo::loadClass('actmeasure');
- Doo::loadClass('change');
- Doo::loadClass('Hashids/Hashids');
- $actmeasure = new actMeasure();
- $change = new Changes();
- $__hashids = new Hashids\Hashids('jlzffileid', 8);
- $cfuhashids = new Hashids\Hashids('cfileupload', 15);
- // session_write_close();
- // if(isset($_POST['sessionid'])){
- // session_id($_POST['sessionid']);
- // setcookie('PHPSESSID',$_POST['sessionid']);
- // session_start();
- // }
- if(!isset($this->params['pmid']) && !is_numeric($this->params['pmid']) && !isset($_POST['uid']) && !isset($_POST['verification'])){
- exit(json_encode(array('success' => false, 'msg' => '参数有误')));
- }
- $pmArray = $actmeasure->getRowByPmid($this->params['pmid']);
- if(empty($pmArray)){
- exit(json_encode(array('success' => false, 'msg' => '不存在此标段,无法上传')));
- }
- $verifiction = $cfuhashids->decode($_POST['verification']);
- if($verifiction[0] != $this->params['pmid'] || $verifiction[1] != $_POST['uid']){
- exit(json_encode(array('success' => false, 'msg' => '用户上传权限验证有误')));
- }
- Doo::loadClass('extras/Uploader');
- $files = array();
- $upload_dir = Doo::conf()->SITE_PATH . 'cfiles/';
- $uploader = new FileUpload('uploadfile');
- $intime = time();
- $extPathdir = $upload_dir.date('Y/md/',$intime);
- if (!$this->dir_create2($extPathdir)) {
- $status = array('success' => FALSE, 'msg' => '文件夹创建失败');
- echo json_encode($status, JSON_UNESCAPED_UNICODE);
- die();
- }
- $files['filename'] = $uploader->getFileNameWithoutExt();
- $files['fileext'] = $uploader->getExtension();
- $files['filesize'] = $uploader->getFileSize();
- $filepath = date('Ymdhis',$intime) . rand(100, 999) . '.' . $files['fileext'];
- $uploader->newFileName = $filepath;
- $files['filepath'] = 'cfiles/'.date('Y/md/',$intime).$filepath;
- $result = $uploader->handleUpload($extPathdir);
- if (!$result) {
- exit(json_encode(array('success' => false, 'msg' => $uploader->getErrorMsg())));
- }
- $files['pid'] = $pmArray['pid'];
- $files['stid'] = $pmArray['stid'];
- $files['pmid'] = $pmArray['pmid'];
- $files['cid'] = isset($this->params['cid']) && is_numeric($this->params['cid']) ? $this->params['cid'] : 0;
- $files['uid'] = $_POST['uid'];
- $files['intime'] = $intime;
- $result2 = $change->insertChangeAtt($files);
- if(empty($result2)){
- exit(json_encode(array('success' => false, 'msg' => '添加到数据库发生错误')));
- }
- $files2 = array();
- $files2['id'] = $result2;
- //加密下载的id
- $fid = $__hashids->encode($result2);
- $files2['downurl'] = '/change/file/download/'.$fid;
- $files2['filename'] = $files['filename'].'.'.$files['fileext'];
- $files2['time'] = date('Y-m-d H:i',$intime);
- $files2['size'] = $this->changefilesize($files['filesize']);
- echo json_encode(array('success' => true, 'files' => $files2));
- }
- function dir_create2($path, $mode = 0777)
- {
- if (is_dir($path))
- return TRUE;
- $path = $this->dir_path($path);
- $parent = dirname($path);
- if (!is_dir($parent)){
- @mkdir($parent, 0777);
- @chmod($parent, 0777);
- }
- @mkdir($path, 0777);
- @chmod($path, 0777);
- return is_dir($path);
- }
- function dir_path($path)
- {
- $path = str_replace('\\', '/', $path);
- if (substr($path, -1) != '/')
- $path = $path . '/';
- return $path;
- }
- //字节转换
- function changefilesize($value){
- $units = array(' B', ' KB', ' MB', ' GB', ' TB');
- for ($i = 0; $value >= 1024 && $i < 4; $i++) $value /= 1024;
- return round($value, 2).$units[$i];
- }
- }
|