<?php

namespace Home\Controller;

use Think\Controller;
use Vendor\PHPExcel;

class ExportModuleController extends ComController
{

    public function  getArchivesListExpor(){
        $Data = I('');
        if (!isset($_SESSION['phone'])) {
            $res['msg'] = '请重新进入公众号';
            $res['flag'] = false;
            echo json_encode($res);
            exit();
        }

        $where="";
        if (!empty($Data['id'])) {
            $where .= " and b.id = ".$Data['id'];
        }

        if (!empty($Data['site_id'])) {
            $where .= " and b.site_id = ".$Data['site_id'];
        }

        if (!empty($Data['supervision_name'])) {
            $where .= " and d.supervision_name = ".$Data['supervision_name'];
        }

        if (!empty($Data['site_name'])) {
            $where .= " and e.site_name = ".$Data['site_name'];
        }


        $R=M()->query("select b.*,c.route_name,c.supervision_id,d.supervision_name,d.phone,e.site_name,s.sitedtl_id,
                        s.cable_hole_describe,s.cable_hole_picture,s.damage_describe,s.damage_picture,
                        s.water_leakage_describe,s.water_leakage_picture,s.annihilator_insufficient_configuration_describe,
                        s.annihilator_insufficient_configuration_picture,s.annihilator_overdue_describe,
                        s.annihilator_overdue_picture,s.pile_up_sundries_describe,s.pile_up_sundries_picture,
                        s.serious_ash_deposition_describe,s.serious_ash_deposition_picture,s.around_environment_humid_describe,
                        s.around_environment_humid_picture,s.around_pile_up_sundries_describe,s.around_pile_up_sundries_picture,
                        s.no_electrician_describe,s.no_electrician_picture,s.electrician_lack_describe,s.electrician_lack_picture,
                        s.overdue_electrician_certificate_describe,s.overdue_electrician_certificate_picture,
                        s.blanket_insufficient_configuration_describe,s.blanket_insufficient_configuration_picture,
                        s.ground_wire_describe,s.ground_wire_picture,s.analog_screen_describe,s.analog_screen_picture 
                        from personnel as a join sitedtl as b on a.site_id=b.site_id join route as c on b.route_id=c.id 
                        join supervision as d on b.supervision_department_id=d.id join site as e on b.site_id=e.id  
                        LEFT JOIN site_archives AS s ON b.id=s.sitedtl_id where a.personnel_phone='".$_SESSION['phone']."'".$where." order by b.id desc");


        vendor('PHPExcel.PHPExcel');
//        vendor('PHPExcel.PHPExcel.Style');
        $objPHPExcel = new \PHPExcel();
        $objPHPExcel->setActiveSheetIndex(0);
        $objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', '户号')
            ->setCellValue('B1', '流变变比')
            ->setCellValue('C1', '单路电源容量')
            ->setCellValue('D1', '线路')
            ->setCellValue('E1', '站点名称')
            ->setCellValue('F1', '监察')
            ->setCellValue('G1', '电缆孔洞')
            ->setCellValue('H1', '电缆孔洞描述')
            ->setCellValue('I1', '门窗墙壁破损')
            ->setCellValue('J1', '门窗墙壁破损描述')
            ->setCellValue('K1', '屋顶、墙壁渗漏水')
            ->setCellValue('L1', '屋顶、墙壁渗漏水描述')
            ->setCellValue('M1', '灭火器配置不足')
            ->setCellValue('N1', '灭火器配置不足描述')
            ->setCellValue('O1', '灭火器超期')
            ->setCellValue('P1', '灭火器超期描述')
            ->setCellValue('Q1', '堆放杂物')
            ->setCellValue('R1', '堆放杂物描述')
            ->setCellValue('S1', '积灰严重')
            ->setCellValue('T1', '积灰严重描述')
            ->setCellValue('U1', '配电房周围环境潮湿')
            ->setCellValue('V1', '配电房周围环境潮湿描述')
            ->setCellValue('W1', '配电房周围堆放杂物')
            ->setCellValue('X1', '配电房周围堆放杂物描述')
            ->setCellValue('Y1', '无电工')
            ->setCellValue('Z1', '无电工描述')
            ->setCellValue('AA1', '电工人数配置不足')
            ->setCellValue('AB1', '电工人数配置不足描述')
            ->setCellValue('AC1', '电工证超期')
            ->setCellValue('AD1', '电工证超期描述')
            ->setCellValue('AE1', '电试超期')
            ->setCellValue('AF1', '设备老旧')
            ->setCellValue('AG1', '绝缘毯配置不足')
            ->setCellValue('AH1', '绝缘毯配置不足描述')
            ->setCellValue('AI1', '接地线与存放位置')
            ->setCellValue('AJ1', '接地线与存放位置描述')
            ->setCellValue('AK1', '模拟屏')
            ->setCellValue('AL1', '模拟屏描述')
            ->setCellValue('AM1', '备注')
            ->setCellValue('AN1', '门挡板')
            ->setCellValue('AO1', '高压柜年份')
            ->setCellValue('AP1', '带电显示器损坏')
            ->setCellValue('AQ1', '是否具备照明')
            ->setCellValue('AR1', '创建人')
            ->setCellValue('AS1', '创建时间');

        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(20);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(20);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(20);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(20);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(20);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(10);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('H')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('I')->setWidth(10);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('J')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('K')->setWidth(10);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('L')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('M')->setWidth(10);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('N')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('O')->setWidth(10);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('P')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('Q')->setWidth(10);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('R')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('S')->setWidth(10);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('T')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('U')->setWidth(10);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('V')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('W')->setWidth(10);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('X')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('Y')->setWidth(10);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('Z')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('AA')->setWidth(10);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('AB')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('AC')->setWidth(10);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('AD')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('AE')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('AF')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('AG')->setWidth(10);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('AH')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('AI')->setWidth(10);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('AJ')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('AK')->setWidth(10);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('AL')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('AM')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('AN')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('AO')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('AP')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('AQ')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('AR')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('AS')->setWidth(30);


        $objPHPExcel->getActiveSheet()->getStyle('A')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('B')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('C')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('D')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('E')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('F')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('G')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('H')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('I')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('J')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('K')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('L')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('M')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('N')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('O')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('P')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('Q')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('R')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('S')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('T')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('U')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('V')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('W')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('X')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('Y')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('Z')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('AA')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('AB')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('AC')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('AD')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('AE')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('AF')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('AG')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('AH')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('AI')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('AJ')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('AK')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('AL')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('AM')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('AN')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('AO')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('AP')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('AQ')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('AR')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('AS')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);

        if (!empty($R)) {
            foreach ($R as $key => $value) {
//                $objPHPExcel->getActiveSheet()->getStyle('A'. ($key + 2))->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                $objPHPExcel->getActiveSheet()->setCellValue('A' . ($key + 2), ' ' . $R[$key]['account_number']);
                $objPHPExcel->getActiveSheet()->setCellValue('B' . ($key + 2), $R[$key]['rheological_change']);
                $objPHPExcel->getActiveSheet()->setCellValue('C' . ($key + 2), $R[$key]['power_capacity']);
                $objPHPExcel->getActiveSheet()->setCellValue('D' . ($key + 2), $R[$key]['route_name']);
                $objPHPExcel->getActiveSheet()->setCellValue('E' . ($key + 2), $R[$key]['site_name']);
                $objPHPExcel->getActiveSheet()->setCellValue('F' . ($key + 2), $R[$key]['supervision_name']);
                $objPHPExcel->getActiveSheet()->setCellValue('G' . ($key + 2), $R[$key]['cable_hole'] == 1 ? '是 ': '否');
                $objPHPExcel->getActiveSheet()->setCellValue('H' . ($key + 2), $R[$key]['cable_hole_describe']);
                $objPHPExcel->getActiveSheet()->setCellValue('I' . ($key + 2), $R[$key]['damage'] == 1 ? '是 ': '否');
                $objPHPExcel->getActiveSheet()->setCellValue('J' . ($key + 2), $R[$key]['damage_describe']);
                $objPHPExcel->getActiveSheet()->setCellValue('K' . ($key + 2), $R[$key]['water_leakage'] == 1 ? '是 ': '否');
                $objPHPExcel->getActiveSheet()->setCellValue('L' . ($key + 2), $R[$key]['water_leakage_describe']);
                $objPHPExcel->getActiveSheet()->setCellValue('M' . ($key + 2), $R[$key]['annihilator_insufficient_configuration'] == 1 ? '是 ': '否');
                $objPHPExcel->getActiveSheet()->setCellValue('N' . ($key + 2), $R[$key]['annihilator_insufficient_configuration_describe']);
                $objPHPExcel->getActiveSheet()->setCellValue('O' . ($key + 2), $R[$key]['annihilator_overdue'] == 1 ? '是 ': '否');
                $objPHPExcel->getActiveSheet()->setCellValue('P' . ($key + 2), $R[$key]['annihilator_overdue_describe']);
                $objPHPExcel->getActiveSheet()->setCellValue('Q' . ($key + 2), $R[$key]['pile_up_sundries'] == 1 ? '是 ': '否');
                $objPHPExcel->getActiveSheet()->setCellValue('R' . ($key + 2), $R[$key]['pile_up_sundries_describe']);
                $objPHPExcel->getActiveSheet()->setCellValue('S' . ($key + 2), $R[$key]['serious_ash_deposition'] == 1 ? '是 ': '否');
                $objPHPExcel->getActiveSheet()->setCellValue('T' . ($key + 2), $R[$key]['serious_ash_deposition_describe']);
                $objPHPExcel->getActiveSheet()->setCellValue('U' . ($key + 2), $R[$key]['around_environment_humid'] == 1 ? '是 ': '否');
                $objPHPExcel->getActiveSheet()->setCellValue('V' . ($key + 2), $R[$key]['around_environment_humid_describe']);
                $objPHPExcel->getActiveSheet()->setCellValue('W' . ($key + 2), $R[$key]['around_pile_up_sundries'] == 1 ? '是 ': '否');
                $objPHPExcel->getActiveSheet()->setCellValue('X' . ($key + 2), $R[$key]['around_pile_up_sundries_describe']);
                $objPHPExcel->getActiveSheet()->setCellValue('Y' . ($key + 2), $R[$key]['no_electrician'] == 1 ? '是 ': '否');
                $objPHPExcel->getActiveSheet()->setCellValue('Z' . ($key + 2), $R[$key]['no_electrician_describe']);
                $objPHPExcel->getActiveSheet()->setCellValue('AA' . ($key + 2), $R[$key]['electrician_lack'] == 1 ? '是 ': '否');
                $objPHPExcel->getActiveSheet()->setCellValue('AB' . ($key + 2), $R[$key]['electrician_lack_describe']);
                $objPHPExcel->getActiveSheet()->setCellValue('AC' . ($key + 2), $R[$key]['overdue_electrician_certificate'] == 1 ? '是 ': '否');
                $objPHPExcel->getActiveSheet()->setCellValue('AD' . ($key + 2), $R[$key]['overdue_electrician_certificate_describe']);
                $objPHPExcel->getActiveSheet()->setCellValue('AE' . ($key + 2), $R[$key]['electric_test_overdue']);
                $objPHPExcel->getActiveSheet()->setCellValue('AF' . ($key + 2), $R[$key]['old_equipment']);
                $objPHPExcel->getActiveSheet()->setCellValue('AG' . ($key + 2), $R[$key]['blanket_insufficient_configuration'] == 1 ? '是 ': '否');
                $objPHPExcel->getActiveSheet()->setCellValue('AH' . ($key + 2), $R[$key]['blanket_insufficient_configuration_describe']);
                $objPHPExcel->getActiveSheet()->setCellValue('AI' . ($key + 2), $R[$key]['ground_wire'] == 1 ? '是 ': '否');
                $objPHPExcel->getActiveSheet()->setCellValue('AJ' . ($key + 2), $R[$key]['ground_wire_describe']);
                $objPHPExcel->getActiveSheet()->setCellValue('AK' . ($key + 2), $R[$key]['analog_screen'] == 1 ? '是 ': '否');
                $objPHPExcel->getActiveSheet()->setCellValue('AL' . ($key + 2), $R[$key]['analog_screen_describe']);
                $objPHPExcel->getActiveSheet()->setCellValue('AM' . ($key + 2), $R[$key]['remarks']);
                $objPHPExcel->getActiveSheet()->setCellValue('AN' . ($key + 2), $R[$key]['door_baffle'] == 1 ? '是 ': '否');
                $objPHPExcel->getActiveSheet()->setCellValue('AO' . ($key + 2), $R[$key]['high_voltage_cabinet']);
                $objPHPExcel->getActiveSheet()->setCellValue('AP' . ($key + 2), $R[$key]['charged_display'] == 1 ? '是 ': '否');
                $objPHPExcel->getActiveSheet()->setCellValue('AQ' . ($key + 2), $R[$key]['lighting'] == 1 ? '具备': '不具备');
                $objPHPExcel->getActiveSheet()->setCellValue('AR' . ($key + 2), $R[$key]['creator']);
                $objPHPExcel->getActiveSheet()->setCellValue('AS' . ($key + 2), $R[$key]['create_time']);
            }
        }
        $filename = '现场档案汇总表' . date('ymd', time()) . '.xls';
        $objPHPExcel->getActiveSheet()->setTitle('现场档案汇总表');
        ob_end_clean();
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
        header('Content-Disposition:inline;filename="' . $filename . '"');
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        $objWriter->save('php://output');
        exit;





        $res['msg'] = '操作成功';
        $res['flag'] = true;
        $res['data'] = $R;
        echo json_encode($res);
    }

