Example #1
0
 public function export($paramObj)
 {
     $hosturl = $_SERVER['HTTP_HOST'];
     $now = date('Ymd');
     $dir = explode('src', __DIR__);
     $source = $dir[0] . 'web/EN_Hr_attendanceTemplate.xls';
     $tmpFile = $dir[0] . 'web/upload/attendance' . $now . '.xls';
     if (file_exists($tmpFile)) {
         //return Utils::WrapResultOK($hosturl.'/upload/attendance'.$now.'.xls');
     }
     $user = $paramObj['user'];
     $ymd = $paramObj['ymd'];
     if (empty($ymd)) {
         $ymd = date('Y-m-d');
     }
     $deptid = $paramObj['deptid'];
     if (empty($deptid)) {
         $dept_name = '公司全员';
     } else {
         $deptMgr = new Dept($this->conn, $this->conn_im, $this->container);
         $deptdata = $deptMgr->getInfo($deptid);
         $dept_name = $deptdata['deptname'];
     }
     $all = $paramObj['all'];
     //应考勤人数
     $attendanced = $paramObj['attendanced'];
     //实际考勤人数
     $delay = $paramObj['delay'];
     //迟到人数
     $notattendance = $paramObj['notattendance'];
     //未考勤人数
     @copy($source, $tmpFile);
     $objReader = \PHPExcel_IOFactory::createReader('Excel5');
     $objPHPExcel = $objReader->load($tmpFile);
     $objPHPExcel->setActiveSheetIndex(0);
     $objWorksheet = $objPHPExcel->getActiveSheet();
     $str = '考勤统计';
     //iconv('gb2312', 'utf-8', '考勤统计');
     $objWorksheet->setTitle($str);
     $objPHPExcel->setActiveSheetIndex(1);
     $objWorksheet = $objPHPExcel->getActiveSheet();
     $str = '实际考勤人数明细';
     //iconv('gb2312', 'utf-8', '实际考勤人数明细');
     $objWorksheet->setTitle($str);
     $objPHPExcel->setActiveSheetIndex(2);
     $objWorksheet = $objPHPExcel->getActiveSheet();
     $str = '未考勤人数明细';
     //iconv('gb2312', 'utf-8', '未考勤人数明细');
     $objWorksheet->setTitle($str);
     $objPHPExcel->setActiveSheetIndex(3);
     $objWorksheet = $objPHPExcel->getActiveSheet();
     $str = '迟到考勤人数明细';
     //iconv('gb2312', 'utf-8', '迟到考勤人数明细');
     $objWorksheet->setTitle($str);
     $objPHPExcel->setActiveSheetIndex(0);
     $objWorksheet = $objPHPExcel->getActiveSheet();
     //写入部门和日期
     $objWorksheet->unmergeCells('F3:I3');
     $objWorksheet->unmergeCells('J3:L3');
     $objWorksheet->setCellValue('F3', $dept_name);
     $objWorksheet->setCellValue('J3', $ymd);
     $objWorksheet->mergeCells('F3:I3');
     $objWorksheet->mergeCells('J3:L3');
     //统计 人
     $objWorksheet->setCellValue('K27', $user->nick_name);
     //写入应考勤人数
     $objWorksheet->setCellValue('G10', $all);
     //实际考勤人数
     $objWorksheet->setCellValue('K10', $attendanced);
     //未考勤人数
     $objWorksheet->setCellValue('G16', $notattendance);
     //迟到考勤人数
     $objWorksheet->setCellValue('K16', $delay);
     $objWorksheet->setCellValue('G22', '—');
     $objWorksheet->setCellValue('K22', '—');
     $paramObj['pageIndex'] = 1;
     $paramObj['limit'] = 1000000;
     //判断是否需要导入实际考勤明细
     $expFlag = isset($paramObj['expdetail_attendanced']) ? (int) $paramObj['expdetail_attendanced'] : 0;
     if ($expFlag === 1) {
         $objPHPExcel->setActiveSheetIndex(1);
         $objWorksheet = $objPHPExcel->getActiveSheet();
         $data = $this->getAllAttend($paramObj);
         $i = 3;
         foreach ($data['data'] as $key => $value) {
             $objWorksheet->setCellValue('A' . $i, $i - 2);
             $objWorksheet->setCellValue('B' . $i, $value['nick_name']);
             $objWorksheet->setCellValue('C' . $i, $value['dept_name']);
             $objWorksheet->setCellValue('D' . $i, $value['mobile_bind']);
             $objWorksheet->setCellValue('E' . $i, $value['state']);
             $i++;
         }
     }
     //判断是否需要未考勤明细
     $expFlag = isset($paramObj['expdetail_notattendanced']) ? (int) $paramObj['expdetail_notattendanced'] : 0;
     if ($expFlag === 1) {
         $data = $this->getNoAtten($paramObj);
         $objPHPExcel->setActiveSheetIndex(2);
         $objWorksheet = $objPHPExcel->getActiveSheet();
         $i = 3;
         foreach ($data['data'] as $key => $value) {
             $objWorksheet->setCellValue('A' . $i, $i - 2);
             $objWorksheet->setCellValue('B' . $i, $value['nick_name']);
             $objWorksheet->setCellValue('C' . $i, $value['dept_name']);
             $objWorksheet->setCellValue('D' . $i, $value['mobile_bind']);
             $objWorksheet->setCellValue('E' . $i, 'state');
             $i++;
         }
     }
     //判断是否需要迟到考勤明细
     $expFlag = isset($paramObj['expdetail_delay']) ? (int) $paramObj['expdetail_delay'] : 0;
     if ($expFlag === 1) {
         $data = $this->getAllLate($paramObj);
         $objPHPExcel->setActiveSheetIndex(3);
         $objWorksheet = $objPHPExcel->getActiveSheet();
         $i = 3;
         foreach ($data['data'] as $key => $value) {
             $objWorksheet->setCellValue('A' . $i, $i - 2);
             $objWorksheet->setCellValue('B' . $i, $value['nick_name']);
             $objWorksheet->setCellValue('C' . $i, $value['dept_name']);
             $objWorksheet->setCellValue('D' . $i, $value['mobile_bind']);
             $objWorksheet->setCellValue('E' . $i, $value['state']);
             $objWorksheet->setCellValue('F' . $i, $value['atten_date']);
             $i++;
         }
     }
     \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5')->save($tmpFile);
     //根据需要也可以是 Excel2007
     //获取协议
     $http = $_SERVER['HTTPS'] != 'on' ? 'http://' : 'https://';
     return Utils::WrapResultOK($http . $hosturl . '/upload/attendance' . $now . '.xls');
 }
