Esempio n. 1
0
 public function getlistAction()
 {
     $request = $this->getRequest()->getParams();
     $limit = $request['limit'];
     $start = $request['start'];
     $fa = new Product_Model_Fa();
     $db = $fa->getAdapter();
     $whereSearch = "1=1";
     //        if(isset($request['search_state']) && $request['search_state'] != 'Active') {
     //        	$whereSearch = " t1.state != 'Active'";
     //        }
     foreach ($request as $k => $v) {
         if ($v) {
             if ($k == 'search_key') {
                 $whereSearch .= " and (ifnull(t1.remark,'') like '%{$v}%' or ifnull(t3.cname,'') like '%{$v}%' or ifnull(t1.description,'') like '%{$v}%')";
             } else {
                 if ("search_fa" == $k && $v) {
                     $nid = "";
                     $faData = $db->query("select group_concat(nid) as nid from oa_product_bom_fa_dev where code like '%{$v}%'")->fetchObject();
                     if ($faData && $faData->nid) {
                         $nid = $faData->nid;
                     }
                     if (!$nid) {
                         $nid = "0";
                     }
                     $whereSearch .= " and t1.id in ({$nid})";
                 } else {
                     if ("search_son" == $k && $v) {
                         $nid = "";
                         $sonData = $db->query("select group_concat(nid) as nid from oa_product_bom_son_dev where code like '%{$v}%'")->fetchObject();
                         if ($sonData && $sonData->nid) {
                             $nid = $sonData->nid;
                         }
                         if (!$nid) {
                             $nid = "0";
                         }
                         $whereSearch .= " and t1.id in ({$nid})";
                     } else {
                         $col = str_replace('search_', '', $k);
                         if ($col != $k) {
                             // 查询条件
                             $whereSearch .= " and ifnull(t1." . $col . ",'') like '%" . $v . "%'";
                         }
                     }
                 }
             }
         }
     }
     $user_session = new Zend_Session_Namespace('user');
     $user = $user_session->user_info['employee_id'];
     $materiel = new Product_Model_Materiel();
     $type = new Product_Model_Type();
     $record = new Dcc_Model_Record();
     $flow = new Admin_Model_Flow();
     $step = new Admin_Model_Step();
     $share = new Dcc_Model_Share();
     $type = new Dcc_Model_Type();
     $review = new Dcc_Model_Review();
     $employee = new Hra_Model_Employee();
     $dept = new Hra_Model_Dept();
     $updbom = new Product_Model_Updbom();
     // 查询条件
     // 类型
     $myType = "";
     if (isset($request['mytype'])) {
         $myType = $request['mytype'];
     }
     // 获取物料数据
     $data = $updbom->getMy($myType, $whereSearch, $user, $start, $limit);
     $totalCount = $updbom->getMyCount($myType, $whereSearch, $user);
     for ($i = 0; $i < count($data); $i++) {
         $upd_type = $data[$i]['upd_type'];
         if ($upd_type == 'ECO') {
             $bomflg = "ecobom";
         } else {
             if ($upd_type == 'DEV') {
                 $bomflg = "devbom";
             }
         }
         $mytype = 2;
         if ($data[$i]['create_user'] == $user) {
             $mytype = 1;
         }
         $data[$i]['create_time'] = strtotime($data[$i]['create_time']);
         $data[$i]['archive_time'] = strtotime($data[$i]['archive_time']);
         // 获取BOM
         $table = "oa_product_bom_fa_dev";
         $bomData = $updbom->getAdapter()->query("select group_concat(concat(code,' V', ver)) as bom from {$table} where type='{$upd_type}' and nid = " . $data[$i]['id'])->fetchObject();
         $data[$i]['bom'] = $bomData->bom;
         // 增加审核状态
         $reviewState = "";
         $step_name = "";
         if ($data[$i]['state'] == 'Active') {
             $reviewState = "已归档";
         } else {
             if ($data[$i]['state'] == 'Reviewing') {
                 // 查询当前审核状态
                 // 查询所有审核阶段
                 $reviewRows = $review->getList("file_id = " . $data[$i]['id'], $bomflg);
                 if (count($reviewRows) > 0) {
                     $first = true;
                     foreach ($reviewRows as $row) {
                         if ($row['finish_flg'] == 1) {
                             if ($step_name) {
                                 $step_name .= "->";
                             }
                             $step_name .= $row['step_name'];
                         } else {
                             if ($step_name) {
                                 $step_name .= "->";
                             }
                             // 第一条未审核记录就是当前待审核记录
                             if ($first) {
                                 $first = false;
                                 $step_name .= "<b>" . $row['step_name'] . "</b>";
                                 $reviewRow = $row;
                                 $actual_user = explode(',', $reviewRow['actual_user']);
                                 $planUser = $reviewRow['plan_user'];
                                 $method = $reviewRow['method'];
                                 $plan_user = explode(',', $planUser);
                                 $diff = array_diff($plan_user, $actual_user);
                                 foreach ($diff as $u) {
                                     if (!$u) {
                                         continue;
                                     }
                                     if ($u == $user) {
                                         $mytype = 3;
                                     }
                                     $e = $employee->fetchRow("id = {$u}");
                                     if ($reviewState) {
                                         $reviewState .= ", ";
                                     }
                                     $reviewState .= $e['cname'] . ":未审核";
                                 }
                                 foreach ($actual_user as $u) {
                                     if (!$u) {
                                         continue;
                                     }
                                     $e = $employee->fetchRow("id = {$u}");
                                     if ($reviewState) {
                                         $reviewState .= ", ";
                                     }
                                     $reviewState .= $e['cname'] . ":已审核";
                                 }
                             } else {
                                 $step_name .= $row['step_name'];
                             }
                         }
                     }
                 }
             } else {
                 if ($data[$i]['state'] == 'Obsolete') {
                     $reviewState = "已作废";
                 } else {
                     if ($data[$i]['state'] == 'Return') {
                         $reviewState = "退回";
                     } else {
                         if ($data[$i]['state'] == 'Draft') {
                             $reviewState = "草稿";
                         } else {
                             $reviewState = $data[$i]['state'];
                         }
                     }
                 }
             }
         }
         $data[$i]['step_name'] = $step_name;
         $data[$i]['review_state'] = $reviewState;
         $data[$i]['mytype'] = $mytype;
         $data[$i]['replacea'] = $data[$i]['replace'];
         $data[$i]['record'] = $record->getHis($data[$i]['id'], $bomflg);
     }
     // 排序
     $dataT3 = array();
     $dataT2 = array();
     $dataT1 = array();
     for ($i = 0; $i < count($data); $i++) {
         if ($data[$i]['mytype'] == 3) {
             $dataT3[] = $data[$i];
         } else {
             if ($data[$i]['mytype'] == 2) {
                 $dataT2[] = $data[$i];
             } else {
                 $dataT1[] = $data[$i];
             }
         }
     }
     $data = array_merge($dataT3, $dataT1, $dataT2);
     $resutl = array("totalCount" => $totalCount, "topics" => $data);
     // 转为json格式并输出
     echo Zend_Json::encode($resutl);
     exit;
 }
