Beispiel #1
0
 public function applyAction()
 {
     // 返回值数组
     $result = array('success' => true, 'info' => '申请成功');
     $request = $this->getRequest()->getParams();
     $seal_id = isset($request['apply_seal_id']) ? $request['apply_seal_id'] : null;
     $review_user = isset($request['review_user']) ? $request['review_user'] : null;
     $apply_reason = isset($request['apply_reason']) ? $request['apply_reason'] : null;
     if ($seal_id) {
         $sealuse = new Hra_Model_Sealuse();
         $now = date('Y-m-d H:i:s');
         $user_session = new Zend_Session_Namespace('user');
         $user_id = $user_session->user_info['user_id'];
         $data = array('seal_id' => $seal_id, 'review_user' => $review_user, 'apply_reason' => $apply_reason, 'apply_user' => $user_id, 'apply_time' => $now);
         try {
             $sealuse->insert($data);
             $mail = new Application_Model_Log_Mail();
             $seal = new Hra_Model_Seal();
             $member = new Admin_Model_Member();
             $employee = new Hra_Model_Employee();
             /* $toIds = $member->getUserids('印章管理员');
                
                $toAddress = array();
                
                foreach ($toIds as $toId){
                    $em = $employee->getEmployeeByUserId($toId);
                    array_push($toAddress, $em['info']['email']);
                } */
             $toAddress = array();
             $em = $employee->getEmployeeByUserId($review_user);
             array_push($toAddress, $em['info']['email']);
             $sealData = $seal->fetchRow("id = " . $seal_id)->toArray();
             $content = '<div>你有一个新的印章使用申请,请登录系统审核:</div>
                                 <div>
                                 <p><b>印章名称:</b>' . $sealData['name'] . '</p>
                                 <p><b>事由:</b>' . $apply_reason . '</p>
                                 <p><b>申请人:</b>' . $user_session->user_info['user_name'] . '</p>
                                 <p><b>申请时间:</b>' . $now . '</p>
                                 </div>';
             $data = array('type' => '消息', 'subject' => '印章-使用申请', 'to' => implode(',', $toAddress), 'cc' => $user_session->user_info['user_email'], 'user_id' => $review_user, 'content' => $content, 'add_date' => $now);
             try {
                 // 记录邮件日志并发送邮件
                 $mail->send($mail->insert($data));
             } catch (Exception $e) {
                 $result['success'] = false;
                 $result['info'] = $e->getMessage();
                 echo Zend_Json::encode($result);
                 exit;
             }
         } catch (Exception $e) {
             $result['success'] = false;
             $result['info'] = $e->getMessage();
         }
     } else {
         $result['success'] = false;
         $result['info'] = '未选择印章';
     }
     echo Zend_Json::encode($result);
     exit;
 }
 public function reviewAction()
 {
     // 返回值数组
     $result = array('success' => true, 'info' => '审核成功');
     $request = $this->getRequest()->getParams();
     $review_type = isset($request['review_type']) ? $request['review_type'] : null;
     $review_step = isset($request['review_step']) ? $request['review_step'] : null;
     $review_id = isset($request['review_id']) ? $request['review_id'] : null;
     $review_operate = isset($request['review_operate']) ? $request['review_operate'] : null;
     $review_remark = isset($request['review_remark']) ? $request['review_remark'] : null;
     if ($review_id && $review_type) {
         $now = date('Y-m-d H:i:s');
         $user_session = new Zend_Session_Namespace('user');
         $user_id = $user_session->user_info['user_id'];
         // 评审意见
         $review_info = '意见: ' . $review_remark;
         $user = new Application_Model_User();
         $review = new Dcc_Model_Review();
         $employee = new Hra_Model_Employee();
         if ($review_type == 'vacation') {
             $vacation = new Hra_Model_Attendance_Vacation();
             $vacationData = $vacation->getData(null, $review_id);
             if ($review_operate == 'no') {
                 // 拒绝
                 $review_info = $now . ': ' . $user_session->user_info['user_name'] . ' [审核-拒绝] [' . $review_info . ']';
                 $timeType = 'review_time_1';
                 if ($vacationData['review_time_1']) {
                     $timeType = 'review_time_2';
                 }
                 $data = array('state' => 1, $timeType => date('Y-m-d H:i:s'), 'review_info' => $vacationData['review_info'] . '<br>' . $review_info);
                 $vacation->update($data, "id = " . $review_id);
                 // 删除当前申请的审核配置
                 $review->delete("type = 'attendance_vacation' and file_id = " . $review_id);
                 // 调休假申请被拒绝后:还原对调加班时间的调休状态
                 if ($vacationData['type'] == 8) {
                     $overtimeIdArr = explode(',', $vacationData['exchange_overtime_ids']);
                     $overtime = new Hra_Model_Attendance_Overtime();
                     foreach ($overtimeIdArr as $overtimeId) {
                         $overtime->update(array('exchange' => 0), "id = " . $overtimeId);
                     }
                 }
                 // 发送邮件通知申请人
                 $reviewResult = '<font style="color: #FF0000"><b>拒绝</b></font>';
                 $mail = new Application_Model_Log_Mail();
                 $applyEmployeeData = $user->fetchRow("id = " . $vacationData['create_user'])->toArray();
                 $applyEmployee = $employee->fetchRow("id = " . $applyEmployeeData['employee_id'])->toArray();
                 $to = $applyEmployee['email'];
                 $mailContent = '<div>请假申请审核:</div>
                                 <div>
                                 <p><b>审核人:</b>' . $user_session->user_info['user_name'] . '</p>
                                 <p><b>审核结果:</b>' . $reviewResult . '</p>
                                 <p><b>审核意见:</b>' . $review_remark . '</p>
                                 <p><b>申请人:</b><a style="color:#008B00;font-weight: bold;">' . $vacationData['apply_user_name'] . '</a></p>
                                 <p><b>请假类别:</b>' . $vacationData['type_name'] . '</p>
                                 <p><b>请假时间:</b><a style="color:#008B00;font-weight: bold;">' . $vacationData['time_from'] . '</a> 至 <a style="color:#008B00;font-weight: bold;">' . $vacationData['time_to'] . '</a></p>
                                 <p><b>代理人:</b>' . $vacationData['agent_name'] . '</p>
                                 <p><b>事由:</b>' . $vacationData['reason'] . '</p>
                                 <p><b>工作交接:</b>' . $vacationData['work'] . '</p>
                                 <p><b>备注:</b>' . $vacationData['remark'] . '</p>
                                 <p><b>创建人:</b>' . $vacationData['creater'] . '</p>
                                 <p><b>申请时间:</b>' . $vacationData['create_time'] . '</p>
                                 <hr>
                                 <p><b>审核日志:</b></p><p>' . $data['review_info'] . '</p>
                                 </div>';
                 $mailData = array('type' => '消息', 'subject' => '请假申请-审核', 'to' => $to, 'user_id' => $vacationData['create_user'], 'content' => $mailContent, 'add_date' => $now);
                 try {
                     // 记录邮件日志并发送邮件
                     $mail->send($mail->insert($mailData));
                 } catch (Exception $e) {
                     $result['success'] = false;
                     $result['info'] = $e->getMessage();
                 }
             } else {
                 // 批准
                 $review_info = $now . ': ' . $user_session->user_info['user_name'] . ' [审核-批准] [' . $review_info . ']';
                 $reviewResult = '<font style="color: #006400"><b>批准</b></font>';
                 $updateData = array();
                 $toArr = array();
                 $subject = '审核';
                 $mailCc = null;
                 if ($review_step == 'review_1') {
                     $step_name = '审核人1';
                     if ($vacationData['review_user_2'] > 0 && $vacationData['review_time_1'] == '') {
                         // 二级审核,当前申请批准后进入第二级审核
                         array_push($toArr, $vacationData['review_employee_2_id']);
                         $updateData = array('review_time_1' => $now, 'review_info' => $vacationData['review_info'] . '<br>' . $review_info);
                     } else {
                         // 一级审核,当前申请批准后进入HRA审核
                         $member = new Admin_Model_Member();
                         $hraAdminUserArr = $member->getMemberWithNoManagerByName('人事主管');
                         $hraEmployeeIdArr = array();
                         foreach ($hraAdminUserArr as $hra) {
                             $hra_info = $user->getEmployeeInfoById($hra['user_id']);
                             array_push($toArr, $hra_info['id']);
                         }
                         if (isset($vacationData['manager_id']) && $vacationData['manager_id'] != '') {
                             array_push($toArr, $vacationData['manager_id']);
                         }
                         $updateData = array('state' => 2, 'review_time_1' => $now, 'review_info' => $vacationData['review_info'] . '<br>' . $review_info);
                     }
                 } else {
                     if ($review_step == 'review_2') {
                         // 二级审核,当前申请批准后进入HRA审核
                         $step_name = '审核人2';
                         $member = new Admin_Model_Member();
                         $hraAdminUserArr = $member->getMemberWithNoManagerByName('人事主管');
                         $hraEmployeeIdArr = array();
                         foreach ($hraAdminUserArr as $hra) {
                             $hra_info = $user->getEmployeeInfoById($hra['user_id']);
                             array_push($toArr, $hra_info['id']);
                         }
                         if (isset($vacationData['manager_id']) && $vacationData['manager_id'] != '') {
                             array_push($toArr, $vacationData['manager_id']);
                         }
                         $updateData = array('state' => 2, 'review_time_2' => $now, 'review_info' => $vacationData['review_info'] . '<br>' . $review_info);
                     } else {
                         if ($review_step == 'review_hra') {
                             // HRA审核,当前申请批准后发布
                             $step_name = '人事审核';
                             $reviewResult = '<font style="color: #006400"><b>发布</b></font>';
                             $subject = '发布';
                             array_push($toArr, $vacationData['apply_employee_id']);
                             $updateData = array('state' => 3, 'release_time' => $now, 'release_user' => $user_id, 'review_info' => $vacationData['review_info'] . '<br>' . $review_info);
                             $mailCc = $vacationData['agent_email'];
                             if ($mailCc != '') {
                                 if ($vacationData['manager_email'] != '') {
                                     $mailCc .= ',' . $vacationData['manager_email'];
                                 }
                             } else {
                                 $mailCc = $vacationData['manager_email'];
                             }
                             if ($vacationData['type'] == 2) {
                                 // 当年假申请批准后,更新年假库的已用时间:根据员工工号以及入司年数
                                 $vacationStorage = new Hra_Model_Vacationstorage();
                                 $vacationStorage->update(array('qty_used' => new Zend_Db_Expr("qty_used + " . $vacationData['qty'])), "number = '" . $vacationData['number'] . "' and in_year_qty = " . $vacationData['in_year_qty']);
                             }
                             // 请假申请发布后,在打卡记录中按请假时间加入打卡时间,且备注请假类别
                             /* $attendance = new Hra_Model_Attendance();
                                $attendance->setClock($vacationData['number'], $vacationData['employment_type'], $vacationData['time_from'], $vacationData['time_to'], $vacationData['type_name']); */
                         }
                     }
                 }
                 // 更新Review表
                 $reviewData = array('actual_user' => $user_session->user_info['employee_id'], 'finish_time' => $now, 'finish_flg' => 1);
                 $review->update($reviewData, "type = 'attendance_vacation' and file_id = " . $review_id . " and step_name = '" . $step_name . "'");
                 // 更新请假申请
                 $vacation->update($updateData, "id = " . $review_id);
                 // 发送邮件
                 if (count($toArr)) {
                     $mailContent = '<div>请假申请审核:</div>
                                     <div>
                                     <p><b>审核人:</b>' . $user_session->user_info['user_name'] . '</p>
                                     <p><b>审核结果:</b>' . $reviewResult . '</p>
                                     <p><b>审核意见:</b>' . $review_remark . '</p>
                                     <p><b>申请人:</b><a style="color:#008B00;font-weight: bold;">' . $vacationData['apply_user_name'] . '</a></p>
                                     <p><b>请假类别:</b><a style="color:#008B00;font-weight: bold;">' . $vacationData['type_name'] . '</a></p>
                                     <p><b>请假时间:</b><a style="color:#008B00;font-weight: bold;">' . $vacationData['time_from'] . '</a> 至 <a style="color:#008B00;font-weight: bold;">' . $vacationData['time_to'] . '</a></p>
                                     <p><b>代理人:</b>' . $vacationData['agent_name'] . '</p>
                                     <p><b>事由:</b>' . $vacationData['reason'] . '</p>
                                     <p><b>工作交接:</b>' . $vacationData['work'] . '</p>
                                     <p><b>备注:</b>' . $vacationData['remark'] . '</p>
                                     <p><b>创建人:</b>' . $vacationData['creater'] . '</p>
                                     <p><b>申请时间:</b>' . $vacationData['create_time'] . '</p>
                                     <hr>
                                     <p><b>审核日志:</b></p><p>' . $updateData['review_info'] . '</p>
                                     </div>';
                     $mailData = array('type' => '消息', 'subject' => '请假申请-' . $subject, 'user_id' => $vacationData['create_user'], 'content' => $mailContent, 'add_date' => $now);
                     if ($mailCc) {
                         $mailData['cc'] = $mailCc;
                     }
                     $help = new Application_Model_Helpers();
                     $resultMail = $help->sendMailToStep($toArr, $mailData);
                     if (!$result['success']) {
                         $result = $resultMail;
                     }
                 }
             }
         } else {
             if ($review_type == 'overtime') {
                 $overtime = new Hra_Model_Attendance_Overtime();
                 $overtimeData = $overtime->getData(null, $review_id);
                 if ($review_operate == 'no') {
                     // 拒绝
                     $review_info = $now . ': ' . $user_session->user_info['user_name'] . ' [审核-拒绝] [' . $review_info . ']';
                     $timeType = 'review_time_1';
                     if ($overtimeData['review_time_1']) {
                         $timeType = 'review_time_2';
                     }
                     $data = array('state' => 1, $timeType => date('Y-m-d H:i:s'), 'review_info' => $overtimeData['review_info'] . '<br>' . $review_info);
                     $overtime->update($data, "id = " . $review_id);
                     // 删除当前申请的审核配置
                     $review->delete("type = 'attendance_overtime' and file_id = " . $review_id);
                     // 发送邮件通知申请人
                     $reviewResult = '<font style="color: #FF0000"><b>拒绝</b></font>';
                     $mail = new Application_Model_Log_Mail();
                     $applyEmployeeData = $user->fetchRow("id = " . $overtimeData['create_user'])->toArray();
                     $applyEmployee = $employee->fetchRow("id = " . $applyEmployeeData['employee_id'])->toArray();
                     $to = $applyEmployee['email'];
                     $mailContent = '<div>加班申请审核:</div>
                                 <div>
                                 <p><b>审核人:</b>' . $user_session->user_info['user_name'] . '</p>
                                 <p><b>审核结果:</b>' . $reviewResult . '</p>
                                 <p><b>审核意见:</b>' . $review_remark . '</p>
                                 <p><b>申请人:</b><a style="color:#008B00;font-weight: bold;">' . $overtimeData['apply_user_name'] . '</a></p>
                                 <p><b>加班时间:</b><a style="color:#008B00;font-weight: bold;">' . $overtimeData['time_from'] . '</a> 至 <a style="color:#008B00;font-weight: bold;">' . $overtimeData['time_to'] . '</a></p>
                                 <p><b>事由:</b>' . $overtimeData['reason'] . '</p>
                                 <p><b>备注:</b>' . $overtimeData['remark'] . '</p>
                                 <p><b>创建人:</b>' . $overtimeData['creater'] . '</p>
                                 <p><b>申请时间:</b>' . $overtimeData['create_time'] . '</p>
                                 <hr>
                                 <p><b>审核日志:</b></p><p>' . $data['review_info'] . '</p>
                                 </div>';
                     $mailData = array('type' => '消息', 'subject' => '加班申请-审核', 'to' => $to, 'user_id' => $overtimeData['create_user'], 'content' => $mailContent, 'add_date' => $now);
                     try {
                         // 记录邮件日志并发送邮件
                         $mail->send($mail->insert($mailData));
                     } catch (Exception $e) {
                         $result['success'] = false;
                         $result['info'] = $e->getMessage();
                     }
                 } else {
                     // 批准
                     $review_info = $now . ': ' . $user_session->user_info['user_name'] . ' [审核-批准] [' . $review_info . ']';
                     $reviewResult = '<font style="color: #006400"><b>批准</b></font>';
                     $updateData = array();
                     $toArr = array();
                     $subject = '审核';
                     if ($review_step == 'review_1') {
                         $step_name = '审核人1';
                         if ($overtimeData['review_user_2'] > 0 && $overtimeData['review_time_1'] == '') {
                             // 二级审核,当前申请批准后进入第二级审核
                             array_push($toArr, $overtimeData['review_employee_2_id']);
                             $updateData = array('review_time_1' => $now, 'review_info' => $overtimeData['review_info'] . '<br>' . $review_info);
                         } else {
                             // 一级审核,当前申请批准后进入HRA审核
                             $member = new Admin_Model_Member();
                             $hraAdminUserArr = $member->getMemberWithNoManagerByName('人事主管');
                             $hraEmployeeIdArr = array();
                             foreach ($hraAdminUserArr as $hra) {
                                 $hra_info = $user->getEmployeeInfoById($hra['user_id']);
                                 array_push($toArr, $hra_info['id']);
                             }
                             if (isset($overtimeData['manager_id']) && $overtimeData['manager_id'] != '') {
                                 array_push($toArr, $overtimeData['manager_id']);
                             }
                             $updateData = array('state' => 2, 'review_time_1' => $now, 'review_info' => $overtimeData['review_info'] . '<br>' . $review_info);
                         }
                     } else {
                         if ($review_step == 'review_2') {
                             // 二级审核,当前申请批准后进入HRA审核
                             $step_name = '审核人2';
                             $member = new Admin_Model_Member();
                             $hraAdminUserArr = $member->getMemberWithNoManagerByName('人事主管');
                             $hraEmployeeIdArr = array();
                             foreach ($hraAdminUserArr as $hra) {
                                 $hra_info = $user->getEmployeeInfoById($hra['user_id']);
                                 array_push($toArr, $hra_info['id']);
                             }
                             if (isset($overtimeData['manager_id']) && $overtimeData['manager_id'] != '') {
                                 array_push($toArr, $overtimeData['manager_id']);
                             }
                             $updateData = array('state' => 2, 'review_time_2' => $now, 'review_info' => $overtimeData['review_info'] . '<br>' . $review_info);
                         } else {
                             if ($review_step == 'review_hra') {
                                 // HRA审核,当前申请批准后发布
                                 $step_name = '人事审核';
                                 $reviewResult = '<font style="color: #006400"><b>发布</b></font>';
                                 $subject = '发布';
                                 array_push($toArr, $overtimeData['apply_employee_id']);
                                 $updateData = array('state' => 3, 'release_time' => $now, 'release_user' => $user_id, 'review_info' => $overtimeData['review_info'] . '<br>' . $review_info);
                             }
                         }
                     }
                     // 更新Review表
                     $reviewData = array('actual_user' => $user_session->user_info['employee_id'], 'finish_time' => $now, 'finish_flg' => 1);
                     $review->update($reviewData, "type = 'attendance_overtime' and file_id = " . $review_id . " and step_name = '" . $step_name . "'");
                     // 更新加班申请
                     $overtime->update($updateData, "id = " . $review_id);
                     // 发送邮件
                     if (count($toArr)) {
                         $mailContent = '<div>加班申请审核:</div>
                                     <div>
                                     <p><b>审核人:</b>' . $user_session->user_info['user_name'] . '</p>
                                     <p><b>审核结果:</b>' . $reviewResult . '</p>
                                     <p><b>审核意见:</b>' . $review_remark . '</p>
                                     <p><b>申请人:</b><a style="color:#008B00;font-weight: bold;">' . $overtimeData['apply_user_name'] . '</a></p>
                                     <p><b>请假时间:</b><a style="color:#008B00;font-weight: bold;">' . $overtimeData['time_from'] . '</a> 至 <a style="color:#008B00;font-weight: bold;">' . $overtimeData['time_to'] . '</a></p>
                                     <p><b>事由:</b>' . $overtimeData['reason'] . '</p>
                                     <p><b>备注:</b>' . $overtimeData['remark'] . '</p>
                                     <p><b>创建人:</b>' . $overtimeData['creater'] . '</p>
                                     <p><b>申请时间:</b>' . $overtimeData['create_time'] . '</p>
                                     <hr>
                                     <p><b>审核日志:</b></p><p>' . $updateData['review_info'] . '</p>
                                     </div>';
                         $mailData = array('type' => '消息', 'subject' => '加班申请-' . $subject, 'user_id' => $overtimeData['create_user'], 'content' => $mailContent, 'add_date' => $now);
                         $help = new Application_Model_Helpers();
                         $resultMail = $help->sendMailToStep($toArr, $mailData);
                         if (!$result['success']) {
                             $result = $resultMail;
                         }
                     }
                 }
             }
         }
     } else {
         $result['success'] = false;
         $result['info'] = "审核失败,审核对象和操作类别不能为空!";
     }
     echo Zend_Json::encode($result);
     exit;
 }