    public function getStatusDetailsListExpor()
    {

        $Date = I();
        $phone = $Date['phone'];
        $company_code = $Date['company_code'];
        $status_type = $Date['status_type'];
        $transfer_type = $Date['transfer_type'];
        $dwtype = $Date['dwtype'];
        if (!empty($_SESSION['phone'])) {
            $phone = $_SESSION['phone'];
        }

        if (!isset($status_type)) {
            $res['msg'] = '操作失败，缺少重要参数';
            $res['flag'] = false;
            echo json_encode($res);
            exit();
        }

        if (!empty($company_code)) {
            $device_list = $this->getDeviceCode($company_code);
        } else {
            $company_code1 = M()->query("select owner_code from sp_owner_phone WHERE phone='" . $phone . "' GROUP BY owner_code limit 1");
            $company_code = $company_code1[0]['owner_code'];
            $device_list = $this->getDeviceCode($company_code);
        }

        $where = '';
        if (!empty($transfer_type)) {
            $where .= " and b.transfer_type='" . $transfer_type . "' ";
        }

        if (!empty($dwtype)) {
            $where .= " and b.dwtype='" . $dwtype . "' ";
        }

        switch ($status_type) {
            case '1':
                $data1 = M()->query("select b.* from sp_v_device_status as a join sp_owner as b on a.device_id=b.owner_code  where a.device_status='离线' and a.device_id in(" . $device_list . ")" . $where);
                $data2 = M()->query("SELECT b.* FROM sp_devices_status AS a JOIN sp_owner AS b ON a.deviceid=b.owner_code WHERE b.dwtype=1 AND a.true_status in(75,300) AND b.company='" . $company_code . "' " . $where);
                break;
            case '2':
                $data1 = M()->query("select b.* from sp_v_device_status as a join sp_owner as b on a.device_id=b.owner_code  where a.device_status='在线' and a.device_id in(" . $device_list . ")" . $where);
                $data2 = M()->query("SELECT b.* FROM sp_devices_status AS a JOIN sp_owner AS b ON a.deviceid=b.owner_code WHERE b.dwtype=1 AND a.true_status='0' AND b.company='" . $company_code . "' " . $where);
                break;
            default:
                $res['msg'] = '操作失败，系统中尚未定义该类型';
                $res['flag'] = false;
                echo json_encode($res);
                exit();
                break;
        }

        $data = array_merge($data1, $data2);
        vendor('PHPExcel.PHPExcel');
//        vendor('PHPExcel.PHPExcel.Style');
        $objPHPExcel = new \PHPExcel();
        $objPHPExcel->setActiveSheetIndex(0);
        $objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', '设备编号')
            ->setCellValue('B1', '设备名称')
            ->setCellValue('C1', '单元地址')
            ->setCellValue('D1', '类型编号')
            ->setCellValue('E1', '传输方式')
            ->setCellValue('F1', '添加时间');

        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(20);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(20);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(30);

        $objPHPExcel->getActiveSheet()->getStyle('A')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('B')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('C')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('D')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('E')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
        $objPHPExcel->getActiveSheet()->getStyle('F')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);

        if (!empty($data)) {
            foreach ($data as $key => $value) {
//                $objPHPExcel->getActiveSheet()->getStyle('A'. ($key + 2))->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                $objPHPExcel->getActiveSheet()->setCellValue('A' . ($key + 2), ' ' . $data[$key]['owner_code']);
                $objPHPExcel->getActiveSheet()->setCellValue('B' . ($key + 2), $data[$key]['owner_name']);
                $objPHPExcel->getActiveSheet()->setCellValue('C' . ($key + 2), $data[$key]['unitinfo']);
                $objPHPExcel->getActiveSheet()->setCellValue('D' . ($key + 2), $data[$key]['dwtype']);
                $objPHPExcel->getActiveSheet()->setCellValue('E' . ($key + 2), $data[$key]['transfer_type']);
                $objPHPExcel->getActiveSheet()->setCellValue('F' . ($key + 2), $data[$key]['install_time']);
            }
        }
        $filename = '设备运行状态列表' . date('ymd', time()) . '.xls';
        $objPHPExcel->getActiveSheet()->setTitle('设备运行状态列表');
        ob_end_clean();
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
        header('Content-Disposition:inline;filename="' . $filename . '"');
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        $objWriter->save('php://output');
        exit;


    }
}