Esempio n. 2
0
 /**
  * @abstract    获取文件JSON数据
  * @return      null
  */
 public function getfilesAction()
 {
     // 请求参数
     $request = $this->getRequest()->getParams();
     $limit = $request['limit'];
     $start = $request['start'];
     $where = "1=1";
     foreach ($request as $k => $v) {
         if ($v) {
             if ($k == 'search_tag') {
                 $cols = array("t1.project_info", "t1.code", "t1.name", "t1.description", "t1.remark", "t2.cname", "t7.model_standard", "t7.model_internal");
                 $arr = preg_split('/\\s+/', trim($v));
                 for ($i = 0; $i < count($arr); $i++) {
                     $tmp = array();
                     foreach ($cols as $c) {
                         $tmp[] = "ifnull({$c},'')";
                     }
                     $arr[$i] = "concat(" . implode(',', $tmp) . ") like '%" . $arr[$i] . "%'";
                 }
                 $where .= " and " . join(' AND ', $arr);
                 //                     $where .= " and (ifnull(t1.project_info,'') like '%$v%' or ifnull(t1.code,'') like '%$v%' or ifnull(t1.name,'') like '%$v%' or ifnull(t1.description,'') like '%$v%' or ifnull(t1.remark,'') like '%$v%' or ifnull(t2.cname,'') like '%$v%')";
             } else {
                 if ("search_category" == $k && $v) {
                     $where .= " and t5.category = '{$v}'";
                 } else {
                     if ("search_archive_date_from" == $k && $v) {
                         $where .= " and t1.archive_time >= '" . str_replace('T', ' ', $v) . "'";
                     } else {
                         if ("search_archive_date_to" == $k && $v) {
                             $where .= " and t1.archive_time <= '" . str_replace('T00:00:00', ' 23:59:59', $v) . "'";
                         } else {
                             $col = str_replace('search_', '', $k);
                             if ($col != $k) {
                                 // 查询条件
                                 $where .= " and ifnull(t1." . $col . ",'') like '%" . $v . "%'";
                             }
                         }
                     }
                 }
             }
         }
     }
     $files = new Dcc_Model_Files();
     $record = new Dcc_Model_Record();
     $flow = new Admin_Model_Flow();
     $step = new Admin_Model_Step();
     $share = new Dcc_Model_Share();
     $type = new Dcc_Model_Type();
     $review = new Dcc_Model_Review();
     $employee = new Hra_Model_Employee();
     $dept = new Hra_Model_Dept();
     $codemaster = new Admin_Model_Codemaster();
     if (isset($request['method'])) {
         $data = $files->getFilesListForEdit($where, $start, $limit);
         $count = $files->getCountForEdit($where, $start, $limit);
         $totalCount = $count;
     } else {
         $data = $files->getFilesList($where . " and (t1.state = 'Active' or t1.state = 'Obsolete')", $start, $limit);
         $count = $files->getCount($where . " and (t1.state = 'Active' or t1.state = 'Obsolete')", $start, $limit);
         $totalCount = $count;
     }
     for ($i = 0; $i < count($data); $i++) {
         $data[$i]['create_time'] = strtotime($data[$i]['create_time']);
         $data[$i]['update_time'] = strtotime($data[$i]['update_time']);
         $data[$i]['archive_time'] = strtotime($data[$i]['archive_time']);
         $data[$i]['codever'] = $data[$i]['code'] . ' V' . $data[$i]['ver'];
         $data[$i]['send_require'] = $data[$i]['send_require'] == 1 ? true : false;
         $data[$i]['description'] = $data[$i]['code_description'];
         // 增加审核状态
         $reviewState = "";
         $step_name = "";
         if ($data[$i]['state'] == 'Active') {
             $reviewState = "已发布";
         } else {
             if ($data[$i]['state'] == 'Reviewing') {
                 // 查询当前审核状态
                 // 查询所有审核阶段
                 $reviewRows = $review->getList("file_id = " . $data[$i]['id'], "files");
                 if (count($reviewRows) > 0) {
                     $first = true;
                     foreach ($reviewRows as $row) {
                         if ($row['finish_flg'] == 1) {
                             if ($step_name) {
                                 $step_name .= "->";
                             }
                             $step_name .= $row['step_name'];
                         } else {
                             if ($step_name) {
                                 $step_name .= "->";
                             }
                             // 第一条未审核记录就是当前待审核记录
                             if ($first) {
                                 $first = false;
                                 $step_name .= "<b>" . $row['step_name'] . "</b>";
                                 $reviewRow = $row;
                                 $actual_user = explode(',', $reviewRow['actual_user']);
                                 $planUser = $reviewRow['plan_user'];
                                 $method = $reviewRow['method'];
                                 $plan_dept = $reviewRow['plan_dept'];
                                 $depts = array();
                                 $plan_user = explode(',', $planUser);
                                 $diff = array_diff($plan_user, $actual_user);
                                 foreach ($diff as $u) {
                                     if (!$u) {
                                         continue;
                                     }
                                     $e = $employee->fetchRow("id = {$u}");
                                     if ($reviewState) {
                                         $reviewState .= ", ";
                                     }
                                     $reviewState .= $e['cname'] . ":未审核";
                                 }
                                 foreach ($depts as $d) {
                                     if ($reviewState) {
                                         $reviewState .= ", ";
                                     }
                                     $reviewState .= $d . ":未审核";
                                 }
                                 foreach ($actual_user as $u) {
                                     if (!$u) {
                                         continue;
                                     }
                                     $e = $employee->fetchRow("id = {$u}");
                                     if ($reviewState) {
                                         $reviewState .= ", ";
                                     }
                                     $reviewState .= $e['cname'] . ":已审核";
                                 }
                             } else {
                                 $step_name .= $row['step_name'];
                             }
                         }
                     }
                 }
             } else {
                 if ($data[$i]['state'] == 'Obsolete') {
                     $reviewState = "已作废";
                 } else {
                     if ($data[$i]['state'] == 'Return') {
                         $reviewState = "退回";
                     } else {
                         $reviewState = $data[$i]['state'];
                     }
                 }
             }
         }
         $data[$i]['step_name'] = $step_name;
         $data[$i]['review_state'] = $reviewState;
         if ($data[$i]['reason_type']) {
             $masterData = $codemaster->fetchRow("type = 5 and code = '" . $data[$i]['reason_type'] . "'");
             $reason_type_name = $masterData->text;
             $data[$i]['reason_type_name'] = $reason_type_name;
         }
     }
     $resutl = array("totalCount" => $totalCount, "topics" => $data);
     echo Zend_Json::encode($resutl);
     exit;
 }
Esempio n. 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();
     $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;
 }
Esempio n. 4
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;
 }
Esempio n. 5
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;
 }
Esempio n. 6
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;
 }
Esempio n. 7
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;
 }