Beispiel #3
0
 /**
  * @abstract    审核
  * @return      null
  */
 public function reviewAction()
 {
     // 返回值数组
     $result = array('success' => true, 'result' => 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['employee_id'];
     $val = (object) $request;
     $materiel = new Product_Model_Materiel();
     $record = new Dcc_Model_Record();
     $review = new Dcc_Model_Review();
     $employee = new Hra_Model_Employee();
     $id = $val->id;
     $remark = $val->remark1;
     $pass = $val->review_result;
     $publish = false;
     // 获取物料信息
     $materielData = $materiel->getOne($id);
     if (!$materielData) {
         $result['result'] = false;
         $result['info'] = "数据状态已改变";
         echo Zend_Json::encode($result);
         exit;
     }
     $review_id = $materielData->review_id;
     // 获取当前审核情况
     // 如果record记录被删除或状态已改变,报错
     $reviewWhere = "id = {$review_id}";
     $reviewRows = $review->getList($reviewWhere);
     if (count($reviewRows) == 0) {
         $result['result'] = false;
         $result['info'] = "非法数据";
         echo Zend_Json::encode($result);
         exit;
     }
     $reviewRow = $reviewRows[0];
     if ($reviewRow['finish_flg'] != 0) {
         $result['result'] = false;
         $result['info'] = "数据状态已改变";
         echo Zend_Json::encode($result);
         exit;
     }
     // 处理记录
     $recordData = array("type" => "materiel", "table_name" => "oa_product_materiel", "table_id" => $id, "handle_user" => $user, "handle_time" => $now, "action" => "审批", "result" => $pass == 1 ? "批准" : ($pass == 2 ? "拒绝" : "转审"), "ip" => $_SERVER['REMOTE_ADDR'], "remark" => $remark);
     // 增加记录
     $record->insert($recordData);
     if ($pass == 1) {
         // 通过方式
         $method = $reviewRow['method'];
         if ($method == 2) {
             // 任何一人处理即通过
             $finish_flg = 1;
             $actual_user = $user;
             $finish_time = $now;
         } else {
             // 所有人都需要审核,检查是否所有人都已经审核
             $plan_user = $reviewRow['plan_user'];
             $actual_user = $reviewRow['actual_user'];
             $actual_user = !$actual_user ? $user : $actual_user . "," . $user;
             // 检查计划审核人和实际审核人是否一致
             if (strlen($plan_user) == strlen($actual_user)) {
                 $finish_flg = 1;
                 $finish_time = $now;
             } else {
                 $finish_flg = 0;
                 $finish_time = null;
             }
         }
         // 审核情况
         $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg);
     } else {
         if ($pass == 3) {
             // 转审
             $finish_flg = 0;
             // 更改审核情况中的审核人
             $plan_users = explode(',', $reviewRow['plan_user']);
             for ($i = 0; $i < count($plan_users); $i++) {
                 if ($plan_users[$i] == $user) {
                     $plan_users[$i] = str_replace('E', '', $val->transfer_id);
                     break;
                 }
             }
             $plan_user = implode(',', $plan_users);
             // 审核情况
             $reviewData = array("plan_user" => $plan_user, "method" => 1);
         } else {
             // 退回
             $actual_user = null;
             $finish_time = null;
             $finish_flg = 0;
             // 退回选项
             $return = $reviewRow['return'];
             if ($return == 2) {
                 // 退到初始状态
                 // 需更新的审核记录: 所有
                 $reviewWhere = "type = 'materiel' and file_id = {$id}";
                 // 审核情况更新数据
                 $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg);
                 // 文件状态不更新
             } else {
                 if ($return == 4) {
                     // 退到本阶段开始
                     // 需更新的审核记录
                     $reviewWhere = "type = 'materiel' and finish_flg = 0 and file_id = {$id}";
                     // 审核情况更新数据
                     $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg);
                     // 文件状态不更新
                 } else {
                     if ($return == 3) {
                         // 退到上一阶段
                         // 需更新的审核记录:最后一个finish_flg为1的数据和第一个finish_flg为0的数据
                         $last_1 = $first_0 = 0;
                         foreach ($reviewRows as $r) {
                             if ($r['finish_flg'] == 1) {
                                 $last_1 = $r['id'];
                             }
                             if ($r['finish_flg'] == 0 && $first_0 == null) {
                                 $first_0 = $r['id'];
                             }
                         }
                         $reviewWhere = "id = {$last_1} or id = {$first_0}";
                         // 审核情况更新数据
                         $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg);
                         // 文件状态不更新
                     } else {
                         $fileWhere = "id = {$id}";
                         // 更新文件状态为退回
                         $mData = array("state" => "Return");
                         // 退到初始状态
                         // 更新所有record的finish_flg为0
                         $reviewWhere = "type = 'materiel' and file_id = {$id}";
                         // 审核情况
                         $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg);
                     }
                 }
             }
         }
     }
     // 如果所有record的记录的finish_flg 都为1,则发布
     if ($finish_flg == 1 && $review->fetchAll("type = 'materiel' and finish_flg = 0 and file_id = {$id}")->count() == 1) {
         $publish = true;
         $code = $val->code;
         if (!$code) {
             // 自动生成物料编码
             $code = $this->getCode($materielData->type);
             if (!$code) {
                 $result['result'] = false;
                 $result['info'] = "生成物料编码失败";
                 echo Zend_Json::encode($result);
                 exit;
             }
         }
         $mData = array("state" => "Active", "code" => $code, "archive_time" => $now);
         $fileWhere = "id = {$id}";
     }
     try {
         // 更新审核情况
         $review->update($reviewData, $reviewWhere);
         // 更新文件
         if (isset($fileWhere)) {
             $materiel->update($mData, $fileWhere);
         }
         $this->operate("物料评审");
     } catch (Exception $e) {
         $result['result'] = false;
         $result['info'] = $e->getMessage();
         echo Zend_Json::encode($result);
         exit;
     }
     // 邮件任务
     // 文件提交者或更新人
     $owner = $materielData['create_user'];
     $dev = false;
     $type = "物料申请";
     // 发邮件的情况:
     // 1、单站审核结束 $finish_flg = 1 && $publish = false
     if ($finish_flg == 1 && !$publish) {
         $subject = $type . "审批";
         // $to = 下一站审核人
         $current = $review->getCurrent("materiel", $id);
         $to = $employee->getInfosByOneLine($current['plan_user']);
         //
         $cc = $employee->getInfosByOneLine($owner);
         $cc = $cc['email'];
         $content = "你有一个" . $type . "需要审批,请登录系统查看详情!";
     }
     // 2、所有审核结束  $publish = true
     if ($publish) {
         $subject = $type . "发布";
         $to = $employee->getInfosByOneLine($owner);
         $cc = "";
         $content = "你申请的" . $type . "已通过审批,分配的物料编码为:" . $code . ",请登录系统查看详情!";
     }
     // 3、退回 isset($return)
     if (isset($return)) {
         $subject = $type . "退回";
         $to = $employee->getInfosByOneLine($owner);
         $cc = "";
         // 原审核人
         if ($reviewRow['plan_user']) {
             $orgUser = $reviewRow['plan_user'];
             $cc = $employee->getInfosByOneLine($orgUser);
             $cc = $cc['email'];
         }
         $content = "你申请的" . $type . "已被退回,请登录系统查看详情!";
     }
     // 4、转审 $pass == 3
     if ($pass == 3) {
         $subject = $type . "转审";
         $toUser = str_replace('E', '', $val->transfer_id);
         $to = $employee->getInfosByOneLine($toUser);
         // 原审核人
         if ($reviewRow['plan_user']) {
             $orgUser = $reviewRow['plan_user'];
             $owner .= "," . $orgUser;
         }
         $cc = $employee->getInfosByOneLine($owner);
         $cc = $cc['email'];
         $content = "有新的" . $type . "被转移到你处审批,请登录系统查看详情!";
     }
     if (isset($subject)) {
         $mailData = array('type' => $type, 'subject' => $subject, 'to' => $to['email'], 'cc' => $cc, 'content' => $content, 'send_time' => $now, 'add_date' => $now);
         $mail = new Application_Model_Log_Mail();
         try {
             $mailId = $mail->insert($mailData);
         } catch (Exception $e) {
             $result['result'] = false;
             $result['info'] = $e->getMessage();
             echo Zend_Json::encode($result);
             exit;
         }
         if ($mailId) {
             $mail->send($mailId);
         }
     }
     echo Zend_Json::encode($result);
     exit;
 }
Beispiel #4
0
 /**
  * 文件发送
  */
 public function sendAction()
 {
     // 返回值数组
     $result = array('success' => true, 'result' => 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['employee_id'];
     $val = (object) $request;
     $upload = new Dcc_Model_Upload();
     $doc_ids = "";
     $doc_names = "";
     if ($val->exfile_ids) {
         // 根据文件id获取归档文件id
         $tmp = $upload->getAdapter()->query("select group_concat(id) as doc_ids, group_concat(code) as doc_names from oa_doc_files where (state = 'Active') and name != '' and file_ids in ( " . $val->exfile_ids . ")")->fetchObject();
         $doc_ids = $tmp->doc_ids;
         $doc_names = $tmp->doc_names;
         $row = $upload->getFileByIds($val->exfile_ids);
         $names = $row['name'];
         $paths = $row['path'];
     }
     if ($paths) {
         foreach (explode(',', $paths) as $path) {
             if (!is_file($path)) {
                 $result['result'] = false;
                 $result['info'] = "文件不存在";
                 echo Zend_Json::encode($result);
                 exit;
             }
         }
         $employee = new Hra_Model_Employee();
         $to = array();
         if ($val->to_id) {
             $toUser = str_replace('E', '', $val->to_id);
             $to = $employee->getInfosByOneLine($toUser);
             $to = explode(',', $to['email']);
         }
         if (isset($val->custom_linkman) && $val->custom_linkman) {
             $to[] = $val->custom_linkman;
         }
         if (isset($val->supply_linkman) && $val->supply_linkman) {
             $to[] = $val->supply_linkman;
         }
         $dept = '';
         if (isset($val->innerdept_id) && $val->innerdept_id) {
             $dept = str_replace('D', '', $val->innerdept_id);
             $sql = "select group_concat(email) as email from oa_employee where dept_id in ({$dept})";
             $data = $employee->getAdapter()->query($sql)->fetchObject();
             if ($data && $data->email) {
                 $toemail = $data->email;
                 foreach (explode(',', $toemail) as $t) {
                     $to[] = $t;
                 }
             }
         }
         $cc = array();
         if ($val->cc_id) {
             $ccUser = str_replace('E', '', $val->cc_id);
             $cc = $employee->getInfosByOneLine($ccUser);
             $cc = explode(',', $cc['email']);
         }
         $u = $employee->getInfosByOneLine($user);
         $cc[] = $u->email;
         if (isset($val->personal_linkman) && $val->personal_linkman) {
             foreach (explode(',', $val->personal_linkman) as $m) {
                 if (strpos($m, '@') != false) {
                     $to[] = $m;
                 }
             }
         }
         $mailData = array('type' => $val->sendtype == '外发' ? "文件外发" : "文件发放", 'subject' => $val->subject, 'to' => implode(',', $to), 'cc' => implode(',', $cc), 'content' => $val->content, 'attachment_name' => $names, 'attachment_path' => $paths, 'send_time' => $now, 'add_date' => $now);
         $mail = new Application_Model_Log_Mail();
         try {
             $mailId = $mail->insert($mailData);
             if ($mailId) {
                 $sendResult = $mail->send($mailId, 0, $val->to_name, $val->footer, true);
             }
             $error_info = "";
             $success = false;
             if ($sendResult) {
                 ${$error_info} = $sendResult['info'];
                 $success = $sendResult['success'];
             }
             $result['result'] = $success;
             $result['info'] = ${$error_info};
             if (isset($val->out_sendtype)) {
                 $outsend = $val->out_sendtype;
             } else {
                 $outsend = "";
             }
             if (isset($val->out_custom)) {
                 $partner = $val->out_custom;
             } else {
                 if (isset($val->out_supply)) {
                     $partner = $val->out_supply;
                 } else {
                     $partner = '';
                 }
             }
             if (isset($val->custom_linkman)) {
                 $linkman = $val->custom_linkman;
             } else {
                 if (isset($val->supply_linkman)) {
                     $linkman = $val->supply_linkman;
                 } else {
                     $linkman = '';
                 }
             }
             // 获取发放编号
             $code = $this->getSendCode();
             // 记录
             $to = $val->to;
             if (isset($val->personal_linkman) && $val->personal_linkman) {
                 $to .= $val->personal_linkman;
             }
             $data = array('code' => $code, 'dept' => $dept, 'partner' => $partner, 'linkman' => $linkman, 'sendtype' => $val->sendtype, 'to_name' => $val->to_name, 'footer' => $val->footer, 'remark' => $val->remark, 'outsendtype' => $outsend, 'to' => $to, 'cc' => $val->cc, 'subject' => $val->subject, 'content' => $val->content, 'doc_ids' => $doc_ids, 'doc_names' => $doc_names, 'file_ids' => $val->exfile_ids, 'file_names' => $names, 'error_info' => $error_info, 'result' => $success, 'handle_time' => $now, 'handle_user' => $user);
             $send = new Dcc_Model_Send();
             $send->insert($data);
         } catch (Exception $e) {
             $result['result'] = false;
             $result['info'] = $e->getMessage();
             echo Zend_Json::encode($result);
             exit;
         }
         if (!$result['info']) {
             $result['info'] = "发送成功";
         }
         echo Zend_Json::encode($result);
         exit;
     } else {
         $result['result'] = false;
         $result['info'] = "文件不存在";
         echo Zend_Json::encode($result);
         exit;
     }
 }
Beispiel #5
0
    public function edititemsAction()
    {
        // 返回值数组
        $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']);
        $receive_id = $json->transfer_id;
        $json_items = $json->items;
        $items_updated = $json_items->updated;
        $items_inserted = $json_items->inserted;
        $items_deleted = $json_items->deleted;
        $receive = new Erp_Model_Stock_receive();
        $items = new Erp_Model_Purchse_Receiveitems();
        $stock = new Erp_Model_Stock_Stock();
        $warehouse = new Erp_Model_Warehouse_Warehouse();
        $receiveData = $receive->getData(null, $receive_id, '调拨');
        // 更新
        if (count($items_updated) > 0) {
            foreach ($items_updated as $val) {
                $data = array('code' => $val->items_code, 'name' => $val->items_name, 'description' => $val->items_description, 'qty' => $val->items_qty, 'unit' => $val->items_unit, 'warehouse_code' => $val->items_warehouse_code, 'warehouse_code_transfer' => $val->items_warehouse_code_transfer, 'remark' => $val->items_remark, 'update_user' => $user_id, 'update_time' => $now);
                try {
                    $items->update($data, "id = " . $val->items_id);
                } catch (Exception $e) {
                    $result['success'] = false;
                    $result['info'] = $e->getMessage();
                    echo Zend_Json::encode($result);
                    exit;
                }
            }
        }
        // 插入
        if (count($items_inserted) > 0) {
            foreach ($items_inserted as $val) {
                $total = round($val->items_qty * $val->items_price, 2);
                $data = array('receive_id' => $receive_id, 'code' => $val->items_code, 'name' => $val->items_name, 'description' => $val->items_description, 'qty' => $val->items_qty, 'price' => $val->items_price, 'total' => $total, 'unit' => $val->items_unit, 'warehouse_code' => $val->items_warehouse_code, 'warehouse_code_transfer' => $val->items_warehouse_code_transfer, 'remark' => $val->items_remark, 'create_user' => $user_id, 'create_time' => $now, 'update_user' => $user_id, 'update_time' => $now);
                try {
                    $receive_item_id = $items->insert($data);
                    // 记录库存数据
                    $stockData = array('code' => $val->items_code, 'warehouse_code' => $val->items_warehouse_code_transfer, 'qty' => $val->items_qty, 'total' => $total, 'create_user' => $user_id, 'create_time' => $now, 'doc_type' => '调拨收货', 'transaction_type' => $receiveData['transaction_type'], 'doc_number' => $receiveData['number']);
                    $stock->insert($stockData);
                    $qty = round(0 - $val->items_qty, 4);
                    $total = round(0 - $total, 2);
                    // 记录库存数据
                    $stockData = array('code' => $val->items_code, 'warehouse_code' => $val->items_warehouse_code, 'qty' => $qty, 'total' => $total, 'create_user' => $user_id, 'create_time' => $now, 'doc_type' => '调拨发货', 'doc_number' => $receiveData['number']);
                    $stock->insert($stockData);
                } catch (Exception $e) {
                    $result['success'] = false;
                    $result['info'] = $e->getMessage();
                    echo Zend_Json::encode($result);
                    exit;
                }
            }
        }
        // 更新总计
        $items->refreshReceiveTotal($receive_id);
        if ($result['success']) {
            // 转储通知(针对从待检仓转出)
            if ($receiveData['transaction_type'] == '外购入库' && $receiveData['order_id'] != '') {
                // 计算收货入库数量(订单、申请)
                $receiveModel = new Erp_Model_Stock_Receive();
                $receiveModel->correctInStockQty($receive_id);
                $member = new Admin_Model_Member();
                $noticeMails = array();
                $noticeUsers = array();
                $noticeTo = $member->getMemberWithManagerByName('外购入库');
                // 通知:外购入库
                foreach ($noticeTo as $n) {
                    if ($n['email'] != '' && !in_array($n['user_id'], $noticeUsers)) {
                        array_push($noticeMails, $n['email']);
                        array_push($noticeUsers, $n['user_id']);
                    }
                }
                $noticeTo = $member->getMemberWithManagerByName('库房');
                // 通知:库房
                foreach ($noticeTo as $n) {
                    if ($n['email'] != '' && !in_array($n['user_id'], $noticeUsers)) {
                        array_push($noticeMails, $n['email']);
                        array_push($noticeUsers, $n['user_id']);
                    }
                }
                // 通知:QA
                $noticeTo = $member->getMemberWithManagerByName('QA');
                foreach ($noticeTo as $n) {
                    if ($n['email'] != '' && !in_array($n['user_id'], $noticeUsers)) {
                        array_push($noticeMails, $n['email']);
                        array_push($noticeUsers, $n['user_id']);
                    }
                }
                // 通知:外购入库通知
                $noticeTo = $member->getMemberWithManagerByName('外购入库通知');
                foreach ($noticeTo as $n) {
                    if ($n['email'] != '' && !in_array($n['user_id'], $noticeUsers)) {
                        array_push($noticeMails, $n['email']);
                        array_push($noticeUsers, $n['user_id']);
                    }
                }
                // 获取采购订单信息
                $order = new Erp_Model_Purchse_Order();
                $order_data = $order->getData(null, $receiveData['order_id']);
                // 获取采购订单相关参与人员
                $receive_items_order = new Erp_Model_Purchse_Receiveitemsorder();
                $relatedUserInfo = $receive_items_order->getReqRelatedUsers(array($order_data['number']));
                foreach ($relatedUserInfo as $n) {
                    if ($n['email'] != '' && !in_array($n['user_id'], $noticeUsers)) {
                        array_push($noticeMails, $n['email']);
                        array_push($noticeUsers, $n['user_id']);
                    }
                }
                $mail = new Application_Model_Log_Mail();
                $itemsTable = '<style type="text/css">
table.gridtable {
	font-family: verdana,arial,sans-serif;
	font-size:11px;
	color:#333333;
	border-width: 1px;
	border-color: #666666;
	border-collapse: collapse;
}
table.gridtable th {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #666666;
	background-color: #dedede;
}
table.gridtable td {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #666666;
	background-color: #ffffff;
}
</style><table class="gridtable"><tr>
                                <th>#</th>
                                <th>物料号</th>
                                <th>物料名称</th>
                                <th>物料描述</th>
                                <th>数量</th>
                                <th>单位</th>
                                <th>出库仓位</th>
                                <th>入库仓位</th>
                                <th>备注</th>
                                </tr>';
                $i = 0;
                foreach ($items_inserted as $val) {
                    $i++;
                    $warehouseInfo = $warehouse->getInfoByCode($val->items_warehouse_code);
                    $warehouseTransferInfo = $warehouse->getInfoByCode($val->items_warehouse_code_transfer);
                    $stockQty = $stock->getStockQty($val->items_code, array($val->items_warehouse_code));
                    $stockTransferQty = $stock->getStockQty($val->items_code, array($val->items_warehouse_code_transfer));
                    $itemsTable .= '<tr>
							<td>' . $i . '</td>
							<td>' . $val->items_code . '</td>
							<td>' . $val->items_name . '</td>
							<td>' . $val->items_description . '</td>
							<td>' . $val->items_qty . '</td>
							<td>' . $val->items_unit . '</td>
							<td>' . $val->items_warehouse_code . ' ' . $warehouseInfo['name'] . ' [' . $stockQty['total'] . ']</td>
							<td>' . $val->items_warehouse_code_transfer . ' ' . $warehouseTransferInfo['name'] . ' [' . $stockTransferQty['total'] . ']</td>
							<td>' . $val->items_remark . '</td>
							</tr>';
                }
                $itemsTable .= '</table>';
                $title = '库存调拨 - ' . $receiveData['transaction_type'] . ' [' . $order_data['supplier_code'] . ' ' . $order_data['supplier_ename'] . ']';
                $mailContent = '<div>' . $title . ',请登录系统查看:</div>
					    <div>
					    <p><b>单据号:</b>' . $receiveData['number'] . '</p>
					    <p><b>日期:</b>' . $receiveData['date'] . '</p>
					    <p><b>采购订单:</b>' . $order_data['number'] . '</p>
					    <p><b>制单人:</b>' . $user_session->user_info['user_name'] . '</p>
					    <p><b>描述:</b>' . $receiveData['description'] . '</p>
					    <p><b>备注:</b>' . $receiveData['remark'] . '</p>
					    </div><div>' . $itemsTable . '</div><hr>';
                $mailData = array('type' => '通知', 'subject' => $title, 'cc' => $user_session->user_info['user_email'], 'content' => $mailContent, 'add_date' => $now, 'to' => implode(',', $noticeMails), 'user_id' => $user_id);
                try {
                    // 记录邮件日志并发送邮件
                    $mail->send($mail->insert($mailData));
                } catch (Exception $e) {
                    $result['success'] = false;
                    $result['info'] = $e->getMessage();
                }
            } else {
                $member = new Admin_Model_Member();
                $noticeMails = array();
                $noticeUsers = array();
                $noticeTo = $member->getMemberWithManagerByName('通知-库存交易-调拨');
                foreach ($noticeTo as $n) {
                    if ($n['email'] != '' && !in_array($n['user_id'], $noticeUsers)) {
                        array_push($noticeMails, $n['email']);
                        array_push($noticeUsers, $n['user_id']);
                    }
                }
                if (count($noticeMails)) {
                    $warehouse = new Erp_Model_Warehouse_Warehouse();
                    $title = '库存交易-调拨-' . $receiveData['transaction_type'];
                    $mailContent = '<div><b>' . $title . '</b>,请登录系统查看:</div>
                            <div>
                            <p><b>单据号:</b>' . $receiveData['number'] . '</p>
                            <p><b>制单员:</b>' . $user_session->user_info['user_name'] . '</p>
                            <p><b>描述:</b>' . $receiveData['description'] . '</p>
                            <p><b>备注:</b>' . $receiveData['remark'] . '</p>
                            <p><b>时间:</b>' . $receiveData['create_time'] . '</p>
                            </div><hr>';
                    $mailContent .= '<div><style type="text/css">
    table.gridtable {
    	font-family: verdana,arial,sans-serif;
    	font-size:12px;
    	color:#333333;
    	border-width: 1px;
    	border-color: #666666;
    	border-collapse: collapse;
    }
    table.gridtable th {
    	border-width: 1px;
    	padding: 8px;
    	border-style: solid;
    	border-color: #666666;
    	background-color: #dedede;
    }
    table.gridtable td {
    	border-width: 1px;
    	padding: 8px;
    	border-style: solid;
    	border-color: #666666;
    	background-color: #ffffff;
    }
    .delete{
    	text-decoration: line-through;
    	color: #FF0000;
    }
    .update{
    	font-weight: bold;
    	color: #000093;
    }
    .inactive{
    	font-weight: bold;
    	color: #999999;
    }
    </style><table class="gridtable">
                    			<tr>
                    			<th>#</th>
                    			<th>物料号</th>
                    			<th>名称</th>
                    			<th>描述</th>
                    			<th>数量</th>
                    			<th>单位</th>
                    			<th>出库仓位</th>
                    			<th>入货仓位</th>
                    			<th>备注</th>
                    			</tr>';
                    $itemsData = $items->getData($receive_id);
                    $i = 0;
                    foreach ($itemsData as $d) {
                        $i++;
                        $warehouseData = $warehouse->getInfoByCode($d['items_warehouse_code']);
                        $warehouseInfo = $warehouseData["code"];
                        if (isset($warehouseData["name"])) {
                            $warehouseInfo = $warehouseData["code"] . ' ' . $warehouseData["name"];
                        }
                        $warehouseTransferData = $warehouse->getInfoByCode($d['items_warehouse_code_transfer']);
                        $warehouseTransferInfo = $warehouseTransferData["code"];
                        if (isset($warehouseTransferData["name"])) {
                            $warehouseTransferInfo = $warehouseTransferData["code"] . ' ' . $warehouseTransferData["name"];
                        }
                        $mailContent .= '<tr>
                            <td>' . $i . '</td>
                            <td>' . $d['items_code'] . '</td>
                            <td>' . $d['items_name'] . '</td>
                            <td>' . $d['items_description'] . '</td>
                            <td>' . $d['items_qty'] . '</td>
                            <td>' . $d['items_unit'] . '</td>
                            <td>' . $warehouseInfo . '</td>
                            <td>' . $warehouseTransferInfo . '</td>
                            <td>' . $d['items_remark'] . '</td>
                          </tr>';
                    }
                    $mailContent .= '</table></div><hr>';
                    $mailData = array('type' => '通知', 'subject' => $title, 'cc' => $user_session->user_info['user_email'], 'content' => $mailContent, 'add_date' => $now, 'to' => implode(',', $noticeMails), 'user_id' => $user_id);
                    try {
                        // 记录邮件日志并发送邮件
                        $mail = new Application_Model_Log_Mail();
                        $mail->send($mail->insert($mailData));
                    } catch (Exception $e) {
                        $result['success'] = false;
                        $result['info'] = $e->getMessage();
                    }
                }
            }
        }
        echo Zend_Json::encode($result);
        exit;
    }
Beispiel #6
0
 public function sendMailToStep($mailTo, $mailData)
 {
     $result = array('success' => true, 'info' => '发送成功');
     $user = new Application_Model_User();
     $employee = new Hra_Model_Employee();
     // 检查是否有接收人
     if (count($mailTo)) {
         $toAddress = array();
         $toIds = array();
         foreach ($mailTo as $employeeId) {
             $em = $employee->getInfoById($employeeId);
             array_push($toAddress, $em['email']);
             $u = $user->fetchRow("employee_id = " . $employeeId)->toArray();
             array_push($toIds, $u['id']);
         }
         $mail = new Application_Model_Log_Mail();
         $mailData['to'] = implode(',', $toAddress);
         $mailData['user_id'] = implode(',', $toIds);
         try {
             // 记录邮件日志并发送邮件
             $mail->send($mail->insert($mailData));
         } catch (Exception $e) {
             $result['success'] = false;
             $result['info'] = $e->getMessage();
         }
     } else {
         $result['success'] = false;
         $result['info'] = '邮件通知没有接受对象';
     }
     return $result;
 }
Beispiel #7
0
    public function mailByHand($receive_id)
    {
        // 返回值数组
        $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'];
        $receive = new Erp_Model_Stock_receive();
        $items = new Erp_Model_Purchse_Receiveitems();
        $itemsorder = new Erp_Model_Purchse_Receiveitemsorder();
        $receive_items_order = new Erp_Model_Purchse_Receiveitemsorder();
        $order = new Erp_Model_Purchse_Order();
        $receiveData = $receive->getData(null, $receive_id);
        $itemsData = $items->getData($receive_id);
        $orderNumArr = array();
        foreach ($itemsData as $item) {
            $numbers = explode(',', $item['items_order_number']);
            foreach ($numbers as $number) {
                if (!in_array($number, $orderNumArr)) {
                    array_push($orderNumArr, $number);
                }
            }
        }
        // 订单关联人员(申请人、审核人)
        $relatedUserInfo = count($orderNumArr) > 0 ? $receive_items_order->getReqRelatedUsers($orderNumArr) : array();
        // 到货通知
        $member = new Admin_Model_Member();
        $warehouse = new Erp_Model_Warehouse_Warehouse();
        $noticeTo = $member->getMemberWithManagerByName('采购到货通知');
        $noticeMails = array();
        $noticeUsers = array();
        foreach ($noticeTo as $n) {
            if ($n['email'] != '' && !in_array($n['user_id'], $noticeUsers)) {
                array_push($noticeMails, $n['email']);
                array_push($noticeUsers, $n['user_id']);
            }
        }
        foreach ($relatedUserInfo as $n) {
            if ($n['email'] != '' && !in_array($n['user_id'], $noticeUsers)) {
                array_push($noticeMails, $n['email']);
                array_push($noticeUsers, $n['user_id']);
            }
        }
        $mail = new Application_Model_Log_Mail();
        $supplierArr = array();
        $supplierIdArr = array();
        $i = 0;
        $itemsTable = '<style type="text/css">
table.gridtable {
	font-family: verdana,arial,sans-serif;
	font-size:11px;
	color:#333333;
	border-width: 1px;
	border-color: #666666;
	border-collapse: collapse;
}
table.gridtable th {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #666666;
	background-color: #dedede;
}
table.gridtable td {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #666666;
	background-color: #ffffff;
}
</style><table class="gridtable"><tr>
                                <th>#</th>
                                <th>供应商</th>
                                <th>采购订单</th>
                                <th>物料号</th>
                                <th>物料名称</th>
                                <th>物料描述</th>
                                <th>收货数量</th>
                                <th>单位</th>
                                <th>收货仓库</th>
                                <th>备注</th>
                                <th>备注</th>
                                <th>申请信息</th>
                                </tr>';
        foreach ($itemsData as $val) {
            $itemInfo = '';
            if ($val['items_order_number']) {
                $itemInfoData = $order->getItemDetails($val['items_order_number'], $val['items_code']);
                $itemInfo = '<table class="gridtable"><tr>
							<th>申请单号</th>
							<th>申请日期</th>
							<th>申请数量</th>
							<th>下单数量</th>
							<th>订单数量</th>
                            <th>客户收件人地址简码</th>
                            <th>客户合同号</th>
							</tr>';
                foreach ($itemInfoData as $d) {
                    $itemInfo .= '<tr>
							      <td>' . $d['req_number'] . '</td>
							      <td>' . $d['req_item_date'] . '</td>
							      <td>' . $d['req_item_qty'] . '</td>
							      <td>' . $d['order_req_item_qty'] . '</td>
							      <td>' . $d['order_item_qty'] . '</td>
							      <td>' . $d['customer_address'] . '</td>
							      <td>' . $d['customer_aggrement'] . '</td>
							      </tr>';
                }
                $itemInfo .= '</table>';
            }
            $i++;
            $numberArr = explode(',', $val['items_order_number']);
            foreach ($numberArr as $n) {
                $supplierData = $order->getSupplierByNumber($n);
                if (isset($supplierData['id']) && !in_array($supplierData['id'], $supplierIdArr)) {
                    array_push($supplierArr, $supplierData['supplier_code'] . ' ' . $supplierData['supplier_name']);
                    array_push($supplierIdArr, $supplierData['id']);
                }
            }
            $warehouseInfo = $warehouse->getInfoByCode($val['items_warehouse_code']);
            $itemsTable .= '<tr>
							<td>' . $i . '</td>
							<td>' . implode(', ', $supplierArr) . '</td>
							<td>' . $val['items_order_number'] . '</td>
							<td>' . $val['items_code'] . '</td>
							<td>' . $val['items_name'] . '</td>
							<td>' . $val['items_description'] . '</td>
							<td>' . $val['items_qty'] . '</td>
							<td>' . $val['items_unit'] . '</td>
							<td>' . $val['items_warehouse_code'] . ' ' . $warehouseInfo['name'] . '</td>
							<td>' . $val['items_remark'] . '</td>
							<td>' . $itemInfo . '</td>
							</tr>';
        }
        $itemsTable .= '</table>';
        $mailContent = '<div>采购到货,请登录系统查看:</div>
					    <div>
					    <p><b>收货单号:</b>' . $receiveData['number'] . '</p>
					    <p><b>收货日期:</b>' . $receiveData['date'] . '</p>
					    <p><b>收货人:</b>' . $user_session->user_info['user_name'] . '</p>
					    <p><b>描述:</b>' . $receiveData['description'] . '</p>
					    <p><b>备注:</b>' . $receiveData['remark'] . '</p>
					    </div><div>' . $itemsTable . '</div><hr>';
        $mailData = array('type' => '通知', 'subject' => '到货通知 - ' . $receiveData['number'] . ' - ' . implode(', ', $supplierArr), 'cc' => $user_session->user_info['user_email'], 'content' => $mailContent, 'add_date' => $now, 'to' => implode(',', $noticeMails), 'user_id' => $user_id);
        try {
            // 记录邮件日志并发送邮件
            //echo '<pre>';print_r($mailData);exit;
            $mail->send($mail->insert($mailData));
        } catch (Exception $e) {
            $result['success'] = false;
            $result['info'] = $e->getMessage();
        }
        echo Zend_Json::encode($result);
        exit;
    }
Beispiel #8
0
 /**
  * @abstract    审核
  * @return      null
  */
 public function reviewAction()
 {
     // 返回值数组
     $result = array('success' => true, 'result' => 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['employee_id'];
     $val = (object) $request;
     $materiel = new Product_Model_Materiel();
     $record = new Dcc_Model_Record();
     $review = new Dcc_Model_Review();
     $employee = new Hra_Model_Employee();
     $desc = new Product_Model_Desc();
     $id = $val->id;
     $remark = $val->remark1;
     $pass = $val->review_result;
     $publish = false;
     if (isset($val->ids) && $val->ids && strpos($val->ids, ',') !== false) {
         // 多个
         $ids = explode(',', $val->ids);
     } else {
         $ids = array($id);
     }
     foreach ($ids as $id) {
         // 获取物料信息
         $materielData = $desc->getOne($id);
         if (!$materielData) {
             $result['result'] = false;
             $result['info'] = "数据状态已改变";
             echo Zend_Json::encode($result);
             exit;
         }
         $review_id = $materielData->review_id;
         // 获取当前审核情况
         // 如果record记录被删除或状态已改变,报错
         $reviewWhere = "id = {$review_id}";
         $reviewRows = $review->getList($reviewWhere, "materiel_desc");
         if (count($reviewRows) == 0) {
             $result['result'] = false;
             $result['info'] = "非法数据";
             echo Zend_Json::encode($result);
             exit;
         }
         $reviewRow = $reviewRows[0];
         if ($reviewRow['finish_flg'] != 0) {
             $result['result'] = false;
             $result['info'] = "数据状态已改变";
             echo Zend_Json::encode($result);
             exit;
         }
         // 处理记录
         $recordData = array("type" => "materiel_desc", "table_name" => "oa_product_materiel_desc", "table_id" => $id, "handle_user" => $user, "handle_time" => $now, "action" => "审批", "result" => $pass == 1 ? "批准" : ($pass == 2 ? "拒绝" : "转审"), "ip" => $_SERVER['REMOTE_ADDR'], "remark" => $remark);
         // 增加记录
         $record->insert($recordData);
         // 通过方式
         $method = $reviewRow['method'];
         if ($pass == 1) {
             if ($method == 2) {
                 // 任何一人处理即通过
                 $finish_flg = 1;
                 $actual_user = $user;
                 $finish_time = $now;
             } else {
                 // 所有人都需要审核,检查是否所有人都已经审核
                 $plan_user = $reviewRow['plan_user'];
                 $actual_user = $reviewRow['actual_user'];
                 $actual_user = !$actual_user ? $user : $actual_user . "," . $user;
                 // 检查计划审核人和实际审核人是否一致
                 $planA = explode(',', $plan_user);
                 $actualA = explode(',', $actual_user);
                 $passFlg = true;
                 foreach ($planA as $u) {
                     if ($u && !in_array($u, $actualA)) {
                         $passFlg = false;
                     }
                 }
                 if ($passFlg) {
                     $finish_flg = 1;
                     $finish_time = $now;
                 } else {
                     $finish_flg = 0;
                     $finish_time = null;
                 }
             }
             // 审核情况
             $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg);
         } else {
             if ($pass == 3) {
                 // 转审
                 $finish_flg = 0;
                 if ($method == 2) {
                     // 处理方式为任意时,一个人转审之后其他人员也删除
                     $plan_user = str_replace('E', '', $val->transfer_id);
                 } else {
                     // 更改审核情况中的审核人
                     $plan_users = explode(',', $reviewRow['plan_user']);
                     for ($i = 0; $i < count($plan_users); $i++) {
                         if ($plan_users[$i] == $user) {
                             $plan_users[$i] = str_replace('E', '', $val->transfer_id);
                             break;
                         }
                     }
                     $plan_user = implode(',', $plan_users);
                 }
                 // 审核情况
                 $reviewData = array("plan_user" => $plan_user, "method" => 1);
             } else {
                 // 退回
                 $actual_user = null;
                 $finish_time = null;
                 $finish_flg = 0;
                 // 退回选项
                 $return = $reviewRow['return'];
                 if ($return == 2) {
                     // 退到初始状态
                     // 需更新的审核记录: 所有
                     $reviewWhere = "type = 'materiel_desc' and file_id = {$id}";
                     // 审核情况更新数据
                     $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg);
                     // 文件状态不更新
                 } else {
                     if ($return == 4) {
                         // 退到本阶段开始
                         // 需更新的审核记录
                         $reviewWhere = "type = 'materiel_desc' and finish_flg = 0 and file_id = {$id}";
                         // 审核情况更新数据
                         $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg);
                         // 文件状态不更新
                     } else {
                         if ($return == 3) {
                             // 退到上一阶段
                             // 需更新的审核记录:最后一个finish_flg为1的数据和第一个finish_flg为0的数据
                             $last_1 = $first_0 = 0;
                             foreach ($reviewRows as $r) {
                                 if ($r['finish_flg'] == 1) {
                                     $last_1 = $r['id'];
                                 }
                                 if ($r['finish_flg'] == 0 && $first_0 == null) {
                                     $first_0 = $r['id'];
                                 }
                             }
                             $reviewWhere = "id = {$last_1} or id = {$first_0}";
                             // 审核情况更新数据
                             $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg);
                             // 文件状态不更新
                         } else {
                             $fileWhere = "id = {$id}";
                             // 更新文件状态为退回
                             $mData = array("state" => "Return");
                             // 退到初始状态
                             // 更新所有record的finish_flg为0
                             $reviewWhere = "type = 'materiel_desc' and file_id = {$id}";
                             // 审核情况
                             $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg);
                         }
                     }
                 }
             }
         }
         // 如果所有record的记录的finish_flg 都为1,则发布
         if ($finish_flg == 1 && $review->fetchAll("type = 'materiel_desc' and finish_flg = 0 and file_id = {$id}")->count() == 1) {
             $publish = true;
             // 修改物料信息
             $descData = array('ver' => $materielData->ver_after, 'name' => $materielData->name_after, 'description' => $materielData->desc_after, 'manufacturers' => $materielData->manufacturers_after, 'supply1' => $materielData->supply1_after, 'supply2' => $materielData->supply2_after, 'data_file_id' => $materielData->data_file_id_after, 'tsr_id' => $materielData->tsr_id_after, 'first_report_id' => $materielData->first_report_id_after);
             $descWhere = "id = " . $materielData->mid;
             $mData = array("state" => "Active", "archive_time" => $now);
             $fileWhere = "id = {$id}";
         }
         try {
             // 更新审核情况
             $review->update($reviewData, $reviewWhere);
             // 更新文件
             if (isset($fileWhere)) {
                 $desc->update($mData, $fileWhere);
             }
             if (isset($descWhere)) {
                 $materiel->update($descData, $descWhere);
             }
             $this->operate("物料变更评审");
         } catch (Exception $e) {
             $result['result'] = false;
             $result['info'] = $e->getMessage();
             echo Zend_Json::encode($result);
             exit;
         }
         // 邮件任务
         // 文件提交者或更新人
         $owner = $materielData['create_user'];
         $dev = false;
         $type = "物料变更申请(物料代码:" . $materielData['code'] . ")";
         // 发邮件的情况:
         // 1、单站审核结束 $finish_flg = 1 && $publish = false
         if ($finish_flg == 1 && !$publish) {
             $subject = $type . "审批";
             // $to = 下一站审核人
             $current = $review->getFirstNoReview("materiel_desc", $id);
             $to = $employee->getInfosByOneLine($current['plan_user']);
             //
             $cc = $employee->getInfosByOneLine($owner);
             $cc = $cc['email'];
             $content = "你有一个" . $type . "需要审批,请登录系统查看详情!";
         }
         // 2、所有审核结束  $publish = true
         if ($publish) {
             $subject = $type . "发布";
             $to = $employee->getInfosByOneLine($owner);
             $cc = $employee->getInfosByOneLine($record->getEmployeeIds($materielData['id'], 'materiel_desc'));
             $cc = $cc['email'];
             //                 $cc = "";
             $detail = "物料代码:" . $materielData['code'];
             if ($materielData['name_before'] != $materielData['name_after']) {
                 if ($detail) {
                     $detail .= '<br>';
                 }
                 $detail .= "名称:" . $materielData['name_before'] . " → " . $materielData['name_after'];
             }
             if ($materielData['desc_before'] != $materielData['desc_after']) {
                 if ($detail) {
                     $detail .= '<br>';
                 }
                 $detail .= "描述:" . $materielData['desc_before'] . " → " . $materielData['desc_after'];
             }
             if ($materielData['supply1_before'] != $materielData['supply1_after']) {
                 if ($detail) {
                     $detail .= '<br>';
                 }
                 $detail .= "供应商1:" . $materielData['supply1_code_before'] . $materielData['supply1_cname_before'] . " → " . $materielData['supply1_code_after'] . $materielData['supply1_cname_after'];
             }
             if ($materielData['supply2_before'] != $materielData['supply2_after']) {
                 if ($detail) {
                     $detail .= '<br>';
                 }
                 $detail .= "供应商2:" . $materielData['supply2_code_before'] . $materielData['supply2_cname_before'] . " → " . $materielData['supply2_code_after'] . $materielData['supply2_cname_after'];
             }
             if ($materielData['manufacturers_before'] != $materielData['manufacturers_after']) {
                 if ($detail) {
                     $detail .= '<br>';
                 }
                 $detail .= "制造商:" . $materielData['manufacturers_before'] . " → " . $materielData['manufacturers_after'];
             }
             $content = "你申请的" . $type . "已通过审批,物料信息已自动变更,请登录系统查看详情!<br>变更详情:<br>{$detail}";
         }
         // 3、退回 isset($return)
         if (isset($return)) {
             $subject = $type . "退回";
             $to = $employee->getInfosByOneLine($owner);
             $cc = "";
             // 原审核人
             if ($reviewRow['plan_user']) {
                 $orgUser = $reviewRow['plan_user'];
                 $cc = $employee->getInfosByOneLine($orgUser);
                 $cc = $cc['email'];
             }
             $content = "你申请的" . $type . "已被退回,请登录系统查看详情!";
         }
         // 4、转审 $pass == 3
         if ($pass == 3) {
             $subject = $type . "转审";
             $toUser = str_replace('E', '', $val->transfer_id);
             $to = $employee->getInfosByOneLine($toUser);
             // 原审核人
             if ($reviewRow['plan_user']) {
                 $orgUser = $reviewRow['plan_user'];
                 $owner .= "," . $orgUser;
             }
             $cc = $employee->getInfosByOneLine($owner);
             $cc = $cc['email'];
             $content = "有新的" . $type . "被转移到你处审批,请登录系统查看详情!";
         }
         if (isset($subject)) {
             $mailData = array('type' => $type, 'subject' => $subject, 'to' => $to['email'], 'cc' => $cc, 'content' => $content, 'send_time' => $now, 'add_date' => $now);
             $mail = new Application_Model_Log_Mail();
             try {
                 $mailId = $mail->insert($mailData);
             } catch (Exception $e) {
                 $result['result'] = false;
                 $result['info'] = $e->getMessage();
                 echo Zend_Json::encode($result);
                 exit;
             }
             if ($mailId) {
                 $mail->send($mailId);
             }
         }
     }
     echo Zend_Json::encode($result);
     exit;
 }
