86 lines
2.5 KiB
PHP
86 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace app\admin\controller;
|
|
|
|
use think\Controller;
|
|
use think\Session;
|
|
use think\Loader;
|
|
use think\Request;
|
|
|
|
class Common extends Controller{
|
|
public function __construct(){
|
|
parent::__construct();
|
|
$user_info = Session::get('user_info');
|
|
$this->assign('user_info',$user_info);
|
|
if(empty($user_info)){
|
|
$this->redirect('/login/index',302);
|
|
exit();
|
|
}
|
|
//角色判断
|
|
$request= Request::instance();
|
|
$curContrller = $request->controller();
|
|
$curAction = $request->action();
|
|
//监控角色可以访问的页面
|
|
$jiankongController = array(
|
|
'Index',
|
|
'Waybill',
|
|
'Game',
|
|
'Memo',
|
|
'Info',
|
|
'Log',
|
|
'Login',
|
|
'Chat',
|
|
'ChatQuickReply',
|
|
);
|
|
if($user_info['role'] == 1){
|
|
if(!in_array($curContrller, $jiankongController)){
|
|
die('您没有权限访问该页面');
|
|
}
|
|
}
|
|
$dlController = array(
|
|
'Info',
|
|
'Index',
|
|
'Agent',
|
|
'Login',
|
|
'Chat',
|
|
'ChatQuickReply',
|
|
);
|
|
if($user_info['role'] == 2){
|
|
if(!in_array($curContrller, $dlController)){
|
|
die('您没有权限访问该页面');
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
*+----------------------------------------------------------
|
|
* 输出Excel函数
|
|
*+----------------------------------------------------------
|
|
* @param string $data 数据
|
|
*+----------------------------------------------------------
|
|
*/
|
|
public function exportExcelCore($data,$savefile=null,$title=null,$sheetname='sheet1'){
|
|
$z = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
|
|
Loader::import('PHPExcel.PHPExcel');
|
|
Loader::import('PHPExcel.PHPExcel.IOFactory.PHPExcel_IOFactory');
|
|
$PHPExcel = new \PHPExcel();
|
|
$PHPSheet = $PHPExcel->getActiveSheet();
|
|
$PHPSheet->setTitle('报表'); //给当前活动sheet设置名称
|
|
//设置行头
|
|
$num = 1;
|
|
foreach($title AS $key => $value){
|
|
$PHPSheet->setCellValue($z[$key].$num,$value);
|
|
}
|
|
$n = 2;
|
|
foreach($data AS $k => $v){
|
|
foreach($v AS $k2 => $v2){
|
|
$PHPSheet->setCellValue($z[$k2].$n,$v2);
|
|
}
|
|
$n++;
|
|
}
|
|
$PHPWriter = \PHPExcel_IOFactory::createWriter($PHPExcel,"Excel5");
|
|
header('Content-Disposition: attachment;filename="'.$savefile.'.xls"');
|
|
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
|
$PHPWriter->save("php://output"); //表示在$path路径下面生成demo.xlsx文件
|
|
}
|
|
} |