<?php
/**
 * Created by PhpStorm.
 * User: sicilon_IT
 * Date: 2020/2/6
 * Time: 23:29
 */

namespace app\index\controller;
use app\index\logic\checkmanger;
use app\index\logic\contactlogic;
use app\index\logic\recuitlogic;
use think\Controller;

class Checkinfo extends Controller {
    /*
     * 20200302
     * steelxu
     * 标准输出检查找包
     * 测试成功后，再看是做到扩展的基础类，还是
     */
    public function stdout($arr) {
        $res_r = array();
        if (empty($arr)) {
            $res_r['code'] = 0;
            $res_r['msg'] = '无数据';
        } else {
            $res_r['code'] = 200;
            $res_r['resultData'] = $arr;
        }

        return $res_r;
    }
    /*
     * web端获取按月按人统计出勤天数，出勤总分的接口
     * 20200206
     * steelxu
     */
    public function summonthcheckinfo() {
        $queryinfo = request()->param();
        //预处理奖励数据
        $l_r = new recuitlogic();
        $l_r->oprrecuitaward();
        $l_check = new checkmanger();
        $r_list = $l_check->getsumcheckinfo($queryinfo);

        if (empty($r_list)) {
            $res_r['code'] = 0;
            $res_r['errmsg'] = '无汇总数据';
        } else {
            $res_r['code'] = 200;
            $res_r['resultData'] = $r_list;
        }
        return json_encode($res_r, 320);
    }

    /*
     * 20230215
     * 统计本公司考勤
     */
    public function sumcompanymonthcheckinfo() {
        $queryinfo = request()->param();
        //预处理奖励数据
        $l_r = new recuitlogic();
        $l_r->oprrecuitaward();
        $l_check = new checkmanger();
        $r_list = $l_check->getsumcompanycheckinfo($queryinfo);

        if (empty($r_list)) {
            $res_r['code'] = 0;
            $res_r['errmsg'] = '无汇总数据';
        } else {
            $res_r['code'] = 200;
            $res_r['resultData'] = $r_list;
        }
        return json_encode($res_r, 320);
    }

    /*
     * 考勤汇总信息导出execl
     * 20200210
     * steelxu
     * 20203005
     * 加身份证号
     */