Beispiel #9
0
 public function editcatalogAction()
 {
     // 返回值数组
     $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'];
     $request = $this->getRequest()->getParams();
     $attribute = isset($request['attribute']) ? $request['attribute'] : false;
     $catalog = new Product_Model_Catalog();
     if ($attribute) {
         $catalog_id = isset($request['id']) ? $request['id'] : null;
         $code = isset($request['code']) ? $request['code'] : null;
         $code_old = isset($request['code_old']) ? $request['code_old'] : null;
         $stage_id = isset($request['stage_id']) && $request['stage_id'] != '' ? $request['stage_id'] : null;
         $remark = isset($request['remark']) ? $request['remark'] : null;
         $date_dvt = isset($request['date_dvt']) && $request['date_dvt'] != '' ? $request['date_dvt'] : null;
         $qa1_date = isset($request['qa1_date']) && $request['qa1_date'] != '' ? $request['qa1_date'] : null;
         $qa2_date = isset($request['qa2_date']) && $request['qa2_date'] != '' ? $request['qa2_date'] : null;
         $evt_date = isset($request['evt_date']) && $request['evt_date'] != '' ? $request['evt_date'] : null;
         $mass_production_date = isset($request['mass_production_date']) && $request['mass_production_date'] != '' ? $request['mass_production_date'] : null;
         if ($catalog_id && $code) {
             if ($catalog->fetchAll("id != " . $catalog_id . " and code = '" . $code . "'")->count() == 0) {
                 $data = array('code' => $code, 'code_old' => $code_old, 'stage_id' => $stage_id, 'remark' => $remark, 'date_dvt' => $date_dvt, 'qa1_date' => $qa1_date, 'qa2_date' => $qa2_date, 'evt_date' => $evt_date, 'mass_production_date' => $mass_production_date, 'update_time' => $now, 'update_user' => $user_id);
                 $where = "id = " . $catalog_id;
                 try {
                     $catalog->update($data, $where);
                 } catch (Exception $e) {
                     $result['success'] = false;
                     $result['info'] = $e->getMessage();
                     echo Zend_Json::encode($result);
                     exit;
                 }
             } else {
                 $result['success'] = false;
                 $result['info'] = '代码重复,请重新分配';
                 echo Zend_Json::encode($result);
                 exit;
             }
         } else {
             $result['success'] = false;
             $result['info'] = '信息不完整,编辑失败!';
         }
     } else {
         $operate = isset($request['operate']) ? $request['operate'] : null;
         $review = isset($request['review']) ? $request['review'] : null;
         $id = isset($request['id']) ? $request['id'] : null;
         $ids = isset($request['ids']) ? $request['ids'] : null;
         $active = isset($request['active']) ? $request['active'] : null;
         $active = $active == 'on' ? 1 : 0;
         $description = isset($request['description']) ? $request['description'] : null;
         $remark = isset($request['remark']) ? $request['remark'] : null;
         $code_customer = isset($request['code_customer']) ? trim($request['code_customer']) : null;
         $model_customer = isset($request['model_customer']) ? trim($request['model_customer']) : null;
         $description_customer = isset($request['description_customer']) ? $request['description_customer'] : null;
         $type_id = isset($request['type_id']) ? $request['type_id'] : null;
         $type_id = isset($request['type_id']) ? $request['type_id'] : null;
         $series_id = isset($request['series_id']) ? $request['series_id'] : null;
         $series_id = isset($request['series_id']) ? $request['series_id'] : null;
         $developmode_id = isset($request['developmode_id']) ? $request['developmode_id'] : null;
         $model_standard = isset($request['model_standard']) ? trim($request['model_standard']) : null;
         $model_internal = isset($request['model_internal']) ? trim($request['model_internal']) : null;
         if ($operate == 'delete' && $id) {
             // 删除
             try {
                 if ($catalog->fetchAll("id = " . $id . " and auditor_id is not null")->count() == 1) {
                     $catalogData = $catalog->fetchRow("id = " . $id)->toArray();
                     $catalog->update(array('delete' => 1, 'review_info' => $catalogData['review_info'] . '<br>' . $now . ': ' . $user_session->user_info['user_name'] . ' [删除]'), "id = " . $id);
                 } else {
                     $catalog->delete("id = " . $id);
                     $review = new Dcc_Model_Review();
                     $review->delete("type = 'product_add' and file_id = " . $id);
                 }
             } catch (Exception $e) {
                 $result['success'] = false;
                 $result['info'] = $e->getMessage();
                 echo Zend_Json::encode($result);
                 exit;
             }
         } else {
             if ($operate == 'disable' && $ids) {
                 // 作废
                 $idArr = explode(',', $ids);
                 foreach ($idArr as $id) {
                     try {
                         if ($catalog->fetchAll("id = " . $id . " and active = 1")->count() == 1) {
                             $catalogData = $catalog->fetchRow("id = " . $id)->toArray();
                             $catalog->update(array('active' => 0, 'review_info' => $catalogData['review_info'] . '<br>' . $now . ': ' . $user_session->user_info['user_name'] . ' [作废]'), "id = " . $id);
                         }
                     } catch (Exception $e) {
                         $result['success'] = false;
                         $result['info'] = $e->getMessage();
                         echo Zend_Json::encode($result);
                         exit;
                     }
                 }
             } else {
                 if ($operate == 'enable' && $ids) {
                     // 启用
                     $idArr = explode(',', $ids);
                     foreach ($idArr as $id) {
                         try {
                             if ($catalog->fetchAll("id = " . $id . " and active = 0")->count() == 1) {
                                 $catalogData = $catalog->fetchRow("id = " . $id)->toArray();
                                 $catalog->update(array('active' => 1, 'review_info' => $catalogData['review_info'] . '<br>' . $now . ': ' . $user_session->user_info['user_name'] . ' [启用]'), "id = " . $id);
                             }
                         } catch (Exception $e) {
                             $result['success'] = false;
                             $result['info'] = $e->getMessage();
                             echo Zend_Json::encode($result);
                             exit;
                         }
                     }
                 } else {
                     if ($operate == 'edit' && $id) {
                         // 判断是否重复
                         if ($catalog->fetchAll("id != " . $id . " and model_internal = '" . $model_internal . "'")->count() == 0) {
                             //type_id = ".$type_id." and series_id = ".$series_id." and
                             $catalogData = $catalog->fetchRow("id = " . $id)->toArray();
                             $data = array('active' => $active, 'type_id' => $type_id, 'series_id' => $series_id, 'developmode_id' => $developmode_id, 'model_standard' => $model_standard, 'model_internal' => $model_internal, 'description' => $description, 'remark' => $remark, 'review' => $review == 1 ? 0 : 2, 'code_customer' => $code_customer, 'model_customer' => $model_customer, 'description_customer' => $description_customer, 'update_time' => $now, 'update_user' => $user_id, 'review_info' => $catalogData['review_info'] . '<br>' . $now . ': ' . $user_session->user_info['user_name'] . ' [修改]');
                             $where = "id = " . $id;
                             try {
                                 $catalog->update($data, $where);
                                 if ($catalogData['review'] == 1) {
                                     // 修改
                                     $member = new Admin_Model_Member();
                                     $user = new Application_Model_User();
                                     $employee = new Hra_Model_Employee();
                                     $flow = new Admin_Model_Flow();
                                     $step = new Admin_Model_Step();
                                     $review = new Dcc_Model_Review();
                                     $flowData = $flow->fetchRow("flow_name = '产品中心-审核'")->toArray();
                                     // 获取审核阶段
                                     $stepIds = $flowData['step_ids'];
                                     $stepArr = explode(',', $stepIds);
                                     $i = 0;
                                     foreach ($stepArr as $s) {
                                         $stepData = $step->fetchRow("id = " . $s)->toArray();
                                         $step_user = $stepData['user'] != '' ? $stepData['user'] : null;
                                         $step_role = $stepData['dept'] != '' ? $stepData['dept'] : null;
                                         $reviewData = array('type' => 'product_add', 'file_id' => $id, 'step_name' => $stepData['step_name'], 'plan_user' => $step_user, 'plan_dept' => $step_role, 'method' => $stepData['method'], 'return' => $stepData['return']);
                                         $review->delete("type = 'product_add' AND file_id = " . $id);
                                         $review->insert($reviewData);
                                         // 第一阶段发送邮件通知
                                         if ($i == 0) {
                                             $employeeIdArr = array();
                                             if ($step_user) {
                                                 $tmpArr = explode(',', $stepData['user']);
                                                 foreach ($tmpArr as $t) {
                                                     if (!in_array($t, $employeeIdArr)) {
                                                         array_push($employeeIdArr, $t);
                                                     }
                                                 }
                                             }
                                             if ($step_role) {
                                                 $tmpArr = $member->getMember($stepData['dept']);
                                                 foreach ($tmpArr as $t) {
                                                     if (!in_array($t, $employeeIdArr)) {
                                                         array_push($employeeIdArr, $t['employee_id']);
                                                     }
                                                 }
                                             }
                                             $toAddress = array();
                                             $toIds = array();
                                             foreach ($employeeIdArr as $employeeId) {
                                                 $em = $employee->getInfoById($employeeId);
                                                 array_push($toAddress, $em['email']);
                                                 $u = $user->fetchRow("employee_id = " . $employeeId)->toArray();
                                                 array_push($toIds, $u['id']);
                                             }
                                             $mail = new Application_Model_Log_Mail();
                                             $mailContent = '<div>产品中心-修改产品信息,请登录系统审核:</div>
                                 <div>
                                 <p><b>标准型号:</b>' . $catalogData['model_standard'] . ' -> ' . $model_standard . '</p>
                                 <p><b>内部型号:</b>' . $catalogData['model_internal'] . ' -> ' . $model_internal . '</p>
                                 <p><b>描述:</b>' . $description . '</p>
                                 <p><b>申请人:</b>' . $user_session->user_info['user_name'] . '</p>
                                 <p><b>申请时间:</b>' . $now . '</p>
                                 </div>';
                                             $mailData = array('type' => '消息', 'subject' => '产品中心-修改', 'to' => implode(',', $toAddress), 'cc' => $user_session->user_info['user_email'], 'user_id' => implode(',', $toIds), 'content' => $mailContent, 'add_date' => $now);
                                             try {
                                                 // 记录邮件日志并发送邮件
                                                 $mail->send($mail->insert($mailData));
                                             } catch (Exception $e) {
                                                 $result['success'] = false;
                                                 $result['info'] = $e->getMessage();
                                                 echo Zend_Json::encode($result);
                                                 exit;
                                             }
                                         }
                                         $i++;
                                     }
                                 } else {
                                     // 变更
                                     $noticeMails = array();
                                     $noticeUsers = array();
                                     $user = new Application_Model_User();
                                     $employee = new Hra_Model_Employee();
                                     $member = new Admin_Model_Member();
                                     $reviewModel = new Dcc_Model_Review();
                                     $reviewerInfo = $reviewModel->getReviewUserInfo('product_add', $id);
                                     // 审核人
                                     $applyEmployeeData = $user->fetchRow("id = " . $catalogData['create_user'])->toArray();
                                     $applyEmployee = $employee->fetchRow("id = " . $applyEmployeeData['employee_id'])->toArray();
                                     // 申请人
                                     $noticeTo = $member->getMemberWithManagerByName('产品中心-PM');
                                     // 管理员
                                     foreach ($noticeTo as $n) {
                                         if ($n['email'] != '' && !in_array($n['user_id'], $noticeUsers)) {
                                             array_push($noticeMails, $n['email']);
                                             array_push($noticeUsers, $n['user_id']);
                                         }
                                     }
                                     foreach ($reviewerInfo as $r) {
                                         if ($r['email'] != '' && !in_array($r['user_id'], $noticeUsers)) {
                                             array_push($noticeMails, $r['email']);
                                             array_push($noticeUsers, $r['user_id']);
                                         }
                                     }
                                     if (!in_array($catalogData['create_user'], $noticeUsers)) {
                                         array_push($noticeMails, $applyEmployee['email']);
                                         array_push($noticeUsers, $catalogData['create_user']);
                                     }
                                     $mail = new Application_Model_Log_Mail();
                                     $mailContent = '<div>产品中心产品信息变更,请登录系统查看:</div>
                                 <div>
                                 <p><b>标准型号:</b>' . $catalogData['model_standard'] . ' -> ' . $model_standard . '</p>
                                 <p><b>内部型号:</b>' . $catalogData['model_internal'] . ' -> ' . $model_internal . '</p>
                                 <p><b>描述:</b>' . $description . '</p>
                                 <p><b>申请人:</b>' . $user_session->user_info['user_name'] . '</p>
                                 <p><b>申请时间:</b>' . $now . '</p>
                                 </div>';
                                     $mailData = array('type' => '消息', 'subject' => '产品中心-变更', 'cc' => $user_session->user_info['user_email'], 'to' => implode(',', $noticeMails), 'user_id' => $user_id, 'content' => $mailContent, 'add_date' => $now);
                                     try {
                                         // 记录邮件日志并发送邮件
                                         $mail->send($mail->insert($mailData));
                                     } catch (Exception $e) {
                                         $result['success'] = false;
                                         $result['info'] = $e->getMessage();
                                         echo Zend_Json::encode($result);
                                         exit;
                                     }
                                 }
                             } catch (Exception $e) {
                                 $result['success'] = false;
                                 $result['info'] = $e->getMessage();
                                 echo Zend_Json::encode($result);
                                 exit;
                             }
                         } else {
                             $result['success'] = false;
                             $result['info'] = '当前型号已存在,请勿重复添加!';
                             echo Zend_Json::encode($result);
                             exit;
                         }
                     } else {
                         if ($operate == 'add') {
                             if ($catalog->fetchAll("model_internal = '" . $model_internal . "'")->count() == 0) {
                                 //type_id = ".$type_id." and series_id = ".$series_id." and
                                 $data = array('active' => $active, 'type_id' => $type_id, 'series_id' => $series_id, 'developmode_id' => $developmode_id, 'model_standard' => $model_standard, 'model_internal' => $model_internal, 'remark' => $remark, 'description' => $description, 'code_customer' => $code_customer, 'model_customer' => $model_customer, 'description_customer' => $description_customer, 'create_time' => $now, 'create_user' => $user_id, 'update_time' => $now, 'update_user' => $user_id, 'review_info' => $now . ': ' . $user_session->user_info['user_name'] . ' [添加]');
                                 try {
                                     $catalog_id = $catalog->insert($data);
                                     $member = new Admin_Model_Member();
                                     $user = new Application_Model_User();
                                     $employee = new Hra_Model_Employee();
                                     $flow = new Admin_Model_Flow();
                                     $step = new Admin_Model_Step();
                                     $review = new Dcc_Model_Review();
                                     $flowData = $flow->fetchRow("flow_name = '产品中心-审核'")->toArray();
                                     // 获取审核阶段
                                     $stepIds = $flowData['step_ids'];
                                     $stepArr = explode(',', $stepIds);
                                     $i = 0;
                                     foreach ($stepArr as $s) {
                                         $stepData = $step->fetchRow("id = " . $s)->toArray();
                                         $step_user = $stepData['user'] != '' ? $stepData['user'] : null;
                                         $step_role = $stepData['dept'] != '' ? $stepData['dept'] : null;
                                         $reviewData = array('type' => 'product_add', 'file_id' => $catalog_id, 'step_name' => $stepData['step_name'], 'plan_user' => $step_user, 'plan_dept' => $step_role, 'method' => $stepData['method'], 'return' => $stepData['return']);
                                         $review->insert($reviewData);
                                         // 第一阶段发送邮件通知
                                         if ($i == 0) {
                                             $employeeIdArr = array();
                                             if ($step_user) {
                                                 $tmpArr = explode(',', $stepData['user']);
                                                 foreach ($tmpArr as $t) {
                                                     if (!in_array($t, $employeeIdArr)) {
                                                         array_push($employeeIdArr, $t);
                                                     }
                                                 }
                                             }
                                             if ($step_role) {
                                                 $tmpArr = $member->getMember($stepData['dept']);
                                                 foreach ($tmpArr as $t) {
                                                     if (!in_array($t, $employeeIdArr)) {
                                                         array_push($employeeIdArr, $t['employee_id']);
                                                     }
                                                 }
                                             }
                                             $toAddress = array();
                                             $toIds = array();
                                             foreach ($employeeIdArr as $employeeId) {
                                                 $em = $employee->getInfoById($employeeId);
                                                 array_push($toAddress, $em['email']);
                                                 $u = $user->fetchRow("employee_id = " . $employeeId)->toArray();
                                                 array_push($toIds, $u['id']);
                                             }
                                             $mail = new Application_Model_Log_Mail();
                                             $mailContent = '<div>产品中心新增产品型号,请登录系统审核:</div>
                                 <div>
                                 <p><b>标准型号:</b>' . $model_standard . '</p>
                                 <p><b>内部型号:</b>' . $model_internal . '</p>
                                 <p><b>描述:</b>' . $description . '</p>
                                 <p><b>申请人:</b>' . $user_session->user_info['user_name'] . '</p>
                                 <p><b>申请时间:</b>' . $now . '</p>
                                 </div>';
                                             $mailData = array('type' => '消息', 'subject' => '产品中心-新建', 'to' => implode(',', $toAddress), 'user_id' => implode(',', $toIds), 'content' => $mailContent, 'add_date' => $now);
                                             try {
                                                 // 记录邮件日志并发送邮件
                                                 $mail->send($mail->insert($mailData));
                                             } catch (Exception $e) {
                                                 $result['success'] = false;
                                                 $result['info'] = $e->getMessage();
                                                 echo Zend_Json::encode($result);
                                                 exit;
                                             }
                                         }
                                         $i++;
                                     }
                                 } catch (Exception $e) {
                                     $result['success'] = false;
                                     $result['info'] = $e->getMessage();
                                     echo Zend_Json::encode($result);
                                     exit;
                                 }
                             } else {
                                 $result['success'] = false;
                                 $result['info'] = '当前型号已存在,请勿重复添加!';
                                 echo Zend_Json::encode($result);
                                 exit;
                             }
                         }
                     }
                 }
             }
         }
     }
     echo Zend_Json::encode($result);
     exit;
 }