Example #2
0
 public function atten_service($parameter)
 {
     try {
         $deptid = $parameter["deptid"];
         $eno = $parameter["eno"];
         $login_account = $parameter["jid"];
         if ($deptid == "v" . $eno) {
             $sql = "select login_account from we_service where objid=? and type=1;";
             $ds = $this->conn->GetData("table", $sql, array((string) $deptid));
             if ($ds && $ds["table"]["recordcount"] > 0) {
                 for ($i = 0; $i < $ds["table"]["recordcount"]; $i++) {
                     $service = $ds["table"]["rows"][$i]["login_account"];
                     $sql = "insert into im_microaccount_memebr(employeeid,microaccount,lastreadid,subscribedate)values(?,?,(select max(id) from im_microaccount_msg where microaccount=?),now())";
                     $para = array((string) $login_account, (string) $service, (string) $service);
                     try {
                         $this->conn_im->ExecSQL($sql, $para);
                     } catch (\Exception $e) {
                         $this->logger->err($e->getMessage());
                     }
                 }
             }
         } else {
             //获取当前部门的所有上级部门
             $deptMgr = new Dept($this->conn, $this->conn_im, $this->container);
             $deptdata = $deptMgr->getInfo($deptid);
             if (empty($deptdata)) {
                 return;
             }
             $path = str_replace('/-10000/v' . $eno . '/', '', rtrim($deptdata['path'], '/'));
             $path = explode('/', $path);
             //获取这些部门关联的公众号
             $sql = "select login_account from we_service where objid in('" . implode("','", $path) . "')  and type=1;";
             $ds = $this->conn->GetData("table", $sql, array());
             if ($ds && $ds["table"]["recordcount"] > 0) {
                 for ($i = 0; $i < $ds["table"]["recordcount"]; $i++) {
                     $service = $ds["table"]["rows"][$i]["login_account"];
                     $sql = "insert into im_microaccount_memebr(employeeid,microaccount,lastreadid,subscribedate)values(?,?,(select max(id) from im_microaccount_msg where microaccount=?),now())";
                     $para = array((string) $login_account, (string) $service, (string) $service);
                     try {
                         $this->conn_im->ExecSQL($sql, $para);
                     } catch (\Exception $e) {
                         $this->logger->err($e->getMessage());
                     }
                 }
             }
         }
     } catch (\Exception $e) {
         $this->logger->err($e);
     }
 }