作者 景龙
1 个管道 的构建 通过 耗费 32 秒

写后台月检,培训演习导出excel

... ... @@ -123,16 +123,16 @@ class AdminCheckController extends AdminBaseController
$arr['status'] = $this->getStatus()[$value['status']];
//获取文件路径
$url = $adminExcel->checkExcelData($arr);
// //按日导出
// $arr_url[$key] = $url;
// $arr_time[$key] = $arr['time'].'报表.xls';
//按日导出
$arr_url[$key] = $url;
$arr_time[$key] = $arr['time'].'报表.xls';
}
// $xlsName = '月检报表';
// //解决zip中文文件名
// $xlsName = $adminCommon->iconv_to_utf8($xlsName);
// $filename = ROOT_PATH . 'public/upload/export/' . $xlsName . '.zip';
// $adminCommon->zip($arr_url,$filename,$arr_time);
$xlsName = '月检报表';
//解决zip中文文件名
$xlsName = $adminCommon->iconv_to_utf8($xlsName);
$filename = ROOT_PATH . 'public/upload/export/' . $xlsName . '.zip';
$adminCommon->zip($arr_url,$filename,$arr_time);
}
//检查是否有数据
... ...
... ... @@ -658,7 +658,7 @@ class AdminCommonController extends AdminBaseController
//月检工期及验收完成时间
if($res['finish_time']){
$arr['finish_time'] = $res['finish_time'];
$arr['finish_time'] = date('Y/m/d',$res['finish_time']);
//培训
$arr['check_period'] = $this->getPeriod($res['finish_time'],$res['ins_m_time']);
}else{
... ... @@ -672,18 +672,115 @@ class AdminCommonController extends AdminBaseController
if($res['images']){
$images = $this->exportUrl($res['images']);
$arr1 = $this->getDayImages($images);
$arr['images'] = $arr1;
$arr['check'][0]['check_name'] = '月检图片';
$arr['check'][0]['images'] = $arr1;
}else{
$arr['images'] = [];
$arr['check'][0]['check_name'] = '月检图片';
$arr['check'][0]['images'] = [];
}
//确认图片
if($res['confirm_images']){
$images = $this->exportUrl($res['confirm_images']);
$arr1 = $this->getDayImages($images);
$arr['confirm_images'] = $arr1;
$arr['check'][1]['check_name'] = '确认完成图片';
$arr['check'][1]['images'] = $arr1;
}else{
$arr['confirm_images'] = [];
$arr['check'][1]['check_name'] = '确认完成图片';
$arr['check'][1]['images'] = [];
}
return $arr;
}
//导出培训演习报表详情
public function trainExportData($res,$table){
$arr = [];
//甲乙方logo,名称,报表名称
if($table == 'train'){
$company = $this->getCompanyName($res['project_id'],'培训');
}else{
$company = $this->getCompanyName($res['project_id'],'演习');
}
if($company){
$arr['a_company'] = $company['a_company'];
$arr['b_company'] = $company['b_company'];
$arr['title'] = $company['title'];
}
//培训演习单号
$arr['number'] = $res['number'];
//培训演习人员(乙方项目组)
$arr['group_name'] = $this->getBUserByProject($res['project_id'],'id,b_sid',1);
//培训演习时间
if($table == 'train'){
$arr['train_time'] = date('Y/m/d',$res['train_time']);
$arr['time'] = date('Y-m-d',$res['train_time']);
}else{
$arr['exercise_time'] = date('Y/m/d',$res['exercise_time']);
$arr['time'] = date('Y-m-d',$res['exercise_time']);
}
//培训演习(甲方发起人)
$user = $this->getUserById(['id'=>$res['uid']]);
if($user){
$arr['user_login'] = $user['user_login'];
}else{
$arr['user_login'] = '';
}
//乙方领导确认人
$leader_user = $this->getUserById(['id'=>$res['b_leader']]);
if($leader_user){
$arr['b_leader_user'] = $leader_user['user_login'];
}else{
$arr['b_leader_user'] = '';
}
//甲方确认完成人
$finish_user = $this->getUserById(['id'=>$res['confirm_uid']]);
if($finish_user){
$arr['confirm_user'] = $finish_user['user_login'];
}else{
$arr['confirm_user'] = '';
}
//培训演习工期及验收完成时间
if($res['finish_time']){
$arr['finish_time'] = date('Y/m/d',$res['finish_time']);
if($table == 'train'){
$arr['check_period'] = $this->getPeriod($res['finish_time'],$res['train_time']);
}else{
$arr['check_period'] = $this->getPeriod($res['finish_time'],$res['exercise_time']);
}
}else{
//验收完成时间
$arr['finish_time'] = '';
//工期
$arr['check_period'] = '';
}
//甲乙方图片
if($res['images']){
$images = $this->exportUrl($res['images']);
$arr1 = $this->getDayImages($images);
$arr['train'][0]['check_name'] = '甲乙方完善图片';
$arr['train'][0]['images'] = $arr1;
}else{
$arr['train'][0]['check_name'] = '甲乙方完善图片';
$arr['train'][0]['images'] = [];
}
//确认图片
if($res['confirm_images']){
$images = $this->exportUrl($res['confirm_images']);
$arr1 = $this->getDayImages($images);
$arr['train'][1]['check_name'] = '确认完成图片';
$arr['train'][1]['images'] = $arr1;
}else{
$arr['train'][1]['check_name'] = '确认完成图片';
$arr['train'][1]['images'] = [];
}
return $arr;
}
... ...
... ... @@ -402,89 +402,313 @@ class AdminExcelDataController extends AdminBaseController
//乙方发起人姓名
$sheet->setCellValue('B6', '乙方发起人');
$sheet->setCellValue('B7', '景龙');
$sheet->setCellValue('B7', $arr['user_login']);
//月检时间
$sheet->setCellValue('D6', '月检时间');
$sheet->setCellValue('D7', '2019/06/30');
$sheet->setCellValue('D7', $arr['ins_m_time']);
//乙方项目组
$sheet->setCellValue('F6', '项目组');
$sheet->setCellValue('F7', '景龙、员工2、尚光泉');
$sheet->setCellValue('F7', $arr['group_name']);
//月检状态
$sheet->setCellValue('I6', '月检状态');
$sheet->setCellValue('I7', '待乙方员工完成');
$sheet->setCellValue('I7', $arr['status']);
//甲方领导确认人
$sheet->setCellValue('B9', '甲方领导确认人');
$sheet->setCellValue('B10', '景龙');
$sheet->setCellValue('B10', $arr['a_leader_user']);
//乙方员工确认人
$sheet->setCellValue('D9', '乙方员工确认人');
$sheet->setCellValue('D10', '景龙');
$sheet->setCellValue('D9', '乙方员工确认完成人');
$sheet->setCellValue('D10', $arr['confirm_user']);
//完成时间
$sheet->setCellValue('F9', '完成时间');
$sheet->setCellValue('F10', '2019/06/30');
$sheet->setCellValue('F10', $arr['finish_time']);
//工期
$sheet->setCellValue('I9', '工期');
$sheet->setCellValue('I10', '15天');
$sheet->setCellValue('I9', '工期(天)');
$sheet->setCellValue('I10', $arr['check_period']);
$array1 = [
'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT,
'textRotation' => 0,
'wrapText' => TRUE
];
$sheet->getStyle('F10')->getAlignment()->applyFromArray($array1);//垂直水平居左
$sheet->getStyle('I10')->getAlignment()->applyFromArray($array1);//垂直水平居左
//循环开始
$cols = 13;
$cells = ['C','E','G','I','K'];
foreach($arr['check'] as $value){
$cols += 1;
//巡检点名称
$array = [
'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,
'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER,
'textRotation' => 0,
'wrapText' => TRUE
];
$sheet->mergeCells('A'.$cols.':B'.$cols);
$sheet->setCellValue('A'.$cols, $value['check_name']);
$sheet->getStyle('A'.$cols)->getAlignment()->applyFromArray($array);//垂直水平居中
//循环第二层
foreach($value['images'] as $image_image){
//渲染图片日期
$col_day = $cols - 1;
$sheet->mergeCells('C'.$col_day.':D'.$col_day);
$sheet->setCellValue('C'.$col_day, $image_image['day']);
//获取图片个数
$length = count($image_image['image']);
$col = ceil($length/5);
for($i=0;$i<$col;$i++) {
$col_i = $cols + $i;
$sheet->getRowDimension($col_i)->setRowHeight(105);
$sheet->mergeCells('C' . $col_i . ':D' . $col_i);
$sheet->mergeCells('E' . $col_i . ':F' . $col_i);
$sheet->mergeCells('G' . $col_i . ':H' . $col_i);
$sheet->mergeCells('I' . $col_i . ':J' . $col_i);
$sheet->mergeCells('K' . $col_i . ':L' . $col_i);
$key = 0;
foreach($image_image['image'] as $k=>$image_value){
$pre = $i+4*$i;
$next = $i+1+4*($i+1);
if($k>=$pre && $k<$next){
//巡检图片
$image = $image_value['image_url'];
if(@fopen($image , 'r' ) ) {
//这是一个坑,刚开始我把实例化图片类放在了循环外面,但是失败了,也就是每个图片都要实例化一次
$obj = new Drawing();
$obj->setPath($image);
// 设置图片的宽度
$obj->setResizeProportional(false);
$obj->setWidthAndHeight(105,130);
//图片显示在F3
$obj->setCoordinates($cells[$key].$col_i);
$obj->setWorksheet($sheet);
}
$key++;
}
}
}
$cols += $col+1;
}
}
$sheet->getStyle( 'A12:M'.$cols)->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
$sheet->getStyle( 'A12:M'.$cols)->getFill()->getStartColor()->setRGB('F3F3F4');//背景颜色浅灰色
$arr['point'] = [
[
'check_name'=>'月检图片',
'images'=>[
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
]
],
[
'check_name'=>'确认完成图片',
'images'=>[
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
]
]
$objWrite = IOFactory::createWriter($spreadsheet, 'Xls');
//直接从浏览器中输出star
// header('pragma:public');
// header("Content-Disposition:attachment;filename=出货装箱单.xls");
// $objWrite->save('php://output');
// exit;
//直接从浏览器中输出end
$file_name = $xlsName.'.xls';
$files_url = ROOT_PATH . '/public/upload/export';
if(!is_dir($files_url)){
mkdir($files_url);
}
$file_url = ROOT_PATH . '/public/upload/export/'.$file_name;
$objWrite->save($file_url);
$sys = $adminCommon->getOperateSys();
if($sys == 'Linux'){
chmod($file_url, 0777);//适用于linux
}
//相对路径
$url = 'upload/export/'.$file_name;
return $url;
}
//培训演习渲染数据到表格上
public function trainExcelData($arr,$table){
$spreadsheet = new Spreadsheet();
$adminCommon = new AdminCommonController();
$sheet = $spreadsheet->getActiveSheet();
$xlsName = $arr['time'];
//设置sheet名称
$name = '报表';
$name = $adminCommon->iconv_to_utf8($name);
$sheet->setTitle($xlsName.$name);
//合并单元格
//报表名称
$sheet->mergeCells('B1:J1');
//甲方logo,甲方公司名称
$sheet->mergeCells('B3:B4');
$sheet->mergeCells('C3:D3');
$sheet->mergeCells('C4:D4');
//乙方logo,乙方公司名称
$sheet->mergeCells('F3:F4');
$sheet->mergeCells('G3:I3');
$sheet->mergeCells('G4:I4');
//乙方发起人姓名
$sheet->mergeCells('B6:C6');
$sheet->mergeCells('B7:C7');
//乙方项目组
$sheet->mergeCells('F6:H6');
$sheet->mergeCells('F7:H7');
//培训演习状态
$sheet->mergeCells('I6:J6');
$sheet->mergeCells('I7:J7');
//培训演习单号
$sheet->mergeCells('K6:L6');
$sheet->mergeCells('K7:L7');
//甲方领导确认人
$sheet->mergeCells('B9:C9');
$sheet->mergeCells('B10:C10');
//乙方员工确认人
$sheet->mergeCells('D9:E9');
$sheet->mergeCells('D10:E10');
$spreadsheet->getDefaultStyle()->getFont()->setName('微软雅黑');//字体
//设置默认宽
$sheet->getDefaultColumnDimension()->setWidth(8);
//设置高度
$sheet->getRowDimension(1)->setRowHeight(45);
// $sheet->getRowDimension(2)->setRowHeight(55);
//***********************背景填充颜色*****************************
$sheet->getStyle( 'A1:M11')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
$sheet->getStyle( 'A1:M11')->getFill()->getStartColor()->setRGB('222B35');//背景颜色
//***********************画出单元格边框结束*****************************
//标题
$sheet->setCellValue('B1', $arr['title']);
$sheet->getStyle('B1')->getFont()->setSize(18);//字体大小
$sheet->getStyle('B1')->getFont()->getColor()->setRGB('FFFFFF');//设置颜色为白色
$sheet->getStyle('B1')->getFont()->setBold(true);//字体加粗
//甲方logo
$imageA = $arr['a_company']['logo'];
if(@fopen($imageA , 'r' ) ) {
//这是一个坑,刚开始我把实例化图片类放在了循环外面,但是失败了,也就是每个图片都要实例化一次
$imageADrawing = new Drawing();
$imageADrawing->setPath($imageA);
// 设置图片的宽度
$imageADrawing->setResizeProportional(false);
$imageADrawing->setWidthAndHeight(40,40);
//图片显示在B3
$imageADrawing->setCoordinates('B3');
$imageADrawing->setWorksheet($sheet);
}
$sheet->getStyle('B3:K10')->getFont()->setSize(8);//字体大小
$sheet->getStyle('C3:G3')->getFont()->getColor()->setRGB('949494');//设置颜色为灰色
$sheet->getStyle('B6:K6')->getFont()->getColor()->setRGB('949494');//设置颜色为灰色
$sheet->getStyle('B9:I9')->getFont()->getColor()->setRGB('949494');//设置颜色为灰色
$sheet->getStyle('C4:G4')->getFont()->getColor()->setRGB('FFFFFF');//设置颜色为白色
$sheet->getStyle('B7:K7')->getFont()->getColor()->setRGB('FFFFFF');//设置颜色为白色
$sheet->getStyle('B10:I10')->getFont()->getColor()->setRGB('FFFFFF');//设置颜色为白色
//甲方公司
$sheet->setCellValue('C3', '甲方公司');
//甲方公司名称
$sheet->setCellValue('C4', $arr['a_company']['company_name']);
//乙方logo
$imageB = $arr['b_company']['logo'];
if(@fopen($imageB , 'r' ) ) {
//这是一个坑,刚开始我把实例化图片类放在了循环外面,但是失败了,也就是每个图片都要实例化一次
$objDrawing = new Drawing();
$objDrawing->setPath($imageB);
// 设置图片的宽度
$objDrawing->setResizeProportional(false);
$objDrawing->setWidthAndHeight(40,40);
//图片显示在F3
$objDrawing->setCoordinates('F3');
$objDrawing->setWorksheet($sheet);
}
//乙方公司
$sheet->setCellValue('G3', '乙方公司');
//乙方公司名称
$sheet->setCellValue('G4', $arr['b_company']['company_name']);
//乙方发起人姓名
$sheet->setCellValue('B6', '甲方发起人');
$sheet->setCellValue('B7', $arr['user_login']);
//培训演习时间
if($table == 'train'){
$sheet->setCellValue('D6', '培训时间');
$sheet->setCellValue('D7', $arr['train_time']);
}else{
$sheet->setCellValue('D6', '演习时间');
$sheet->setCellValue('D7', $arr['exercise_time']);
}
//乙方项目组
$sheet->setCellValue('F6', '项目组');
$sheet->setCellValue('F7', $arr['group_name']);
//培训演习状态
if($table == 'train'){
$sheet->setCellValue('I6', '培训状态');
}else{
$sheet->setCellValue('I6', '演习状态');
}
$sheet->setCellValue('I7', $arr['status']);
//培训演习单号
if($table == 'train'){
$sheet->setCellValue('K6', '培训单号');
}else{
$sheet->setCellValue('K6', '演习单号');
}
$sheet->setCellValue('K7', $arr['number']);
$sheet->getStyle('K7')->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER);//解决长数字显示为科学计数法
//乙方领导确认人
$sheet->setCellValue('B9', '乙方领导确认人');
$sheet->setCellValue('B10', $arr['b_leader_user']);
//甲方员工确认完成人
$sheet->setCellValue('D9', '甲方员工确认完成人');
$sheet->setCellValue('D10', $arr['confirm_user']);
//完成时间
$sheet->setCellValue('F9', '完成时间');
$sheet->setCellValue('F10', $arr['finish_time']);
//工期
$sheet->setCellValue('I9', '工期(天)');
$sheet->setCellValue('I10', $arr['check_period']);
$array1 = [
'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT,
'textRotation' => 0,
'wrapText' => TRUE
];
$sheet->getStyle('K7')->getAlignment()->applyFromArray($array1);//垂直水平居左
$sheet->getStyle('F10')->getAlignment()->applyFromArray($array1);//垂直水平居左
$sheet->getStyle('I10')->getAlignment()->applyFromArray($array1);//垂直水平居左
foreach($arr['point'] as $value){
$cols += 0;
//循环开始
$cols = 13;
$cells = ['C','E','G','I','K'];
foreach($arr['train'] as $value){
$cols += 1;
//巡检点名称
$array = [
'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,
... ... @@ -495,41 +719,48 @@ class AdminExcelDataController extends AdminBaseController
$sheet->mergeCells('A'.$cols.':B'.$cols);
$sheet->setCellValue('A'.$cols, $value['check_name']);
$sheet->getStyle('A'.$cols)->getAlignment()->applyFromArray($array);//垂直水平居中
//获取图片个数
$length = count($value['images']);
$col = ceil($length/5);
for($i=0;$i<$col;$i++){
$col_i = $cols+$i;
$sheet->getRowDimension($col_i)->setRowHeight(105);
$sheet->mergeCells('C'.$col_i.':D'.$col_i);
$sheet->mergeCells('E'.$col_i.':F'.$col_i);
$sheet->mergeCells('G'.$col_i.':H'.$col_i);
$sheet->mergeCells('I'.$col_i.':J'.$col_i);
$sheet->mergeCells('K'.$col_i.':L'.$col_i);
$key = 0;
foreach($value['images'] as $k=>$image_value){
$pre = $i+4*$i;
$next = $i+1+4*($i+1);
if($k>=$pre && $k<$next){
//巡检图片
$image = $image_value['image_url'];
if(@fopen($image , 'r' ) ) {
//这是一个坑,刚开始我把实例化图片类放在了循环外面,但是失败了,也就是每个图片都要实例化一次
$obj = new Drawing();
$obj->setPath($image);
// 设置图片的宽度
$obj->setResizeProportional(false);
$obj->setWidthAndHeight(105,130);
//图片显示在F3
$obj->setCoordinates($cells[$key].$col_i);
$obj->setWorksheet($sheet);
//循环第二层
foreach($value['images'] as $image_image){
//渲染图片日期
$col_day = $cols - 1;
$sheet->mergeCells('C'.$col_day.':D'.$col_day);
$sheet->setCellValue('C'.$col_day, $image_image['day']);
//获取图片个数
$length = count($image_image['image']);
$col = ceil($length/5);
for($i=0;$i<$col;$i++) {
$col_i = $cols + $i;
$sheet->getRowDimension($col_i)->setRowHeight(105);
$sheet->mergeCells('C' . $col_i . ':D' . $col_i);
$sheet->mergeCells('E' . $col_i . ':F' . $col_i);
$sheet->mergeCells('G' . $col_i . ':H' . $col_i);
$sheet->mergeCells('I' . $col_i . ':J' . $col_i);
$sheet->mergeCells('K' . $col_i . ':L' . $col_i);
$key = 0;
foreach($image_image['image'] as $k=>$image_value){
$pre = $i+4*$i;
$next = $i+1+4*($i+1);
if($k>=$pre && $k<$next){
//巡检图片
$image = $image_value['image_url'];
if(@fopen($image , 'r' ) ) {
//这是一个坑,刚开始我把实例化图片类放在了循环外面,但是失败了,也就是每个图片都要实例化一次
$obj = new Drawing();
$obj->setPath($image);
// 设置图片的宽度
$obj->setResizeProportional(false);
$obj->setWidthAndHeight(105,130);
//图片显示在F3
$obj->setCoordinates($cells[$key].$col_i);
$obj->setWorksheet($sheet);
}
$key++;
}
$key++;
}
}
$cols += $col+1;
}
$cols += $col+1;
}
$sheet->getStyle( 'A12:M'.$cols)->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
$sheet->getStyle( 'A12:M'.$cols)->getFill()->getStartColor()->setRGB('F3F3F4');//背景颜色浅灰色
... ... @@ -537,10 +768,10 @@ class AdminExcelDataController extends AdminBaseController
$objWrite = IOFactory::createWriter($spreadsheet, 'Xls');
//直接从浏览器中输出star
header('pragma:public');
header("Content-Disposition:attachment;filename=出货装箱单.xls");
$objWrite->save('php://output');
exit;
// header('pragma:public');
// header("Content-Disposition:attachment;filename=出货装箱单.xls");
// $objWrite->save('php://output');
// exit;
//直接从浏览器中输出end
$file_name = $xlsName.'.xls';
... ...
... ... @@ -115,4 +115,44 @@ class AdminExerciseController extends AdminBaseController
->find();
return $res;
}
//导出数据
public function exportData(){
$param = $this->request->param();
$adminCommon = new AdminCommonController();
$adminExcel = new AdminExcelDataController();
$res_ins = $adminCommon->exportCheckList('exercise',$param,'t.*');
$arr_url = [];
$arr_time = [];
foreach($res_ins as $key=>$value){
$arr = $adminCommon->trainExportData($value,'exercise');
$arr['status'] = $this->getStatus()[$value['status']];
//获取文件路径
$url = $adminExcel->trainExcelData($arr,'exercise');
//按日导出
$arr_url[$key] = $url;
$arr_time[$key] = $arr['time'].'报表.xls';
}
$xlsName = '演习报表';
//解决zip中文文件名
$xlsName = $adminCommon->iconv_to_utf8($xlsName);
$filename = ROOT_PATH . 'public/upload/export/' . $xlsName . '.zip';
$adminCommon->zip($arr_url,$filename,$arr_time);
}
//检查是否有数据
public function checkData(){
$param = $this->request->param();
$adminCommon = new AdminCommonController();
$res_ins = $adminCommon->exportCheckList('exercise',$param,'t.id');
if($res_ins){
$adminCommon->apiResponse(1);
}else{
$adminCommon->apiResponse(0,'暂无数据');
}
}
}
... ...
... ... @@ -115,4 +115,44 @@ class AdminTrainController extends AdminBaseController
->find();
return $res;
}
//导出数据
public function exportData(){
$param = $this->request->param();
$adminCommon = new AdminCommonController();
$adminExcel = new AdminExcelDataController();
$res_ins = $adminCommon->exportCheckList('train',$param,'t.*');
$arr_url = [];
$arr_time = [];
foreach($res_ins as $key=>$value){
$arr = $adminCommon->trainExportData($value,'train');
$arr['status'] = $this->getStatus()[$value['status']];
//获取文件路径
$url = $adminExcel->trainExcelData($arr,'train');
//按日导出
$arr_url[$key] = $url;
$arr_time[$key] = $arr['time'].'报表.xls';
}
$xlsName = '培训报表';
//解决zip中文文件名
$xlsName = $adminCommon->iconv_to_utf8($xlsName);
$filename = ROOT_PATH . 'public/upload/export/' . $xlsName . '.zip';
$adminCommon->zip($arr_url,$filename,$arr_time);
}
//检查是否有数据
public function checkData(){
$param = $this->request->param();
$adminCommon = new AdminCommonController();
$res_ins = $adminCommon->exportCheckList('train',$param,'t.id');
if($res_ins){
$adminCommon->apiResponse(1);
}else{
$adminCommon->apiResponse(0,'暂无数据');
}
}
}
... ...
... ... @@ -7,19 +7,15 @@
</ul>
<form class="well form-inline margin-top-20" method="post" action="{:url('AdminExercise/index')}">
项目名称:
<input class="form-control" type="text" name="name" style="width: 200px;" value="{:input('request.name')}"
placeholder="请输入项目名称">
<input class="form-control" type="text" name="name" style="width: 200px;" value="{:input('request.name')}" id="project_name" placeholder="请输入项目名称">
演习时间:
<input type="text" class="form-control js-bootstrap-datetime" name="start_time"
value="{$start_time|default=''}"
style="width: 140px;" autocomplete="off">-
<input type="text" class="form-control js-bootstrap-datetime" name="end_time"
value="{$end_time|default=''}"
style="width: 140px;" autocomplete="off"> &nbsp;
培训时间:
<input type="text" class="form-control js-bootstrap-datetime" style="width:160px;" name="start_time" value="{$start_time|default=''}" autocomplete="off" id="start_time" placeholder="请输入开始时间">-
<input type="text" class="form-control js-bootstrap-datetime" style="width:160px;" name="end_time" value="{$end_time|default=''}" autocomplete="off" id="end_time" placeholder="请输入结束时间"> &nbsp;
<input type="submit" class="btn btn-primary" value="搜索"/>
<a class="btn btn-danger" href="{:url('AdminExercise/index')}">清空</a>
</form>
<button class="btn btn-success" id="export_data">导出演习数据</button>
<form method="post" class="js-ajax-form">
<table class="table table-hover table-bordered">
<thead>
... ... @@ -65,4 +61,49 @@
</div>
<script src="__STATIC__/js/admin.js"></script>
</body>
</html>
\ No newline at end of file
</html>
<script>
$(function(){
//导出数据
$('#export_data').click(function(){
var project_name = $('#project_name').val();
var start_time = $('#start_time').val();
var end_time = $('#end_time').val();
var code = checkData(start_time,end_time,project_name);
if(code == 1){
window.location.href = 'exportData?start_time='+start_time+'&end_time='+end_time+'&name='+project_name;
}
});
});
//检查是否有可导出的数据
function checkData(start_time,end_time,project_name){
if(start_time == ''){
alert('请输入演习开始时间');
return false;
}
if(end_time == ''){
alert('请输入演习结束时间');
return false;
}
var code = 1;
$.ajax({
type:'GET',
url:'checkData' ,
data:{
'start_time':start_time,
'end_time':end_time,
'name':project_name
},
dataType:'json',
async:false,//同步
success:function(data){
if (data.code == 0) {
alert(data.msg);
code = 0;
}
}
});
return code;
}
</script>
\ No newline at end of file
... ...
... ... @@ -7,19 +7,15 @@
</ul>
<form class="well form-inline margin-top-20" method="post" action="{:url('AdminTrain/index')}">
项目名称:
<input class="form-control" type="text" name="name" style="width: 200px;" value="{:input('request.name')}"
placeholder="请输入项目名称">
<input class="form-control" type="text" name="name" style="width: 200px;" value="{:input('request.name')}" id="project_name" placeholder="请输入项目名称">
培训时间:
<input type="text" class="form-control js-bootstrap-datetime" name="start_time"
value="{$start_time|default=''}"
style="width: 140px;" autocomplete="off">-
<input type="text" class="form-control js-bootstrap-datetime" name="end_time"
value="{$end_time|default=''}"
style="width: 140px;" autocomplete="off"> &nbsp;
<input type="text" class="form-control js-bootstrap-datetime" style="width:160px;" name="start_time" value="{$start_time|default=''}" autocomplete="off" id="start_time" placeholder="请输入开始时间">-
<input type="text" class="form-control js-bootstrap-datetime" style="width:160px;" name="end_time" value="{$end_time|default=''}" autocomplete="off" id="end_time" placeholder="请输入结束时间"> &nbsp;
<input type="submit" class="btn btn-primary" value="搜索"/>
<a class="btn btn-danger" href="{:url('AdminTrain/index')}">清空</a>
</form>
<button class="btn btn-success" id="export_data">导出培训数据</button>
<form method="post" class="js-ajax-form">
<table class="table table-hover table-bordered">
<thead>
... ... @@ -65,4 +61,49 @@
</div>
<script src="__STATIC__/js/admin.js"></script>
</body>
</html>
\ No newline at end of file
</html>
<script>
$(function(){
//导出数据
$('#export_data').click(function(){
var project_name = $('#project_name').val();
var start_time = $('#start_time').val();
var end_time = $('#end_time').val();
var code = checkData(start_time,end_time,project_name);
if(code == 1){
window.location.href = 'exportData?start_time='+start_time+'&end_time='+end_time+'&name='+project_name;
}
});
});
//检查是否有可导出的数据
function checkData(start_time,end_time,project_name){
if(start_time == ''){
alert('请输入培训开始时间');
return false;
}
if(end_time == ''){
alert('请输入培训结束时间');
return false;
}
var code = 1;
$.ajax({
type:'GET',
url:'checkData' ,
data:{
'start_time':start_time,
'end_time':end_time,
'name':project_name
},
dataType:'json',
async:false,//同步
success:function(data){
if (data.code == 0) {
alert(data.msg);
code = 0;
}
}
});
return code;
}
</script>
\ No newline at end of file
... ...