Beispiel #10
0
 private function send($id, $updFlg)
 {
     $user_session = new Zend_Session_Namespace('user');
     $user = $user_session->user_info['employee_id'];
     $user_name = $user_session->user_info['user_name'];
     $now = date('Y-m-d H:i:s');
     $employee = new Hra_Model_Employee();
     $mail = new Application_Model_Log_Mail();
     $task = new User_Model_Task();
     $process = new User_Model_Process();
     $record = $task->getJoinList("id=" . $id);
     if (!$record) {
         return;
     }
     $record = $record[0];
     if ($record['type'] == '独立') {
         $where = " task_id = {$id} and employee_id = {$user}";
     } else {
         $where = " task_id = {$id}";
     }
     $join = array('type' => INNERJOIN, 'table' => $employee, 'condition' => $employee->getName() . '.id = ' . $process->getName() . '.employee_id', 'cols' => array('cname'));
     $pro = $process->getJoinList($where, $join);
     $to_id = $record['responsible_id'];
     $cc_id = $record['follow_id'];
     // 上级
     if ($to_id == $user) {
         $up = $employee->getAdapter()->query("select manager_id from oa_employee where id = {$user}")->fetchObject();
         if ($up && $up->manager_id && $up->manager_id != $user) {
             if ($cc_id) {
                 $cc_id .= ',' . $up->manager_id;
             } else {
                 $cc_id = $up->manager_id;
             }
         }
     }
     $to = $employee->getAdapter()->query("select group_concat(email) as mail_to from oa_employee where id in ( " . $to_id . ")")->fetchObject();
     $ccmail = null;
     if ($cc_id) {
         $cc = $employee->getAdapter()->query("select group_concat(email) as mail_to from oa_employee where id in ( " . $cc_id . ")")->fetchObject();
         $ccmail = $cc->mail_to;
     }
     if ($updFlg == 'add') {
         $title = "新任务提示";
         $content = $user_name . "创建了新任务 " . $record['title'];
     } else {
         if ($updFlg == 'update') {
             $title = "任务更新提示";
             $content = $user_name . "更新了任务 " . $record['title'];
         } else {
             $title = "任务删除提示";
             $content = $user_name . "删除了任务 " . $record['title'];
         }
     }
     $content .= "<p><b>任务名称:</b>" . $record['title'] . "</p>";
     $content .= "<p><b>当前状态:</b>" . $record['state'] . "</p>";
     $content .= "<p><b>任务时间:</b>" . $record['start'] . "到" . $record['end'] . "</p>";
     $content .= "<p><b>任务描述:</b>" . $record['notes'] . "</p>";
     $content .= "<p><b>重要程度:</b>" . $record['important'] . "</p>";
     $content .= "<p><b>优先级:</b>" . $record['priority'] . "</p>";
     $content .= "<p><b>协作模式:</b>" . $record['type'] . "</p>";
     $creater = $employee->getById($record['create_user']);
     $content .= "<p><b>创建人:</b>" . $creater['cname'] . "</p>";
     $content .= "<p><b>创建时间:</b>" . $record['create_time'] . "</p>";
     $content .= "<p><b>进度</b></p>";
     foreach ($pro as $p) {
         $content .= "<p>&nbsp;&nbsp;";
         if ($record['type'] == '协作') {
             $content .= $p['cname'] . "&nbsp;&nbsp;";
         }
         $content .= $p['update_time'] . "&nbsp;&nbsp;" . $p['status'] . "&nbsp;&nbsp;" . $p['rate'] . "%&nbsp;&nbsp;" . $p['remark'] . "</p>";
     }
     $mailData = array('type' => '任务', 'subject' => $title, 'to' => $to->mail_to, 'cc' => $ccmail, 'content' => $content, 'send_time' => $now, 'add_date' => $now);
     $mailId = $mail->insert($mailData);
     if ($mailId) {
         $mail->send($mailId);
     }
 }
Beispiel #11
0
 /**
  * @abstract    审核
  * @return      null
  */
 public function reviewAction()
 {
     // 返回值数组
     $result = array('success' => true, 'result' => 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['employee_id'];
     $val = (object) $request;
     $materiel = new Product_Model_Materiel();
     $record = new Dcc_Model_Record();
     $review = new Dcc_Model_Review();
     $employee = new Hra_Model_Employee();
     $id = $val->id;
     $remark = $val->remark1;
     $pass = $val->review_result;
     $publish = false;
     if (isset($val->code) && $val->code != '') {
         $code = $val->code;
         // 检查code是否重复
         if ($materiel->fetchAll("id != {$id} and code = '" . $code . "'")->count() > 0) {
             $result['result'] = false;
             $result['info'] = "代码“" . $code . "”已经存在";
             echo Zend_Json::encode($result);
             exit;
         }
     }
     if (isset($val->ids) && $val->ids && strpos($val->ids, ',') !== false) {
         // 多个
         $ids = explode(',', $val->ids);
     } else {
         $ids = array($id);
     }
     $newCodes = array();
     foreach ($ids as $id) {
         // 获取物料信息
         $materielData = $materiel->getOne($id);
         if (!$materielData) {
             $result['result'] = false;
             $result['info'] = "数据状态已改变";
             echo Zend_Json::encode($result);
             exit;
         }
         $review_id = $materielData->review_id;
         // 获取当前审核情况
         // 如果record记录被删除或状态已改变,报错
         $reviewWhere = "id = {$review_id}";
         $reviewRows = $review->getList($reviewWhere, "materiel");
         if (count($reviewRows) == 0) {
             $result['result'] = false;
             $result['info'] = "非法数据";
             echo Zend_Json::encode($result);
             exit;
         }
         $reviewRow = $reviewRows[0];
         if ($reviewRow['finish_flg'] != 0) {
             $result['result'] = false;
             $result['info'] = "数据状态已改变";
             echo Zend_Json::encode($result);
             exit;
         }
         // 处理记录
         $recordData = array("type" => "materiel", "table_name" => "oa_product_materiel", "table_id" => $id, "handle_user" => $user, "handle_time" => $now, "action" => "审批", "result" => $pass == 1 ? "批准" : ($pass == 2 ? "拒绝" : "转审"), "ip" => $_SERVER['REMOTE_ADDR'], "remark" => $remark);
         // 增加记录
         $record->insert($recordData);
         // 通过方式
         $method = $reviewRow['method'];
         if ($pass == 1) {
             if ($method == 2) {
                 // 任何一人处理即通过
                 $finish_flg = 1;
                 $actual_user = $user;
                 $finish_time = $now;
             } else {
                 // 所有人都需要审核,检查是否所有人都已经审核
                 $plan_user = $reviewRow['plan_user'];
                 $actual_user = $reviewRow['actual_user'];
                 $actual_user = !$actual_user ? $user : $actual_user . "," . $user;
                 // 检查计划审核人和实际审核人是否一致
                 $planA = explode(',', $plan_user);
                 $actualA = explode(',', $actual_user);
                 $passFlg = true;
                 foreach ($planA as $u) {
                     if ($u && !in_array($u, $actualA)) {
                         $passFlg = false;
                     }
                 }
                 if ($passFlg) {
                     $finish_flg = 1;
                     $finish_time = $now;
                 } else {
                     $finish_flg = 0;
                     $finish_time = null;
                 }
             }
             // 审核情况
             $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg);
         } else {
             if ($pass == 3) {
                 // 转审
                 $finish_flg = 0;
                 if ($method == 2) {
                     // 处理方式为任意时,一个人转审之后其他人员也删除
                     $plan_user = str_replace('E', '', $val->transfer_id);
                 } else {
                     // 更改审核情况中的审核人
                     $plan_users = explode(',', $reviewRow['plan_user']);
                     // 审核人不在审核人列表中,并且是管理员,则替换所有人
                     if (!in_array($user, $plan_users) && (Application_Model_User::checkPermissionByRoleName('物料管理员') || Application_Model_User::checkPermissionByRoleName('系统管理员'))) {
                         $plan_users = array(str_replace('E', '', $val->transfer_id));
                     } else {
                         for ($i = 0; $i < count($plan_users); $i++) {
                             if ($plan_users[$i] == $user) {
                                 $plan_users[$i] = str_replace('E', '', $val->transfer_id);
                                 break;
                             }
                         }
                     }
                     $plan_user = implode(',', $plan_users);
                 }
                 // 审核情况
                 $reviewData = array("plan_user" => $plan_user, "method" => 1);
             } else {
                 // 退回
                 $actual_user = null;
                 $finish_time = null;
                 $finish_flg = 0;
                 // 退回选项
                 $return = $reviewRow['return'];
                 if ($return == 2) {
                     // 退到初始状态
                     // 需更新的审核记录: 所有
                     $reviewWhere = "type = 'materiel' and file_id = {$id}";
                     // 审核情况更新数据
                     $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg);
                     // 文件状态不更新
                 } else {
                     if ($return == 4) {
                         // 退到本阶段开始
                         // 需更新的审核记录
                         $reviewWhere = "type = 'materiel' and finish_flg = 0 and file_id = {$id}";
                         // 审核情况更新数据
                         $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg);
                         // 文件状态不更新
                     } else {
                         if ($return == 3) {
                             // 退到上一阶段
                             // 需更新的审核记录:最后一个finish_flg为1的数据和第一个finish_flg为0的数据
                             $last_1 = $first_0 = 0;
                             foreach ($reviewRows as $r) {
                                 if ($r['finish_flg'] == 1) {
                                     $last_1 = $r['id'];
                                 }
                                 if ($r['finish_flg'] == 0 && $first_0 == null) {
                                     $first_0 = $r['id'];
                                 }
                             }
                             $reviewWhere = "id = {$last_1} or id = {$first_0}";
                             // 审核情况更新数据
                             $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg);
                             // 文件状态不更新
                         } else {
                             $fileWhere = "id = {$id}";
                             // 更新文件状态为退回
                             $mData = array("state" => "Return");
                             // 退到初始状态
                             // 更新所有record的finish_flg为0
                             $reviewWhere = "type = 'materiel' and file_id = {$id}";
                             // 审核情况
                             $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg);
                         }
                     }
                 }
             }
         }
         // 如果所有record的记录的finish_flg 都为1,则发布
         if ($finish_flg == 1 && $review->fetchAll("type = 'materiel' and finish_flg = 0 and file_id = {$id}")->count() == 1) {
             $publish = true;
             if (!isset($code) || !$code) {
                 // 自动生成物料编码
                 $code = $this->getCode($materielData->type, $materielData->project_no);
                 if (!$code) {
                     $result['result'] = false;
                     $result['info'] = "生成物料编码失败";
                     echo Zend_Json::encode($result);
                     exit;
                 } else {
                     if (count($ids) > 1) {
                         $newCodes[] = $code;
                         $result['info'] = "审批成功";
                     } else {
                         $result['info'] = "审批成功,系统分配物料号:{$code}";
                     }
                 }
             }
             $mData = array("state" => "Active", "code" => $code, "archive_time" => $now);
             $fileWhere = "id = {$id}";
             // 如果有ds等文件,这些文件也设置为已归档
             $data_file_id = $materielData->data_file_id;
             $tsr_id = $materielData->tsr_id;
             $first_report_id = $materielData->first_report_id;
             if ($data_file_id || $tsr_id || $first_report_id) {
                 $uploadUpdWhere = " archive = 0 and (1=0 ";
                 if ($data_file_id) {
                     $uploadUpdWhere .= " or id = " . $data_file_id;
                 }
                 if ($tsr_id) {
                     $uploadUpdWhere .= " or id = " . $tsr_id;
                 }
                 if ($first_report_id) {
                     $uploadUpdWhere .= " or id = " . $first_report_id;
                 }
                 $uploadUpdWhere .= ")";
                 $uploadUpdData = array('archive' => 1, 'archive_time' => $now);
             }
         }
         try {
             // 更新审核情况
             $review->update($reviewData, $reviewWhere);
             // 更新文件
             if (isset($fileWhere)) {
                 $materiel->update($mData, $fileWhere);
             }
             // 更新上传文件
             if (isset($uploadUpdData)) {
                 $upload = new Dcc_Model_Upload();
                 $upload->update($uploadUpdData, $uploadUpdWhere);
             }
             $this->operate("物料评审");
         } catch (Exception $e) {
             $result['result'] = false;
             $result['info'] = $e->getMessage();
             echo Zend_Json::encode($result);
             exit;
         }
         // 邮件任务
         // 文件提交者或更新人
         $owner = $materielData['create_user'];
         $dev = false;
         $type = "物料申请";
         // 发邮件的情况:
         // 1、单站审核结束 $finish_flg = 1 && $publish = false
         if ($finish_flg == 1 && !$publish) {
             $subject = $type . "审批";
             // $to = 下一站审核人
             $current = $review->getFirstNoReview("materiel", $id);
             $to = $employee->getInfosByOneLine($current['plan_user']);
             //
             $cc = $employee->getInfosByOneLine($owner);
             $cc = $cc['email'];
             $content = "你有一个" . $type . "需要审批,请登录系统查看详情!";
         }
         // 2、所有审核结束  $publish = true
         if ($publish) {
             $subject = $type . "发布";
             $to = $employee->getInfosByOneLine($owner);
             $cc = $employee->getInfosByOneLine($record->getEmployeeIds($materielData['id'], 'materiel'));
             $cc = $cc['email'];
             $config = new Zend_Config_Ini(CONFIGS_PATH . '/application.ini', 'production');
             if (isset($config) && isset($config->email->apply->publish)) {
                 $to_plus = $config->email->apply->publish;
                 if ($to_plus) {
                     if ($cc) {
                         $cc .= "," . $to_plus;
                     } else {
                         $cc = $to_plus;
                     }
                 }
             }
             //                 $cc = "";
             $his = "<p><b>审核记录:</b><br>" . str_replace(',', '<br>', $record->getHis($materielData['id'], 'materiel')) . "</p>";
             $content = "你申请的" . $type . "已通过审批。<p><b>物料编码:</b>" . $code . "</p><p><b>类别:</b>" . $this->getTypeByConnect($materielData['type'], '') . "</p><p><b>名称:</b>" . $materielData['name'] . "</p><p><b>描述:</b>" . $materielData['description'] . "</p><p><b>申请人:</b>" . $materielData['creater'] . "</p><p><b>申请时间:</b>" . $materielData['create_time'] . "</p>" . $his . "<p>请登录系统查看详情!</p>";
         }
         // 3、退回 isset($return)
         if (isset($return)) {
             $subject = $type . "退回";
             $to = $employee->getInfosByOneLine($owner);
             $cc = "";
             // 原审核人
             if ($reviewRow['plan_user']) {
                 $orgUser = $reviewRow['plan_user'];
                 $cc = $employee->getInfosByOneLine($orgUser);
                 $cc = $cc['email'];
             }
             $content = "你申请的" . $type . "已被退回,<p><b>退回原因:</b>" . $remark . "</p>,请登录系统查看详情!";
         }
         // 4、转审 $pass == 3
         if ($pass == 3) {
             $subject = $type . "转审";
             $toUser = str_replace('E', '', $val->transfer_id);
             $to = $employee->getInfosByOneLine($toUser);
             // 原审核人
             if ($reviewRow['plan_user']) {
                 $orgUser = $reviewRow['plan_user'];
                 $owner .= "," . $orgUser;
             }
             $cc = $employee->getInfosByOneLine($owner);
             $cc = $cc['email'];
             $content = "有新的" . $type . "被转移到你处审批,请登录系统查看详情!";
         }
         if (isset($subject)) {
             $mailData = array('type' => $type, 'subject' => $subject, 'to' => $to['email'], 'cc' => $cc, 'content' => $content, 'send_time' => $now, 'add_date' => $now);
             $mail = new Application_Model_Log_Mail();
             try {
                 $mailId = $mail->insert($mailData);
             } catch (Exception $e) {
                 $result['result'] = false;
                 $result['info'] = $e->getMessage();
                 echo Zend_Json::encode($result);
                 exit;
             }
             if ($mailId) {
                 $mail->send($mailId);
             }
         }
         $code = null;
     }
     if (count($newCodes) > 0) {
         $result['info'] .= ',系统分配物料号分别为:' . implode(',', $newCodes);
     }
     echo Zend_Json::encode($result);
     exit;
 }