    //
    public function outtoexecl() {
        //获取传入参数

        $queryinfo = $queryinfo = request()->param();
        //预处理奖励数据
        $l_r = new recuitlogic();
        $l_r->oprrecuitaward();
        $month = $queryinfo['monthinfo'];
        $year = $queryinfo['yearinfo'];
        //获取数据
        $l_check = new checkmanger();
        $r_list = $l_check->getsumcheckinfo($queryinfo);
        //获取当用天数
        $daysofm = date('t', strtotime($year . '-' . $month . '-1'));

        //加载类库
        vendor('PHPExcel.PHPExcel');
        $objPHPExcel = new \PHPExcel();
        //4.激活当前的sheet表
        $objPHPExcel->setActiveSheetIndex(0);
        //5.设置表格头（即excel表格的第一行）
        $objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', 'ID')
            ->setCellValue('B1', '姓名')
            ->setCellValue('C1', '记工天数')
            ->setCellValue('D1', '当月计分')
            ->setCellValue('E1', '身份证号');
        for ($j = 1; $j <= $daysofm; $j++) {
            $columnname = strval($j);
            if (strlen($columnname) < 2) {
                $columnname = '0' . $columnname;
            }
            $fcolumnchar = \PHPExcel_Cell::stringFromColumnIndex($j + 4);
            $objPHPExcel->setActiveSheetIndex(0)->setCellValue($fcolumnchar . '1', $columnname);
        }
        $fcolumnchar = \PHPExcel_Cell::stringFromColumnIndex($daysofm + 5);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue($fcolumnchar . '1', '推荐奖励');

        //设置A列水平居中
        $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        //设置单元格宽度
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(8);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(12);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(12);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(12);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(20);
        //6.循环刚取出来的数组，将数据逐一添加到excel表格。
        for ($i = 0; $i < count($r_list); $i++) {
            $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $r_list[$i]['wid']); //ID
            $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $r_list[$i]['wname']); //名称
            $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $r_list[$i]['daycount']); //说明
            $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $r_list[$i]['monthsum']); //说明
            $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), "'" . $r_list[$i]['sfz']); //说明
            for ($j = 1; $j <= $daysofm; $j++) {
                $fname = strval($j);
                if (strlen($fname) < 2) {
                    $fname = '0' . $fname;
                }
                //$eecll=new \PHPExcel_Cell()
                $fcolumnstr = \PHPExcel_Cell::stringFromColumnIndex($j + 4);
                $objPHPExcel->getActiveSheet()->setCellValue($fcolumnstr . ($i + 2), (array_key_exists($fname, $r_list[$i]) ? $r_list[$i][$fname] : '-')); //说明
            }
            $fcolumnstr = \PHPExcel_Cell::stringFromColumnIndex($daysofm + 5);
            $objPHPExcel->getActiveSheet()->setCellValue($fcolumnstr . ($i + 2), $r_list[$i]['sumaward']); //说明

        }
        //7.设置保存的Excel表格名称
        $filename = $year . '年' . $month . '月考勤统计表' . date('ymd', time()) . '.xls';
        //8.设置当前激活的sheet表格名称；
        $objPHPExcel->getActiveSheet()->setTitle('考勤信息' . $year . '年' . $month . '月');
        //9.设置浏览器窗口下载表格
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
        header('Content-Disposition:inline;filename="' . $filename . '"');
        //生成excel文件
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        //下载文件在浏览器窗口
        $objWriter->save('php://output');
        //原代码没有返回
        $res_r['code'] = 200;
        $res_r['resultData'] = $filename;
        return json_encode($res_r, 320);
    }

    /*
     * 20230215
     */
    public function outcompanytoexecl() {
        //获取传入参数

        $queryinfo = $queryinfo = request()->param();
        //预处理奖励数据
        $l_r = new recuitlogic();
        $l_r->oprrecuitaward();
        $month = $queryinfo['monthinfo'];
        $year = $queryinfo['yearinfo'];
        $cid = $queryinfo['companyid'];
        //获取数据
        $l_check = new checkmanger();
        $r_list = $l_check->getsumcompanycheckinfo($queryinfo);
        //获取当用天数
        $daysofm = date('t', strtotime($year . '-' . $month . '-1'));

        //加载类库
        vendor('PHPExcel.PHPExcel');
        $objPHPExcel = new \PHPExcel();
        //4.激活当前的sheet表
        $objPHPExcel->setActiveSheetIndex(0);
        //5.设置表格头（即excel表格的第一行）
        $objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', 'ID')
            ->setCellValue('B1', '姓名')
            ->setCellValue('C1', '记工天数')
            ->setCellValue('D1', '当月计分')
            ->setCellValue('E1', '身份证号');
        for ($j = 1; $j <= $daysofm; $j++) {
            $columnname = strval($j);
            if (strlen($columnname) < 2) {
                $columnname = '0' . $columnname;
            }
            $fcolumnchar = \PHPExcel_Cell::stringFromColumnIndex($j + 4);
            $objPHPExcel->setActiveSheetIndex(0)->setCellValue($fcolumnchar . '1', $columnname);
        }
        $fcolumnchar = \PHPExcel_Cell::stringFromColumnIndex($daysofm + 5);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue($fcolumnchar . '1', '推荐奖励');

        //设置A列水平居中
        $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        //设置单元格宽度
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(8);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(12);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(12);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(12);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(20);
        //6.循环刚取出来的数组，将数据逐一添加到excel表格。
        for ($i = 0; $i < count($r_list); $i++) {
            $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $r_list[$i]['wid']); //ID
            $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $r_list[$i]['wname']); //名称
            $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $r_list[$i]['daycount']); //说明
            $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $r_list[$i]['monthsum']); //说明
            if (array_key_exists('sfz', $r_list[$i])) {
                $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), "'" . $r_list[$i]['sfz']); //说明
            }

            for ($j = 1; $j <= $daysofm; $j++) {
                $fname = strval($j);
                if (strlen($fname) < 2) {
                    $fname = '0' . $fname;
                }
                //$eecll=new \PHPExcel_Cell()
                $fcolumnstr = \PHPExcel_Cell::stringFromColumnIndex($j + 4);
                $objPHPExcel->getActiveSheet()->setCellValue($fcolumnstr . ($i + 2), (array_key_exists($fname, $r_list[$i]) ? $r_list[$i][$fname] : '-')); //说明
            }
            $fcolumnstr = \PHPExcel_Cell::stringFromColumnIndex($daysofm + 5);
            $objPHPExcel->getActiveSheet()->setCellValue($fcolumnstr . ($i + 2), $r_list[$i]['sumaward']); //说明

        }
        //7.设置保存的Excel表格名称
        $filename = $year . '年' . $month . '月考勤统计表' . date('ymd', time()) . '.xls';
        //8.设置当前激活的sheet表格名称；
        $objPHPExcel->getActiveSheet()->setTitle('考勤信息' . $year . '年' . $month . '月');
        //9.设置浏览器窗口下载表格
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
        header('Content-Disposition:inline;filename="' . $filename . '"');
        //生成excel文件
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        //下载文件在浏览器窗口
        $objWriter->save('php://output');
        //原代码没有返回
        $res_r['code'] = 200;
        $res_r['resultData'] = $filename;
        return json_encode($res_r, 320);
    }

    /*
     * 20200307
     * 做一个加班请求
     */

    public function queryworkovertime() {
        $queryinfo = request()->param();

        $pagenum = $queryinfo['pageNum'];
        $pagesize = $queryinfo['pageSize'];
        $l_check = new checkmanger();
        $rlist = $l_check->getworkovertime($pagenum, $pagesize);

        return json_encode($this->stdout($rlist), 320);
    }

    /*
     *
     * 20230215
     * 修改请求加班记录的功能
     * 只能请求本公司的数据
     */
    public function querycompanyworkovertime() {
        $queryinfo = request()->param();

        $pagenum = $queryinfo['pageNum'];
        $pagesize = $queryinfo['pageSize'];
        $cid = $queryinfo['companyid'];
        $l_check = new checkmanger();
        $rlist = $l_check->getworkovertimebycid($pagenum, $pagesize, $cid);

        return json_encode($this->stdout($rlist), 320);
    }
    /*
     * 20200310
     * 请求各合同下各班组的月度统计
     */
    public function queryglistmonthsum() {
        $queryinfo = request()->param();
        $l_contact = new contactlogic();
        $gsumlist = $l_contact->getgroupsumbycid($queryinfo);
        // print_r($gsumlist);
//        var_dump($gsumlist);
//       if (array_key_exists('0',$gsumlist)){
//           $r_list=$gsumlist[0]->data;
//       }else{
//           $r_list=$gsumlist;
//       }
//        var_dump($r_list);
        return json_encode($this->stdout($gsumlist), 320);
    }

    /*
     * 20200316
     * w合同下班组统计，到个人
     * getworkersumbycid
     */
    public function querywlistsummonth() {
        $queryinfo = request()->param();
        $l_contact = new contactlogic();
        $gsumlist = $l_contact->getworkersumbycid($queryinfo);
        return json_encode($this->stdout($gsumlist), 320);
    }

    /*
     * 20200318
     * 导出按合同汇总考勤数据
     */

    public function workersumtoexecl() {
        //获取数据
        $queryinfo = request()->param();
        $yearinfo = $queryinfo['yearinfo'];
        $monthinfo = $queryinfo['monthinfo'];
        $cname = $queryinfo['cname'];
        $l_contact = new contactlogic();
        //获取当用天数
        $daysofm = date('t', strtotime($yearinfo . '-' . $monthinfo . '-1'));
        $gsumlist = $l_contact->getworkersumbycid($queryinfo);

        //加载类库
        vendor('PHPExcel.PHPExcel');
        $objPHPExcel = new \PHPExcel();
        //4.激活当前的sheet表
        $objPHPExcel->setActiveSheetIndex(0);
        //5.设置表格头（即excel表格的第一行）
        $objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', '班组/工人')
            ->setCellValue('B1', '当月总记分');
        for ($j = 1; $j <= $daysofm; $j++) {
            $columnname = strval($j);
            if (strlen($columnname) < 2) {
                $columnname = '0' . $columnname;
            }
            $fcolumnchar = \PHPExcel_Cell::stringFromColumnIndex($j + 2);
            $objPHPExcel->setActiveSheetIndex(0)->setCellValue($fcolumnchar . '1', $columnname);
        }
        //设置A列水平居中
        $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        //设置单元格宽度
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(20);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(15);
        //6.循环刚取出来的数组，将数据逐一添加到excel表格。
        $rowindex = 0;
        for ($i = 0; $i < count($gsumlist); $i++) {
            //班组汇总信息
            $objPHPExcel->getActiveSheet()->setCellValue('A' . ($rowindex + 2), $gsumlist[$i]['gname']); //ID
            $objPHPExcel->getActiveSheet()->setCellValue('B' . ($rowindex + 2), $gsumlist[$i]['summonth']); //名称
            for ($j = 1; $j <= $daysofm; $j++) {
                //  for ($j=13; $j<=16;$j++){//测试临时
                $daystr = strval($j);
                if (strlen($daystr) < 2) {
                    $daystr = '0' . $daystr;
                }
                $fname = $yearinfo . '-' . $monthinfo . '-' . $daystr;
                //$eecll=new \PHPExcel_Cell()
                $fcolumnstr = \PHPExcel_Cell::stringFromColumnIndex($j + 2);
                $objPHPExcel->getActiveSheet()->setCellValue($fcolumnstr . ($rowindex + 2), (array_key_exists($fname, $gsumlist[$i]) ? $gsumlist[$i][$fname] : '-')); //说明
                //  $objPHPExcel->getActiveSheet()->setCellValue($fcolumnstr.($rowindex+2),$gsumlist[$i][$fname]);//说明
            }
            $rowindex++; //行控制
            //员工数据
            for ($workerindex = 0; $workerindex < count($gsumlist[$i]['detail']); $workerindex++) {
                $objPHPExcel->getActiveSheet()->setCellValue('A' . ($rowindex + 2), $gsumlist[$i]['detail'][$workerindex]['gname']); //
                $objPHPExcel->getActiveSheet()->setCellValue('B' . ($rowindex + 2), $gsumlist[$i]['detail'][$workerindex]['summonth']); //
                for ($j = 1; $j <= $daysofm; $j++) {
                    $daystr = strval($j);
                    if (strlen($daystr) < 2) {
                        $daystr = '0' . $daystr;
                    }
                    $fname = $yearinfo . '-' . $monthinfo . '-' . $daystr;
                    //$eecll=new \PHPExcel_Cell()
                    $fcolumnstr = \PHPExcel_Cell::stringFromColumnIndex($j + 2);
                    $objPHPExcel->getActiveSheet()->setCellValue($fcolumnstr . ($rowindex + 2), (array_key_exists($fname, $gsumlist[$i]['detail'][$workerindex]) ? $gsumlist[$i]['detail'][$workerindex][$fname] : '-')); //说明
                }
                $rowindex++; //行控制
            }
        }
        //7.设置保存的Excel表格名称
        $filename = $cname . '考勤汇总' . date('ymd', time()) . '.xls';
        //8.设置当前激活的sheet表格名称；
        $objPHPExcel->getActiveSheet()->setTitle($cname . '考勤汇总');
        //9.设置浏览器窗口下载表格
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
        header('Content-Disposition:inline;filename="' . $filename . '"');
        //生成excel文件
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        //下载文件在浏览器窗口
        $objWriter->save('php://output');
        //原代码没有返回
        $res_r['code'] = 200;
        $res_r['resultData'] = $filename;
        return json_encode($res_r, 320);
    }

    /*
     * 20200320
     * 自动导出所有的项目合同考勤，分页
     *
     */

    public function allworkersumtoexecl() {
        /*
         * 准备
         */
        //获取数据
        $queryinfo = request()->param();
        $yearinfo = $queryinfo['yearinfo'];
        $monthinfo = $queryinfo['monthinfo'];
        //获取所有导出的合同
        $l_contact = new contactlogic();
        $list_contact = $l_contact->getclist();
        //获取当用天数
        $daysofm = date('t', strtotime($yearinfo . '-' . $monthinfo . '-1'));
        //加载类库
        vendor('PHPExcel.PHPExcel');
        $objPHPExcel = new \PHPExcel();
        $pageindex = 0; //初始化页数
        /*
         * 循环处理所有合同
         */
        foreach ($list_contact as $contact) {
            $queryinfo['cid'] = $contact['id'];
            $cname = $contact['contactname'];
            //获取合同的数据
            $gsumlist = $l_contact->getworkersumbycid($queryinfo);

            //4.激活当前的sheet表
            if ($pageindex > 0) {
                $objPHPExcel->createSheet();
            }
            $objPHPExcel->setActiveSheetIndex($pageindex);
            //5.设置表格头（即excel表格的第一行）
            $objPHPExcel->setActiveSheetIndex($pageindex)
                ->setCellValue('A1', '班组')
                ->setCellValue('B1', '总分')
                ->setCellValue('C1', '班组')
                ->setCellValue('D1', '工人')
                ->setCellValue('E1', '当月总记分');
            for ($j = 1; $j <= $daysofm; $j++) {
                $columnname = strval($j);
                if (strlen($columnname) < 2) {
                    $columnname = '0' . $columnname;
                }
                $fcolumnchar = \PHPExcel_Cell::stringFromColumnIndex($j + 4);
                $objPHPExcel->setActiveSheetIndex($pageindex)->setCellValue($fcolumnchar . '1', $columnname);

//                $objPHPExcel->setActiveSheetIndex($pageindex)->getStyle($fcolumnchar)->getAlignment()
//                    ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
//                $objPHPExcel->setActiveSheetIndex($pageindex)->getColumnDimension($fcolumnchar)->setWidth(6);
            }

            $fcolumnchar = \PHPExcel_Cell::stringFromColumnIndex($daysofm + 5);
            $objPHPExcel->setActiveSheetIndex($pageindex)->setCellValue($fcolumnchar . '1', '招工成本');
            //设置A列水平居中
            $objPHPExcel->setActiveSheetIndex($pageindex)->getStyle('A')->getAlignment()
                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
            $objPHPExcel->setActiveSheetIndex($pageindex)->getStyle('B')->getAlignment()
                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
            $objPHPExcel->setActiveSheetIndex($pageindex)->getStyle('C')->getAlignment()
                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
            $objPHPExcel->setActiveSheetIndex($pageindex)->getStyle('D')->getAlignment()
                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
            $objPHPExcel->setActiveSheetIndex($pageindex)->getStyle('E')->getAlignment()
                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
            //设置单元格宽度
            $objPHPExcel->setActiveSheetIndex($pageindex)->getColumnDimension('A')->setWidth(20);
            $objPHPExcel->setActiveSheetIndex($pageindex)->getColumnDimension('B')->setWidth(11);
            $objPHPExcel->setActiveSheetIndex($pageindex)->getColumnDimension('C')->setWidth(20);
            $objPHPExcel->setActiveSheetIndex($pageindex)->getColumnDimension('D')->setWidth(10);
            $objPHPExcel->setActiveSheetIndex($pageindex)->getColumnDimension('E')->setWidth(13);

            //6.循环刚取出来的数组，将数据逐一添加到excel表格。
            $rowindex = 0;
            for ($i = 0; $i < count($gsumlist); $i++) {
//                //班组汇总信息
//               // var_dump($gsumlist[$i]);
//                $objPHPExcel->getActiveSheet()->setCellValue('A'.($rowindex+2),$gsumlist[$i]['gname']);//ID
//                $objPHPExcel->getActiveSheet()->setCellValue('B'.($rowindex+2),$gsumlist[$i]['summonth']);//名称
//                for ($j=1; $j<=$daysofm;$j++){
//                    //  for ($j=13; $j<=16;$j++){//测试临时
//                    $daystr=strval($j);
//                    if (strlen($daystr)<2){
//                        $daystr='0'.$daystr;
//                    }
//                    $fname=$yearinfo.'-'.$monthinfo.'-'.$daystr;
//                    //$eecll=new \PHPExcel_Cell()
//                    $fcolumnstr=\PHPExcel_Cell::stringFromColumnIndex($j+2);
//                    $objPHPExcel->getActiveSheet()->setCellValue($fcolumnstr.($rowindex+2),(array_key_exists($fname,$gsumlist[$i])?$gsumlist[$i][$fname]:'-'));//说明
//                    //  $objPHPExcel->getActiveSheet()->setCellValue($fcolumnstr.($rowindex+2),$gsumlist[$i][$fname]);//说明
//                }
//                $rowindex++;//行控制
                //员工数据
                $firstworker = $rowindex + 2;
                $workercounts = count($gsumlist[$i]['detail']);
                for ($workerindex = 0; $workerindex < $workercounts; $workerindex++) {
                    $objPHPExcel->getActiveSheet()->setCellValue('A' . ($rowindex + 2), $gsumlist[$i]['gname']);
                    $objPHPExcel->getActiveSheet()->setCellValue('C' . ($rowindex + 2), $gsumlist[$i]['gname']);
                    $objPHPExcel->getActiveSheet()->setCellValue('D' . ($rowindex + 2), $gsumlist[$i]['detail'][$workerindex]['gname']); //
                    $objPHPExcel->getActiveSheet()->setCellValue('E' . ($rowindex + 2), $gsumlist[$i]['detail'][$workerindex]['summonth']); //
                    for ($j = 1; $j <= $daysofm; $j++) {
                        $daystr = strval($j);
                        if (strlen($daystr) < 2) {
                            $daystr = '0' . $daystr;
                        }
                        $fname = $yearinfo . '-' . $monthinfo . '-' . $daystr;
                        //$eecll=new \PHPExcel_Cell()
                        $fcolumnstr = \PHPExcel_Cell::stringFromColumnIndex($j + 4);
                        $objPHPExcel->getActiveSheet()->setCellValue($fcolumnstr . ($rowindex + 2), (array_key_exists($fname, $gsumlist[$i]['detail'][$workerindex]) ? $gsumlist[$i]['detail'][$workerindex][$fname] : '-')); //说明
                    }
                    //招工成本处理
                    $fcolumnstr = \PHPExcel_Cell::stringFromColumnIndex($daysofm + 5);
                    $objPHPExcel->getActiveSheet()->setCellValue($fcolumnstr . ($rowindex + 2), (array_key_exists('recuitcost', $gsumlist[$i]['detail'][$workerindex]) ? $gsumlist[$i]['detail'][$workerindex]['recuitcost'] : '-'));

                    $rowindex++; //行控制
                }
                if ($workercounts > 0) {
                    $endworker = $rowindex + 1; //最后一行
                    $objPHPExcel->getActiveSheet()->mergeCells('A' . $firstworker . ':A' . $endworker);
                    $objPHPExcel->getActiveSheet()->getstyle('A' . $firstworker . ':A' . $endworker)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
                    $objPHPExcel->getActiveSheet()->mergeCells('B' . $firstworker . ':B' . $endworker);
                    $objPHPExcel->getActiveSheet()->getstyle('B' . $firstworker . ':B' . $endworker)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
                    $objPHPExcel->getActiveSheet()->setCellValue('B' . $firstworker, $gsumlist[$i]['summonth']);
                } else {
                    $objPHPExcel->getActiveSheet()->setCellValue('A' . ($rowindex + 2), $gsumlist[$i]['gname']);
                    $objPHPExcel->getActiveSheet()->setCellValue('B' . ($rowindex + 2), 0);
                    $rowindex++;
                }

            }
            //8.设置当前激活的sheet表格名称；
            $objPHPExcel->getActiveSheet()->setTitle($cname . '考勤汇总');
            $pageindex++;

        }

        //7.设置保存的Excel表格名称
        $filename = '考勤汇总' . date('ymd', time()) . '.xls';

        //9.设置浏览器窗口下载表格
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
        header('Content-Disposition:inline;filename="' . $filename . '"');
        //生成excel文件
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        //下载文件在浏览器窗口
        $objWriter->save('php://output');
        //原代码没有返回
        $res_r['code'] = 200;
        $res_r['resultData'] = $filename;
        return json_encode($res_r, 320);
    }

    /*
     * 20201029
     * 自动导出所有的项目合同考勤，分页
     * 并且合并成一个表
     * 在allworkersumtoexecl（）方法基础上修改
     *
     *
     */

    public function allworkersumuniontoexecl() {
        /*
         * 准备
         */
        //获取数据
        $queryinfo = request()->param();
        $yearinfo = $queryinfo['yearinfo'];
        $monthinfo = $queryinfo['monthinfo'];
        $strmonth = $yearinfo . '-' . $monthinfo;
        //获取所有导出的合同
        $l_contact = new contactlogic();
        $list_contact = $l_contact->getclist();
        //获取当用天数
        $daysofm = date('t', strtotime($yearinfo . '-' . $monthinfo . '-1'));
        //加载类库
        vendor('PHPExcel.PHPExcel');
        $objPHPExcel = new \PHPExcel();
        $pageindex = 0; //初始化页数，后面不再循环  todo 去掉此变理
        /*
         * 循环处理所有合同
         */
        $rowindex = 0;

        //4.激活当前的sheet表

        $objPHPExcel->setActiveSheetIndex($pageindex);
        //5.设置表格头（即excel表格的第一行）
        $objPHPExcel->setActiveSheetIndex($pageindex)
            ->setCellValue('A1', '合同')
            ->setCellValue('B1', '班组')
            ->setCellValue('C1', '总分')
            ->setCellValue('D1', '月度')
            ->setCellValue('E1', '工人')
            ->setCellValue('F1', '身份证')
            ->setCellValue('G1', '当月总记分');
        for ($j = 1; $j <= $daysofm; $j++) {
            $columnname = strval($j);
            if (strlen($columnname) < 2) {
                $columnname = '0' . $columnname;
            }
            $fcolumnchar = \PHPExcel_Cell::stringFromColumnIndex($j + 6);
            $objPHPExcel->setActiveSheetIndex($pageindex)->setCellValue($fcolumnchar . '1', $columnname);

        }

        $fcolumnchar = \PHPExcel_Cell::stringFromColumnIndex($daysofm + 7);
        $objPHPExcel->setActiveSheetIndex($pageindex)->setCellValue($fcolumnchar . '1', '招工成本');
        //设置A列水平居中
        $objPHPExcel->setActiveSheetIndex($pageindex)->getStyle('A')->getAlignment()
            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex($pageindex)->getStyle('B')->getAlignment()
            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex($pageindex)->getStyle('C')->getAlignment()
            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex($pageindex)->getStyle('D')->getAlignment()
            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex($pageindex)->getStyle('E')->getAlignment()
            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex($pageindex)->getStyle('F')->getAlignment()
            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        //设置F列为文本列
        $objPHPExcel->getActiveSheet()->getStyle('F')->getNumberFormat()
            ->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT); //
        $objPHPExcel->setActiveSheetIndex($pageindex)->getStyle('G')->getAlignment()
            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        //设置单元格宽度
        $objPHPExcel->setActiveSheetIndex($pageindex)->getColumnDimension('A')->setWidth(20);
        $objPHPExcel->setActiveSheetIndex($pageindex)->getColumnDimension('B')->setWidth(20);
        $objPHPExcel->setActiveSheetIndex($pageindex)->getColumnDimension('C')->setWidth(11);
        $objPHPExcel->setActiveSheetIndex($pageindex)->getColumnDimension('D')->setWidth(20);
        $objPHPExcel->setActiveSheetIndex($pageindex)->getColumnDimension('E')->setWidth(10);
        $objPHPExcel->setActiveSheetIndex($pageindex)->getColumnDimension('F')->setWidth(18);
        $objPHPExcel->setActiveSheetIndex($pageindex)->getColumnDimension('G')->setWidth(13);
        //6.循环刚取出来的数组，将数据逐一添加到excel表格。
        foreach ($list_contact as $contact) {
            $queryinfo['cid'] = $contact['id'];
            $cname = $contact['contactname'];
            //获取合同的数据
            $gsumlist = $l_contact->getworkersumbycid($queryinfo);

            for ($i = 0; $i < count($gsumlist); $i++) {

                $firstworker = $rowindex + 2;
                $workercounts = count($gsumlist[$i]['detail']);
                for ($workerindex = 0; $workerindex < $workercounts; $workerindex++) {
                    $objPHPExcel->getActiveSheet()->setCellValue('A' . ($rowindex + 2), $cname);
                    $objPHPExcel->getActiveSheet()->setCellValue('B' . ($rowindex + 2), $gsumlist[$i]['gname']);
                    $objPHPExcel->getActiveSheet()->setCellValue('D' . ($rowindex + 2), $strmonth);
                    $objPHPExcel->getActiveSheet()->setCellValue('E' . ($rowindex + 2), $gsumlist[$i]['detail'][$workerindex]['gname']); //
                    $objPHPExcel->getActiveSheet()->setCellValue('F' . ($rowindex + 2), $gsumlist[$i]['detail'][$workerindex]['sfz']); //
                    $objPHPExcel->getActiveSheet()->setCellValue('G' . ($rowindex + 2), $gsumlist[$i]['detail'][$workerindex]['summonth']); //
                    for ($j = 1; $j <= $daysofm; $j++) {
                        $daystr = strval($j);
                        if (strlen($daystr) < 2) {
                            $daystr = '0' . $daystr;
                        }
                        $fname = $yearinfo . '-' . $monthinfo . '-' . $daystr;
                        //$eecll=new \PHPExcel_Cell()
                        $fcolumnstr = \PHPExcel_Cell::stringFromColumnIndex($j + 6);
                        $objPHPExcel->getActiveSheet()->setCellValue($fcolumnstr . ($rowindex + 2), (array_key_exists($fname, $gsumlist[$i]['detail'][$workerindex]) ? $gsumlist[$i]['detail'][$workerindex][$fname] : '-')); //说明
                    }
                    //招工成本处理
                    $fcolumnstr = \PHPExcel_Cell::stringFromColumnIndex($daysofm + 7);
                    $objPHPExcel->getActiveSheet()->setCellValue($fcolumnstr . ($rowindex + 2), (array_key_exists('recuitcost', $gsumlist[$i]['detail'][$workerindex]) ? $gsumlist[$i]['detail'][$workerindex]['recuitcost'] : '-'));

                    $rowindex++; //行控制
                }
                if ($workercounts > 0) {
                    $endworker = $rowindex + 1; //最后一行
                    //根据客户要求，不再分隔，20201106
//                    $objPHPExcel->getActiveSheet()->mergeCells('A'.$firstworker.':A'.$endworker);
//                    $objPHPExcel->getActiveSheet()->getstyle('A'.$firstworker.':A'.$endworker)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
//                    $objPHPExcel->getActiveSheet()->mergeCells('B'.$firstworker.':B'.$endworker);
//                    $objPHPExcel->getActiveSheet()->getstyle('B'.$firstworker.':B'.$endworker)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
                    $objPHPExcel->getActiveSheet()->mergeCells('C' . $firstworker . ':C' . $endworker);
                    $objPHPExcel->getActiveSheet()->getstyle('C' . $firstworker . ':C' . $endworker)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
                    $objPHPExcel->getActiveSheet()->setCellValue('C' . $firstworker, $gsumlist[$i]['summonth']);

                } else {
                    $objPHPExcel->getActiveSheet()->setCellValue('A' . ($rowindex + 2), $cname);
                    $objPHPExcel->getActiveSheet()->setCellValue('B' . ($rowindex + 2), $gsumlist[$i]['gname']);
                    $objPHPExcel->getActiveSheet()->setCellValue('C' . ($rowindex + 2), 0);
                    $rowindex++;
                }

            }
            //8.设置当前激活的sheet表格名称；
            //  $objPHPExcel->getActiveSheet()->setTitle($cname .'考勤汇总');
            //  $pageindex++;

        }

        $objPHPExcel->getActiveSheet()->setTitle($strmonth . '考勤汇总');

        //7.设置保存的Excel表格名称
        $filename = '考勤汇总' . date('ymd', time()) . '.xls';

        //9.设置浏览器窗口下载表格
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
        header('Content-Disposition:inline;filename="' . $filename . '"');
        //生成excel文件
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        //下载文件在浏览器窗口
        $objWriter->save('php://output');
        //原代码没有返回
        $res_r['code'] = 200;
        $res_r['resultData'] = $filename;
        return json_encode($res_r, 320);
    }

    /*
     * 20230215
     *  获取本公司的项目合同汇总
     */
    public function companyworkersumuniontoexecl() {
        /*
         * 准备
         */
        //获取数据
        $queryinfo = request()->param();
        $yearinfo = $queryinfo['yearinfo'];
        $monthinfo = $queryinfo['monthinfo'];
        $cid = $queryinfo['companyid']; //公司id
        $strmonth = $yearinfo . '-' . $monthinfo;
        //获取所有导出的合同
        $l_contact = new contactlogic();
        $list_contact = $l_contact->getcompanyclist($cid);
        //获取当用天数
        $daysofm = date('t', strtotime($yearinfo . '-' . $monthinfo . '-1'));
        //加载类库
        vendor('PHPExcel.PHPExcel');
        $objPHPExcel = new \PHPExcel();
        $pageindex = 0; //初始化页数，后面不再循环  todo 去掉此变理
        /*
         * 循环处理所有合同
         */
        $rowindex = 0;

        //4.激活当前的sheet表

        $objPHPExcel->setActiveSheetIndex($pageindex);
        //5.设置表格头（即excel表格的第一行）
        $objPHPExcel->setActiveSheetIndex($pageindex)
            ->setCellValue('A1', '合同')
            ->setCellValue('B1', '班组')
            ->setCellValue('C1', '总分')
            ->setCellValue('D1', '月度')
            ->setCellValue('E1', '工人')
            ->setCellValue('F1', '身份证')
            ->setCellValue('G1', '当月总记分');
        for ($j = 1; $j <= $daysofm; $j++) {
            $columnname = strval($j);
            if (strlen($columnname) < 2) {
                $columnname = '0' . $columnname;
            }
            $fcolumnchar = \PHPExcel_Cell::stringFromColumnIndex($j + 6);
            $objPHPExcel->setActiveSheetIndex($pageindex)->setCellValue($fcolumnchar . '1', $columnname);

        }

        $fcolumnchar = \PHPExcel_Cell::stringFromColumnIndex($daysofm + 7);
        $objPHPExcel->setActiveSheetIndex($pageindex)->setCellValue($fcolumnchar . '1', '招工成本');
        //设置A列水平居中
        $objPHPExcel->setActiveSheetIndex($pageindex)->getStyle('A')->getAlignment()
            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex($pageindex)->getStyle('B')->getAlignment()
            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex($pageindex)->getStyle('C')->getAlignment()
            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex($pageindex)->getStyle('D')->getAlignment()
            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex($pageindex)->getStyle('E')->getAlignment()
            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex($pageindex)->getStyle('F')->getAlignment()
            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        //设置F列为文本列
        $objPHPExcel->getActiveSheet()->getStyle('F')->getNumberFormat()
            ->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT); //
        $objPHPExcel->setActiveSheetIndex($pageindex)->getStyle('G')->getAlignment()
            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        //设置单元格宽度
        $objPHPExcel->setActiveSheetIndex($pageindex)->getColumnDimension('A')->setWidth(20);
        $objPHPExcel->setActiveSheetIndex($pageindex)->getColumnDimension('B')->setWidth(20);
        $objPHPExcel->setActiveSheetIndex($pageindex)->getColumnDimension('C')->setWidth(11);
        $objPHPExcel->setActiveSheetIndex($pageindex)->getColumnDimension('D')->setWidth(20);
        $objPHPExcel->setActiveSheetIndex($pageindex)->getColumnDimension('E')->setWidth(10);
        $objPHPExcel->setActiveSheetIndex($pageindex)->getColumnDimension('F')->setWidth(18);
        $objPHPExcel->setActiveSheetIndex($pageindex)->getColumnDimension('G')->setWidth(13);
        //6.循环刚取出来的数组，将数据逐一添加到excel表格。
        foreach ($list_contact as $contact) {
            $queryinfo['cid'] = $contact['id'];
            $cname = $contact['contactname'];
            //获取合同的数据
            $gsumlist = $l_contact->getworkersumbycid($queryinfo);

            for ($i = 0; $i < count($gsumlist); $i++) {

                $firstworker = $rowindex + 2;
                $workercounts = count($gsumlist[$i]['detail']);
                for ($workerindex = 0; $workerindex < $workercounts; $workerindex++) {
                    $objPHPExcel->getActiveSheet()->setCellValue('A' . ($rowindex + 2), $cname);
                    $objPHPExcel->getActiveSheet()->setCellValue('B' . ($rowindex + 2), $gsumlist[$i]['gname']);
                    $objPHPExcel->getActiveSheet()->setCellValue('D' . ($rowindex + 2), $strmonth);
                    $objPHPExcel->getActiveSheet()->setCellValue('E' . ($rowindex + 2), $gsumlist[$i]['detail'][$workerindex]['gname']); //
                    $objPHPExcel->getActiveSheet()->setCellValue('F' . ($rowindex + 2), "'" . $gsumlist[$i]['detail'][$workerindex]['sfz']); //
                    $objPHPExcel->getActiveSheet()->setCellValue('G' . ($rowindex + 2), $gsumlist[$i]['detail'][$workerindex]['summonth']); //
                    for ($j = 1; $j <= $daysofm; $j++) {
                        $daystr = strval($j);
                        if (strlen($daystr) < 2) {
                            $daystr = '0' . $daystr;
                        }
                        $fname = $yearinfo . '-' . $monthinfo . '-' . $daystr;
                        //$eecll=new \PHPExcel_Cell()
                        $fcolumnstr = \PHPExcel_Cell::stringFromColumnIndex($j + 6);
                        $objPHPExcel->getActiveSheet()->setCellValue($fcolumnstr . ($rowindex + 2), (array_key_exists($fname, $gsumlist[$i]['detail'][$workerindex]) ? $gsumlist[$i]['detail'][$workerindex][$fname] : '-')); //说明
                    }
                    //招工成本处理
                    $fcolumnstr = \PHPExcel_Cell::stringFromColumnIndex($daysofm + 7);
                    $objPHPExcel->getActiveSheet()->setCellValue($fcolumnstr . ($rowindex + 2), (array_key_exists('recuitcost', $gsumlist[$i]['detail'][$workerindex]) ? $gsumlist[$i]['detail'][$workerindex]['recuitcost'] : '-'));

                    $rowindex++; //行控制
                }
                if ($workercounts > 0) {
                    $endworker = $rowindex + 1; //最后一行
                    //根据客户要求，不再分隔，20201106
//                    $objPHPExcel->getActiveSheet()->mergeCells('A'.$firstworker.':A'.$endworker);
//                    $objPHPExcel->getActiveSheet()->getstyle('A'.$firstworker.':A'.$endworker)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
//                    $objPHPExcel->getActiveSheet()->mergeCells('B'.$firstworker.':B'.$endworker);
//                    $objPHPExcel->getActiveSheet()->getstyle('B'.$firstworker.':B'.$endworker)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
                    $objPHPExcel->getActiveSheet()->mergeCells('C' . $firstworker . ':C' . $endworker);
                    $objPHPExcel->getActiveSheet()->getstyle('C' . $firstworker . ':C' . $endworker)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
                    $objPHPExcel->getActiveSheet()->setCellValue('C' . $firstworker, $gsumlist[$i]['summonth']);

                } else {
                    $objPHPExcel->getActiveSheet()->setCellValue('A' . ($rowindex + 2), $cname);
                    $objPHPExcel->getActiveSheet()->setCellValue('B' . ($rowindex + 2), $gsumlist[$i]['gname']);
                    $objPHPExcel->getActiveSheet()->setCellValue('C' . ($rowindex + 2), 0);
                    $rowindex++;
                }

            }
            //8.设置当前激活的sheet表格名称；
            //  $objPHPExcel->getActiveSheet()->setTitle($cname .'考勤汇总');
            //  $pageindex++;

        }

        $objPHPExcel->getActiveSheet()->setTitle($strmonth . '考勤汇总');

        //7.设置保存的Excel表格名称
        $filename = '考勤汇总' . date('ymd', time()) . '.xls';

        //9.设置浏览器窗口下载表格
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
        header('Content-Disposition:inline;filename="' . $filename . '"');
        //生成excel文件
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        //下载文件在浏览器窗口
        $objWriter->save('php://output');
        //原代码没有返回
        $res_r['code'] = 200;
        $res_r['resultData'] = $filename;
        return json_encode($res_r, 320);
    }

    /**
     * 导出5天类有记工人员的清单
     * 用户名，身份证号，手机号，工地名
     *
     * @return void
     * @author wj
     * @date 2025-02-17
     */
    public function hasreocdeuserlistexport() {

        $m_cm = new checkmanger();
        // $ispost = request()->isPost();
        $queryinfo = request()->param();
        $isexport = !isset($queryinfo['isexport']) || empty($queryinfo['isexport']) ? 0 : 1;
        $count = $m_cm->hasreocdeuserlist(true);
        if (!$isexport) {
            $pageNum = !isset($queryinfo['pageNum']) || empty($queryinfo['pageNum']) ? 1 : $queryinfo['pageNum'];
            $pageSize = !isset($queryinfo['pageSize']) || empty($queryinfo['pageSize']) ? 10 : $queryinfo['pageSize'];
            if (empty($count)) {
                $res_r['code'] = 0;
                $res_r['msg'] = '无数据';
                $res_r['data'] = [];
                return json_encode($res_r, 320);
            }

            $list = $m_cm->hasreocdeuserlist(false, $pageNum, $pageSize);
            $res_r['code'] = 200;
            $res_r['msg'] = '查询成功';
            $data = [
                'count' => $count,
                'pageNum' => $pageNum,
                'pageSize' => $pageSize,
                'list' => $list,
            ];
            $res_r['data'] = $data;
            return json_encode($res_r, 320);
        } else {
            if (empty($count)) {
                $this->error('无数据');
            }
            $size = 100;
            $totalpage = ceil($count / $size);
            vendor('PHPExcel.PHPExcel');
            $objPHPExcel = new \PHPExcel();
            $pageindex = 0;
            $objPHPExcel->setActiveSheetIndex($pageindex);
            //5.设置表格头（即excel表格的第一行）
            $objPHPExcel->setActiveSheetIndex($pageindex)
                ->setCellValue('A1', '用户名')
                ->setCellValue('B1', '身份证号')
                ->setCellValue('C1', '手机号')
                ->setCellValue('D1', '工地名');
            $objPHPExcel->setActiveSheetIndex($pageindex)->getStyle('A')->getAlignment()
                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
            $objPHPExcel->setActiveSheetIndex($pageindex)->getStyle('B')->getAlignment()
                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
            $objPHPExcel->setActiveSheetIndex($pageindex)->getStyle('C')->getAlignment()
                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
            $objPHPExcel->setActiveSheetIndex($pageindex)->getStyle('D')->getAlignment()
                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
            $objPHPExcel->setActiveSheetIndex($pageindex)->getColumnDimension('A')->setWidth(20);
            $objPHPExcel->setActiveSheetIndex($pageindex)->getColumnDimension('B')->setWidth(50);
            $objPHPExcel->setActiveSheetIndex($pageindex)->getColumnDimension('C')->setWidth(20);
            $objPHPExcel->setActiveSheetIndex($pageindex)->getColumnDimension('D')->setWidth(50);
            $rowindex = 2;
            for ($page = 1; $page <= $totalpage; $page++) {
                $list = $m_cm->hasreocdeuserlist(false, $page, $size);
                foreach ($list as $key => $value) {
                    $wname = $value['wname'];
                    $shengfengid = " " . $value['shengfengid'];
                    $telno = $value['telno'];
                    $pname = $value['pname'];
                    $objPHPExcel->getActiveSheet()->setCellValue('A' . $rowindex, $wname);
                    $objPHPExcel->getActiveSheet()->setCellValue('B' . $rowindex, $shengfengid);
                    $objPHPExcel->getActiveSheet()->setCellValue('C' . $rowindex, $telno);
                    $objPHPExcel->getActiveSheet()->setCellValue('D' . $rowindex, $pname);
                    $rowindex += 1;
                }
                unset($list);
            }
            $title = '记工清单';
            $objPHPExcel->getActiveSheet()->setTitle($title);
            $filename = $title . "_" . date('ymd', time()) . '.xls';
            $filename = urlencode($filename);

            //9.设置浏览器窗口下载表格
            header("Content-Type: application/force-download");
            header("Content-Type: application/octet-stream");
            header("Content-Type: application/download");
            header('Content-Type: text/html; charset=utf-8');
            header('Content-Disposition:inline;filename="' . $filename . '"');
            //生成excel文件
            $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
            //下载文件在浏览器窗口
            $objWriter->save('php://output');
        }
    }
}