|
|
@@ -3,6 +3,7 @@
|
|
|
namespace app\admin\controller;
|
|
|
|
|
|
use app\common\controller\Backend;
|
|
|
+use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
|
|
use \think\Db;
|
|
|
use \think\Session;
|
|
|
/**
|
|
|
@@ -114,8 +115,224 @@ class Res extends Backend
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- //数据报告
|
|
|
+ //数据报告导出
|
|
|
public function report(){
|
|
|
- $this->error('此功能暂未开发');
|
|
|
+ if ($this->request->isGet()){
|
|
|
+ $judge=null;
|
|
|
+ $data=array();
|
|
|
+ $ids = input('id');
|
|
|
+ $id = explode(',',$ids);
|
|
|
+ for ($i=0;$i<count($id);$i++){
|
|
|
+ $res = Db::name('res')->where('id',$id[$i])->find();
|
|
|
+ if ($res['judge'] == 1){
|
|
|
+ $judge = '合格';
|
|
|
+ }else{
|
|
|
+ $judge = '不合格';
|
|
|
+ }
|
|
|
+ $entrust = Db::name('entrust')->where('id',$res['entrust_id'])->find();
|
|
|
+ $gather = Db::name($entrust['gather_tab'])->where('pid',$entrust['gather_id'])->select();
|
|
|
+ $data[$i] = [
|
|
|
+ 'name' => $entrust['name'],
|
|
|
+ 'sell_bach' => $entrust['sell_bach'],
|
|
|
+ 'bach' => $entrust['bach'],
|
|
|
+ 'massage' => '',
|
|
|
+ 'user_name' => $entrust['user_name'],
|
|
|
+ 'create' => $res['create'],
|
|
|
+ 'resname' => $entrust['sample_no'],
|
|
|
+ 'dis' => $res['dis'],
|
|
|
+ 'dis_impurity' => $res['dis_impurity'],
|
|
|
+ 'ben_total' => $res['ben_total'],
|
|
|
+ 'ben' => $res['ben'],
|
|
|
+ 'judge' => $judge,
|
|
|
+ 'maker' => $res['maker'],
|
|
|
+ 'remark' => '',
|
|
|
+ '0' => $gather[0]['potency'],
|
|
|
+ '1' => $gather[1]['potency'],
|
|
|
+ '2' => $gather[2]['potency'],
|
|
|
+ '3' => $gather[3]['potency'],
|
|
|
+ '4' => $gather[4]['potency'],
|
|
|
+ '5' => $gather[5]['potency'],
|
|
|
+ '6' => $gather[6]['potency'],
|
|
|
+ '7' => $gather[7]['potency'],
|
|
|
+ '8' => $gather[8]['potency'],
|
|
|
+ '9' => $gather[9]['potency'],
|
|
|
+ '10' => $gather[10]['potency'],
|
|
|
+ '11' => $gather[11]['potency'],
|
|
|
+ '12' => $gather[12]['potency'],
|
|
|
+ '13' => $gather[13]['potency'],
|
|
|
+ '14' => $gather[14]['potency'],
|
|
|
+ '15' => $gather[15]['potency'],
|
|
|
+ '16' => $gather[16]['potency'],
|
|
|
+ '17' => $gather[17]['potency'],
|
|
|
+ '18' => $gather[18]['potency'],
|
|
|
+ '19' => $gather[19]['potency'],
|
|
|
+ '20' => $gather[20]['potency'],
|
|
|
+ '21' => $gather[21]['potency'],
|
|
|
+ '22' => $gather[22]['potency'],
|
|
|
+ '23' => $gather[23]['potency'],
|
|
|
+ '24' => $gather[24]['potency'],
|
|
|
+ '25' => $gather[25]['potency'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $this->exceloutput($data);
|
|
|
+ }else{
|
|
|
+ $this->error('参数错误');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //excel格式
|
|
|
+ public function exceloutput($data){
|
|
|
+ vendor("phpoffice/phpspreadsheet/src/PhpSpreadsheet/Spreadsheet");
|
|
|
+ $objexcel = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
|
|
+ $sheet = $objexcel->getActiveSheet();
|
|
|
+ //设置全局单元格垂直居中
|
|
|
+ $objexcel->getDefaultStyle()->getAlignment()->setVertical(Alignment::HORIZONTAL_CENTER);
|
|
|
+ //设置全局单元格水平居中
|
|
|
+ $objexcel->getDefaultStyle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
|
|
|
+ //设置全局单元格自动换行
|
|
|
+ $objexcel->getDefaultStyle()->getAlignment()->setWrapText(true);
|
|
|
+ //设置单元格宽度
|
|
|
+ $sheet->getDefaultColumnDimension()->setWidth(18);
|
|
|
+ //合并单元格,设置表头格式
|
|
|
+ $sheet->mergeCells('A1:AN1');
|
|
|
+ $sheet->mergeCells('A2:A3');
|
|
|
+ $sheet->mergeCells('B2:B3');
|
|
|
+ $sheet->mergeCells('C2:C3');
|
|
|
+ $sheet->mergeCells('D2:D3');
|
|
|
+ $sheet->mergeCells('E2:E3');
|
|
|
+ $sheet->mergeCells('F2:F3');
|
|
|
+ $sheet->mergeCells('G2:G3');
|
|
|
+ $sheet->mergeCells('H2:H3');
|
|
|
+ $sheet->mergeCells('I2:K2');
|
|
|
+ $sheet->mergeCells('L2:L3');
|
|
|
+ $sheet->mergeCells('M2:M3');
|
|
|
+ $sheet->mergeCells('N2:N3');
|
|
|
+ $sheet->mergeCells('O2:O3');
|
|
|
+ $sheet->mergeCells('P2:P3');
|
|
|
+ $sheet->mergeCells('Q2:Q3');
|
|
|
+ $sheet->mergeCells('R2:R3');
|
|
|
+ $sheet->mergeCells('S2:S3');
|
|
|
+ $sheet->mergeCells('T2:T3');
|
|
|
+ $sheet->mergeCells('U2:U3');
|
|
|
+ $sheet->mergeCells('V2:V3');
|
|
|
+ $sheet->mergeCells('W2:W3');
|
|
|
+ $sheet->mergeCells('X2:X3');
|
|
|
+ $sheet->mergeCells('Y2:Y3');
|
|
|
+ $sheet->mergeCells('Z2:Z3');
|
|
|
+ $sheet->mergeCells('AA2:AA3');
|
|
|
+ $sheet->mergeCells('AB2:AB3');
|
|
|
+ $sheet->mergeCells('AC2:AC3');
|
|
|
+ $sheet->mergeCells('AD2:AD3');
|
|
|
+ $sheet->mergeCells('AE2:AE3');
|
|
|
+ $sheet->mergeCells('AF2:AF3');
|
|
|
+ $sheet->mergeCells('AG2:AG3');
|
|
|
+ $sheet->mergeCells('AH2:AH3');
|
|
|
+ $sheet->mergeCells('AI2:AI3');
|
|
|
+ $sheet->mergeCells('AJ2:AJ3');
|
|
|
+ $sheet->mergeCells('AK2:AK3');
|
|
|
+ $sheet->mergeCells('AL2:AL3');
|
|
|
+ $sheet->mergeCells('AM2:AM3');
|
|
|
+ $sheet->mergeCells('AN2:AN3');
|
|
|
+ //设置表头
|
|
|
+ $sheet->setCellValue('A2', '产品名称');
|
|
|
+ $sheet->setCellValue('B2','销售订单号');
|
|
|
+ $sheet->setCellValue('C2','生产批次号');
|
|
|
+ $sheet->setCellValue('D2','样品信息');
|
|
|
+ $sheet->setCellValue('E2','送样人');
|
|
|
+ $sheet->setCellValue('F2','检测日期');
|
|
|
+ $sheet->setCellValue('G2','检测编号');
|
|
|
+ $sheet->setCellValue('H2','溶剂残留总量 ≤70.0mg/m²');
|
|
|
+ $sheet->setCellValue('I2','溶剂杂质');
|
|
|
+ $sheet->setCellValue('I3','溶剂杂质总量 ≤7.0mg/m²');
|
|
|
+ $sheet->setCellValue('J3','苯系物总量 ≤0.7mg/m²');
|
|
|
+ $sheet->setCellValue('K3','苯含量 ≤0.010mg/m²');
|
|
|
+ $sheet->setCellValue('L2','判定结论');
|
|
|
+ $sheet->setCellValue('M2','检测人');
|
|
|
+ $sheet->setCellValue('N2','备注');
|
|
|
+ $sheet->setCellValue('O2','甲醇');
|
|
|
+ $sheet->setCellValue('P2','乙醇');
|
|
|
+ $sheet->setCellValue('Q2','异丙醇');
|
|
|
+ $sheet->setCellValue('R2','丙酮');
|
|
|
+ $sheet->setCellValue('S2','正丙醇');
|
|
|
+ $sheet->setCellValue('T2','丁酮');
|
|
|
+ $sheet->setCellValue('U2','乙酸乙酯');
|
|
|
+ $sheet->setCellValue('V2','乙酸异丙酯');
|
|
|
+ $sheet->setCellValue('W2','正丁醇');
|
|
|
+ $sheet->setCellValue('X2','苯');
|
|
|
+ $sheet->setCellValue('Y2','1-甲氧基-2-丙醇');
|
|
|
+ $sheet->setCellValue('Z2','乙酸正丙酯');
|
|
|
+ $sheet->setCellValue('AA2','2-乙氧基乙醇');
|
|
|
+ $sheet->setCellValue('AB2','4-甲基-2-戊酮');
|
|
|
+ $sheet->setCellValue('AC2','1-乙氧基-2-丙醇');
|
|
|
+ $sheet->setCellValue('AD2','甲苯');
|
|
|
+ $sheet->setCellValue('AE2','乙酸正丁酯');
|
|
|
+ $sheet->setCellValue('AF2','乙苯');
|
|
|
+ $sheet->setCellValue('AG2','间、对-二甲苯');
|
|
|
+ $sheet->setCellValue('AH2','邻-二甲苯');
|
|
|
+ $sheet->setCellValue('AI2','苯乙烯');
|
|
|
+ $sheet->setCellValue('AJ2','2-乙氧基乙基乙酸酯');
|
|
|
+ $sheet->setCellValue('AK2','环己酮');
|
|
|
+ $sheet->setCellValue('AL2','丁二酸二甲酯');
|
|
|
+ $sheet->setCellValue('AM2','戊二酸二甲酯');
|
|
|
+ $sheet->setCellValue('AN2','己二酸二甲酯');
|
|
|
+ //设置A列宽度
|
|
|
+ $sheet->getColumnDimension('A')->setWidth(25);
|
|
|
+ //插入表格内容
|
|
|
+ for ($i=0;$i<count($data);$i++){
|
|
|
+ $k = $i+4;
|
|
|
+ $sheet->getCell('A'.$k)->setValue($data[$i]['name']);
|
|
|
+ $sheet->getCell('B'.$k)->setValue($data[$i]['sell_bach']);
|
|
|
+ $sheet->getCell('C'.$k)->setValue($data[$i]['bach']);
|
|
|
+ $sheet->getCell('D'.$k)->setValue($data[$i]['massage']);
|
|
|
+ $sheet->getCell('E'.$k)->setValue($data[$i]['user_name']);
|
|
|
+ $sheet->getCell('F'.$k)->setValue($data[$i]['create']);
|
|
|
+ $sheet->getCell('G'.$k)->setValue($data[$i]['resname']);
|
|
|
+ $sheet->getCell('H'.$k)->setValue($data[$i]['dis']);
|
|
|
+ $sheet->getCell('I'.$k)->setValue($data[$i]['dis_impurity']);
|
|
|
+ $sheet->getCell('J'.$k)->setValue($data[$i]['ben_total']);
|
|
|
+ $sheet->getCell('K'.$k)->setValue($data[$i]['ben']);
|
|
|
+ $sheet->getCell('L'.$k)->setValue($data[$i]['judge']);
|
|
|
+ $sheet->getCell('M'.$k)->setValue($data[$i]['maker']);
|
|
|
+ $sheet->getCell('N'.$k)->setValue($data[$i]['remark']);
|
|
|
+ $sheet->getCell('O'.$k)->setValue($data[$i]['0']);
|
|
|
+ $sheet->getCell('P'.$k)->setValue($data[$i][1]);
|
|
|
+ $sheet->getCell('Q'.$k)->setValue($data[$i][2]);
|
|
|
+ $sheet->getCell('R'.$k)->setValue($data[$i][3]);
|
|
|
+ $sheet->getCell('S'.$k)->setValue($data[$i][4]);
|
|
|
+ $sheet->getCell('T'.$k)->setValue($data[$i][5]);
|
|
|
+ $sheet->getCell('U'.$k)->setValue($data[$i][6]);
|
|
|
+ $sheet->getCell('V'.$k)->setValue($data[$i][7]);
|
|
|
+ $sheet->getCell('W'.$k)->setValue($data[$i][8]);
|
|
|
+ $sheet->getCell('X'.$k)->setValue($data[$i][9]);
|
|
|
+ $sheet->getCell('Y'.$k)->setValue($data[$i][10]);
|
|
|
+ $sheet->getCell('Z'.$k)->setValue($data[$i][11]);
|
|
|
+ $sheet->getCell('AA'.$k)->setValue($data[$i][12]);
|
|
|
+ $sheet->getCell('AB'.$k)->setValue($data[$i][13]);
|
|
|
+ $sheet->getCell('AC'.$k)->setValue($data[$i][14]);
|
|
|
+ $sheet->getCell('AD'.$k)->setValue($data[$i][15]);
|
|
|
+ $sheet->getCell('AE'.$k)->setValue($data[$i][16]);
|
|
|
+ $sheet->getCell('AF'.$k)->setValue($data[$i][17]);
|
|
|
+ $sheet->getCell('AG'.$k)->setValue($data[$i][18]);
|
|
|
+ $sheet->getCell('AH'.$k)->setValue($data[$i][19]);
|
|
|
+ $sheet->getCell('AI'.$k)->setValue($data[$i][20]);
|
|
|
+ $sheet->getCell('AJ'.$k)->setValue($data[$i][21]);
|
|
|
+ $sheet->getCell('AK'.$k)->setValue($data[$i][22]);
|
|
|
+ $sheet->getCell('AL'.$k)->setValue($data[$i][23]);
|
|
|
+ $sheet->getCell('AM'.$k)->setValue($data[$i][24]);
|
|
|
+ $sheet->getCell('AN'.$k)->setValue($data[$i][25]);
|
|
|
+ //不合格字体设置红色
|
|
|
+ $start = 'A'.$k; $xend = 'AN'.$k;
|
|
|
+ if ($data[$i]['judge'] == '不合格'){
|
|
|
+ $sheet->getStyle("$start:$xend")->getFont()->getColor()
|
|
|
+ ->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_RED);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //excel文件格式
|
|
|
+ $filename = '数据报告'.date('ymdhis',time()).'.xlsx';
|
|
|
+ header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
|
|
+ header('Content-Disposition: attachment;filename="'.$filename.'"');
|
|
|
+ header('Cache-Control: max-age=0');
|
|
|
+ $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($objexcel, 'Xlsx');
|
|
|
+ $writer->save('php://output');
|
|
|
+ exit;
|
|
|
}
|
|
|
}
|