Beispiel #12
0
 public function getpasswordAction()
 {
     // 返回值数组
     $result = array('success' => true, 'info' => '密码找回邮件已发往你的邮箱,请通过邮件中的链接地址重设密码。');
     // 请求参数
     $request = $this->getRequest()->getParams();
     if (isset($request['email'])) {
         $email = $request['email'];
         $user = new Application_Model_User();
         $checkEmail = $user->checkEmail($email);
         if ($checkEmail['success']) {
             $mail = new Application_Model_Log_Mail();
             $now = date('Y-m-d H:i:s');
             $key = time() . rand(1, 100);
             $link = HOME_PATH . '/public/login/resetpassword/user_id/' . $checkEmail['user_id'] . '/key/' . $key;
             $data = array('type' => '找回密码', 'subject' => '找回密码', 'to' => $email, 'key' => $key, 'user_id' => $checkEmail['user_id'], 'content' => '请通过以下链接重设密码:<br><a href="' . $link . '">' . $link . '</a>', 'add_date' => $now);
             try {
                 // 记录邮件日志
                 $mailId = $mail->insert($data);
                 // 发送邮件
                 $mail->send($mailId);
                 // 记录日志
                 $computer_name = gethostbyaddr(getenv("REMOTE_ADDR"));
                 // 计算机名
                 $data = array('operate' => '找回密码', 'target' => 'Login', 'computer_name' => $computer_name, 'ip' => $_SERVER['REMOTE_ADDR'], 'remark' => $email, 'time' => $now);
                 $operate = new Application_Model_Log_Operate();
                 try {
                     $operate->insert($data);
                 } catch (Exception $e) {
                     $result['success'] = false;
                     $result['info'] = $e->getMessage();
                     echo Zend_Json::encode($result);
                     exit;
                 }
             } catch (Exception $e) {
                 $result['success'] = false;
                 $result['info'] = $e->getMessage();
                 echo Zend_Json::encode($result);
                 exit;
             }
         } else {
             $result = $checkEmail;
         }
     } else {
         $result = array('success' => false, 'info' => '邮箱地址错误');
     }
     echo Zend_Json::encode($result);
     exit;
 }
Beispiel #13
0
 /**
  * @abstract    审核文件
  * @return      null
  */
 public function reviewAction()
 {
     // 返回值数组
     $result = array('success' => true, 'result' => 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['employee_id'];
     $val = (object) $request;
     $files = new Dcc_Model_Files();
     $record = new Dcc_Model_Record();
     $review = new Dcc_Model_Review();
     $formval = new Admin_Model_Formval();
     $employee = new Hra_Model_Employee();
     $upgrade = new Dcc_Model_Upgrade();
     $id = $val->id;
     $remark = $val->remark;
     $pass = $val->review_result;
     $review_id = $val->review_id;
     $publish = false;
     // 获取文件信息
     $filesData = $files->getOne($id);
     // 获取当前审核情况
     // 如果record记录被删除或状态已改变,报错
     $reviewWhere = "id = {$review_id}";
     $reviewRows = $review->getList($reviewWhere, "files");
     if (count($reviewRows) == 0) {
         $result['result'] = false;
         $result['info'] = "非法数据";
         echo Zend_Json::encode($result);
         exit;
     }
     $reviewRow = $reviewRows[0];
     if ($reviewRow['finish_flg'] != 0) {
         $result['result'] = false;
         $result['info'] = "数据状态已改变";
         echo Zend_Json::encode($result);
         exit;
     }
     // 处理记录
     $recordData = array("type" => "files", "table_name" => "oa_doc_files", "table_id" => $id, "handle_user" => $user, "handle_time" => $now, "action" => "审批", "result" => $pass == 1 ? "批准" : ($pass == 2 ? "拒绝" : "转审"), "ip" => $_SERVER['REMOTE_ADDR'], "remark" => $remark);
     // 增加记录
     $record->insert($recordData);
     // 通过方式
     $method = $reviewRow['method'];
     if ($pass == 1) {
         if ($method == 2) {
             // 任何一人处理即通过
             $finish_flg = 1;
             $actual_user = $user;
             $finish_time = $now;
         } else {
             // 所有人都需要审核,检查是否所有人都已经审核
             $plan_user = $reviewRow['plan_user'];
             $actual_user = $reviewRow['actual_user'];
             $actual_user = !$actual_user ? $user : $actual_user . "," . $user;
             // 检查计划审核人和实际审核人是否一致
             //                $plan_dept = $reviewRow['plan_dept'];
             //                if ($plan_dept) {
             //                    // 获取部门所有人员
             //                    $tmpUser = $employee->getAdapter()->query("select group_concat(id) as ids from oa_employee where dept_id in ( " . $plan_dept . ")")->fetchObject();
             //                    if ($tmpUser->ids) {
             //                        if ($plan_user)
             //                            $plan_user .= ",";
             //                        $plan_user .= $tmpUser->ids;
             //                    }
             //                }
             $planA = explode(',', $plan_user);
             $actualA = explode(',', $actual_user);
             $passFlg = true;
             foreach ($planA as $u) {
                 if ($u && !in_array($u, $actualA)) {
                     $passFlg = false;
                 }
             }
             if ($passFlg) {
                 $finish_flg = 1;
                 $finish_time = $now;
             } else {
                 $finish_flg = 0;
                 $finish_time = null;
             }
         }
         // 审核情况
         $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg);
     } else {
         if ($pass == 3) {
             // 转审
             $finish_flg = 0;
             if ($method == 2) {
                 // 处理方式为任意时,一个人转审之后其他人员也删除
                 $plan_user = str_replace('E', '', $val->transfer_id);
             } else {
                 // 更改审核情况中的审核人
                 $plan_users = explode(',', $reviewRow['plan_user']);
                 // 审核人不在审核人列表中,并且是管理员,则替换所有人
                 if (!in_array($user, $plan_users) && (Application_Model_User::checkPermissionByRoleName('文件管理员') || Application_Model_User::checkPermissionByRoleName('系统管理员'))) {
                     $plan_users = array(str_replace('E', '', $val->transfer_id));
                 } else {
                     for ($i = 0; $i < count($plan_users); $i++) {
                         if ($plan_users[$i] == $user) {
                             $plan_users[$i] = str_replace('E', '', $val->transfer_id);
                             break;
                         }
                     }
                 }
                 $plan_user = implode(',', $plan_users);
             }
             // 审核情况
             $reviewData = array("plan_user" => $plan_user, "method" => 1);
         } else {
             // 退回
             $actual_user = null;
             $finish_time = null;
             $finish_flg = 0;
             // 退回选项
             $return = $reviewRow['return'];
             if ($return == 2) {
                 // 退到初始状态
                 // 需更新的审核记录: 所有
                 $reviewWhere = "type = 'files' and file_id = {$id}";
                 // 审核情况更新数据
                 $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg);
                 // 文件状态不更新
             } else {
                 if ($return == 4) {
                     // 退到本阶段开始
                     // 需更新的审核记录
                     $reviewWhere = "type = 'files' and finish_flg = 0 and file_id = {$id}";
                     // 审核情况更新数据
                     $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg);
                     // 文件状态不更新
                 } else {
                     if ($return == 3) {
                         // 退到上一阶段
                         // 需更新的审核记录:最后一个finish_flg为1的数据和第一个finish_flg为0的数据
                         $last_1 = $first_0 = 0;
                         foreach ($reviewRows as $r) {
                             if ($r['finish_flg'] == 1) {
                                 $last_1 = $r['id'];
                             }
                             if ($r['finish_flg'] == 0 && $first_0 == null) {
                                 $first_0 = $r['id'];
                             }
                         }
                         $reviewWhere = "id = {$last_1} or id = {$first_0}";
                         // 审核情况更新数据
                         $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg);
                         // 文件状态不更新
                     } else {
                         $fileWhere = "id = {$id}";
                         // 更新文件状态为退回
                         $fileData = array("state" => "Return");
                         // 退到初始状态
                         // 更新所有record的finish_flg为0
                         $reviewWhere = "type = 'files' and file_id = {$id}";
                         // 审核情况
                         $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg);
                     }
                 }
             }
         }
     }
     $filesRow = $files->getOne($reviewRow['file_id']);
     // 判断是否需要更新文件
     // 如果所有record的记录的finish_flg 都为1,则发布
     if ($finish_flg == 1 && $review->fetchAll("type = 'files' and finish_flg = 0 and file_id = {$id}")->count() == 1) {
         $publish = true;
         $obsolute = false;
         // 如果是多个文件同时归档,需拆分
         if (strpos($filesRow['code'], ',') !== false) {
             $codes = explode(',', $filesRow['code']);
             $names = explode(',', $filesRow['name']);
             $file_ids = explode(',', $filesRow['file_ids']);
             $vers = explode(',', $filesRow['ver']);
             $description = explode('|', $filesRow['description']);
             $project_info = explode(',', $filesRow['project_info']);
             $ids = array();
             $k = 0;
             for ($i = 0; $i < count($names); $i++) {
                 $ids[] = "";
                 $length = substr_count($names[$i], '|');
                 for ($j = 0; $j <= $length; $j++) {
                     if (isset($ids[$i]) && $ids[$i]) {
                         $ids[$i] .= ',';
                     }
                     $ids[$i] .= $file_ids[$k++];
                 }
             }
             for ($i = 0; $i < count($codes); $i++) {
                 // 更新第一条
                 if ($i == 0) {
                     $data = array("state" => "Active", "code" => $codes[$i], "name" => $names[$i], "file_ids" => $ids[$i], "ver" => $vers[$i], "description" => $description[$i], "project_info" => $project_info[$i], "archive_time" => $now);
                     try {
                         $files->update($data, "id = {$id}");
                         // 如果是升版,登录升版信息
                         if ($vers[$i] > 1.0) {
                             $upgradeTmpData = array("project_no" => $project_info[$i], "description" => $description[$i]);
                             $upgrade->update($upgradeTmpData, "file_id=" . $id);
                         }
                     } catch (Exception $e) {
                         $result['result'] = false;
                         $result['info'] = $e->getMessage();
                         echo Zend_Json::encode($result);
                         exit;
                     }
                 } else {
                     $data = array("state" => "Active", "code" => $codes[$i], "ver" => $vers[$i], "tag" => $filesRow['tag'], "name" => $names[$i], "file_ids" => $ids[$i], "description" => $description[$i], "project_info" => $project_info[$i], "remark" => $filesRow['remark'], "create_time" => $filesRow['create_time'], "update_time" => $filesRow['update_time'], "create_user" => $filesRow['create_user'], "update_user" => $filesRow['update_user'], "archive_time" => $now, "add_flg" => $filesRow['add_flg']);
                     try {
                         $sid = $files->insert($data);
                         // 拆分智能表单数据
                         if ($sid) {
                             $sids[] = $sid;
                             $whereMenu = "oa_doc_files_" . $id;
                             $menus = $formval->getListByMenu($whereMenu);
                             foreach ($menus as $menu) {
                                 $menuData = array("attrid" => $menu['attrid'], "value" => $menu['value'], "menu" => "oa_doc_files_" . $sid);
                                 $formval->insert($menuData);
                             }
                             // 如果是升版,登录升版信息
                             if ($vers[$i] > 1.0) {
                                 $obsolute = true;
                                 $upgradeRow = $upgrade->fetchAll("file_id = {$id}")->toArray();
                                 foreach ($upgradeRow as $row) {
                                     $upgradeTmpData = array("file_id" => $sid, "reason" => $row['reason'], "reason_type" => $row['reason_type'], "project_no" => $project_info[$i], "description" => $description[$i], "create_user" => $row['create_user'], "create_time" => $row['create_time'], "update_user" => $row['update_user'], "update_time" => $row['update_time']);
                                     $upgrade->insert($upgradeTmpData);
                                 }
                             }
                             $recordRow = $record->fetchAll("type='files' and table_name='oa_doc_files' and table_id={$id}")->toArray();
                             foreach ($recordRow as $row) {
                                 // 增加记录
                                 $recordTmpData = array("type" => $row['type'], "table_name" => $row['table_name'], "table_id" => $sid, "handle_user" => $row['handle_user'], "handle_time" => $row['handle_time'], "action" => $row['action'], "result" => $row['result'], "ip" => $row['ip'], "remark" => $row['remark']);
                                 $record->insert($recordTmpData);
                             }
                         }
                     } catch (Exception $e) {
                         $result['result'] = false;
                         $result['info'] = $e->getMessage();
                         echo Zend_Json::encode($result);
                         exit;
                     }
                 }
             }
         }
         $fileData = array("state" => "Active", "archive_time" => $now);
         $fileWhere = "id = {$id}";
         // 更新文件状态为已归档
         $uploadData = array("archive" => 1, "archive_time" => $now);
         $upload = new Dcc_Model_Upload();
         // 获取上传文件id
         $ids = $filesRow['file_ids'];
         $uploadWhere = "id in ({$ids})";
         $upload->update($uploadData, $uploadWhere);
         // 更新旧版文件的状态为已作废
         if (strpos($filesData['ver'], '1.0') === false || $obsolute) {
             if (isset($sids) && count($sids) > 0) {
                 $obsoluteWhere = " id not in (" . implode(',', $sids) . ") and FIND_IN_SET(code, '" . $filesRow['code'] . "')";
             } else {
                 $obsoluteWhere = " FIND_IN_SET(code, '" . $filesRow['code'] . "')";
             }
             $obsoluteData = array("state" => "Obsolete");
         }
     }
     try {
         // 更新审核情况
         $review->update($reviewData, $reviewWhere);
         if (isset($obsoluteData) && isset($obsoluteWhere)) {
             $files->update($obsoluteData, $obsoluteWhere);
         }
         // 更新文件
         if (isset($fileWhere)) {
             $files->update($fileData, $fileWhere);
         }
         $this->operate("文件审批");
     } catch (Exception $e) {
         $result['result'] = false;
         $result['info'] = $e->getMessage();
         echo Zend_Json::encode($result);
         exit;
     }
     // 邮件任务
     // 文件提交者或更新人
     $owner = $filesData['create_user'];
     if ($filesData['create_user'] != $filesData['update_user']) {
         $owner .= "," . $filesData['update_user'];
     }
     $dev = false;
     $type = "新文件";
     if (stripos($filesData['ver'], '1.0') === false) {
         $dev = true;
         $type = "升版文件";
     }
     $content = "<p><b>文件号:</b>" . $filesData['code'] . "</p><p><b>版本:</b>" . $filesData['ver'] . "</p><p><b>文件描述:</b>" . $filesData['description'] . "</p><p><b>备注:</b>" . $filesData['remark'] . "</p><p><b>申请人:</b>" . $filesData['creater'] . "</p><p><b>申请时间:</b>" . $filesData['create_time'] . "</p><p>请登录系统查看详情!</p>";
     // 发邮件的情况:
     // 1、单站审核结束 $finish_flg = 1 && $publish = false
     if ($finish_flg == 1 && !$publish) {
         $subject = $type . "审批";
         // $to = 下一站审核人
         $current = $review->getFirstNoReview("files", $id);
         $to = $employee->getInfosByOneLine($current['plan_user']);
         //
         $cc = $employee->getInfosByOneLine($owner);
         $cc = $cc['email'];
         //$cc = "";
         $content = "你有一个" . $type . "需要审批," . $content;
     }
     // 2、所有审核结束  $publish = true
     if ($publish) {
         $subject = $type . "发布";
         $to = $employee->getInfosByOneLine($owner);
         $cc = $employee->getInfosByOneLine($record->getEmployeeIds($filesData['id'], 'files'));
         $cc = $cc['email'];
         //            $cc = "";
         $content .= "<p><b>审核记录:</b><br>" . str_replace(',', '<br>', $record->getHis($filesData['id'], 'files', 'oa_doc_files')) . "</p>";
         $content = "你申请的" . $type . "已通过审批," . $content;
     }
     // 3、退回 isset($return)
     if (isset($return)) {
         $subject = $type . "退回";
         $to = $employee->getInfosByOneLine($owner);
         $cc = "";
         // 原审核人
         if ($reviewRow['plan_user']) {
             $orgUser = $reviewRow['plan_user'];
             $cc = $employee->getInfosByOneLine($orgUser);
             $cc = $cc['email'];
         }
         $content = "你申请的" . $type . "已被退回,<p><b>退回原因:</b>" . $remark . "</p>" . $content;
     }
     // 4、转审 $pass == 3
     if ($pass == 3) {
         $subject = $type . "转审";
         $toUser = str_replace('E', '', $val->transfer_id);
         $to = $employee->getInfosByOneLine($toUser);
         // 原审核人
         if ($reviewRow['plan_user']) {
             $orgUser = $reviewRow['plan_user'];
             $owner .= "," . $orgUser;
         }
         $cc = $employee->getInfosByOneLine($owner);
         $cc = $cc['email'];
         //             $cc = "";
         $content = "有新的" . $type . "被转移到你处审批:" . $content;
     }
     if (isset($subject)) {
         $mailData = array('type' => $type, 'subject' => $subject, 'to' => $to['email'], 'cc' => $cc, 'content' => $content, 'send_time' => $now, 'add_date' => $now);
         $mail = new Application_Model_Log_Mail();
         try {
             $mailId = $mail->insert($mailData);
         } catch (Exception $e) {
             $result['result'] = false;
             $result['info'] = $e->getMessage();
             echo Zend_Json::encode($result);
             exit;
         }
         if ($mailId) {
             $mail->send($mailId);
         }
     }
     echo Zend_Json::encode($result);
     exit;
 }
Beispiel #14
0
 /**
  * 保存文件编码
  */
 public function savecodeAction()
 {
     $request = $this->getRequest();
     $id = $request->getParam('id');
     $code = $request->getParam('code');
     if ($id && $code) {
         $code = strtoupper($code);
         // 检查文件编码是否已经存在
         $codeModel = new Dcc_Model_Code();
         $data = $codeModel->fetchAll("code = '{$code}'")->toArray();
         if ($data && count($data) > 0) {
             $result['success'] = false;
             $result['info'] = "文件编码已存在!";
             echo Zend_Json::encode($result);
             exit;
         }
         $now = date('Y-m-d H:i:s');
         $user_session = new Zend_Session_Namespace('user');
         $user = $user_session->user_info['employee_id'];
         $data = array('code' => $code, 'state' => 'Active', 'update_user' => $user, 'update_time' => $now);
         $where = "id = " . $id;
         $codeData = $codeModel->getById($id);
         try {
             $codeModel->update($data, $where);
             $record = new Dcc_Model_Record();
             $review = new Dcc_Model_Review();
             // 处理记录
             $recordData = array("type" => "code_apply", "table_name" => "oa_doc_code", "table_id" => $id, "handle_user" => $user, "handle_time" => $now, "action" => "审批", "result" => '批准', "ip" => $_SERVER['REMOTE_ADDR']);
             // 增加记录
             $record->insert($recordData);
             // 审核情况
             $reviewData = array("actual_user" => $user, "finish_time" => $now, "finish_flg" => 1);
             $review->update($reviewData, "type='code_apply' and file_id = " . $id);
             // 发邮件
             $type = "文件编码申请";
             $subject = "文件编码申请审核";
             $user_name = $user_session->user_info['user_name'];
             $to = $codeModel->getAdapter()->query("select group_concat(email) as mail_to from oa_employee where id =(select create_user from oa_doc_code where id = {$id})")->fetchObject();
             $content = "<p>你有一个文件编码申请已分配,文件号:{$code}</p>";
             $content .= "<p><b>文件描述:</b>" . $codeData['description'] . "</p><p><b>备注:</b>" . $codeData['remark'] . "</p><p><b>申请时间:</b>" . $codeData['create_time'] . "</p><p>请登录系统查看详情!</p>";
             $mailData = array('type' => $type, 'subject' => $subject, 'to' => $to->mail_to, 'content' => $content, 'send_time' => $now, 'add_date' => $now);
             $mail = new Application_Model_Log_Mail();
             $mailId = $mail->insert($mailData);
             if ($mailId) {
                 $mail->send($mailId);
             }
             $result['success'] = true;
             $result['info'] = '分配成功';
             echo Zend_Json::encode($result);
             exit;
         } catch (Exception $e) {
             $result['success'] = false;
             $result['info'] = $e->getMessage();
             echo Zend_Json::encode($result);
             exit;
         }
     }
 }
