/** * @abstract 获取文件JSON数据 * @return null */ public function getlistAction() { // 请求参数 $request = $this->getRequest()->getParams(); $user_session = new Zend_Session_Namespace('user'); $user = $user_session->user_info['employee_id']; $limit = $request['limit']; $start = $request['start']; $where = "table_name = 'oa_doc_upload'"; if (isset($request['search_name']) && $request['search_name']) { $where .= " and t3.name like '%" . $request['search_name'] . "%'"; } if (isset($request['search_description']) && $request['search_description']) { $where .= " and description like '%" . $request['search_description'] . "%'"; } if (isset($request['search_date_from']) && $request['search_date_from']) { $where .= " and handle_time >= '" . $request['search_date_from'] . " 00:00:00'"; } if (isset($request['search_date_to']) && $request['search_date_to']) { $where .= " and handle_time <= '" . $request['search_date_to'] . " 23:59:59'"; } if (isset($request['search_type']) && $request['search_type']) { $where .= " and action = '" . $request['search_type'] . "'"; } if (isset($request['search_handle_user']) && $request['search_handle_user']) { $handler_user = $request['search_handle_user']; $employee = new Hra_Model_Employee(); if (count($handlers = $employee->fetchAll("ename = '{$handler_user}' or cname = '{$handler_user}'")->toArray()) > 0) { $whereHandler = "("; foreach ($handlers as $handler) { if ($whereHandler != '(') { $whereHandler .= " or "; } $whereHandler .= " handle_user = "******")"; } if (isset($whereHandler) && $whereHandler != '()') { $where .= " and " . $whereHandler; } } $log = new Dcc_Model_Log(); $wherePage = $where . " and t1.type = 'files'"; $data = $log->getList($wherePage, $start, $limit); for ($i = 0; $i < count($data); $i++) { $data[$i]['handle_time'] = strtotime($data[$i]['handle_time']); } $whereAll = $where . " and type='files'"; $resutl = array("totalCount" => count($log->getList($wherePage, null, null)), "topics" => $data); echo Zend_Json::encode($resutl); exit; }
/** * 刷新员工年假库 * 1、根据员工用功形式获取员工的其实年假设置; * 2、 * @param number $employee_id */ public function refreshStorage($employee_id = null, $cover = 0) { $result = array('success' => true, 'info' => '刷新成功'); $qty = 0; $employee = new Hra_Model_Employee(); $paramModel = new Hra_Model_Attendanceparams(); // 获取所有用工形式的首年年假设置天数 $vacationSet = $paramModel->getParamByType('vacation'); $employeeCond = ""; // 刷新个人或全部在职员工的最近一年的年假天数 if ($employee_id) { $employeeCond = " and id = " . $employee_id; } $data = $employee->fetchAll("active = 1" . $employeeCond)->toArray(); $now = date('Y-m-d H:i:s'); $user_session = new Zend_Session_Namespace('user'); $user_id = $user_session->user_info['user_id']; foreach ($data as $d) { // 根据转正日期 if ($d['regularization_date'] != '') { // 起始年假天数(来自基础设置) $qtyStart = $vacationSet[$d['employment_type']]; // 入司年数 $in_year_qty = 0; // 2014-10-08之后入职的员工按入职日期开始计算,否则按转正日期计算 if (strtotime($d['entry_date']) >= strtotime('2014-10-08')) { $in_year_qty = $employee->getInCompanyYearQty($d['entry_date']); //入职日期 } else { $in_year_qty = $employee->getInCompanyYearQty($d['regularization_date']); //转正日期 } $qty = 0; if ($in_year_qty > 0) { // 根据入司年数计算员工最近一年应有几天年假 $qty = $qtyStart + $in_year_qty - 1; } if ($qty >= 0) { // 当员工最近一年的年假已记录时,更新(用户选择是否覆盖)员工最近的年假天数,否则插入新数据 $oldDataRes = $this->fetchAll("number = '" . $d['number'] . "' and in_year_qty = " . $in_year_qty); if ($oldDataRes->count() > 0 && $cover == 1) { $oldData = $oldDataRes->toArray(); // 当员工当前入司年份有数据时,更新记录 $t = array('qty' => $qty, 'remark' => '刷新更新', 'update_user' => $user_id, 'update_time' => $now); try { $this->update($t, "id = " . $oldData[0]['id']); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); return $result; } } else { if ($oldDataRes->count() == 0) { // 当员工当前入司年份没有数据时,插入新记录 $t = array('number' => $d['number'], 'in_year_qty' => $in_year_qty, 'qty' => $qty, 'remark' => '刷新生成', 'create_user' => $user_id, 'create_time' => $now, 'update_user' => $user_id, 'update_time' => $now); try { $this->insert($t); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); return $result; } } } } } } return $result; }
public function getStatisticsList($condition = array()) { $data = array(); $employee = new Hra_Model_Employee(); $sql = $employee->select()->setIntegrityCheck(false)->from(array('t1' => $this->_dbprefix . 'employee'))->joinLeft(array('t2' => $this->_dbprefix . 'employee_dept'), "t2.id = t1.dept_id", array('dept_name' => 'name'))->joinLeft(array('t3' => $this->_dbprefix . 'employee_post'), "t3.id = t1.post_id", array('post_name' => 'name'))->joinLeft(array('t4' => $this->_dbprefix . 'user'), "t4.employee_id = t1.id", array('user_id' => 'id'))->joinLeft(array('t5' => $this->_dbprefix . 'employee_type'), "t1.employment_type = t5.id", array('employment_type' => 'name'))->where("(t1.leave_date is null or (t1.leave_date is not null and t1.leave_date >= '" . $condition['date_from'] . "' and t1.leave_date <= '" . $condition['date_to'] . "'))")->order(array("t1.employment_type", "t1.number")); if ($condition['employment_type'] != '') { $sql->where("employment_type = " . $condition['employment_type']); } if ($condition['key']) { $sql->where("t1.ename like '" . $condition['key'] . "' or t1.cname like '" . $condition['key'] . "' or t1.number like '" . $condition['key'] . "'"); } $total = $employee->fetchAll($sql)->count(); if ($condition['type'] != 'csv') { $sql->limitPage($condition['page'], $condition['limit']); } $data = $employee->fetchAll($sql)->toArray(); $workday = new Hra_Model_Workday(); $vacation = new Hra_Model_Attendance_Vacation(); $overtime = new Hra_Model_Attendance_Overtime(); // 员工工作日设置(目前均按弹性员工工作日设置处理) $workdaySetting = $workday->getDayQtyBase(1, 1, $condition['date_from'], $condition['date_to']); $holidaySetting = $workday->getDayQtyBase(3, 1, $condition['date_from'], $condition['date_to']); for ($i = 0; $i < count($data); $i++) { $data[$i]['workday_qty'] = $workdaySetting['day']; $data[$i]['workhour_qty'] = $workdaySetting['hour']; $data[$i]['holiday_qty'] = $holidaySetting['day']; $data[$i]['attendance_qty'] = null; $data[$i]['attendance_hour_qty'] = 0; $data[$i]['v_personal_qty'] = null; $data[$i]['v_vacation_qty'] = null; $data[$i]['v_sick_qty'] = null; $data[$i]['v_marriage_qty'] = null; $data[$i]['v_funeral_qty'] = null; $data[$i]['v_childbirth_qty'] = null; $data[$i]['v_childbirth_with_qty'] = null; $data[$i]['v_other_qty'] = null; $data[$i]['o_workday_qty'] = null; $data[$i]['o_restday_qty'] = null; $data[$i]['o_holiday_qty'] = null; $data[$i]['late_qty'] = null; $data[$i]['leave_early_qty'] = null; $data[$i]['absence_halfday_qty'] = null; $data[$i]['absence_qty'] = null; if ($data[$i]['user_id']) { // 出勤天数 $sql = $this->select()->from($this->_name)->where("number = '" . $data[$i]['number'] . "' and clock_in >= '" . $condition['date_from'] . " 00:00:00' and clock_out <= '" . $condition['date_to'] . " 23:59:59'")->group("date_format(clock_in, '%Y-%m-%d')"); $aData = $this->fetchAll($sql)->toArray(); foreach ($aData as $a) { $data[$i]['attendance_hour_qty'] += $a['clock_hours']; } $data[$i]['attendance_qty'] = count($aData); // 请假天数 $data[$i]['v_personal_qty'] = $vacation->getVacationQty($data[$i]['user_id'], 1, $condition['date_from'], $condition['date_to']); $data[$i]['v_vacation_qty'] = $vacation->getVacationQty($data[$i]['user_id'], 2, $condition['date_from'], $condition['date_to']); $data[$i]['v_sick_qty'] = $vacation->getVacationQty($data[$i]['user_id'], 3, $condition['date_from'], $condition['date_to']); $data[$i]['v_marriage_qty'] = $vacation->getVacationQty($data[$i]['user_id'], 4, $condition['date_from'], $condition['date_to']); $data[$i]['v_funeral_qty'] = $vacation->getVacationQty($data[$i]['user_id'], 5, $condition['date_from'], $condition['date_to']); $data[$i]['v_childbirth_qty'] = $vacation->getVacationQty($data[$i]['user_id'], 6, $condition['date_from'], $condition['date_to']); $data[$i]['v_childbirth_with_qty'] = $vacation->getVacationQty($data[$i]['user_id'], 7, $condition['date_from'], $condition['date_to']); $data[$i]['v_other_qty'] = $vacation->getVacationQty($data[$i]['user_id'], 8, $condition['date_from'], $condition['date_to']); // 加班天数 $data[$i]['o_workday_qty'] = $overtime->getOvertimeQty($data[$i]['user_id'], 1, $condition['date_from'], $condition['date_to']); $data[$i]['o_restday_qty'] = $overtime->getOvertimeQty($data[$i]['user_id'], 2, $condition['date_from'], $condition['date_to']); $data[$i]['o_holiday_qty'] = $overtime->getOvertimeQty($data[$i]['user_id'], 3, $condition['date_from'], $condition['date_to']); //其它统计(迟到、早退、旷工次数) $other = $this->getAbsenceQty($data[$i]['number'], $condition['date_from'], $condition['date_to']); $data[$i]['late_qty'] = $other[1]; $data[$i]['leave_early_qty'] = $other[2]; $data[$i]['absence_halfday_qty'] = $other[3]; $data[$i]['absence_qty'] = $other[4]; } } if ($condition['type'] == 'csv') { $data_csv = array(); $title = array('cnt' => '#', 'employment_type' => '用工形式', 'number' => '工号', 'cname' => '中文名', 'ename' => '英文名', 'dept_name' => '部门', 'post_name' => '职位', 'active' => '状态', 'attendance' => '出勤/考勤 [天]', 'holiday_qty' => '法定假日', 'v_personal_qty' => '事假', 'v_vacation_qty' => '年假', 'v_sick_qty' => '病假', 'v_marriage_qty' => '婚假', 'v_funeral_qty' => '丧假', 'v_childbirth_qty' => '产假', 'v_childbirth_with_qty' => '陪产假', 'v_other_qty' => '调休', 'o_workday_qty' => '工作日加班', 'o_restday_qty' => '休息日加班', 'o_holiday_qty' => '法定假日加班', 'late_qty' => '迟到', 'leave_early_qty' => '早退', 'absence_halfday_qty' => '旷工半天', 'absence_qty' => '旷工一天'); array_push($data_csv, $title); $i = 0; foreach ($data as $d) { $i++; $info = array('cnt' => $i, 'employment_type' => $d['employment_type'] == 0 ? '弹性' : '非弹性', 'number' => $d['number'], 'cname' => $d['cname'], 'ename' => $d['ename'], 'dept_name' => $d['dept_name'], 'post_name' => $d['post_name'], 'active' => $d['active'] == 1 ? '在职' : '离职', 'attendance' => $d['workday_qty'] . ' { ' . $d['attendance_qty'] . ' }', 'attendance_hours' => $d['workhour_qty'] . ' { ' . $d['attendance_hour_qty'] . ' }', 'holiday_qty' => $d['holiday_qty'], 'v_personal_qty' => $d['v_personal_qty'], 'v_vacation_qty' => $d['v_vacation_qty'], 'v_sick_qty' => $d['v_sick_qty'], 'v_marriage_qty' => $d['v_marriage_qty'], 'v_funeral_qty' => $d['v_funeral_qty'], 'v_childbirth_qty' => $d['v_childbirth_qty'], 'v_childbirth_with_qty' => $d['v_childbirth_with_qty'], 'v_other_qty' => $d['v_other_qty'], 'o_workday_qty' => $d['o_workday_qty'], 'o_restday_qty' => $d['o_restday_qty'], 'o_holiday_qty' => $d['o_holiday_qty'], 'late_qty' => $d['late_qty'], 'leave_early_qty' => $d['leave_early_qty'], 'absence_halfday_qty' => $d['absence_halfday_qty'], 'absence_qty' => $d['absence_qty']); array_push($data_csv, $info); } return $data_csv; } return array('total' => $total, 'rows' => $data); }
/** * 编辑用工形式信息 */ public function edittypeAction() { // 返回值数组 $result = array('success' => true, 'info' => '编辑成功'); $request = $this->getRequest()->getParams(); $now = date('Y-m-d H:i:s'); $user_session = new Zend_Session_Namespace('user'); $user_id = $user_session->user_info['user_id']; $json = json_decode($request['json']); $updated = $json->updated; $inserted = $json->inserted; $deleted = $json->deleted; $type = new Hra_Model_Type(); if (count($updated) > 0) { foreach ($updated as $val) { $data = array('active' => $val->active, 'name' => $val->name, 'description' => $val->description, 'remark' => $val->remark, 'update_time' => $now, 'update_user' => $user_id); if ($type->fetchAll("id != " . $val->id . " and name = '" . $val->name . "'")->count() > 0) { $result['success'] = false; $result['info'] = $val->name . "已存在,请勿重复添加!"; } else { try { $type->update($data, "id = " . $val->id); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } } } if (count($inserted) > 0) { foreach ($inserted as $val) { $data = array('active' => $val->active, 'name' => $val->name, 'description' => $val->description, 'remark' => $val->remark, 'create_time' => $now, 'create_user' => $user_id, 'update_time' => $now, 'update_user' => $user_id); if ($type->fetchAll("name = '" . $val->name . "'")->count() > 0) { $result['success'] = false; $result['info'] = $val->name . "已存在,请勿重复添加!"; } else { try { $type->insert($data); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } } } if (count($deleted) > 0) { $employee = new Hra_Model_Employee(); foreach ($deleted as $val) { if ($employee->fetchAll("type_id = " . $val->id)->count() == 0) { try { $type->delete("id = " . $val->id); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } else { $result['success'] = false; $result['info'] = $val->id . '存在关联员工信息,不能删除'; echo Zend_Json::encode($result); exit; } } } echo Zend_Json::encode($result); exit; }
/** * 发送邮件 * @param number $mailId 邮件任务ID * @param number $activeLimit 邮件失效期限 * @return multitype:boolean string */ public function send($mailId, $activeLimit = 0, $to_name = '', $footer = '', $header = false) { set_time_limit(0); $errInfo = ''; if ($mailId) { $send_state = 0; $now = date('Y-m-d H:i:s'); // 获取邮件任务 $where = ""; if ($activeLimit > 0) { $where = " and datediff('" . date('Y-m-d') . "', add_date) < " . $activeLimit; } $data = $this->fetchRow("id = " . $mailId . $where)->toArray(); if ($data) { // 检查邮件信息是否正确 $errInfo = $this->check($data); if (!$errInfo) { $employeeModel = new Hra_Model_Employee(); // 读取邮件发送配置 $mailServerConfig = new Zend_Config_Ini(CONFIGS_PATH . '/application.ini', 'mail'); $transport = new Zend_Mail_Transport_Smtp($mailServerConfig->smtp->server, $mailServerConfig->smtp->params->toArray()); if ($header) { $mail_header = ''; } else { $mail_header = '<div>' . $to_name . '您好,<br><br></div>'; } if (!$footer) { $mail_footer = '<div style="color:FF0000;"><br><br>系统邮件,请勿回复!</div><div>' . SYS_COPYRIGHT . '</div>'; } else { $mail_footer = '<div style="color:FF0000;">' . $footer . '</div>'; } $mail = new Zend_Mail('UTF-8'); $mail->setSubject($data['type'] . '-' . $data['subject']); $mail->setBodyHtml($mail_header . '<div>' . $data['content'] . '</div>' . $mail_footer); $mail->setFrom($mailServerConfig->smtp->from, $mailServerConfig->smtp->fromname); $sendCnt = 0; // 添加收件人 $toArr = explode(',', $data['to']); foreach ($toArr as $toMail) { // 文件外发会用到外部邮箱,不能从employee表检查 /*if(stripos($toMail, '@') != flase) { $mail->addTo($toMail); $sendCnt++; } if(stripos($toMail, SYS_EMAIL_SUFFIX) != flase) { // 内部邮箱,检查是否在职 if($employeeModel->fetchAll("active = 1 and email = '".$toMail."'")->count() > 0){ $mail->addTo($toMail); $sendCnt++; } } else { $mail->addTo($toMail); $sendCnt++; }*/ if ($employeeModel->fetchAll("active = 1 and email = '" . $toMail . "'")->count() > 0) { $mail->addTo($toMail); $sendCnt++; } } // 添加抄送人 if ($data['cc']) { $ccArr = explode(',', $data['cc']); foreach ($ccArr as $ccMail) { if ($employeeModel->fetchAll("active = 1 and email = '" . $ccMail . "'")->count() > 0) { $mail->addCc($ccMail); $sendCnt++; } } } if ($sendCnt > 0) { // 添加附件 if ($data['attachment_path']) { $fileNameArr = explode(',', $data['attachment_name']); $filePathArr = explode(',', $data['attachment_path']); for ($i = 0; $i < count($filePathArr); $i++) { $mail->createAttachment(file_get_contents($filePathArr[$i]), 'application/octet-stream', Zend_Mime::DISPOSITION_INLINE, Zend_Mime::ENCODING_BASE64, "=?UTF-8?B?" . base64_encode($fileNameArr[$i]) . "?="); } } // 发送 try { $mail->send($transport); $send_state = 1; } catch (Exception $e) { $errInfo = $e->getMessage(); } } } // 记录发送结果 try { $this->update(array('state' => $send_state, 'send_time' => $now, 'err_info' => $errInfo), "id = " . $mailId); } catch (Exception $e) { $errInfo = $e->getMessage(); } } else { $errInfo = "邮件已过期"; } } else { $errInfo = "邮件ID为空"; } $result = array('success' => $errInfo ? false : true, 'info' => $errInfo); return $result; }
/** * @abstract 添加、删除、修改部门属性 * @return null */ public function editAction() { // 返回值数组 $result = array('success' => true, 'info' => '编辑成功'); $request = $this->getRequest()->getParams(); $now = date('Y-m-d H:i:s'); $user_session = new Zend_Session_Namespace('user'); $user = $user_session->user_info['user_id']; $json = json_decode($request['json']); $updated = $json->updated; $inserted = $json->inserted; $deleted = $json->deleted; $dept = new Hra_Model_Dept(); if (count($updated) > 0) { foreach ($updated as $val) { $data = array('parentid' => $val->parentId, 'name' => $val->name, 'manager_id' => $val->manager_id, 'description' => $val->description, 'remark' => $val->remark, 'active' => $val->active, 'update_time' => $now, 'update_user' => $user); $where = "id = " . $val->id; try { $dept->update($data, $where); } catch (Exception $e) { $result['result'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } } if (count($inserted) > 0) { foreach ($inserted as $val) { $data = array('parentid' => $val->parentId, 'name' => $val->name, 'manager_id' => $val->manager_id, 'description' => $val->description, 'remark' => $val->remark, 'active' => $val->active, 'create_time' => $now, 'create_user' => $user, 'update_time' => $now, 'update_user' => $user); try { $dept->insert($data); } catch (Exception $e) { $result['result'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } } if (count($deleted) > 0) { foreach ($deleted as $val) { $employee = new Hra_Model_Employee(); if ($employee->fetchAll("dept_id = " . $val->id)->count() == 0) { try { $dept->deleteDeptTreeData($val->id); } catch (Exception $e) { $result['result'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } else { $result['result'] = false; $result['info'] = '部门ID' . $val->id . '已使用,不能删除'; echo Zend_Json::encode($result); exit; } } } echo Zend_Json::encode($result); exit; }
public function addtestdataAction() { $result = array('success' => true, 'info' => '导入成功'); $now = date('Y-m-d H:i:s'); $user_session = new Zend_Session_Namespace('user'); $user_id = $user_session->user_info['user_id']; $employee = new Hra_Model_Employee(); $eArr = $employee->fetchAll()->toArray(); $dateStart = '2014-01-01'; $attendance = new Hra_Model_Attendance(); for ($i = 0; $i < 59; $i++) { $date = date('Y-m-d', strtotime($dateStart . "+" . $i . " day")); $w = date('w', strtotime($date)); if ($w != 0 && $w != 6) { foreach ($eArr as $e) { $data = array('number' => $e['number'], 'time' => $date . ' 08:55:12', 'type' => 1, 'remark' => '123', 'create_user' => $user_id, 'create_time' => $now, 'update_user' => $user_id, 'update_time' => $now); $attendance->insert($data); $data = array('number' => $e['number'], 'time' => $date . ' 18:01:33', 'type' => 2, 'remark' => '456', 'create_user' => $user_id, 'create_time' => $now, 'update_user' => $user_id, 'update_time' => $now); $attendance->insert($data); } } } echo Zend_Json::encode($result); exit; }