Ejemplo n.º 1
0
 public function updateArchiveTime()
 {
     $data = $this->fetchAll("bom_upd_time is null or bom_upd_time = '0000-00-00 00:00:00'")->toArray();
     $newbom = new Product_Model_Newbom();
     $updbom = new Product_Model_Updbom();
     foreach ($data as $fa) {
         if (!$fa['nid']) {
             continue;
         }
         $nid = $fa['nid'];
         if ($fa['ver'] == '1.0') {
             $row = $newbom->fetchRow("id = {$nid}");
             if ($row) {
                 $archive_time = $row['archive_time'];
             }
         } else {
             $row = $updbom->fetchRow("id = {$nid}");
             if ($row) {
                 $archive_time = $row['archive_time'];
             }
         }
         if (isset($archive_time)) {
             $this->update(array('bom_upd_time' => $archive_time), "sid = " . $fa['sid']);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * @abstract    删除
  * @return      null
  */
 public function removeAction()
 {
     // 返回值数组
     $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'];
     $json = json_decode($request['json']);
     $deleted = $json->deleted;
     $updbom = new Product_Model_Updbom();
     $fadev = new Product_Model_Fadev();
     $sondev = new Product_Model_Sondev();
     $fa = new Product_Model_Fa();
     $son = new Product_Model_Son();
     $record = new Dcc_Model_Record();
     $review = new Dcc_Model_Review();
     if (count($deleted) > 0) {
         foreach ($deleted as $val) {
             $id = $val->id;
             $upd_type = $val->upd_type;
             if ($upd_type == 'ECO') {
                 $bomflg = "ecobom";
                 $table = "oa_product_bom_eco";
             } else {
                 if ($upd_type == 'DEV') {
                     $bomflg = "devbom";
                     $table = "oa_product_bom_dev";
                 }
             }
             // 操作记录
             $data = array('type' => $bomflg, 'table_name' => $table, 'table_id' => $id, 'handle_user' => $user, 'handle_time' => $now, 'action' => "删除", 'ip' => $_SERVER['REMOTE_ADDR']);
             // 获取bom fa表的recordkey
             $sql = "select recordkey from oa_product_bom_fa_dev where nid={$id} and (type='DEV' or type='ECO')";
             $keys = $fa->getAdapter()->query($sql)->fetchObject();
             if ($keys && $keys->recordkey) {
                 $recordkey = $keys->recordkey;
             } else {
                 $sql = "select recordkey from oa_product_bom_fa where nid={$id} and (type='DEV' or type='ECO')";
                 $keys = $fa->getAdapter()->query($sql)->fetchObject();
                 if ($keys && $keys->recordkey) {
                     $recordkey = $keys->recordkey;
                 }
             }
             try {
                 // 增加record记录
                 $record->insert($data);
                 // 删除review记录
                 $review->delete("type = '{$bomflg}' and file_id = {$id}");
                 // 删除bom表
                 $updbom->delete("id = {$id}");
                 if (isset($recordkey) && $recordkey) {
                     $where = "recordkey = {$recordkey}";
                     $fadev->delete($where);
                     $sondev->delete($where);
                     $fa->delete($where);
                     $son->delete($where);
                 }
             } catch (Exception $e) {
                 $result['result'] = false;
                 $result['info'] = $e->getMessage();
                 echo Zend_Json::encode($result);
                 exit;
             }
         }
     }
     echo Zend_Json::encode($result);
     exit;
 }
Ejemplo 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;
     $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;
 }