Beispiel #15
0
 public function reviewAction()
 {
     // 返回值数组
     $result = array('success' => true, 'info' => '审核成功');
     $request = $this->getRequest()->getParams();
     $review_id = isset($request['review_id']) ? $request['review_id'] : null;
     //$review_type_id = isset($request['review_type_id']) ? $request['review_type_id'] : null;
     $review_operate = isset($request['review_operate']) ? $request['review_operate'] : null;
     $review_current_step = isset($request['review_current_step']) ? $request['review_current_step'] : null;
     // 当前阶段(review表ID)
     $review_last_step = isset($request['review_last_step']) ? $request['review_last_step'] : null;
     // 是否当前阶段为最后一阶段
     $review_to_finish = isset($request['review_to_finish']) ? $request['review_to_finish'] : null;
     // 是否批准后当前阶段结束
     $review_next_step = isset($request['review_next_step']) ? $request['review_next_step'] : null;
     // 下一阶段(review表ID)
     $review_remark = isset($request['review_remark']) ? $request['review_remark'] : null;
     $review_transfer_user = isset($request['review_transfer_user']) ? $request['review_transfer_user'] : null;
     //转审人
     $review_transfer = $request['review_transfer'] == 1 ? true : false;
     if ($review_id && $review_operate) {
         $transfer = new Erp_Model_Purchse_Transfer();
         $now = date('Y-m-d H:i:s');
         $user_session = new Zend_Session_Namespace('user');
         $user_id = $user_session->user_info['user_id'];
         $employee_id = $user_session->user_info['employee_id'];
         // 评审意见
         $review_info = '意见: ' . $review_remark;
         $req = new Erp_Model_Purchse_Req();
         $user = new Application_Model_User();
         $review = new Dcc_Model_Review();
         $employee = new Hra_Model_Employee();
         $reqData = $req->getData(null, $review_id);
         // 更新审核状态及审核意见
         if ($review_operate == 'transfer') {
             // 转审
             $review_info = $reqData['review_info'] . '<br>' . $now . ': ' . $user_session->user_info['user_name'] . ' [审核-转审] [' . $review_info . ']';
             $req->update(array('review_info' => $review_info), "id = " . $review_id);
             $reviewState = $review->fetchRow("type = 'purchse_req_add' and finish_flg = 0 and file_id = " . $review_id, "id")->toArray();
             // 转审对象
             $transferUserInfo = $user->getEmployeeInfoById($review_transfer_user);
             $reviewUsers = $reviewState['plan_user'];
             $reviewUserArr = explode(',', $reviewUsers);
             $reviewer = array();
             if ($reviewState['method'] == 2) {
                 // 任意: 直接替换审核人为转审对象
                 foreach ($reviewUserArr as $review_user) {
                     if ($review_user == $employee_id) {
                         array_push($reviewer, $transferUserInfo['id']);
                     }
                 }
             } else {
                 // 全部: 替换当前审核人为转审对象,其余审核人保留
                 foreach ($reviewUserArr as $review_user) {
                     if ($review_user == $employee_id) {
                         array_push($reviewer, $transferUserInfo['id']);
                     } else {
                         if (!in_array($review_user, $reviewer)) {
                             array_push($reviewer, $review_user);
                         }
                     }
                 }
             }
             $reviewerstr = implode(',', $reviewer);
             $review->update(array('plan_user' => $reviewerstr), "id = " . $reviewState['id']);
             // 发送邮件通知制单人
             $reviewResult = '<font style="color: #FF0000"><b>转审</b></font>';
             $mail = new Application_Model_Log_Mail();
             $to = $transferUserInfo['email'];
             $mailContent = '<div>采购申请审核:</div>
                             <div>
                             <p><b>审核人:</b>' . $user_session->user_info['user_name'] . '</p>
                             <p><b>审核结果:</b>' . $reviewResult . '</p>
                             <p><b>审核意见:</b>' . $review_remark . '</p>
                             <p><b>申请单号:</b>' . $reqData['number'] . '</p>
                             <p><b>申请部门:</b>' . $reqData['dept'] . '</p>
                             <p><b>申请人:</b>' . $reqData['apply_user_name'] . '</p>
                             <p><b>制单人:</b>' . $reqData['creater'] . '</p>
                             <p><b>类别:</b>' . $reqData['type'] . '</p>
                             <p><b>事由:</b>' . $reqData['reason'] . '</p>
                             <p><b>金额:</b><a style="color: #467500;font-weight: bold;">¥' . round($reqData['total'], 2) . '</a></p>
                             <p><b>备注:</b>' . $reqData['remark'] . '</p>
                             <p><b>制单时间:</b>' . $reqData['create_time'] . '</p>
                             <p><b>更新时间:</b>' . $reqData['update_time'] . '</p>
                             <hr>
                             <p><b>审核日志:</b></p><p>' . $reqData['review_info'] . '</p>
                             </div>';
             $mailData = array('type' => '消息', 'subject' => '采购申请-转审', 'to' => $to, 'cc' => $user_session->user_info['user_email'], 'user_id' => $user_session->user_info['user_id'], 'content' => $mailContent, 'add_date' => $now);
             try {
                 // 记录邮件日志并发送邮件
                 $mail->send($mail->insert($mailData));
             } catch (Exception $e) {
                 $result['success'] = false;
                 $result['info'] = $e->getMessage();
             }
         } else {
             if ($review_operate == 'no') {
                 // 更新采购申请状态
                 $review_info = $now . ': ' . $user_session->user_info['user_name'] . ' [审核-拒绝] [' . $review_info . ']';
                 $data = array('state' => 1, 'transfer_description' => null, 'review_info' => $reqData['review_info'] . '<br>' . $review_info);
                 $req->update($data, "id = " . $review_id);
                 if ($review_transfer) {
                     $transfer->update(array('state' => 1), "id = " . $reqData['transfer_id']);
                 }
                 // 删除当前申请的审核配置
                 $review->delete("type = 'purchse_req_add' and file_id = " . $review_id);
                 // 发送邮件通知制单人
                 $reviewResult = '<font style="color: #FF0000"><b>拒绝</b></font>';
                 $mail = new Application_Model_Log_Mail();
                 $applyEmployeeData = $user->fetchRow("id = " . $reqData['create_user'])->toArray();
                 $applyEmployee = $employee->fetchRow("id = " . $applyEmployeeData['employee_id'])->toArray();
                 $to = $applyEmployee['email'];
                 $mailContent = '<div>采购申请审核:</div>
                             <div>
                             <p><b>审核人:</b>' . $user_session->user_info['user_name'] . '</p>
                             <p><b>审核结果:</b>' . $reviewResult . '</p>
                             <p><b>审核意见:</b>' . $review_remark . '</p>
                             <p><b>申请单号:</b>' . $reqData['number'] . '</p>
                             <p><b>申请部门:</b>' . $reqData['dept'] . '</p>
                             <p><b>申请人:</b>' . $reqData['apply_user_name'] . '</p>
                             <p><b>制单人:</b>' . $reqData['creater'] . '</p>
                             <p><b>类别:</b>' . $reqData['type'] . '</p>
                             <p><b>事由:</b>' . $reqData['reason'] . '</p>
                             <p><b>金额:</b><a style="color: #467500;font-weight: bold;">¥' . round($reqData['total'], 2) . '</a></p>
                             <p><b>备注:</b>' . $reqData['remark'] . '</p>
                             <p><b>制单时间:</b>' . $reqData['create_time'] . '</p>
                             <p><b>更新时间:</b>' . $reqData['update_time'] . '</p>
                             <hr>
                             <p><b>审核日志:</b></p><p>' . $reqData['review_info'] . '</p>
                             </div>';
                 $mailData = array('type' => '消息', 'subject' => '采购申请-审核', 'to' => $to, 'cc' => $user_session->user_info['user_email'], 'user_id' => $reqData['create_user'], 'content' => $mailContent, 'add_date' => $now);
                 try {
                     // 记录邮件日志并发送邮件
                     $mail->send($mail->insert($mailData));
                 } catch (Exception $e) {
                     $result['success'] = false;
                     $result['info'] = $e->getMessage();
                 }
             } else {
                 $help = new Application_Model_Helpers();
                 $review_info = $now . ': ' . $user_session->user_info['user_name'] . ' [审核-批准] [' . $review_info . ']';
                 $reqUpdateData = array('review_info' => $reqData['review_info'] . '<br>' . $review_info);
                 $reviewData = $review->fetchRow("id = " . $review_current_step)->toArray();
                 $actual_user = $reviewData['actual_user'] == '' ? $user_session->user_info['employee_id'] : $reviewData['actual_user'] . ',' . $user_session->user_info['employee_id'];
                 $data = array('actual_user' => $actual_user, 'finish_time' => $now, 'finish_flg' => 1);
                 // 当前审核阶段为最后一阶段
                 if ($review_last_step == 1) {
                     // 当前阶段已完结
                     if ($review_to_finish == 1) {
                         if ($review_transfer) {
                             if ($reqData['transfer_type'] == '取消') {
                                 $this->cancelReq($review_id);
                             } else {
                                 $this->approveTransferUpdateItems($reqData['transfer_id']);
                             }
                             $transfer->update(array('state' => 2), "id = " . $reqData['transfer_id']);
                         }
                         $data = array('actual_user' => $actual_user, 'finish_time' => $now, 'finish_flg' => 1);
                         $reviewResult = '<font style="color: #006400"><b>发布</b></font>';
                         // 发布
                         // 更新申请状态
                         $reqUpdateData['state'] = 2;
                         $reqUpdateData['transfer_description'] = null;
                         $reqUpdateData['release_time'] = $now;
                         // 更新审核记录表
                         $review->update($data, "id = " . $review_current_step);
                         $mail = new Application_Model_Log_Mail();
                         $applyEmployeeData = $user->fetchRow("id = " . $reqData['create_user'])->toArray();
                         $applyEmployee = $employee->fetchRow("id = " . $applyEmployeeData['employee_id'])->toArray();
                         $to = $applyEmployee['email'];
                         $cc = $user_session->user_info['user_email'];
                         // 发布通知采购员
                         $buyer = new Erp_Model_Purchse_Buyer();
                         $buyerData = $buyer->getData();
                         foreach ($buyerData as $b) {
                             $cc .= ',' . $b['email'];
                         }
                         $mailContent = '<div>采购申请审核批准,请登录系统查看:</div>
                             <div>
                             <p><b>审核人:</b>' . $user_session->user_info['user_name'] . '</p>
                             <p><b>审核结果:</b>' . $reviewResult . '</p>
                             <p><b>审核意见:</b>' . $review_remark . '</p>
                             <p><b>申请单号:</b>' . $reqData['number'] . '</p>
                             <p><b>申请部门:</b>' . $reqData['dept'] . '</p>
                             <p><b>申请人:</b>' . $reqData['apply_user_name'] . '</p>
                             <p><b>制单人:</b>' . $reqData['creater'] . '</p>
                             <p><b>类别:</b>' . $reqData['type'] . '</p>
                             <p><b>事由:</b>' . $reqData['reason'] . '</p>
                             <p><b>金额:</b><a style="color: #467500;font-weight: bold;">¥' . round($reqData['total'], 2) . '</a></p>
                             <p><b>备注:</b>' . $reqData['remark'] . '</p>
                             <p><b>制单时间:</b>' . $reqData['create_time'] . '</p>
                             <p><b>更新时间:</b>' . $reqData['update_time'] . '</p>
                             <hr>
                             <p><b>审核日志:</b></p><p>' . $reqUpdateData['review_info'] . '</p>
                             </div>';
                         $mailData = array('type' => '消息', 'subject' => '采购申请-发布', 'to' => $to, 'cc' => $cc, 'user_id' => $reqData['create_user'], 'content' => $mailContent, 'add_date' => $now);
                         try {
                             // 记录邮件日志并发送邮件
                             $mail->send($mail->insert($mailData));
                         } catch (Exception $e) {
                             $result['success'] = false;
                             $result['info'] = $e->getMessage();
                         }
                     } else {
                         $data = array('actual_user' => $actual_user);
                         $review->update($data, "id = " . $review_current_step);
                         // 等待其他审核人批准
                     }
                 } else {
                     // 当前阶段已完结
                     if ($review_to_finish == 1) {
                         $data = array('actual_user' => $actual_user, 'finish_time' => $now, 'finish_flg' => 1);
                         $reviewResult = '<font style="color: #006400"><b>批准</b></font>';
                         // 进入下一阶段
                         // 更新审核记录表
                         $review->update($data, "id = " . $review_current_step);
                         // 邮件通知下一阶段审核人
                         $reviewNextStepData = $review->fetchRow("id = " . $review_next_step)->toArray();
                         $mailTo = explode(',', $reviewNextStepData['plan_user']);
                         if ($mailTo) {
                             $mailContent = '<div>新建采购申请,请登录系统查看:</div>
                                         <div>
                                         <p><b>申请单号:</b>' . $reqData['number'] . '</p>
                                         <p><b>申请部门:</b>' . $reqData['dept'] . '</p>
                                         <p><b>申请人:</b>' . $reqData['apply_user_name'] . '</p>
                                         <p><b>制单人:</b>' . $reqData['creater'] . '</p>
                                         <p><b>类别:</b>' . $reqData['type'] . '</p>
                                         <p><b>事由:</b>' . $reqData['reason'] . '</p>
                                         <p><b>金额:</b><a style="color: #467500;font-weight: bold;">¥' . round($reqData['total'], 2) . '</a></p>
                                         <p><b>备注:</b>' . $reqData['remark'] . '</p>
                                         <p><b>制单时间:</b>' . $reqData['create_time'] . '</p>
                                         <p><b>更新时间:</b>' . $reqData['update_time'] . '</p>
                                         <hr>
                                         <p><b>审核日志:</b></p><p>' . $reqUpdateData['review_info'] . '</p>
                                         </div>';
                             $mailData = array('type' => '消息', 'subject' => '采购申请-新申请', 'cc' => $user_session->user_info['user_email'], 'content' => $mailContent, 'add_date' => $now);
                             $resultMail = $help->sendMailToStep($mailTo, $mailData);
                             if (!$resultMail['success']) {
                                 $result = $resultMail;
                             }
                         }
                     } else {
                         $data = array('actual_user' => $actual_user);
                         $review->update($data, "id = " . $review_current_step);
                         // 等待其他审核人批准
                     }
                 }
                 // 更新申请状态
                 $req->update($reqUpdateData, "id = " . $review_id);
             }
         }
     }
     echo Zend_Json::encode($result);
     exit;
 }
Beispiel #16
0
    public function edititemsAction()
    {
        // 返回值数组
        $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']);
        $send_id = $json->send_id;
        $json_items = $json->items;
        $items_updated = $json_items->updated;
        $items_inserted = $json_items->inserted;
        $items_deleted = $json_items->deleted;
        $receive = new Erp_Model_Stock_receive();
        $items = new Erp_Model_Purchse_Receiveitems();
        $itemsSend = new Erp_Model_Sale_Receiveitemsordersale();
        $stock = new Erp_Model_Stock_Stock();
        $receiveData = $receive->getData(null, $send_id, '销售交货');
        // 更新
        if (count($items_updated) > 0) {
            foreach ($items_updated as $val) {
                $data = array('code' => $val->items_code, 'name' => $val->items_name, 'description' => $val->items_description, 'qty' => $val->items_qty, 'unit' => $val->items_unit, 'customer_code' => $val->items_customer_code, 'customer_description' => $val->items_customer_description, 'warehouse_code' => $val->items_warehouse_code, 'remark' => $val->items_remark, 'update_user' => $user_id, 'update_time' => $now);
                try {
                    $items->update($data, "id = " . $val->items_id);
                } catch (Exception $e) {
                    $result['success'] = false;
                    $result['info'] = $e->getMessage();
                    echo Zend_Json::encode($result);
                    exit;
                }
            }
        }
        // 插入
        if (count($items_inserted) > 0) {
            foreach ($items_inserted as $val) {
                $total = round($val->items_qty * $val->items_price, 2);
                $code = $val->items_code_internal != '' ? $val->items_code_internal : $val->items_code;
                $product_code = $val->items_code_internal != '' ? $val->items_code : '';
                $data = array('receive_id' => $send_id, 'code' => $code, 'product_code' => $product_code, 'name' => $val->items_name, 'description' => $val->items_description, 'qty' => $val->items_qty, 'price' => $val->items_price, 'total' => $total, 'unit' => $val->items_unit, 'customer_code' => $val->items_customer_code, 'customer_description' => $val->items_customer_description, 'warehouse_code' => $val->items_warehouse_code, 'remark' => $val->items_remark, 'order_number' => $val->items_order_number, 'create_user' => $user_id, 'create_time' => $now, 'update_user' => $user_id, 'update_time' => $now);
                try {
                    $receive_item_id = $items->insert($data);
                    // 记录分拆数据
                    $itemData = array('receive_number' => $receiveData['number'], 'receive_item_id' => $receive_item_id, 'items_order_item_id' => $val->items_order_item_id, 'items_order_currency' => $val->items_order_currency, 'items_order_date' => $val->items_order_date, 'items_code' => $code, 'items_product_code' => $product_code, 'items_customer_code' => $val->items_customer_code, 'items_customer_description' => $val->items_customer_description, 'items_remark' => $val->items_remark, 'items_qty' => $val->items_qty, 'items_price' => $val->items_price, 'items_warehouse_code' => $val->items_warehouse_code, 'items_order_id' => $val->items_order_id, 'items_order_number' => $val->items_order_number);
                    $this->saveItemDetails($itemData);
                } catch (Exception $e) {
                    $result['success'] = false;
                    $result['info'] = $e->getMessage();
                    echo Zend_Json::encode($result);
                    exit;
                }
            }
        }
        // 更新总计
        $items->refreshReceiveTotal($send_id);
        if ($result['success']) {
            $member = new Admin_Model_Member();
            $noticeMails = array();
            $noticeUsers = array();
            $noticeTo = $member->getMemberWithManagerByName('通知-销售交货');
            foreach ($noticeTo as $n) {
                if ($n['email'] != '' && !in_array($n['user_id'], $noticeUsers)) {
                    array_push($noticeMails, $n['email']);
                    array_push($noticeUsers, $n['user_id']);
                }
            }
            if (count($noticeMails)) {
                $warehouse = new Erp_Model_Warehouse_Warehouse();
                $title = '销售交货-' . $receiveData['transaction_type'];
                $mailContent = '<div><b>' . $title . '</b>,请登录系统查看:</div>
                        <div>
                        <p><b>单据号:</b>' . $receiveData['number'] . '</p>
                        <p><b>制单员:</b>' . $user_session->user_info['user_name'] . '</p>
                        <p><b>描述:</b>' . $receiveData['description'] . '</p>
                        <p><b>备注:</b>' . $receiveData['remark'] . '</p>
                        <p><b>时间:</b>' . $receiveData['create_time'] . '</p>
                        </div><hr>';
                $mailContent .= '<div><style type="text/css">
table.gridtable {
	font-family: verdana,arial,sans-serif;
	font-size:12px;
	color:#333333;
	border-width: 1px;
	border-color: #666666;
	border-collapse: collapse;
}
table.gridtable th {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #666666;
	background-color: #dedede;
}
table.gridtable td {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #666666;
	background-color: #ffffff;
}
.delete{
	text-decoration: line-through;
	color: #FF0000;
}
.update{
	font-weight: bold;
	color: #000093;
}
.inactive{
	font-weight: bold;
	color: #999999;
}
</style><table class="gridtable">
                			<tr>
                			<th>#</th>
                			<th>内部型号 / 物料号</th>
                			<th>名称</th>
                			<th>描述</th>
                			<th>数量</th>
                			<th>单位</th>
                			<th>客户产品型号</th>
                			<th>客户产品描述</th>
                			<th>交货仓位</th>
                			<th>备注</th>
                			</tr>';
                $itemsData = $items->getData($send_id);
                $i = 0;
                foreach ($itemsData as $d) {
                    $i++;
                    $warehouseData = $warehouse->getInfoByCode($d['items_warehouse_code']);
                    $warehouseInfo = $warehouseData["code"];
                    if (isset($warehouseData["name"])) {
                        $warehouseInfo = $warehouseData["code"] . ' ' . $warehouseData["name"];
                    }
                    $mailContent .= '<tr>
                        <td>' . $i . '</td>
                        <td>' . $d['items_code'] . '</td>
                        <td>' . $d['items_name'] . '</td>
                        <td>' . $d['items_description'] . '</td>
                        <td>' . $d['items_qty'] . '</td>
                        <td>' . $d['items_unit'] . '</td>
                        <td>' . $d['items_customer_code'] . '</td>
                        <td>' . $d['items_customer_description'] . '</td>
                        <td>' . $warehouseInfo . '</td>
                        <td>' . $d['items_remark'] . '</td>
                      </tr>';
                }
                $mailContent .= '</table></div><hr>';
                $mailData = array('type' => '通知', 'subject' => $title, 'cc' => $user_session->user_info['user_email'], 'content' => $mailContent, 'add_date' => $now, 'to' => implode(',', $noticeMails), 'user_id' => $user_id);
                try {
                    // 记录邮件日志并发送邮件
                    $mail = new Application_Model_Log_Mail();
                    $mail->send($mail->insert($mailData));
                } catch (Exception $e) {
                    $result['success'] = false;
                    $result['info'] = $e->getMessage();
                }
            }
        }
        echo Zend_Json::encode($result);
        exit;
    }
Beispiel #17
0
 public function reviewAction()
 {
     // 返回值数组
     $result = array('success' => true, 'info' => '审核成功');
     $request = $this->getRequest()->getParams();
     $review_id = isset($request['review_id']) ? $request['review_id'] : null;
     $review_operate = isset($request['review_operate']) ? $request['review_operate'] : null;
     $review_current_step = isset($request['review_current_step']) ? $request['review_current_step'] : null;
     // 当前阶段(review表ID)
     $review_last_step = isset($request['review_last_step']) ? $request['review_last_step'] : null;
     // 是否当前阶段为最后一阶段
     $review_to_finish = isset($request['review_to_finish']) ? $request['review_to_finish'] : null;
     // 是否批准后当前阶段结束
     $review_next_step = isset($request['review_next_step']) ? $request['review_next_step'] : null;
     // 下一阶段(review表ID)
     $review_remark = isset($request['review_remark']) ? $request['review_remark'] : null;
     $review_transfer_user = isset($request['review_transfer_user']) ? $request['review_transfer_user'] : null;
     //转审人
     if ($review_id && $review_operate) {
         $now = date('Y-m-d H:i:s');
         $user_session = new Zend_Session_Namespace('user');
         $user_id = $user_session->user_info['user_id'];
         $employee_id = $user_session->user_info['employee_id'];
         // 评审意见
         $review_info = '意见: ' . $review_remark;
         $price = new Erp_Model_Sale_Price();
         $user = new Application_Model_User();
         $review = new Dcc_Model_Review();
         $employee = new Hra_Model_Employee();
         $priceData = $price->getData(null, $review_id);
         // 更新审核状态及审核意见
         if ($review_operate == 'transfer') {
             // 转审
             $tmp = $priceData['review_info'] != '' ? $priceData['review_info'] . '<br>' : '';
             $review_info = $tmp . $now . ': ' . $user_session->user_info['user_name'] . ' [审核-转审] [' . $review_info . ']';
             $price->update(array('review_info' => $review_info), "id = " . $review_id);
             $reviewState = $review->fetchRow("type = 'sale_price_add' and finish_flg = 0 and file_id = " . $review_id, "id")->toArray();
             // 转审对象
             $transferUserInfo = $user->getEmployeeInfoById($review_transfer_user);
             $reviewUsers = $reviewState['plan_user'];
             $reviewUserArr = explode(',', $reviewUsers);
             $reviewer = array();
             if ($reviewState['method'] == 2) {
                 // 任意: 直接替换审核人为转审对象
                 foreach ($reviewUserArr as $review_user) {
                     if ($review_user == $employee_id) {
                         array_push($reviewer, $transferUserInfo['id']);
                     }
                 }
             } else {
                 // 全部: 替换当前审核人为转审对象,其余审核人保留
                 foreach ($reviewUserArr as $review_user) {
                     if ($review_user == $employee_id) {
                         array_push($reviewer, $transferUserInfo['id']);
                     } else {
                         if (!in_array($review_user, $reviewer)) {
                             array_push($reviewer, $review_user);
                         }
                     }
                 }
             }
             $reviewerstr = implode(',', $reviewer);
             $review->update(array('plan_user' => $reviewerstr), "id = " . $reviewState['id']);
             // 发送邮件通知制单人
             $reviewResult = '<font style="color: #FF0000"><b>转审</b></font>';
             $mail = new Application_Model_Log_Mail();
             $to = $transferUserInfo['email'];
             $mailContent = '<div>销售价格申请审核:</div>
                             <div>
                             <p><b>审核人:</b>' . $user_session->user_info['user_name'] . '</p>
                             <p><b>审核结果:</b>' . $reviewResult . '</p>
                             <p><b>审核意见:</b>' . $review_remark . '</p>
                             <p><b>申请单号:</b>' . $priceData['number'] . '</p>
                             <p><b>申请人:</b>' . $priceData['creater'] . '</p>
                             <p><b>描述:</b>' . $priceData['description'] . '</p>
                             <p><b>备注:</b>' . $priceData['remark'] . '</p>
                             <hr>
                             <p><b>审核日志:</b></p><p>' . $priceData['review_info'] . '</p>
                             </div>';
             $mailData = array('type' => '消息', 'subject' => '销售价格申请-转审', 'to' => $to, 'cc' => $user_session->user_info['user_email'], 'user_id' => $user_session->user_info['user_id'], 'content' => $mailContent, 'add_date' => $now);
             try {
                 // 记录邮件日志并发送邮件
                 $mail->send($mail->insert($mailData));
             } catch (Exception $e) {
                 $result['success'] = false;
                 $result['info'] = $e->getMessage();
             }
         } else {
             if ($review_operate == 'no') {
                 // 更新申请状态
                 $review_info = $now . ': ' . $user_session->user_info['user_name'] . ' [审核-拒绝] [' . $review_info . ']';
                 $tmp = $priceData['review_info'] != '' ? $priceData['review_info'] . '<br>' : '';
                 $data = array('state' => 1, 'review_info' => $tmp . $review_info);
                 $price->update($data, "id = " . $review_id);
                 // 删除当前申请的审核配置
                 $review->delete("type = 'sale_price_add' and file_id = " . $review_id);
                 // 发送邮件通知制单人
                 $reviewResult = '<font style="color: #FF0000"><b>拒绝</b></font>';
                 $mail = new Application_Model_Log_Mail();
                 $applyEmployeeData = $user->fetchRow("id = " . $priceData['create_user'])->toArray();
                 $applyEmployee = $employee->fetchRow("id = " . $applyEmployeeData['employee_id'])->toArray();
                 $to = $applyEmployee['email'];
                 $mailContent = '<div>销售价格申请审核:</div>
                             <div>
                             <p><b>审核人:</b>' . $user_session->user_info['user_name'] . '</p>
                             <p><b>审核结果:</b>' . $reviewResult . '</p>
                             <p><b>审核意见:</b>' . $review_remark . '</p>
                             <p><b>申请单号:</b>' . $priceData['number'] . '</p>
                             <p><b>申请人:</b>' . $priceData['creater'] . '</p>
                             <p><b>描述:</b>' . $priceData['description'] . '</p>
                             <p><b>备注:</b>' . $priceData['remark'] . '</p>
                             <hr>
                             <p><b>审核日志:</b></p><p>' . $priceData['review_info'] . '</p>
                             </div>';
                 $mailData = array('type' => '消息', 'subject' => '销售价格申请-审核', 'to' => $to, 'cc' => $user_session->user_info['user_email'], 'user_id' => $priceData['create_user'], 'content' => $mailContent, 'add_date' => $now);
                 try {
                     // 记录邮件日志并发送邮件
                     $mail->send($mail->insert($mailData));
                 } catch (Exception $e) {
                     $result['success'] = false;
                     $result['info'] = $e->getMessage();
                 }
             } else {
                 $help = new Application_Model_Helpers();
                 $review_info = $now . ': ' . $user_session->user_info['user_name'] . ' [审核-批准] [' . $review_info . ']';
                 $tmp = $priceData['review_info'] != '' ? $priceData['review_info'] . '<br>' : '';
                 $reqUpdateData = array('review_info' => $tmp . $review_info);
                 $reviewData = $review->fetchRow("id = " . $review_current_step)->toArray();
                 $actual_user = $reviewData['actual_user'] == '' ? $user_session->user_info['employee_id'] : $reviewData['actual_user'] . ',' . $user_session->user_info['employee_id'];
                 $data = array('actual_user' => $actual_user, 'finish_time' => $now, 'finish_flg' => 1);
                 // 当前审核阶段为最后一阶段
                 if ($review_last_step == 1) {
                     // 当前阶段已完结
                     if ($review_to_finish == 1) {
                         $data = array('actual_user' => $actual_user, 'finish_time' => $now, 'finish_flg' => 1);
                         $reviewResult = '<font style="color: #006400"><b>发布</b></font>';
                         // 发布:检查客户的当前产品(包括类别)是否存在生效价格(如存在则更新历史价格为作废)
                         $price->updatePriceByPriceId($review_id);
                         // 更新申请状态
                         $reqUpdateData['state'] = 2;
                         $reqUpdateData['release_time'] = $now;
                         // 更新审核记录表
                         $review->update($data, "id = " . $review_current_step);
                         $mail = new Application_Model_Log_Mail();
                         $applyEmployeeData = $user->fetchRow("id = " . $priceData['create_user'])->toArray();
                         $applyEmployee = $employee->fetchRow("id = " . $applyEmployeeData['employee_id'])->toArray();
                         $to = $applyEmployee['email'];
                         $cc = $user_session->user_info['user_email'];
                         $mailContent = '<div>销售价格审核批准,请登录系统查看:</div>
                             <div>
                             <p><b>审核人:</b>' . $user_session->user_info['user_name'] . '</p>
                             <p><b>审核结果:</b>' . $reviewResult . '</p>
                             <p><b>审核意见:</b>' . $review_remark . '</p>
                             <p><b>申请单号:</b>' . $priceData['number'] . '</p>
                             <p><b>申请人:</b>' . $priceData['creater'] . '</p>
                             <p><b>描述:</b>' . $priceData['description'] . '</p>
                             <p><b>备注:</b>' . $priceData['remark'] . '</p>
                             <hr>
                             <p><b>审核日志:</b></p><p>' . $reqUpdateData['review_info'] . '</p>
                             </div>';
                         $mailData = array('type' => '消息', 'subject' => '销售价格申请-发布', 'to' => $to, 'cc' => $cc, 'user_id' => $priceData['create_user'], 'content' => $mailContent, 'add_date' => $now);
                         try {
                             // 记录邮件日志并发送邮件
                             $mail->send($mail->insert($mailData));
                         } catch (Exception $e) {
                             $result['success'] = false;
                             $result['info'] = $e->getMessage();
                         }
                     } else {
                         $data = array('actual_user' => $actual_user);
                         $review->update($data, "id = " . $review_current_step);
                     }
                 } else {
                     // 当前阶段已完结
                     if ($review_to_finish == 1) {
                         $data = array('actual_user' => $actual_user, 'finish_time' => $now, 'finish_flg' => 1);
                         $reviewResult = '<font style="color: #006400"><b>批准</b></font>';
                         // 进入下一阶段
                         // 更新审核记录表
                         $review->update($data, "id = " . $review_current_step);
                         // 邮件通知下一阶段审核人
                         $reviewNextStepData = $review->fetchRow("id = " . $review_next_step)->toArray();
                         $mailTo = explode(',', $reviewNextStepData['plan_user']);
                         if ($mailTo) {
                             $mailContent = '<div>销售价格申请,请登录系统查看:</div>
                                         <div>
                                         <p><b>审核人:</b>' . $user_session->user_info['user_name'] . '</p>
                                         <p><b>审核结果:</b>' . $reviewResult . '</p>
                                         <p><b>审核意见:</b>' . $review_remark . '</p>
                                         <p><b>申请单号:</b>' . $priceData['number'] . '</p>
                                         <p><b>申请人:</b>' . $priceData['creater'] . '</p>
                                         <p><b>描述:</b>' . $priceData['description'] . '</p>
                                         <p><b>备注:</b>' . $priceData['remark'] . '</p>
                                         <hr>
                                         <p><b>审核日志:</b></p><p>' . $reqUpdateData['review_info'] . '</p>
                                         </div>';
                             $mailData = array('type' => '消息', 'subject' => '销售价格申请-新申请', 'cc' => $user_session->user_info['user_email'], 'content' => $mailContent, 'add_date' => $now);
                             $resultMail = $help->sendMailToStep($mailTo, $mailData);
                             if (!$resultMail['success']) {
                                 $result = $resultMail;
                             }
                         }
                     } else {
                         $data = array('actual_user' => $actual_user);
                         $review->update($data, "id = " . $review_current_step);
                         // 等待其他审核人批准
                     }
                 }
                 // 更新申请状态
                 $price->update($reqUpdateData, "id = " . $review_id);
             }
         }
     }
     echo Zend_Json::encode($result);
     exit;
 }
