Exemplo n.º 1
0
 public function photoAction()
 {
     $result = array('success' => true, 'info' => '上传成功');
     $request = $this->getRequest()->getParams();
     $employee_id = isset($request['employee_id']) ? $request['employee_id'] : null;
     if ($employee_id && isset($_FILES['attach_file'])) {
         $now = date('Y-m-d H:i:s');
         $user_session = new Zend_Session_Namespace('user');
         $user_id = $user_session->user_info['user_id'];
         $file = $_FILES['attach_file'];
         $file_name = $file['name'];
         $file_extension = strrchr($file_name, ".");
         /* if ($file_extension != '.jpg') {
                $result = array(
                        'success'   => false,
                        'info'      => '格式错误,请选择格式为jpg的相片文件!'
                );
                
                echo Zend_Json::encode($result);
                
                exit;
            } */
         $h = new Application_Model_Helpers();
         $tmp_file_name = $h->getMicrotimeStr() . $file_extension;
         $savepath = "../upload/portrait/";
         if (!is_dir($savepath)) {
             mkdir($savepath);
             // 目录不存在则创建目录
         }
         $tmp_file_path = $savepath . $tmp_file_name;
         move_uploaded_file($file["tmp_name"], $tmp_file_path);
         $employee = new Hra_Model_Employee();
         $employeeData = $employee->getInfoById($employee_id);
         if ($employeeData['photo_path'] != '' && file_exists($employeeData['photo_path'])) {
             unlink($employeeData['photo_path']);
         }
         $employeeData = array('photo_path' => $tmp_file_path, 'update_user' => $user_id, 'update_time' => $now);
         $employee->update($employeeData, "id = " . $employee_id);
     }
     echo Zend_Json::encode($result);
     exit;
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
0
 /**
  * 根据ID获取用户信息
  * @param unknown $id
  * @return Ambigous <multitype:, array>
  */
 public function getEmployeeInfoById($id)
 {
     $user = $this->fetchRow("id = " . $id)->toArray();
     $employee = new Hra_Model_Employee();
     return $employee->getInfoById($user['employee_id']);
 }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
0
 /**
  * @abstract    添加文件编码
  * @return      null
  */
 public function saveAction()
 {
     // 返回值数组
     $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;
     $code = new Dcc_Model_Code();
     $type = new Dcc_Model_Type();
     $db = $code->getAdapter();
     if ($val->id) {
         // 编辑
         if (isset($val->code) && $val->code) {
             $auto_code = $val->code;
             // 检查是否文件号已经存在
             if ($code->fetchAll("id != " . $val->id . " and code = '" . $auto_code . "'")->count() > 0) {
                 $result['result'] = false;
                 $result['info'] = "文件编码“" . $val->code . "”已经存在";
                 echo Zend_Json::encode($result);
                 exit;
             }
         } else {
             $auto_code = "";
         }
         $data = array('code' => $auto_code, 'active' => isset($val->active) ? 1 : 0, 'project_no' => $val->project_no, 'project_standard_no' => isset($val->project_standard_no) ? $val->project_standard_no : "", 'description' => $val->description, 'remark' => $val->remark, 'update_time' => $now, 'update_user' => $user);
         try {
             $code->update($data, "id = " . $val->id);
             $result['info'] = "修改成功";
         } catch (Exception $e) {
             $result['result'] = false;
             $result['info'] = $e->getMessage();
             echo Zend_Json::encode($result);
             exit;
         }
     } else {
         // 检查是自动生成编码还是手动
         $typedata = $db->query("select t2.automethod from oa_doc_type t1 inner join oa_doc_auto t2 on t1.autotype=t2.id where t1.state = 1 and t1.id = " . $val->prefix)->fetchObject();
         if ($typedata && $typedata->automethod != 'H' && $typedata->automethod != 'A' && $typedata->automethod != 'F') {
             $auto_code = $this->getCode($val->prefix, $val->project_no);
             if (!$auto_code) {
                 $result['result'] = false;
                 $result['info'] = "文件编码获取失败";
                 echo Zend_Json::encode($result);
                 exit;
             }
         } else {
             if ($typedata && $typedata->automethod == 'A' && (!isset($val->code) || !$val->code)) {
                 $auto_code = "";
                 // 需发邮件
                 $mailId = '';
                 $type = "文件编码申请";
                 $subject = "文件号分配";
                 // $to =   文件管理员
                 $employee = new Hra_Model_Employee();
                 $member = new Admin_Model_Member();
                 $role = new Admin_Model_Role();
                 $toArr = array();
                 $roleArr = $role->getRoleIdByName('文件管理员');
                 $roleData = array();
                 if ($roleArr['role_id']) {
                     $roleData = $member->getMember($roleArr['role_id']);
                 }
                 foreach ($roleData as $r) {
                     if ($r['user_id'] == 1) {
                         continue;
                     }
                     $toArr[] = $r['email'];
                 }
                 $to = implode(',', $toArr);
                 if ($to) {
                     $emp = $employee->getInfoById($user);
                     $userName = '';
                     if (count($emp) > 0) {
                         $userName = $emp[0]['cname'];
                     }
                     $user_name = $user_session->user_info['user_name'];
                     $content = "<p>你有一个文件编码申请需要分配文件号</p>";
                     $content .= "<p><b>文件描述:</b>" . $val->description . "</p><p><b>备注:</b>" . $val->remark . "</p><p><b>申请人:</b>" . $user_name . "</p><p><b>申请时间:</b>" . $now . "</p><p>请登录系统查看详情!</p>";
                     $mailData = array('type' => $type, 'subject' => $subject, 'to' => $to, 'content' => $content, 'send_time' => $now, 'add_date' => $now);
                     $mail = new Application_Model_Log_Mail();
                     try {
                         $mailId = $mail->insert($mailData);
                     } catch (Exception $e) {
                     }
                     if ($mailId) {
                         $mail->send($mailId);
                     }
                 }
             } else {
                 if ($typedata && $typedata->automethod == 'F' && (!isset($val->code) || !$val->code)) {
                     // 流程
                     // 获取当前文件类别对应的流程ID
                     $row = $type->getList("id='{$val->prefix}'");
                     $flow_id = '';
                     if ($row && count($row) > 0) {
                         $flow_id = $row[0]['apply_flow_id'];
                     } else {
                         $result['info'] = "文件类型未设置审核流程";
                         echo Zend_Json::encode($result);
                         exit;
                     }
                     // 根据流程ID获取阶段
                     $flow = new Admin_Model_Flow();
                     $step = new Admin_Model_Step();
                     $member = new Admin_Model_Member();
                     $employee = new Hra_Model_Employee();
                     $mail = new Application_Model_Log_Mail();
                     $record = new Dcc_Model_Record();
                     $review = new Dcc_Model_Review();
                     $flowRow = $flow->getRow($flow_id);
                     $step_ids = $flowRow['step_ids'];
                     if ($step_ids) {
                         $data = array('prefix' => $val->prefix, 'code' => '', 'state' => 'Reviewing', 'active' => isset($val->active) ? 1 : 0, 'project_no' => $val->project_no, 'project_standard_no' => isset($val->project_standard_no) ? $val->project_standard_no : "", 'description' => $val->description, 'remark' => $val->remark, 'create_time' => $now, 'create_user' => $user, 'update_time' => $now, 'update_user' => $user);
                         try {
                             $id = $code->insert($data);
                             $inserted = true;
                             // 操作记录
                             $data = array('type' => "code_apply", 'table_name' => "oa_doc_code", 'table_id' => $id, 'handle_user' => $user, 'handle_time' => $now, 'action' => "申请", 'ip' => $_SERVER['REMOTE_ADDR']);
                             $record->insert($data);
                         } catch (Exception $e) {
                             $result['result'] = false;
                             $result['info'] = $e->getMessage();
                             echo Zend_Json::encode($result);
                             exit;
                         }
                         $stepRows = $step->getListByFlow($step_ids);
                         $state = "Reviewing";
                         // 把阶段信息插入review记录
                         $first = true;
                         foreach ($stepRows as $s) {
                             $plan_user = $s['user'];
                             if ($s['dept']) {
                                 $tmpUser = array();
                                 $plan_dept = $s['dept'];
                                 foreach (explode(',', $plan_dept) as $role) {
                                     $tmpRole = $member->getMemberWithNoManager($role);
                                     foreach ($tmpRole as $m) {
                                         $tmpUser[] = $m['user_id'];
                                     }
                                 }
                                 if (count($tmpUser) == 0 && !$plan_user) {
                                     $tmpUser = $member->getUserids("系统管理员");
                                 }
                                 if (count($tmpUser) > 0) {
                                     $tmpUser = $employee->getAdapter()->query("select group_concat(employee_id) as users from oa_user where active = 1 and id in ( " . implode(',', $tmpUser) . ")")->fetchObject();
                                     $users = $tmpUser->users;
                                 }
                                 if ($users) {
                                     if ($plan_user) {
                                         $plan_user .= ",";
                                     }
                                     $plan_user .= $users;
                                 }
                             }
                             $repeatUser = explode(',', $plan_user);
                             $repeatUser = array_unique($repeatUser);
                             $plan_user = implode(',', $repeatUser);
                             $reviewData = array('type' => "code_apply", 'file_id' => $id, 'plan_user' => $plan_user, 'method' => $s['method'], 'return' => $s['return'], 'step_name' => $s['step_name'], 'step_ename' => $s['step_ename']);
                             $review->insert($reviewData);
                             // 邮件任务
                             if ($first) {
                                 // 需发邮件
                                 $mailId = '';
                                 $type = "文件编码申请";
                                 $subject = "文件编码申请审核";
                                 $user_name = $user_session->user_info['user_name'];
                                 $to = $employee->getAdapter()->query("select group_concat(email) as mail_to from oa_employee where id in ( " . $plan_user . ")")->fetchObject();
                                 $content = "<p>你有一个文件编码申请需要审核</p>";
                                 $content .= "<p><b>文件描述:</b>" . $val->description . "</p><p><b>备注:</b>" . $val->remark . "</p><p><b>申请人:</b>" . $user_name . "</p><p><b>申请时间:</b>" . $now . "</p><p>请登录系统查看详情!</p>";
                                 $mailData = array('type' => $type, 'subject' => $subject, 'to' => $to->mail_to, 'content' => $content, 'send_time' => $now, 'add_date' => $now);
                                 $mailId = $mail->insert($mailData);
                                 if ($mailId) {
                                     $mail->send($mailId);
                                 }
                             }
                             $first = false;
                         }
                         $result['info'] = "申请成功,已通知相关人员审核";
                         echo Zend_Json::encode($result);
                         exit;
                     }
                 } else {
                     $auto_code = $val->code;
                     // 检查是否文件号已经存在
                     if ($auto_code && $code->fetchAll("code = '" . $auto_code . "'")->count() > 0) {
                         $result['result'] = false;
                         $result['info'] = "文件编码“" . $val->code . "”已经存在";
                         echo Zend_Json::encode($result);
                         exit;
                     }
                 }
             }
         }
         $auto_code = strtoupper($auto_code);
         $data = array('prefix' => $val->prefix, 'code' => $auto_code, 'state' => isset($state) ? 'Reviewing' : 'Active', 'active' => isset($val->active) ? 1 : 0, 'project_no' => $val->project_no, 'project_standard_no' => isset($val->project_standard_no) ? $val->project_standard_no : "", 'description' => $val->description, 'remark' => $val->remark, 'create_time' => $now, 'create_user' => $user, 'update_time' => $now, 'update_user' => $user);
         try {
             $code->insert($data);
             if ($auto_code) {
                 $result['info'] = "申请成功,文件编码:{$auto_code}";
             } else {
                 $result['info'] = "申请成功,请通知管理员分配文件编码";
             }
         } catch (Exception $e) {
             $result['result'] = false;
             $result['info'] = $e->getMessage();
             echo Zend_Json::encode($result);
             exit;
         }
     }
     echo Zend_Json::encode($result);
     exit;
 }