public function importActiveSaveAction() { $request = $this->get("request"); $account = trim($request->get("account")); $passWord = trim($request->get("passWord")); if (empty($account) || empty($passWord)) { return $this->render('JustsyBaseBundle:Error:index.html.twig', array('error' => "帐号或者密码不能为空")); } $staffmgr = new Staff($this->get("we_data_access"), $this->get("we_data_access_im"), $account); $isexist = $staffmgr->isExist(); if ($isexist != null) { return $this->render('JustsyBaseBundle:Error:index.html.twig', array('error' => "帐号已可以正常使用")); } try { $importData = $staffmgr->getImportInfo(); ////判断帐号、姓名、手机是否重复或已使用 $arrayName = array((string) $importData["login_account"], (string) $importData["eno"], (string) $importData["nick_name"]); $sql = "select (select nick_name from we_staff where login_account=?) accountcheck ,"; $sql = $sql . " (select nick_name from we_staff where eno=? and nick_name=?) namecheck "; $mobileNO = trim($importData["mobile"]); if (!empty($mobileNO)) { $sql = $sql . " ,(select nick_name from we_staff where mobile=?) mobilecheck "; $arrayName[] = (string) $mobileNO; } $da = $this->get("we_data_access"); $ds = $da->getdata("t", $sql, $arrayName); if ($ds) { $dr = $ds["t"]["rows"][0]; if (!empty($dr["accountcheck"])) { if ($dr["accountcheck"] == $importData["nick_name"]) { throw new \Exception("您的帐号的已激活,可以正常使用。"); } else { throw new \Exception("该帐号已被" . $dr["accountcheck"] . "使用!"); } } else { if (!empty($dr["namecheck"])) { throw new \Exception("姓名已存在,不能重复激活!"); } else { if (!empty($dr["mobilecheck"])) { throw new \Exception("手机号已被" . $dr["mobilecheck"] . "使用,请使用其他有效手机号码注册!"); } } } } //激活人员帐号 $sdo = new \Justsy\BaseBundle\Controller\ActiveController(); $sdo->setContainer($this->container); $sdo->doSaveAction(); //根据导入信息更新注册信息 $staffmgr->updateByImport($importData); $staffmgr->deleteImportPhy(); } catch (\Exception $e) { $this->get("logger")->err($e); return $this->render('JustsyBaseBundle:Error:index.html.twig', array('error' => $e->getMessage())); } $data = $staffmgr->getInfo(); $data["t_code"] = substr($passWord, 0, 1) . "******" . substr($passWord, -1); $data["password"] = $passWord; return $this->render('JustsyBaseBundle:Active:import_succeed.html.twig', array('edomain' => $data["eno"], 'data' => $data)); }
public function importEmployeeAction($network_domain) { $request = $this->get("request"); $user = $this->get('security.context')->getToken()->getUser(); //判断当前导入人员是否是企业邮箱 $userDomain = explode("@", $user->getUserName()); $da = $this->get("we_data_access"); $sql = "select 1 from we_public_domain where domain_name=?"; $ds = $da->GetData("mt", $sql, array((string) $userDomain[1])); $mailType = count($ds["mt"]["rows"]) > 0 ? "0" : "1"; //1表示是企业邮箱 try { $upfile = $request->files->get("filedata"); $tmpPath = $upfile->getPathname(); $oldName = $upfile->getClientOriginalName(); $fixs = explode(".", strtolower($oldName)); if (count($fixs) < 2) { $re = array('s' => 0, 'message' => "文件类型不正确"); } else { $fixedType = $fixs[count($fixs) - 1]; if ($fixedType != "xlsx" && $fixedType != "xls") { $re = array('s' => 0, 'message' => "文件类型不正确"); } else { $newFileName = $user->openid . date('y-m-d-H-m-s') . "." . $fixedType; if (move_uploaded_file($tmpPath, 'upload/' . $newFileName)) { $da = $this->container->get('we_data_access'); $objReader = \PHPExcel_IOFactory::createReader($fixedType == "xlsx" ? 'Excel2007' : "Excel5"); //use excel2007 for 2007 format $objPHPExcel = $objReader->load($_SERVER['DOCUMENT_ROOT'] . '/upload/' . $newFileName); $objWorksheet = $objPHPExcel->getActiveSheet(); $highestRow = $objWorksheet->getHighestRow(); $highestColumn = $objWorksheet->getHighestColumn(); $highestColumnIndex = \PHPExcel_Cell::columnIndexFromString($highestColumn); //总列数 //获取标题行 $titleAry = array(); $account_index = 0; $name_index = 0; $mobile_index = 0; $duty_index = 0; $dept_index = 0; $pwd_index = 0; for ($row = 0; $row <= 1; $row++) { for ($col = 0; $col < $highestColumnIndex; $col++) { $titleAry[$col] = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue(); if (strpos($titleAry[$col], "邮箱") !== false) { $account_index = $col; } else { if (strpos($titleAry[$col], "姓名") !== false) { $name_index = $col; } else { if (strpos($titleAry[$col], "手机") !== false) { $mobile_index = $col; } else { if (strpos($titleAry[$col], "职务") !== false) { $duty_index = $col; } else { if (strpos($titleAry[$col], "部门") !== false) { $dept_index = $col; } else { if (strpos($titleAry[$col], "密码") !== false) { $pwd_index = $col; } } } } } } } } $dm = $this->get("we_data_access_im"); $titleAry[] = "eno"; $err_list = array(); $active = new \Justsy\BaseBundle\Controller\ActiveController(); $active->setContainer($this->container); //获取数据行 for ($row = 2; $row <= $highestRow; $row++) { $strs = array(); for ($col = 0; $col < $highestColumnIndex; $col++) { $strs[$col] = trim((string) $objWorksheet->getCellByColumnAndRow($col, $row)->getValue()); } $strs[] = $user->eno; $name = $strs[$name_index]; if (empty($name)) { $err_list[] = array("name" => "", "row" => $row, "msg" => "姓名不能为空"); continue; } if (strlen($name) == 1) { $err_list[] = array("name" => "", "row" => $row, "msg" => "姓名不能少于2个字符"); continue; } //获取填写的帐号 $account = $strs[$account_index]; if (empty($account)) { $err_list[] = array("name" => $name, "row" => $row, "msg" => "邮箱帐号不能为空"); continue; } if (!Utils::validateEmail($account)) { $err_list[] = array("name" => $name, "row" => $row, "msg" => "邮箱帐号格式不正确"); continue; } $staffmgr = new Staff($this->get("we_data_access"), $this->get("we_data_access_im"), $account); if ($staffmgr->checkNickname($user->eno, $name) === true) { $err_list[] = array("name" => "", "row" => $row, "msg" => "[" . $name . "]已经注册,请检查!"); continue; } //if($mailType=="1" && explode("@",$account)[1]!=$userDomain[1] ) //{ // $err_list[]=array("name"=>$name,"row"=>($row),"msg"=>"不允许导入公共邮箱$account"); // continue; //} $mobile = $strs[$mobile_index]; if (!empty($mobile)) { if (!Utils::validateMobile($mobile)) { $err_list[] = array("name" => $name, "row" => $row, "msg" => "手机号码格式不正确"); continue; } } //判断帐号是否已经注册 $isexist = $staffmgr->isExist($mobile); if (!empty($isexist)) { //已注册 $err_list[] = array("name" => $name, "msg" => "邮箱或手机号已被使用"); continue; } //判断是否已导入,已导入,则不再发邮件 $isImport = false; try { $isImport = $staffmgr->getImportInfo(); } catch (\Exception $err) { } try { $staffmgr->importReg($titleAry, $strs); //判断是否设置了密码 $pwd = $strs[$pwd_index]; if (!empty($pwd)) { $sql = "select ename from we_enterprise where eno=?"; $ds = $da->GetData("t", $sql, array((string) $user->eno)); //自动激活 $active = new \Justsy\BaseBundle\Controller\ActiveController(); $active->setContainer($this->container); $active->doSave(array('account' => $account, 'realName' => $name, 'passWord' => $pwd, 'eno' => $user->eno, 'ename' => $user->ename, 'eshortname' => $user->eshortname, 'isNew' => '0', 'mailtype' => "1", 'isSendMessage' => "N", 'import' => '1')); $dm->ExecSQL("call dept_emp_stat(?)", array((string) $user->eno)); $staffmgr = new Staff($da, $dm, $account); $importData = $staffmgr->getImportInfo(); $staffmgr->updateByImport($importData); $staffmgr->deleteImportPhy(); } else { if ($isImport === false) { if ($active->doSave(array('account' => $account, 'passWord' => empty($mobile) ? $account : $mobile, 'realName' => $name, 'eno' => $user->eno, 'ename' => $user->ename, 'eshortname' => $user->eshortname, 'isNew' => '0', 'mailtype' => "1", 'isSendMessage' => "N", 'import' => '1'))) { $staffmgr = new Staff($da, $dm, $account); //根据导入信息更新注册信息 $importData = $staffmgr->getImportInfo(); $staffmgr->updateByImport($importData); $staffmgr->deleteImportPhy(); } } else { $err_list[] = array("name" => $name, "msg" => "注册失败!"); } } } catch (\Exception $err) { //写导入数据发生异常 $err_list[] = array("name" => $name, "msg" => "导入失败:" . $err->getMessage()); continue; } } $re = array('s' => 1, 'error_list' => $err_list); } else { $re = array('s' => 0, 'message' => "文件上传失败"); } try { unlink($tmpPath); } catch (\Exception $e) { } } } } catch (\Exception $ex) { $re = array('s' => 0, 'message' => "导入失败"); } $response = new Response("<script>parent.import_callback(" . json_encode($re) . ")</script>"); $response->headers->set('Content-Type', 'text/html'); return $response; }