Beispiel #18
0
 public function newAction()
 {
     $result = array('success' => true, 'info' => '提交成功');
     $request = $this->getRequest()->getParams();
     $operate = isset($request['operate']) && $request['operate'] != '' ? $request['operate'] : null;
     $id = isset($request['id']) && $request['id'] != '' ? $request['id'] : null;
     $moderator = isset($request['moderator']) && $request['moderator'] != '' ? $request['moderator'] : null;
     $subject = isset($request['subject']) && $request['subject'] != '' ? $request['subject'] : null;
     $room_id = isset($request['room_id']) && $request['room_id'] != '' ? $request['room_id'] : null;
     $time_from = isset($request['time_from']) && $request['time_from'] != '' ? $request['time_from'] : null;
     $time_to = isset($request['time_to']) && $request['time_to'] != '' ? $request['time_to'] : null;
     $members = isset($request['members_id']) && $request['members_id'] != '' ? $request['members_id'] : null;
     $remark = isset($request['remark']) && $request['remark'] != '' ? $request['remark'] : null;
     if ($subject && $members && $operate && $moderator && $time_from && $time_to) {
         $meeting = new Res_Model_Meeting();
         $user = new Application_Model_User();
         if ($meeting->checkMeetingConflict($room_id, $time_from, $time_to, $id)) {
             $result['success'] = false;
             $result['info'] = '会议室预定冲突,请重新选择会议室!';
         } else {
             // 检查成员会议时间冲突
             $membersAdded = $meeting->getConflictMembers($time_from, $time_to, $members, $id);
             if (count($membersAdded) > 0) {
                 $result['success'] = false;
                 $result['info'] = '会议时间冲突!<br>' . implode('<br>', $membersAdded);
             } else {
                 $now = date('Y-m-d H:i:s');
                 $user_session = new Zend_Session_Namespace('user');
                 $user_id = $user_session->user_info['user_id'];
                 $membersArr = explode(',', $members);
                 $membersCnameArr = array();
                 $membersEnameArr = array();
                 foreach ($membersArr as $m) {
                     $memberInfo = $user->getEmployeeInfoById($m);
                     array_push($membersCnameArr, $memberInfo['cname']);
                     array_push($membersEnameArr, $memberInfo['ename']);
                 }
                 $data = array('state' => 0, 'room_id' => $room_id, 'subject' => $subject, 'moderator' => $moderator, 'time_from' => $time_from, 'time_to' => $time_to, 'members' => $members, 'members_cname' => implode(',', $membersCnameArr), 'members_ename' => implode(',', $membersEnameArr), 'remark' => $remark, 'update_user' => $user_id, 'update_time' => $now);
                 if ($operate == 'edit') {
                     $type = '更新';
                     $meeting->update($data, "id = " . $id);
                 } else {
                     $type = '新建';
                     $data['number'] = $meeting->getNewNum();
                     $data['create_user'] = $user_id;
                     $data['create_time'] = $now;
                     $id = $meeting->insert($data);
                 }
                 $meetingData = $meeting->getData(null, $id);
                 $mail = new Application_Model_Log_Mail();
                 $moderatorInfo = $user->getEmployeeInfoById($moderator);
                 $mailContent = '<div>会议预定 - ' . $type . ':</div>
                                 <div>
                                 <p><b>预订人:</b>' . $meetingData['updater'] . '</p>
                                 <p><b>会议室:</b>' . $meetingData['room_name'] . '</p>
                                 <p><b>主题:</b>' . $meetingData['subject'] . '</p>
                                 <p><b>时间:</b>' . $meetingData['time_from'] . ' - ' . $meetingData['time_to'] . '</p>
                                 <p><b>主持人:</b>' . $moderatorInfo['cname'] . '</p>
                                 <p><b>参会人员:</b>' . $meetingData['members_cname'] . '</p>
                                 <p><b>备注:</b>' . $meetingData['remark'] . '</p>
                                 </div>';
                 $memberArr = explode(',', $meetingData['members']);
                 array_push($memberArr, $moderator);
                 $toArr = array();
                 foreach ($memberArr as $m) {
                     $memberInfo = $user->getEmployeeInfoById($m);
                     $memberInfo = $user->getEmployeeInfoById($m);
                     array_push($toArr, $memberInfo['email']);
                 }
                 $mailData = array('type' => '消息', 'subject' => '会议预定', 'to' => implode(',', $toArr), 'cc' => $user_session->user_info['user_email'], 'user_id' => $meetingData['create_user'], 'content' => $mailContent, 'add_date' => $now);
                 try {
                     // 记录邮件日志并发送邮件
                     $mail->insert($mailData);
                     $mail->send($mail->insert($mailData));
                 } catch (Exception $e) {
                     $result['success'] = false;
                     $result['info'] = $e->getMessage();
                 }
             }
         }
     } else {
         $result['success'] = false;
         $result['info'] = '参数错误';
     }
     echo Zend_Json::encode($result);
     exit;
 }
Beispiel #19
0
 public function sendmsgAction()
 {
     // 返回值数组
     $result = array('success' => true, 'info' => '发送成功');
     $request = $this->getRequest()->getParams();
     // 标题
     $title = isset($request['msg_title']) ? $request['msg_title'] : null;
     // 优先级
     $priority = isset($request['msg_priority']) ? $request['msg_priority'] : null;
     // 是否发送邮件
     $sendmail = isset($request['msg_sendmail']) ? $request['msg_sendmail'] : null;
     // 内容
     $content = isset($request['msg_content']) ? $request['msg_content'] : null;
     // 备注
     $remark = isset($request['msg_remark']) ? $request['msg_remark'] : null;
     // 接收人用户ID
     $receivers_ids = isset($request['msg_receivers_ids']) ? $request['msg_receivers_ids'] : null;
     // 接收人邮箱
     $receivers_email = isset($request['msg_receivers_email']) ? $request['msg_receivers_email'] : null;
     // 接收人
     $receivers = isset($request['msg_receivers']) ? $request['msg_receivers'] : null;
     if ($title && $priority && $content && $receivers_ids) {
         $receiverIdArr = explode(',', $receivers_ids);
         $receiverEmailArr = explode(',', $receivers_email);
         $receiverArr = explode(',', $receivers);
         $now = date('Y-m-d H:i:s');
         $user_session = new Zend_Session_Namespace('user');
         $user_id = $user_session->user_info['user_id'];
         $user_name = $user_session->user_info['user_name'];
         // 记录消息内容
         $msg = new Application_Model_Log_Msg();
         $email = $sendmail == 'on' ? 1 : 0;
         $data = array('title' => $title, 'priority' => $priority, 'content' => $content, 'remark' => $remark, 'email' => $email, 'receivers' => $receivers, 'create_time' => $now, 'create_user' => $user_id, 'update_time' => $now, 'update_user' => $user_id);
         $msg_id = null;
         try {
             $msg_id = $msg->insert($data);
         } catch (Exception $e) {
             $result['success'] = false;
             $result['info'] = $e->getMessage();
             echo Zend_Json::encode($result);
             exit;
         }
         // 记录接收人信息
         $msgsend = new Application_Model_Log_Msgsend();
         foreach ($receiverIdArr as $r) {
             $data = array('msg_id' => $msg_id, 'user_id' => $r, 'email' => $email);
             try {
                 $msgsend->insert($data);
             } catch (Exception $e) {
                 $result['success'] = false;
                 $result['info'] = $e->getMessage();
                 echo Zend_Json::encode($result);
                 exit;
             }
         }
         // 当选择同时发送邮件时,向接收人发送邮件消息
         if ($sendmail == 'on') {
             $mail = new Application_Model_Log_Mail();
             $mailContent = '<div>你有一条新消息:</div>
                         <div><b>发送人:</b>' . $user_name . '</div>
                         <div><b>发送时间:</b>' . $now . '</div>
                         <div><b>优先级:</b>' . $priority . '</div>
                         <div><b>内容:</b><br>' . $content . '<br></div>
                         <div><b>备注:</b>' . $remark . '</div>';
             for ($i = 0; $i < count($receiverEmailArr); $i++) {
                 $data = array('type' => '消息', 'subject' => $title, 'to' => $receiverEmailArr[$i], 'user_id' => $receiverArr[$i], 'content' => $mailContent, 'add_date' => $now);
                 try {
                     // 记录邮件日志并发送邮件
                     $mail->send($mail->insert($data));
                 } catch (Exception $e) {
                     $result['success'] = false;
                     $result['info'] = $e->getMessage();
                     echo Zend_Json::encode($result);
                     exit;
                 }
             }
         }
         // 记录日志
         $operate = new Application_Model_Log_Operate();
         $computer_name = gethostbyaddr(getenv("REMOTE_ADDR"));
         // 计算机名
         $data = array('operate' => '发送消息', 'user_id' => $user_id, 'target' => 'Contact', 'computer_name' => $computer_name, 'ip' => $_SERVER['REMOTE_ADDR'], 'remark' => $receivers, 'time' => $now);
         try {
             $operate->insert($data);
         } catch (Exception $e) {
             $result['success'] = false;
             $result['info'] = $e->getMessage();
             echo Zend_Json::encode($result);
             exit;
         }
     } else {
         $result['result'] = false;
         $result['info'] = '发送失败:信息不完整!';
     }
     echo Zend_Json::encode($result);
     exit;
 }
Beispiel #20
0
    public function edititemsAction()
    {
        // 返回值数组
        $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']);
        $return_id = $json->return_id;
        $json_items = $json->items;
        $items_updated = $json_items->updated;
        $items_inserted = $json_items->inserted;
        $items_deleted = $json_items->deleted;
        $receive = new Erp_Model_Stock_receive();
        $items = new Erp_Model_Purchse_Receiveitems();
        $itemsorder = new Erp_Model_Purchse_Receiveitemsorder();
        $receiveData = $receive->getData(null, $return_id, '采购退货');
        // 更新
        if (count($items_updated) > 0) {
            foreach ($items_updated as $val) {
                $data = array('order_number' => $val->items_order_number, 'code' => $val->items_code, 'name' => $val->items_name, 'description' => $val->items_description, 'qty' => $val->items_qty, 'unit' => $val->items_unit, 'remark' => $val->items_remark, 'update_user' => $user_id, 'update_time' => $now);
                try {
                    $items->update($data, "id = " . $val->items_id);
                    // 记录分拆数据
                    $splitData = array('receive_number' => $receiveData['number'], 'receive_item_id' => $val->items_id, 'items_order_qty' => $val->items_order_qty, 'items_order_item_price' => $val->items_order_item_price, 'items_code' => $val->items_code, 'items_order_id' => $val->items_order_id, 'items_order_number' => $val->items_order_number);
                    $this->saveSplitItem($splitData);
                } catch (Exception $e) {
                    $result['success'] = false;
                    $result['info'] = $e->getMessage();
                    echo Zend_Json::encode($result);
                    exit;
                }
            }
        }
        // 此次退货货的采购订单号
        $orderNumArr = array();
        // 插入
        if (count($items_inserted) > 0) {
            foreach ($items_inserted as $val) {
                $data = array('receive_id' => $return_id, 'order_number' => $val->items_order_number, 'code' => $val->items_code, 'name' => $val->items_name, 'description' => $val->items_description, 'qty' => $val->items_qty, 'price' => $val->items_price, 'unit' => $val->items_unit, 'remark' => $val->items_remark, 'warehouse_code' => $val->items_warehouse_code, 'create_user' => $user_id, 'create_time' => $now, 'update_user' => $user_id, 'update_time' => $now);
                try {
                    $receive_item_id = $items->insert($data);
                    // 记录分拆数据
                    $splitData = array('return_number' => $receiveData['number'], 'receive_item_id' => $receive_item_id, 'items_qty' => $val->items_qty, 'items_price' => $val->items_price, 'items_code' => $val->items_code, 'items_order_id' => $val->items_order_id, 'items_order_item_id' => $val->items_order_item_id, 'items_warehouse_code' => $val->items_warehouse_code, 'items_order_number' => $val->items_order_number);
                    $this->saveSplitItem($splitData);
                    if (!in_array($val->items_order_number, $orderNumArr)) {
                        array_push($orderNumArr, $val->items_order_number);
                    }
                } catch (Exception $e) {
                    $result['success'] = false;
                    $result['info'] = $e->getMessage();
                    echo Zend_Json::encode($result);
                    exit;
                }
            }
        }
        // 更新总计
        $items->refreshReceiveTotal($return_id);
        // 退货通知
        $receive_items_order = new Erp_Model_Purchse_Receiveitemsorder();
        $order = new Erp_Model_Purchse_Order();
        $relatedUserInfo = count($orderNumArr) > 0 ? $receive_items_order->getReqRelatedUsers($orderNumArr) : array();
        $member = new Admin_Model_Member();
        $warehouse = new Erp_Model_Warehouse_Warehouse();
        $noticeTo = $member->getMemberWithManagerByName('采购退货通知');
        $noticeMails = array();
        $noticeUsers = array();
        foreach ($noticeTo as $n) {
            if ($n['email'] != '' && !in_array($n['user_id'], $noticeUsers)) {
                array_push($noticeMails, $n['email']);
                array_push($noticeUsers, $n['user_id']);
            }
        }
        foreach ($relatedUserInfo as $n) {
            if ($n['email'] != '' && !in_array($n['user_id'], $noticeUsers)) {
                array_push($noticeMails, $n['email']);
                array_push($noticeUsers, $n['user_id']);
            }
        }
        $mail = new Application_Model_Log_Mail();
        $supplierArr = array();
        $i = 0;
        $itemsTable = '<style type="text/css">
table.gridtable {
	font-family: verdana,arial,sans-serif;
	font-size:11px;
	color:#333333;
	border-width: 1px;
	border-color: #666666;
	border-collapse: collapse;
}
table.gridtable th {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #666666;
	background-color: #dedede;
}
table.gridtable td {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #666666;
	background-color: #ffffff;
}
</style><table class="gridtable"><tr>
                                <th>#</th>
                                <th>供应商</th>
                                <th>采购订单</th>
                                <th>物料号</th>
                                <th>物料名称</th>
                                <th>物料描述</th>
                                <th>退货数量</th>
                                <th>单位</th>
                                <th>退货仓库</th>
                                <th>备注</th>
                                <th>订单信息</th>
                                </tr>';
        foreach ($items_inserted as $val) {
            $itemInfo = '';
            if ($val->items_order_number) {
                $itemInfoData = $order->getItemDetails($val->items_order_number, $val->items_code);
                $itemInfo = '<table class="gridtable"><tr>
							<th>申请单号</th>
							<th>申请日期</th>
							<th>申请数量</th>
							<th>下单数量</th>
							<th>订单数量</th>
                            <th>客户收件人地址简码</th>
                            <th>客户合同号</th>
							</tr>';
                foreach ($itemInfoData as $d) {
                    $itemInfo .= '<tr>
							      <td>' . $d['req_number'] . '</td>
							      <td>' . $d['req_item_date'] . '</td>
							      <td>' . $d['req_item_qty'] . '</td>
							      <td>' . $d['order_req_item_qty'] . '</td>
							      <td>' . $d['order_item_qty'] . '</td>
							      <td>' . $d['customer_address'] . '</td>
							      <td>' . $d['customer_aggrement'] . '</td>
							      </tr>';
                }
                $itemInfo .= '</table>';
                $supplier = $d['supplier_code'] . ' ' . $d['supplier_name'];
                if (!in_array($supplier, $supplierArr)) {
                    array_push($supplierArr, $supplier);
                }
            }
            $i++;
            $warehouseInfo = $warehouse->getInfoByCode($val->items_warehouse_code);
            $itemsTable .= '<tr>
							<td>' . $i . '</td>
							<td>' . $supplier . '</td>
							<td>' . $val->items_order_number . '</td>
							<td>' . $val->items_code . '</td>
							<td>' . $val->items_name . '</td>
							<td>' . $val->items_description . '</td>
							<td>' . $val->items_qty . '</td>
							<td>' . $val->items_unit . '</td>
							<td>' . $val->items_warehouse_code . ' ' . $warehouseInfo['name'] . '</td>
							<td>' . $val->items_remark . '</td>
							<td>' . $itemInfo . '</td>
							</tr>';
        }
        $itemsTable .= '</table>';
        $mailContent = '<div>采购退货,请登录系统查看:</div>
					    <div>
					    <p><b>退货单号:</b>' . $receiveData['number'] . '</p>
					    <p><b>收货日期:</b>' . $receiveData['date'] . '</p>
					    <p><b>收货人:</b>' . $user_session->user_info['user_name'] . '</p>
					    <p><b>描述:</b>' . $receiveData['description'] . '</p>
					    <p><b>备注:</b>' . $receiveData['remark'] . '</p>
					    </div><div>' . $itemsTable . '</div><hr>';
        $mailData = array('type' => '通知', 'subject' => '退货通知 - ' . $receiveData['number'] . ' - ' . implode(', ', $supplierArr), 'cc' => $user_session->user_info['user_email'], 'content' => $mailContent, 'add_date' => $now, 'to' => implode(',', $noticeMails), 'user_id' => implode(',', $noticeUsers));
        try {
            // 记录邮件日志并发送邮件
            $mail->send($mail->insert($mailData));
        } catch (Exception $e) {
            $result['success'] = false;
            $result['info'] = $e->getMessage();
        }
        echo Zend_Json::encode($result);
        exit;
    }
