params['update']) && $this->params['update'] == 'all' ? '' : ' AND `fc_report`.itemid=0'; if(isset($_POST['itemcode'])){ Doo::loadModel('item'); $items = new Item(); $itemmsg = $items->getRowbyCode($_POST['itemcode']); $name = '项目'; if(!empty($itemmsg)){ $addsql = ' AND `fc_report`.itemid='.$itemmsg['itemid']; }else{ $arr = array('status' => 'true', 'msg' => '当前'.$name.'报表为空', 'info' => ''); echo $this->decodeUnicode(json_encode($arr)); exit; } } if(isset($_POST['areacate']) && is_numeric($_POST['areacate'])){ $addsql .= ' AND (`fc_report`.areacate=3 OR `fc_report`.areacate='.$_POST['areacate'].')'; } $sql = 'SELECT `fc_report`.reportid,reportname,areacate,cateid,parentid,`fc_report`.edittime,`fc_report`.itemid FROM `fc_report` left join `fc_version` on `fc_report`.reportid=`fc_version`.reportid where `fc_report`.reportid=`fc_version`.reportid'.$addsql.' and `fc_version`.status=2 group by `fc_report`.reportid order by `fc_report`.edittime desc'; $query = Doo::db ()->query ( $sql ); $reportlist = $query->fetchAll (); if(!empty($reportlist)){ foreach ($reportlist as $k => $v) { Doo::loadModel('category'); $category = new Category(); if($v['parentid'] != 0){ $catename = $category->getnamebyid($v['parentid']).'/'.$category->getnamebyid($v['cateid']); }else{ $catename = $category->getnamebyid($v['cateid']); } $reportlist[$k]['catename'] = $catename; $reportlist[$k]['edittime'] = date('YmdHis',$v['edittime']); Doo::loadModel('version'); $versions = new Version(); $reportlist[$k]['desc'] = $versions->getRowbyVername(date('YmdHis',$v['edittime']))['content']; unset($reportlist[$k]['cateid']); unset($reportlist[$k]['parentid']); } $arr = array('status' => 'true', 'msg' => '', 'info' => $reportlist); echo $this->decodeUnicode(json_encode($arr)); exit; } $arr = array('status' => 'true', 'msg' => '当前'.$name.'报表为空', 'info' => ''); echo $this->decodeUnicode(json_encode($arr)); exit; } /* * 报表更新调用接口 * */ public function GetUpdateReport(){ Doo::loadModel('report'); $report = new Report(); if(isset($_POST['idlist'])){ $idlist = explode(',',$_POST['idlist']); $infoarr = array(); foreach($idlist as $k => $v){ $reportmsg = $report->getRowbyid($v); $infoarr[$k]['id'] = $v; $infoarr[$k]['edittime'] = !empty($reportmsg) ? date('YmdHis',$reportmsg['edittime']) : ''; Doo::loadModel('category'); $category = new Category(); if($reportmsg['parentid'] != 0){ $catename = $category->getnamebyid($reportmsg['parentid']).'/'.$category->getnamebyid($reportmsg['cateid']); }else{ $catename = $category->getnamebyid($reportmsg['cateid']); } $infoarr[$k]['catename'] = $catename; Doo::loadModel('version'); $versions = new Version(); $content = $versions->getRowbyVername($infoarr[$k]['edittime'])['content']; $infoarr[$k]['desc'] = !empty($content) ? $content : ''; } $arr = array('status' => 'true', 'msg' => '', 'info' => $infoarr); echo $this->decodeUnicode(json_encode($arr)); exit; }else{ $arr = array('status' => 'false', 'msg' => '传递的参数有误', 'info' => ''); echo $this->decodeUnicode(json_encode($arr)); exit; } } /** * 下载最新报表或对应版本报表 * */ public function DownloadReport(){ if(isset($this->params['reportid']) && is_numeric($this->params['reportid'])){ Doo::loadModel('version'); $version = new Version(); if(isset($this->params['version'])){ $vermsg = $version->getOne(array('select' => 'verid,addtime', 'where' => 'status!=0 and reportid='.$this->params['reportid'].' and vername="'.$this->params['version'].'"', 'desc' => 'addtime', 'asArray' => TRUE)); }else{ $vermsg = $version->getOne(array('select' => 'verid,addtime', 'where' => 'status!=0 and reportid='.$this->params['reportid'], 'desc' => 'addtime', 'asArray' => TRUE)); } if(!empty($vermsg)){ include (DOO::conf()->SITE_PATH . 'protected/plugin/io.han.php'); $this->IoHandler = new IoHandler(); $baseurl = '/opt/www/vc/'; $verurl = $this->params['reportid'].'/'.$vermsg['verid'].'_'.date('YmdHis',$vermsg['addtime']); $vername = $baseurl."jlbb/".$verurl.'.xml'; if($this->IoHandler->ReadFile($vername)){ $arr = array('status' => 'true', 'msg' => '', 'info' => array('downloadurl' => Doo::conf()->APP_URL.'api/getxml/'.$verurl.'/'.filesize($vername))); echo $this->decodeUnicode(json_encode($arr)); exit; }else{ $arr = array('status' => 'false', 'msg' => '本报表不存在下载地址', 'info' => ''); echo $this->decodeUnicode(json_encode($arr)); exit; } }else{ $arr = array('status' => 'false', 'msg' => '当前报表不存在版本信息,无法下载', 'info' => ''); echo $this->decodeUnicode(json_encode($arr)); exit; } }else{ $arr = array('status' => 'false', 'msg' => '请传入报表id值', 'info' => ''); echo $this->decodeUnicode(json_encode($arr)); exit; } } /** * 获取报表最近3个版本 * */ public function VersionMsg(){ if(isset($this->params['reportid']) && is_numeric($this->params['reportid']) ){ Doo::loadModel('version'); $version = new Version(); $verlist = $version->find(array('select' => 'verid,vername,content,addtime', 'where' => 'status=2 and reportid='.$this->params['reportid'], 'desc' => 'addtime','limit' => 3, 'asArray' => TRUE)); if(!empty($verlist)){ include (DOO::conf()->SITE_PATH . 'protected/plugin/io.han.php'); $this->IoHandler = new IoHandler(); foreach($verlist as $k => $v){ $baseurl = '/opt/www/vc/'; $verurl = $this->params['reportid'].'/'.$v['verid'].'_'.date('YmdHis',$v['addtime']); $vername = $baseurl."jlbb/".$verurl.'.xml'; if($this->IoHandler->ReadFile($vername)){ $verlist[$k]['downloadurl'] = Doo::conf()->APP_URL.'api/getxml/'.$verurl.'/'.filesize($vername); }else{ $arr = array('status' => 'false', 'msg' => $v['vername'].'版本不存在下载地址', 'info' => ''); echo $this->decodeUnicode(json_encode($arr)); exit; } unset($verlist[$k]['verid']); unset($verlist[$k]['addtime']); } $arr = array('status' => 'true', 'msg' => '', 'info' => $verlist); echo $this->decodeUnicode(json_encode($arr)); exit; }else{ $arr = array('status' => 'false', 'msg' => '本报表不存在版本信息', 'info' => ''); echo $this->decodeUnicode(json_encode($arr)); exit; } }else{ $arr = array('status' => 'false', 'msg' => '请传入报表id值', 'info' => ''); echo $this->decodeUnicode(json_encode($arr)); exit; } } public function DownloadUrl(){ $pathf = '/opt/www/vc/jlbb/'; $reportid = $this->params['reportid']; $xmlname = $this->params['xml']; $size = $this->params['filesize']; $url = $pathf.'/'.$reportid.'/'.$xmlname.'.xml'; $this->file_down($url,$xmlname,$size); exit; } /** * 文件下载 * @param $filepath 文件路径 * @param $filename 文件名称 */ function file_down($filepath, $filename = '', $filesize, $filetype = 'xml') { if (ob_get_length() !== false) @ob_end_clean(); header('Pragma: public'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Cache-Control: no-store, no-cache, must-revalidate'); header('Cache-Control: pre-check=0, post-check=0, max-age=0'); header('Content-Transfer-Encoding: binary'); header('Content-Encoding: none'); header('Content-type: ' . $filetype); header('Content-Disposition: attachment; filename="' . iconv("UTF-8", "GBK", $filename ). '.' . $filetype .'"'); header('Content-length: ' . $filesize); @readfile($filepath); exit; } function decodeUnicode($str) { return preg_replace_callback('/\\\\u([0-9a-f]{4})/i', create_function( '$matches', 'return mb_convert_encoding(pack("H*", $matches[1]), "UTF-8", "UCS-2BE");' ), $str); } }