Beispiel #21
0
    public function generatePurchseDeliveryUpdateEmail($time, $diff)
    {
        $item = new Erp_Model_Purchse_Orderitems();
        $mail = new Application_Model_Log_Mail();
        $emails = array();
        $now = date('Y-m-d H:i:s');
        $notice = $item->getDeliveryNotice($time, $diff);
        $table = '<style type="text/css">
table.gridtable {
	font-family: verdana,arial,sans-serif;
	font-size:11px;
	color:#333333;
	border-width: 1px;
	border-color: #666666;
	border-collapse: collapse;
}
table.gridtable th {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #666666;
	background-color: #dedede;
}
table.gridtable td {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #666666;
	background-color: #ffffff;
}
</style><table class="gridtable"><tr>
                                <th>#</th>
                                <th>采购订单</th>
                                <th>采购员</th>
                                <th>物料号</th>
                                <th>物料名称</th>
                                <th>物料描述</th>
                                <th>申请单号</th>
                                <th>申请数量</th>
                                <th>采购数量</th>
                                <th>订单数量</th>
                                <th>项目信息</th>
                                <th>需求日期</th>
                                <th>预计交期</th>
                                <th>交期备注</th>
                                <th>申请制单人</th>
                                <th>申请人</th>
                                <th>交期更新时间</th>
                                </tr>';
        foreach ($notice as $n) {
            $itemTable = $table;
            $applier_id = 0;
            $noticeMails = array();
            $i = 0;
            foreach ($n as $item) {
                $i++;
                $applier_id = $item['req_creater_id'];
                if (!in_array($item['req_creater_email'], $noticeMails)) {
                    array_push($noticeMails, $item['req_creater_email']);
                }
                if (!in_array($item['req_applier_email'], $noticeMails)) {
                    array_push($noticeMails, $item['req_applier_email']);
                }
                $itemTable .= '<tr>
                        <td>' . $i . '</td>
                        <td>' . $item['order_number'] . '</td>
                        <td>' . $item['order_buyer'] . '</td>
                        <td>' . $item['item_code'] . '</td>
                        <td>' . $item['item_name'] . '</td>
                        <td>' . $item['item_description'] . '</td>
                        <td>' . $item['req_number'] . '</td>
                        <td><b>' . $item['req_qty'] . '</b></td>
                        <td><b>' . $item['req_order_qty'] . '</b></td>
                        <td>' . $item['item_qty'] . '</td>
                        <td>' . $item['item_project_info'] . '</td>
                        <td><b>' . $item['item_request_date'] . '</b></td>
                        <td><b>' . $item['item_delivery_date'] . '</b></td>
                        <td>' . $item['item_delivery_remark'] . '</td>
                        <td>' . $item['req_creater_name'] . '</td>
                        <td>' . $item['req_applier_name'] . '</td>
                        <td><b>' . $item['item_update_time'] . '</b></td>
                        <tr>';
            }
            $itemTable .= '</table>';
            $mailContent = '<div>采购交期更新,请登录系统查看:</div><div>' . $itemTable . '</div><hr>';
            $mailData = array('type' => '通知', 'subject' => '采购交期更新', 'content' => $mailContent, 'add_date' => $now, 'to' => implode(',', $noticeMails), 'user_id' => $applier_id);
            $mail->insert($mailData);
        }
    }
Beispiel #22
0
 public function reviewAction()
 {
     // 返回值数组
     $result = array('success' => true, 'info' => '审核成功');
     $request = $this->getRequest()->getParams();
     /* echo '<pre>';
        print_r($request);
        exit; */
     $review_id = isset($request['review_id']) ? $request['review_id'] : null;
     $review_operate = isset($request['review_operate']) ? $request['review_operate'] : null;
     $review_current_step = isset($request['review_current_step']) ? $request['review_current_step'] : null;
     // 当前阶段(review表ID)
     $review_last_step = isset($request['review_last_step']) ? $request['review_last_step'] : null;
     // 是否当前阶段为最后一阶段
     $review_to_finish = isset($request['review_to_finish']) ? $request['review_to_finish'] : null;
     // 是否批准后当前阶段结束
     $review_next_step = isset($request['review_next_step']) ? $request['review_next_step'] : null;
     // 下一阶段(review表ID)
     $review_remark = isset($request['review_remark']) ? $request['review_remark'] : null;
     if ($review_id && $review_operate) {
         $now = date('Y-m-d H:i:s');
         $user_session = new Zend_Session_Namespace('user');
         $user_id = $user_session->user_info['user_id'];
         // 评审意见
         $review_info = '意见: ' . $review_remark;
         $invoice = new Erp_Model_Purchse_Invoice();
         $invoiceItems = new Erp_Model_Purchse_Invoiceitems();
         $user = new Application_Model_User();
         $review = new Dcc_Model_Review();
         $employee = new Hra_Model_Employee();
         $invoiceData = $invoice->getData(null, $review_id);
         // 更新审核状态及审核意见
         if ($review_operate == 'no') {
             // 更新采购申请状态
             $review_info = $now . ': ' . $user_session->user_info['user_name'] . ' [审核-拒绝] [' . $review_info . ']';
             $data = array('state' => 1, 'review_info' => $invoiceData['review_info'] . '<br>' . $review_info);
             // 更新订单状态
             $invoice->update($data, "id = " . $review_id);
             // 删除当前申请的审核配置
             $review->delete("type = 'purchse_invoice_add' and file_id = " . $review_id);
             // 发送邮件通知申请人
             $reviewResult = '<font style="color: #FF0000"><b>拒绝</b></font>';
             $mail = new Application_Model_Log_Mail();
             $applyEmployeeData = $user->fetchRow("id = " . $invoiceData['create_user'])->toArray();
             $applyEmployee = $employee->fetchRow("id = " . $applyEmployeeData['employee_id'])->toArray();
             $to = $applyEmployee['email'];
             // 获取币种信息
             $currency = new Erp_Model_Setting_Currency();
             $currencyInfo = $currency->getInfoByCode($invoiceData['currency']);
             $total = $invoiceData['total'];
             if ($invoiceData['currency'] != 'CNY') {
                 $total = $invoiceData['forein_total'];
             }
             $mailContent = '<div>采购发票审核:</div>
                             <div>
                             <p><b>审核人:</b>' . $user_session->user_info['user_name'] . '</p>
                             <p><b>审核结果:</b>' . $reviewResult . '</p>
                             <p><b>审核意见:</b>' . $review_remark . '</p>
                             <p><b>发票号:</b>' . $invoiceData['number'] . '</p>
                             <p><b>申请人:</b>' . $invoiceData['creater'] . '</p>
                             <p><b>金额:</b><a style="color: #467500;font-weight: bold;">' . $currencyInfo['symbol'] . $total . '</a></p>
                             <p><b>备注:</b>' . $invoiceData['remark'] . '</p>
                             <p><b>申请时间:</b>' . $invoiceData['create_time'] . '</p>
                             <p><b>更新时间:</b>' . $invoiceData['update_time'] . '</p>
                             <hr>
                             <p><b>审核日志:</b></p><p>' . $invoiceData['review_info'] . '</p>
                             </div>';
             $mailData = array('type' => '消息', 'subject' => '采购发票-审核', 'to' => $to, 'cc' => $user_session->user_info['user_email'], 'user_id' => $invoiceData['create_user'], 'content' => $mailContent, 'add_date' => $now);
             try {
                 // 记录邮件日志并发送邮件
                 $mail->send($mail->insert($mailData));
             } catch (Exception $e) {
                 $result['success'] = false;
                 $result['info'] = $e->getMessage();
             }
         } else {
             $help = new Application_Model_Helpers();
             $review_info = $now . ': ' . $user_session->user_info['user_name'] . ' [审核-批准] [' . $review_info . ']';
             $invoiceUpdateData = array('review_info' => $invoiceData['review_info'] . '<br>' . $review_info);
             $reviewData = $review->fetchRow("id = " . $review_current_step)->toArray();
             $actual_user = $reviewData['actual_user'] == '' ? $user_session->user_info['employee_id'] : $reviewData['actual_user'] . ',' . $user_session->user_info['employee_id'];
             $data = array('actual_user' => $actual_user, 'finish_time' => $now, 'finish_flg' => 1);
             // 当前审核阶段为最后一阶段
             if ($review_last_step == 1) {
                 // 当前阶段已完结
                 if ($review_to_finish == 1) {
                     $data = array('actual_user' => $actual_user, 'finish_time' => $now, 'finish_flg' => 1);
                     $reviewResult = '<font style="color: #006400"><b>发布</b></font>';
                     // 发布
                     // 更新申请状态
                     $invoiceUpdateData['state'] = 2;
                     $invoiceUpdateData['release_time'] = $now;
                     // 更新审核记录表
                     $review->update($data, "id = " . $review_current_step);
                     $mail = new Application_Model_Log_Mail();
                     $applyEmployeeData = $user->fetchRow("id = " . $invoiceData['create_user'])->toArray();
                     $applyEmployee = $employee->fetchRow("id = " . $applyEmployeeData['employee_id'])->toArray();
                     $to = $applyEmployee['email'];
                     // 获取币种信息
                     $currency = new Erp_Model_Setting_Currency();
                     $currencyInfo = $currency->getInfoByCode($invoiceData['currency']);
                     $total = $invoiceData['total'];
                     if ($invoiceData['currency'] != 'CNY') {
                         $total = $invoiceData['forein_total'];
                     }
                     $mailContent = '<div>采购发票审核批准,请登录系统查看:</div>
                             <div>
                             <p><b>审核人:</b>' . $user_session->user_info['user_name'] . '</p>
                             <p><b>审核结果:</b>' . $reviewResult . '</p>
                             <p><b>审核意见:</b>' . $review_remark . '</p>
                             <p><b>发票号:</b>' . $invoiceData['number'] . '</p>
                             <p><b>申请人:</b>' . $invoiceData['creater'] . '</p>
                             <p><b>金额:</b><a style="color: #467500;font-weight: bold;">' . $currencyInfo['symbol'] . $total . '</a></p>
                             <p><b>备注:</b>' . $invoiceData['remark'] . '</p>
                             <p><b>申请时间:</b>' . $invoiceData['create_time'] . '</p>
                             <p><b>更新时间:</b>' . $invoiceData['update_time'] . '</p>
                             <hr>
                             <p><b>审核日志:</b></p><p>' . $invoiceUpdateData['review_info'] . '</p>
                             </div>';
                     $mailData = array('type' => '消息', 'subject' => '采购发票-发布', 'to' => $to, 'cc' => $user_session->user_info['user_email'], 'user_id' => $invoiceData['create_user'], 'content' => $mailContent, 'add_date' => $now);
                     try {
                         // 记录邮件日志并发送邮件
                         $mail->send($mail->insert($mailData));
                     } catch (Exception $e) {
                         $result['success'] = false;
                         $result['info'] = $e->getMessage();
                     }
                 } else {
                     $data = array('actual_user' => $actual_user);
                     $review->update($data, "id = " . $review_current_step);
                 }
             } else {
                 // 当前阶段已完结
                 if ($review_to_finish == 1) {
                     $data = array('actual_user' => $actual_user, 'finish_time' => $now, 'finish_flg' => 1);
                     $reviewResult = '<font style="color: #006400"><b>批准</b></font>';
                     // 进入下一阶段
                     // 更新审核记录表
                     $review->update($data, "id = " . $review_current_step);
                     // 邮件通知下一阶段审核人
                     if ($review->fetchAll("id = " . $review_next_step)->count() > 0) {
                         $reviewNextStepData = $review->fetchRow("id = " . $review_next_step)->toArray();
                         $mailTo = explode(',', $reviewNextStepData['plan_user']);
                         if ($mailTo) {
                             // 获取币种信息
                             $currency = new Erp_Model_Setting_Currency();
                             $currencyInfo = $currency->getInfoByCode($invoiceData['currency']);
                             $total = $invoiceData['total'];
                             if ($invoiceData['currency'] != 'CNY') {
                                 $total = $invoiceData['forein_total'];
                             }
                             $mailContent = '<div>新建采购发票,请登录系统查看:</div>
                                             <div>
                                             <p><b>订单号:</b>' . $invoiceData['number'] . '</p>
                                             <p><b>申请人:</b>' . $invoiceData['creater'] . '</p>
                                             <p><b>金额:</b><a style="color: #467500;font-weight: bold;">' . $currencyInfo['symbol'] . $total . '</a></p>
                                             <p><b>备注:</b>' . $invoiceData['remark'] . '</p>
                                             <p><b>申请时间:</b>' . $invoiceData['create_time'] . '</p>
                                             <p><b>更新时间:</b>' . $invoiceData['update_time'] . '</p>
                                             <hr>
                                             <p><b>审核日志:</b></p><p>' . $invoiceUpdateData['review_info'] . '</p>
                                             </div>';
                             $mailData = array('type' => '消息', 'subject' => '采购发票-新建', 'cc' => $user_session->user_info['user_email'], 'content' => $mailContent, 'add_date' => $now);
                             $resultMail = $help->sendMailToStep($mailTo, $mailData);
                             if (!$resultMail['success']) {
                                 $result = $resultMail;
                             }
                         }
                     }
                 } else {
                     $data = array('actual_user' => $actual_user);
                     $review->update($data, "id = " . $review_current_step);
                 }
             }
             // 更新申请状态
             $invoice->update($invoiceUpdateData, "id = " . $review_id);
         }
     }
     echo Zend_Json::encode($result);
     exit;
 }
Beispiel #23
0
 /**
  * @abstract    审核
  * @return      null
  */
 public function reviewAction()
 {
     // 返回值数组
     $result = array('success' => true, 'result' => 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['employee_id'];
     $val = (object) $request;
     $record = new Dcc_Model_Record();
     $review = new Dcc_Model_Review();
     $employee = new Hra_Model_Employee();
     $db = $employee->getAdapter();
     $fadev = new Product_Model_Fadev();
     $fa = new Product_Model_Fa();
     $sondev = new Product_Model_Sondev();
     $id = $val->id;
     $remark = $val->remark;
     $pass = $val->review_result;
     $type = $val->type;
     $publish = false;
     if ($type == 'new') {
         $table = "oa_product_bom_new";
         $recordType = "bom";
         $bomModel = new Product_Model_Newbom();
     } else {
         if ($type == 'ECO') {
             $table = "oa_product_bom_eco";
             $recordType = "ecobom";
             $bomModel = new Product_Model_Updbom();
         } else {
             if ($type == 'DEV') {
                 $table = "oa_product_bom_dev";
                 $recordType = "devbom";
                 $bomModel = new Product_Model_Updbom();
             }
         }
     }
     // 获取物料信息
     $bomData = $bomModel->getOne($id);
     if (!$bomData) {
         $result['result'] = false;
         $result['info'] = "数据状态已改变";
         echo Zend_Json::encode($result);
         exit;
     }
     $review_id = $bomData->review_id;
     // 获取当前审核情况
     // 如果record记录被删除或状态已改变,报错
     $reviewWhere = "id = {$review_id}";
     $reviewRows = $review->getList($reviewWhere, $recordType);
     if (count($reviewRows) == 0 || !$type) {
         $result['result'] = false;
         $result['info'] = "非法数据";
         echo Zend_Json::encode($result);
         exit;
     }
     $reviewRow = $reviewRows[0];
     if ($reviewRow['finish_flg'] != 0) {
         $result['result'] = false;
         $result['info'] = "数据状态已改变";
         echo Zend_Json::encode($result);
         exit;
     }
     $bomfaData = $fadev->fetchAll("type = '{$type}' and nid=" . $id)->toArray();
     // 处理记录
     $recordData = array("type" => $recordType, "table_name" => $table, "table_id" => $id, "handle_user" => $user, "handle_time" => $now, "action" => "审批", "result" => $pass == 1 ? "批准" : ($pass == 2 ? "拒绝" : "转审"), "ip" => $_SERVER['REMOTE_ADDR'], "remark" => $remark);
     // 增加记录
     $record->insert($recordData);
     // 通过方式
     $method = $reviewRow['method'];
     if ($pass == 1) {
         if ($method == 2) {
             // 任何一人处理即通过
             $finish_flg = 1;
             $actual_user = $user;
             $finish_time = $now;
         } else {
             // 所有人都需要审核,检查是否所有人都已经审核
             $plan_user = $reviewRow['plan_user'];
             $actual_user = $reviewRow['actual_user'];
             $actual_user = !$actual_user ? $user : $actual_user . "," . $user;
             // 检查计划审核人和实际审核人是否一致
             if (strlen($plan_user) == strlen($actual_user)) {
                 $finish_flg = 1;
                 $finish_time = $now;
             } else {
                 $finish_flg = 0;
                 $finish_time = null;
             }
         }
         // 审核情况
         $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg);
     } else {
         if ($pass == 3) {
             // 转审
             $finish_flg = 0;
             if ($method == 2) {
                 // 处理方式为任意时,一个人转审之后其他人员也删除
                 $plan_user = str_replace('E', '', $val->transfer_id);
             } else {
                 // 更改审核情况中的审核人
                 $plan_users = explode(',', $reviewRow['plan_user']);
                 for ($i = 0; $i < count($plan_users); $i++) {
                     if ($plan_users[$i] == $user) {
                         $plan_users[$i] = str_replace('E', '', $val->transfer_id);
                         break;
                     }
                 }
                 $plan_user = implode(',', $plan_users);
             }
             // 审核情况
             $reviewData = array("plan_user" => $plan_user);
         } else {
             // 退回
             $actual_user = null;
             $finish_time = null;
             $finish_flg = 0;
             // 退回选项
             $return = $reviewRow['return'];
             if ($return == 2) {
                 // 退到初始状态
                 // 需更新的审核记录: 所有
                 $reviewWhere = "type = '{$recordType}' and file_id = {$id}";
                 // 审核情况更新数据
                 $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg);
                 // 文件状态不更新
             } else {
                 if ($return == 4) {
                     // 退到本阶段开始
                     // 需更新的审核记录
                     $reviewWhere = "type = '{$recordType}' and finish_flg = 0 and file_id = {$id}";
                     // 审核情况更新数据
                     $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg);
                     // 文件状态不更新
                 } else {
                     if ($return == 3) {
                         // 退到上一阶段
                         // 需更新的审核记录:最后一个finish_flg为1的数据和第一个finish_flg为0的数据
                         $last_1 = $first_0 = 0;
                         foreach ($reviewRows as $r) {
                             if ($r['finish_flg'] == 1) {
                                 $last_1 = $r['id'];
                             }
                             if ($r['finish_flg'] == 0 && $first_0 == null) {
                                 $first_0 = $r['id'];
                             }
                         }
                         $reviewWhere = "id = {$last_1} or id = {$first_0}";
                         // 审核情况更新数据
                         $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg);
                         // 文件状态不更新
                     } else {
                         $fileWhere = "id = {$id}";
                         // 更新文件状态为退回
                         $mData = array("state" => "Return");
                         // 退到初始状态
                         // 更新所有record的finish_flg为0
                         $reviewWhere = "type = '{$recordType}' and file_id = {$id}";
                         // 审核情况
                         $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg);
                     }
                 }
             }
         }
     }
     // 如果所有record的记录的finish_flg 都为1,则发布
     if ($finish_flg == 1 && $review->fetchAll("type = '{$recordType}' and finish_flg = 0 and file_id = {$id}")->count() == 1) {
         $publish = true;
         $mData = array("state" => "Active", "archive_time" => $now);
         $fileWhere = "id = {$id}";
         $creater = $bomData['create_user'];
         // 如果是多个BOM,需要拆分
         foreach ($bomfaData as $bomfa) {
             // 升版的情况,旧版作废
             $facode = $bomfa['code'];
             if ($type != 'new') {
                 $obsoleteData = array("state" => "Obsolete");
                 $obsoleteWhere = "code = '{$facode}' and recordkey != '" . $bomfa['recordkey'] . "'";
                 $fa->update($obsoleteData, $obsoleteWhere);
             }
             $recordkey = $bomfa['recordkey'];
             $sql = "insert into oa_product_bom_fa (nid, recordkey, id, code, project_no, bom_file, qty, state, ver, type, remark, create_user) select nid, recordkey, id, code, project_no, bom_file, qty, state, ver, type, remark, '{$creater}' from oa_product_bom_fa_dev where recordkey = {$recordkey}";
             $db->query($sql);
             $sql = "insert into oa_product_bom_son (nid, recordkey, pid, id, code, qty, partposition, `replace`, remark) select nid, recordkey, pid, id, code, qty, partposition, `replace`, remark from oa_product_bom_son_dev where recordkey = {$recordkey}";
             $db->query($sql);
         }
     }
     try {
         // 更新审核情况
         $review->update($reviewData, $reviewWhere);
         // 更新BOM
         if (isset($fileWhere)) {
             $bomModel->update($mData, $fileWhere);
         }
         $this->operate("BOM审批");
     } catch (Exception $e) {
         $result['result'] = false;
         $result['info'] = $e->getMessage();
         echo Zend_Json::encode($result);
         exit;
     }
     // 邮件任务
     // 文件提交者或更新人
     $owner = $bomData['create_user'];
     $dev = false;
     $boms = array();
     foreach ($bomfaData as $fa) {
         if ($type == 'new') {
             $boms[] = $fa['code'];
         } else {
             $boms[] = $fa['code'] . " V" . $fa['ver'];
         }
     }
     $bomflg = "devbom";
     if ($type == 'ECO') {
         $bomflg = "ecobom";
     }
     if ($type == 'new') {
         $subject_type = "新BOM申请";
         $content = "<b>BOM号:</b>" . implode(',', $boms) . "</p>" . "<p><b>描述:</b>" . $bomData['description'] . "</p>" . "<p><b>备注:</b>" . $bomData['remark'] . "</p>" . "<p><b>申请人:</b>" . $bomData['creater'] . "</p>" . "<p><b>申请时间:</b>" . $bomData['create_time'] . "</p>" . "<p>请登录系统查看详情!</p>";
     } else {
         $subject_type = "BOM升版";
         $reson_type = "";
         if ($bomData['reason_type']) {
             $codemaster = new Admin_Model_Codemaster();
             $mstData = $codemaster->getList("type=6 and code='" . $bomData['reason_type'] . "'");
             if ($mstData && count($mstData) > 0) {
                 $reson_type = $mstData[0]['text'];
             }
         }
         $content = "<b>BOM号:</b>" . implode(',', $boms) . "</p>" . "<p><b>升版类型:</b>" . $bomData['upd_type'] . "</p>" . "<p><b>升版原因分类:</b>" . $reson_type . "</p>" . "<p><b>升版原因:</b>" . $bomData['upd_reason'] . "</p>" . "<p><b>升版描述:</b>" . $bomData['description'] . "</p>" . "<p><b>备注:</b>" . $bomData['remark'] . "</p>" . "<p><b>申请人:</b>" . $bomData['creater'] . "</p>" . "<p><b>申请时间:</b>" . $bomData['create_time'] . "</p>" . "<p>请登录系统查看详情!</p>";
     }
     $content = "<p><b>BOM号:</b>" . implode(',', $boms) . "</p><p><b>版本:</b>1.0</p><p><b>描述:</b>" . $bomData['description'] . "</p><p><b>备注:</b>" . $bomData['remark'] . "</p><p><b>申请人:</b>" . $bomData['creater'] . "</p><p><b>申请时间:</b>" . $bomData['create_time'] . "</p><p>请登录系统查看详情!</p>";
     // 发邮件的情况:
     // 1、单站审核结束 $finish_flg = 1 && $publish = false
     if ($finish_flg == 1 && !$publish) {
         $subject = $subject_type . "审批";
         // $to = 下一站审核人
         $current = $review->getCurrent($bomflg, $id);
         $to = $employee->getInfosByOneLine($current['plan_user']);
         //
         $cc = $employee->getInfosByOneLine($owner);
         $cc = $cc['email'];
         $content = "你有一个" . $subject_type . "需要审批,{$content}";
     }
     // 2、所有审核结束  $publish = true
     if ($publish) {
         $subject = $subject_type . "发布";
         $to = $employee->getInfosByOneLine($owner);
         $cc = $employee->getInfosByOneLine($record->getEmployeeIds($bomData['id'], 'bom'));
         $cc = $cc['email'];
         $content .= "<hr><p><b>审核记录:</b><br>" . str_replace(',', '<br>', $record->getHis($bomData['id'], $bomflg)) . "</p>";
         $content = "你申请的" . $subject_type . "已通过审批,{$content}";
     }
     // 3、退回 isset($return)
     if (isset($return)) {
         $subject = $subject_type . "退回";
         $to = $employee->getInfosByOneLine($owner);
         $cc = "";
         // 原审核人
         if ($reviewRow['plan_user']) {
             $orgUser = $reviewRow['plan_user'];
             $cc = $employee->getInfosByOneLine($orgUser);
             $cc = $cc['email'];
         }
         $content = "你申请的" . $subject_type . "已被退回,<p><b>退回原因:</b>" . $remark . "</p>,{$content}";
     }
     // 4、转审 $pass == 3
     if ($pass == 3) {
         $subject = $subject_type . "转审";
         $toUser = str_replace('E', '', $val->transfer_id);
         $to = $employee->getInfosByOneLine($toUser);
         // 原审核人
         if ($reviewRow['plan_user']) {
             $orgUser = $reviewRow['plan_user'];
             $owner .= "," . $orgUser;
         }
         $cc = $employee->getInfosByOneLine($owner);
         $cc = $cc['email'];
         $content = "有新的" . $subject_type . "被转移到你处审批,{$content}";
     }
     if (isset($subject)) {
         $mailData = array('type' => $subject_type, 'subject' => $subject, 'to' => $to['email'], 'cc' => $cc, 'content' => $content, 'send_time' => $now, 'add_date' => $now);
         $mail = new Application_Model_Log_Mail();
         try {
             $mailId = $mail->insert($mailData);
         } catch (Exception $e) {
             $result['result'] = false;
             $result['info'] = $e->getMessage();
             echo Zend_Json::encode($result);
             exit;
         }
         if ($mailId) {
             $mail->send($mailId);
         }
     }
     echo Zend_Json::encode($result);
     exit;
 }