/** * 获取阶段 */ public function getListByFlow() { // 参数 $request = $this->getRequest()->getParams(); $id = $request['id']; $model = new Admin_Model_Step(); $data = $model->getListByFlow($id); echo Zend_Json::encode($data); exit; }
/** * @abstract 保存 * @return null */ public function saveAction() { // 返回值数组 $result = array('success' => true, 'result' => true, 'info' => '保存成功'); $request = $this->getRequest()->getParams(); $now = date('Y-m-d H:i:s'); $user_session = new Zend_Session_Namespace('user'); $user = $user_session->user_info['employee_id']; $val = (object) $request; $materiel = new Product_Model_Materiel(); $record = new Dcc_Model_Record(); $review = new Dcc_Model_Review(); $employee = new Hra_Model_Employee(); $mail = new Application_Model_Log_Mail(); $member = new Admin_Model_Member(); $desc = new Product_Model_Desc(); if (isset($val->mid) && $val->mid) { $mid = $val->mid; $md = $materiel->fetchRow("id = {$mid}"); } else { $result['result'] = false; $result['info'] = "数据加载失败"; echo Zend_Json::encode($result); exit; } // 根据物料类别获取审批流 $typeId = $md->type; $stepRows = array(); if ($typeId) { $type = new Product_Model_Type(); // 获取当前物料类别对应的流程ID 如果找不到,继续往上搜索 $flow_id = $type->getFlowId($typeId, 'upd'); if ($flow_id) { // 根据流程ID获取阶段 $flow = new Admin_Model_Flow(); $step = new Admin_Model_Step(); $flowRow = $flow->getRow($flow_id); $step_ids = $flowRow['step_ids']; if ($step_ids) { $stepRows = $step->getListByFlow($step_ids); $state = "Reviewing"; } } } // 新增还是编辑 if (isset($val->id) && $val->id) { $result['info'] = '修改成功'; $data = array('mid' => $mid, 'code' => $md->code, 'state' => 'Reviewing', 'type_before' => $md->type, 'type_after' => $md->type, 'desc_before' => $md->description, 'desc_after' => $val->desc_after, 'supply1_before' => $md->supply1, 'supply1_after' => $val->supply1_after, 'supply2_before' => $md->supply2, 'supply2_after' => $val->supply2_after, 'manufacturers_before' => $md->manufacturers, 'manufacturers_after' => $val->manufacturers_after, 'data_file_id_before' => $md->data_file_id, 'data_file_id_after' => $val->data_file_id_after, 'tsr_id_before' => $md->tsr_id, 'tsr_id_after' => $val->tsr_id_after, 'first_report_id_before' => $md->first_report_id, 'first_report_id_after' => $val->first_report_id_after, 'name_before' => $md->name, 'name_after' => $val->name_after, 'remark' => $val->remark, 'create_user' => $user, 'create_time' => $now); $id = $val->id; $where = "id = " . $id; try { if ($id) { $desc->update($data, $where); // 操作记录 $data = array('type' => "materiel_desc", 'table_name' => "oa_product_materiel_desc", 'table_id' => $id, 'handle_user' => $user, 'handle_time' => $now, 'action' => "编辑", 'ip' => $_SERVER['REMOTE_ADDR']); $record->insert($data); // 审核流程 // 删除已存在的审核记录 $review->delete("type = 'materiel_desc' and file_id = " . $id); // 把阶段信息插入review记录 $first = true; foreach ($stepRows as $s) { $plan_user = $s['user']; if ($s['dept']) { $tmpUser = array(); $plan_dept = $s['dept']; foreach (explode(',', $plan_dept) as $role) { $tmpRole = $member->getMemberWithNoManager($role); foreach ($tmpRole as $m) { $tmpUser[] = $m['user_id']; } } if (count($tmpUser) == 0 && !$plan_user) { $tmpUser = $member->getUserids("系统管理员"); } if (count($tmpUser) > 0) { $tmpUser = $employee->getAdapter()->query("select group_concat(employee_id) as users from oa_user where active = 1 and id in ( " . implode(',', $tmpUser) . ")")->fetchObject(); $users = $tmpUser->users; } if ($users) { if ($plan_user) { $plan_user .= ","; } $plan_user .= $users; } } $repeatUser = explode(',', $plan_user); $repeatUser = array_unique($repeatUser); $plan_user = implode(',', $repeatUser); $reviewData = array('type' => "materiel_desc", 'file_id' => $id, 'plan_user' => $plan_user, 'method' => $s['method'], 'return' => $s['return'], 'step_name' => $s['step_name'], 'step_ename' => $s['step_ename']); $review->insert($reviewData); } } } catch (Exception $e) { $result['result'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } echo Zend_Json::encode($result); exit; } else { $data = array('mid' => $mid, 'code' => $md->code, 'state' => 'Reviewing', 'ver_before' => $md->ver, 'ver_after' => $md->ver + 0.1, 'type_before' => $md->type, 'type_after' => $md->type, 'desc_before' => $md->description, 'desc_after' => $val->desc_after, 'supply1_before' => $md->supply1, 'supply1_after' => $val->supply1_after, 'supply2_before' => $md->supply2, 'supply2_after' => $val->supply2_after, 'manufacturers_before' => $md->manufacturers, 'manufacturers_after' => $val->manufacturers_after, 'data_file_id_before' => $md->data_file_id, 'data_file_id_after' => $val->data_file_id_after, 'tsr_id_before' => $md->tsr_id, 'tsr_id_after' => $val->tsr_id_after, 'first_report_id_before' => $md->first_report_id, 'first_report_id_after' => $val->first_report_id_after, 'name_before' => $md->name, 'name_after' => $val->name_after, 'remark' => $val->remark, 'create_user' => $user, 'create_time' => $now); try { $id = $desc->insert($data); if ($id) { // 操作记录 $data = array('type' => "materiel_desc", 'table_name' => "oa_product_materiel_desc", 'table_id' => $id, 'handle_user' => $user, 'handle_time' => $now, 'action' => "申请", 'ip' => $_SERVER['REMOTE_ADDR']); $record->insert($data); // 审核流程 // 把阶段信息插入review记录 $first = true; foreach ($stepRows as $s) { $plan_user = $s['user']; if ($s['dept']) { $tmpUser = array(); $plan_dept = $s['dept']; foreach (explode(',', $plan_dept) as $role) { $tmpRole = $member->getMemberWithNoManager($role); foreach ($tmpRole as $m) { $tmpUser[] = $m['user_id']; } } if (count($tmpUser) == 0 && !$plan_user) { $tmpUser = $member->getUserids("系统管理员"); } if (count($tmpUser) > 0) { $tmpUser = $employee->getAdapter()->query("select group_concat(employee_id) as users from oa_user where active = 1 and id in ( " . implode(',', $tmpUser) . ")")->fetchObject(); $users = $tmpUser->users; } if ($users) { if ($plan_user) { $plan_user .= ","; } $plan_user .= $users; } } $repeatUser = explode(',', $plan_user); $repeatUser = array_unique($repeatUser); $plan_user = implode(',', $repeatUser); $reviewData = array('type' => "materiel_desc", 'file_id' => $id, 'plan_user' => $plan_user, 'method' => $s['method'], 'return' => $s['return'], 'step_name' => $s['step_name'], 'step_ename' => $s['step_ename']); $review->insert($reviewData); // 邮件任务 if ($first) { $to = $employee->getAdapter()->query("select group_concat(email) as mail_to from oa_employee where id in ( " . $plan_user . ")")->fetchObject(); $mailData = array('type' => '物料号变更审批', 'subject' => '物料号变更审批', 'to' => $to->mail_to, 'cc' => '', 'content' => '你有新物料号变更申请(物料代码:' . $md["code"] . ')需要审核,请登录系统查看详情', 'send_time' => $now, 'add_date' => $now); $mailId = $mail->insert($mailData); if ($mailId) { $mail->send($mailId); } } $first = false; } } } catch (Exception $e) { $result['result'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } echo Zend_Json::encode($result); exit; } }
/** * grid用 */ public function getstepAction() { // 请求参数 $request = $this->getRequest()->getParams(); $ids = $request['ids']; $step = new Admin_Model_Step(); $employee = new Hra_Model_Employee(); $where = "t1.id in ({$ids})"; $data = $step->getListByFlow($ids); for ($i = 0; $i < count($data); $i++) { $step_user = $data[$i]['user']; if ($step_user) { $step_user_name = $employee->getInfosByOneLine($step_user); $data[$i]['step_user_name'] = $step_user_name['cname']; } $step_dept = $data[$i]['dept']; if ($step_dept) { $tmp = $step->getAdapter()->query("select group_concat(name) as name from oa_user_role where id in ( " . $step_dept . ")")->fetchObject(); $step_dept_name = $tmp->name; $data[$i]['step_dept_name'] = $step_dept_name; } } echo Zend_Json::encode($data); exit; }
public function exportcsvAction() { $request = $this->getRequest()->getParams(); $whereSearch = "1=1"; foreach ($request as $k => $v) { if ($v) { if ($k == 'search_tag') { $whereSearch .= " and (ifnull(t1.code,'') like '%{$v}%' or ifnull(t1.fullname,'') like '%{$v}%' or ifnull(t1.name,'') like '%{$v}%' or ifnull(t1.description,'') like '%{$v}%' or ifnull(t1.remark,'') like '%{$v}%' or ifnull(t1.secretlevel,'') like '%{$v}%')"; } else { if ($k == 'search_type') { if ($v) { $v = json_decode($v); $v = implode(',', $v); if ($v) { $whereSearch .= " and t1.category in ({$v})"; } } } else { $col = str_replace('search_', '', $k); if ($col != $k) { // 查询条件 $whereSearch .= " and ifnull(t1." . $col . ",'') like '%" . $v . "%'"; } } } } } print chr(0xef) . chr(0xbb) . chr(0xbf); $record = new Dcc_Model_Record(); $type = new Dcc_Model_Type(); $flow = new Admin_Model_Flow(); $step = new Admin_Model_Step(); $data = $type->getTypeList($whereSearch); $data_csv = array(); $title = array('cnt' => '#', 'id' => 'ID', 'code' => '文件简号', 'name' => '中文解释', 'fullname' => '全称', 'category' => '文件类别', 'resp_dept_id' => '责任部门', 'resp_emp_id' => '责任人', 'filerequire' => '文件是否必须', 'secretlevel' => '文件密级', 'template' => '文件模板编号', 'duration' => '审核时效', 'length' => '流水号长度', 'autotype' => '自动编码方式', 'description' => '描述', 'model_id' => '新文件自定义表单', 'dev_model_id' => '新版自定义表单', 'flow_id' => '新文件审批流程', 'dev_flow_id' => '升版文件审批流程', 'remark' => '备注', 'creater' => '添加人', 'create_time' => '生效日期', 'update_time' => '取消日期'); $title = $this->object_array($title); $date = date('YmdHsi'); $filename = "type_list" . $date; $path = "../temp/" . $filename . ".csv"; $file = fopen($path, "w"); fputcsv($file, $title); array_push($data_csv, $title); $typeids = array(); $typenames = array(); $k = 0; for ($i = 0; $i < count($data); $i++) { if ($data[$i]['state'] != 1) { } else { $data[$i]['update_time'] = ""; } $data[$i]['state'] = $data[$i]['state'] == 1 ? true : false; $data[$i]['autocode'] = $data[$i]['autocode'] == 1 ? true : false; $data[$i]['modelrequire'] = $data[$i]['modelrequire'] == 1 ? true : false; $data[$i]['filerequire'] = $data[$i]['filerequire'] == 1 ? '是' : '否'; // 查询所有审核阶段 if ($data[$i]['step_ids']) { $stepRows = $step->getListByFlow($data[$i]['step_ids']); $step_name = ""; if (count($stepRows) > 0) { $first = true; foreach ($stepRows as $row) { if ($step_name) { $step_name .= "->"; } $step_name .= $row['step_name']; } } $data[$i]['step'] = $step_name; } if ($data[$i]['dev_step_ids']) { $devStepRows = $step->getListByFlow($data[$i]['dev_step_ids']); $dev_step_name = ""; if (count($devStepRows) > 0) { $first = true; foreach ($devStepRows as $row) { if ($dev_step_name) { $dev_step_name .= "->"; } $dev_step_name .= $row['step_name']; } } $data[$i]['dev_step'] = $dev_step_name; } $data[$i]['resp_emp_name'] = ""; $data[$i]['resp_dept_name'] = ""; $data[$i]['grant_dept_name'] = ""; if ($data[$i]['resp_emp_id']) { $emp = $data[$i]['resp_emp_id']; $sql = "select GROUP_CONCAT(name) as resp_emp_name from oa_employee_post where id in ({$emp})"; $db = $step->getAdapter(); $result = $db->query($sql)->fetchObject(); $data[$i]['resp_emp_name'] = $result->resp_emp_name; } if ($data[$i]['resp_dept_id']) { $dept = $data[$i]['resp_dept_id']; $sql = "select GROUP_CONCAT(name) as resp_dept_name from oa_employee_dept where id in ({$dept})"; $db = $step->getAdapter(); $result = $db->query($sql)->fetchObject(); $data[$i]['resp_dept_name'] = $result->resp_dept_name; } if ($data[$i]['grant_dept_id']) { $dept = $data[$i]['grant_dept_id']; $sql = "select GROUP_CONCAT(name) as grant_dept_name from oa_employee_dept where id in ({$dept})"; $db = $step->getAdapter(); $result = $db->query($sql)->fetchObject(); $data[$i]['grant_dept_name'] = $result->grant_dept_name; } //$data[$i]['record'] = $record->getHis($data[$i]['id'], 'materiel'); $d = $data[$i]; $k++; $info = array('cnt' => $k, 'id' => $d['id'], 'code' => $d['code'], 'name' => $d['name'], 'fullname' => $d['fullname'], 'category' => $d['category_name'], 'resp_dept_id' => $d['resp_dept_name'], 'resp_emp_id' => $d['resp_emp_name'], 'filerequire' => $d['filerequire'], 'secretlevel' => $d['secretlevel'], 'template' => $d['template'], 'duration' => $d['duration'], 'length' => $d['length'], 'autotype' => $d['auto_description'], 'description' => $d['description'], 'model_id' => $d['model_name'], 'dev_model_id' => $d['dev_model_name'], 'flow_id' => $d['flow_name'], 'dev_flow_id' => $d['dev_flow_name'], 'remark' => $d['remark'], 'creater' => $d['creater'], 'create_time' => $d['create_time'], 'update_time' => $d['update_time']); $d = $this->object_array($info); array_push($data_csv, $info); fputcsv($file, $d); } fclose($file); $this->operate("文件分类导出"); echo $filename; exit; }
/** * @abstract 保存 * @return null */ public function editAction() { // 返回值数组 $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(); $mail = new Application_Model_Log_Mail(); $member = new Admin_Model_Member(); // 根据物料类别获取审批流 $typeId = $val->type_id; $stepRows = array(); if ($typeId) { $type = new Product_Model_Type(); // 获取当前物料类别对应的流程ID 如果找不到,继续往上搜索 $flow_id = $type->getFlowId($typeId, 'new'); if ($flow_id) { // 根据流程ID获取阶段 $flow = new Admin_Model_Flow(); $step = new Admin_Model_Step(); $flowRow = $flow->getRow($flow_id); $step_ids = $flowRow['step_ids']; if ($step_ids) { $stepRows = $step->getListByFlow($step_ids); $state = "Reviewing"; } } } // 新增还是编辑 if (isset($val->id) && $val->id) { $result['info'] = '修改成功'; $data = array('type' => $val->type_id, 'description' => $val->description, 'remark' => $val->remark, 'ver' => $val->ver, 'unit' => $val->unit, 'state' => isset($state) ? 'Reviewing' : 'Active', 'manufacturers' => $val->manufacturers, 'supply1' => $val->supply1, 'supply2' => $val->supply2, 'mpq' => $val->mpq, 'moq' => $val->moq, 'tod' => $val->tod, 'data_file_id' => $val->data_file_id, 'first_report_id' => $val->first_report_id); $id = $val->id; $where = "id = " . $id; try { if ($id) { $materiel->update($data, $where); /* $attrval = new Admin_Model_Formval(); // 自定义字段 foreach($request as $field => $value) { if(stripos($field, "intelligenceField") !== false) { $attrId = str_replace("intelligenceField", "", $field); $menu = 'oa_doc_files_'.$id; $formval = array( 'attrid' => $attrId, 'value' => $value, 'menu' => $menu ); $where = "attrid = ".$attrId." and menu = '".$menu."'"; if($attrval->fetchAll($where)->count() > 0) { // 更新 $attrval->update($formval, $where); } else { $attrval->insert($formval); } } } */ // 操作记录 $data = array('type' => "materiel", 'table_name' => "oa_product_materiel", 'table_id' => $id, 'handle_user' => $user, 'handle_time' => $now, 'action' => "编辑", 'ip' => $_SERVER['REMOTE_ADDR']); $record->insert($data); // 审核流程 // 删除已存在的审核记录 $review->delete("type = 'materiel' and file_id = " . $id); // 把阶段信息插入review记录 $first = true; foreach ($stepRows as $s) { $plan_user = $s['user']; if ($s['dept']) { $tmpUser = array(); $plan_dept = $s['dept']; foreach (explode(',', $plan_dept) as $role) { $tmpRole = $member->getMemberWithNoManager($role); foreach ($tmpRole as $m) { $tmpUser[] = $m['user_id']; } } if (count($tmpUser) == 0 && !$plan_user) { $tmpUser = $member->getUserids("系统管理员"); } if (count($tmpUser) > 0) { $tmpUser = $employee->getAdapter()->query("select group_concat(employee_id) as users from oa_user where active = 1 and id in ( " . implode(',', $tmpUser) . ")")->fetchObject(); $users = $tmpUser->users; } if ($users) { if ($plan_user) { $plan_user .= ","; } $plan_user .= $users; } } $repeatUser = explode(',', $plan_user); $repeatUser = array_unique($repeatUser); $plan_user = implode(',', $repeatUser); $reviewData = array('type' => "materiel", 'file_id' => $id, 'plan_user' => $plan_user, 'method' => $s['method'], 'return' => $s['return'], 'step_name' => $s['step_name'], 'step_ename' => $s['step_ename']); $review->insert($reviewData); } } } catch (Exception $e) { $result['result'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } echo Zend_Json::encode($result); exit; } else { $data = array('type' => $val->type_id, 'description' => $val->description, 'remark' => $val->remark, 'ver' => $val->ver, 'unit' => $val->unit, 'state' => isset($state) ? 'Reviewing' : 'Active', 'manufacturers' => $val->manufacturers, 'supply1' => $val->supply1, 'supply2' => $val->supply2, 'mpq' => $val->mpq, 'moq' => $val->moq, 'tod' => $val->tod, 'data_file_id' => $val->data_file_id, 'first_report_id' => $val->first_report_id, 'create_user' => $user, 'create_time' => $now); try { $id = $materiel->insert($data); if ($id) { /* // 自定义字段 $attrval = new Admin_Model_Formval(); foreach($request as $field => $value) { if(stripos($field, "intelligenceField") !== false && $value) { $attrId = str_replace("intelligenceField", "", $field); $menu = 'oa_doc_files_'.$id; $formval = array( 'attrid' => $attrId, 'value' => $value, 'menu' => $menu ); $attrval->insert($formval); } } */ // 操作记录 $data = array('type' => "materiel", 'table_name' => "oa_product_materiel", 'table_id' => $id, 'handle_user' => $user, 'handle_time' => $now, 'action' => "申请", 'ip' => $_SERVER['REMOTE_ADDR']); $record->insert($data); // 审核流程 // 把阶段信息插入review记录 $first = true; foreach ($stepRows as $s) { $plan_user = $s['user']; if ($s['dept']) { $tmpUser = array(); $plan_dept = $s['dept']; foreach (explode(',', $plan_dept) as $role) { $tmpRole = $member->getMemberWithNoManager($role); foreach ($tmpRole as $m) { $tmpUser[] = $m['user_id']; } } if (count($tmpUser) == 0 && !$plan_user) { $tmpUser = $member->getUserids("系统管理员"); } if (count($tmpUser) > 0) { $tmpUser = $employee->getAdapter()->query("select group_concat(employee_id) as users from oa_user where active = 1 and id in ( " . implode(',', $tmpUser) . ")")->fetchObject(); $users = $tmpUser->users; } if ($users) { if ($plan_user) { $plan_user .= ","; } $plan_user .= $users; } } $repeatUser = explode(',', $plan_user); $repeatUser = array_unique($repeatUser); $plan_user = implode(',', $repeatUser); $reviewData = array('type' => "materiel", 'file_id' => $id, 'plan_user' => $plan_user, 'method' => $s['method'], 'return' => $s['return'], 'step_name' => $s['step_name'], 'step_ename' => $s['step_ename']); $review->insert($reviewData); // 邮件任务 if ($first) { $to = $employee->getAdapter()->query("select group_concat(email) as mail_to from oa_employee where id in ( " . $plan_user . ")")->fetchObject(); $mailData = array('type' => '物料号归档审批', 'subject' => '物料号归档审批', 'to' => $to->mail_to, 'cc' => '', 'content' => '你有新物料号归档申请需要审核,请登录系统查看详情', 'send_time' => $now, 'add_date' => $now); $mailId = $mail->insert($mailData); if ($mailId) { $mail->send($mailId); } } $first = false; } } } catch (Exception $e) { $result['result'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } echo Zend_Json::encode($result); exit; } }
/** * @abstract 文件升版 * @return null */ public function upgradeAction() { // 返回值数组 $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']; $user_name = $user_session->user_info['user_name']; $val = (object) $request; $json = json_decode($request['json']); $code_file_code_id = $json->code_id; $code_file_code = $json->code; $code_file_file_id = $json->file_id; $code_file_file = $json->file; $code_file_desc = isset($json->code_file_desc) ? $json->code_file_desc : ''; $code_file_project_no = isset($json->code_file_project_no) ? $json->code_file_project_no : ''; $files = new Dcc_Model_Files(); $upload = new Dcc_Model_Upload(); $record = new Dcc_Model_Record(); $review = new Dcc_Model_Review(); $upgrade = new Dcc_Model_Upgrade(); $employee = new Hra_Model_Employee(); $mail = new Application_Model_Log_Mail(); $member = new Admin_Model_Member(); $code = $code_file_code[0]; $stepRows = array(); if (count($code) > 0 && $code) { $codeModel = new Dcc_Model_Code(); // 获取当前文件类别对应的流程ID $row = $codeModel->getTypeInfo("t1.code = '{$code}'"); $flow_id = $row['dev_flow_id']; if ($flow_id) { // 根据流程ID获取阶段 $flow = new Admin_Model_Flow(); $step = new Admin_Model_Step(); $flowRow = $flow->getRow($flow_id); $step_ids = $flowRow['step_ids']; if ($step_ids) { $stepRows = $step->getListByFlow($step_ids); $state = $stepRows[0]['step_name']; } } } // 获取所有文件的版本号 $vers = array(); foreach ($code_file_code as $c) { $d = $files->getAdapter()->query("select max(ver)+0.1 as ver from oa_doc_files where code = :code and state = 'Active' and del_flg = 0", array('code' => $c))->fetch(); $v = round($d['ver'], 1); if (strcmp($v, (int) $v) === 0) { $v .= ".0"; } $vers[] = $v; } // 新增还是编辑 if ($val->id) { $result['info'] = '修改成功'; $data = array('state' => isset($state) ? 'Reviewing' : 'Active', 'code' => implode(',', $code_file_code), 'name' => implode(',', $code_file_file), 'file_ids' => implode(',', $code_file_file_id), 'ver' => implode(',', $vers), 'description' => $code_file_desc, 'project_info' => implode(',', $code_file_project_no), 'remark' => $val->remark, 'tag' => $val->tag, 'update_time' => $now, 'update_user' => $user); $id = $val->id; $where = "id = " . $id; // 修改升版记录 $upgradeData = array('reason' => $val->reason, 'reason_type' => $val->reason_type, 'update_time' => $now, 'update_user' => $user); $upgradeWhere = "file_id = {$id}"; try { if ($id) { $upgrade->update($upgradeData, $upgradeWhere); $files->update($data, $where); $attrval = new Admin_Model_Formval(); // 自定义字段 foreach ($request as $field => $value) { if (stripos($field, "intelligenceField") !== false) { $attrId = str_replace("intelligenceField", "", $field); $menu = 'oa_doc_files_' . $id; $formval = array('attrid' => $attrId, 'value' => $value, 'menu' => $menu); $where = "attrid = " . $attrId . " and menu = '" . $menu . "'"; if ($attrval->fetchAll($where)->count() > 0) { // 更新 $attrval->update($formval, $where); } else { $attrval->insert($formval); } } } // 操作记录 $data = array('type' => "files", 'table_name' => "oa_doc_files", 'table_id' => $id, 'handle_user' => $user, 'handle_time' => $now, 'action' => "编辑", 'ip' => $_SERVER['REMOTE_ADDR']); $record->insert($data); // 审核流程 // 删除已存在的审核记录 $review->delete("type='files' and file_id = " . $id); // 把阶段信息插入review记录 $first = true; foreach ($stepRows as $s) { $plan_user = $s['user']; if ($s['dept']) { $plan_dept = $s['dept']; // 根据角色id和项目号获取用户成员列表 $roleid = $s['dept']; $codeTmp = $employee->getAdapter()->query("select project_no from oa_doc_code where code = '{$code}'")->fetchObject(); $projectno = $codeTmp->project_no; // 如果不存在项目号,则直接取角色中的用户 否则根据角色id和项目号获取roleset id $tmpUser = array(); $tmpBool = true; if ($projectno) { // 根据角色id和项目号获取roleset id $rolesetTmp = $employee->getAdapter()->query("select group_concat(id) as id from oa_product_catalog_roleset where active=1 and catalog_id='{$projectno}' and role_id in ( " . $roleid . ")")->fetchObject(); $rolesetid = $rolesetTmp->id; if ($rolesetid) { $tmpBool = false; $userTmp = $employee->getAdapter()->query("select group_concat(user_id) as ids from oa_product_catalog_roleset_member where roleset_id in ( " . $rolesetid . ")")->fetchObject(); $tmpUser = explode(',', $userTmp->ids); // 如果没有取到用户,还是使用默认用户 if (count($tmpUser) == 0) { $tmpBool = true; } } } if ($tmpBool) { foreach (explode(',', $plan_dept) as $role) { $tmpRole = $member->getMemberWithNoManager($role); foreach ($tmpRole as $m) { $tmpUser[] = $m['user_id']; } } } if (count($tmpUser) == 0 && !$plan_user) { $tmpUser = $member->getUserids("系统管理员"); } // user id 转换成employee id if (count($tmpUser) > 0) { $tmpUser = $employee->getAdapter()->query("select group_concat(employee_id) as users from oa_user where active = 1 and id in ( " . implode(',', $tmpUser) . ")")->fetchObject(); $users = $tmpUser->users; } // 获取角色所有人员 // $tmpUser = $employee->getAdapter()->query("select group_concat(id) as ids from oa_employee where dept_id in ( " . $plan_dept . ")")->fetchObject(); if ($users) { if ($plan_user) { $plan_user .= ","; } $plan_user .= $users; } $repeatUser = explode(',', $plan_user); $repeatUser = array_unique($repeatUser); $plan_user = implode(',', $repeatUser); } $reviewData = array('type' => "files", 'file_id' => $id, 'plan_dept' => $s['dept'], 'plan_user' => $plan_user, 'method' => $s['method'], 'return' => $s['return'], 'step_name' => $s['step_name'], 'step_ename' => $s['step_ename']); $review->insert($reviewData); // 邮件任务 if ($first) { $to = $employee->getAdapter()->query("select group_concat(email) as mail_to from oa_employee where id in ( " . $plan_user . ")")->fetchObject(); $content = "你有文件升版需要审核,<p><b>文件号:</b>" . implode(',', $code_file_code) . "</p><p><b>版本:</b>" . implode(',', $vers) . "</p><p><b>升版原因:</b>" . $val->reason . "</p><p><b>备注:</b>" . $val->remark . "</p><p><b>申请人:</b>" . $user_name . "</p><p><b>申请时间:</b>" . $now . "</p><p>请登录系统查看详情!</p>"; $mailData = array('type' => '升版文件', 'subject' => '升版文件评审', 'to' => $to->mail_to, 'cc' => '', 'content' => $content, 'send_time' => $now, 'add_date' => $now); $mailId = $mail->insert($mailData); if ($mailId) { $mail->send($mailId); } } $first = false; } // 没有审批流程,旧版文件自动作废 if (!isset($state)) { $sids = array($id); if (isset($sids) && count($sids) > 0) { if (count($code_file_code) > 0) { $codes = array(); foreach ($code_file_code as $c) { $codes[] = $c; } } if (isset($codes) && count($codes) > 0) { for ($i = 0; $i < count($codes); $i++) { $codes[$i] = "'" . $codes[$i] . "'"; } } $obsoluteWhere = " id not in (" . implode(',', $sids) . ") and code in (" . implode(',', $codes) . ")"; } $obsoluteData = array("state" => "Obsolete"); if (isset($obsoluteWhere)) { $files->update($obsoluteData, $obsoluteWhere); } // 更改文件状态为归档 $uploadData = array("archive" => 1, "archive_time" => $now); $uploadWhere = "id in (" . implode(',', $code_file_file_id) . ")"; // 更新文件 $upload->update($uploadData, $uploadWhere); } } } catch (Exception $e) { $result['result'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } echo Zend_Json::encode($result); exit; } else { $data = array('state' => isset($state) ? 'Reviewing' : 'Active', 'code' => implode(',', $code_file_code), 'name' => implode(',', $code_file_file), 'file_ids' => implode(',', $code_file_file_id), 'ver' => implode(',', $vers), 'description' => $code_file_desc, 'project_info' => implode(',', $code_file_project_no), 'remark' => $val->remark, 'tag' => $val->tag, 'create_time' => $now, 'create_user' => $user, 'update_time' => $now, 'update_user' => $user); try { $id = $files->insert($data); if ($id) { // 升版记录 $upgradeData = array('file_id' => $id, 'reason' => $val->reason, 'reason_type' => $val->reason_type, 'create_time' => $now, 'create_user' => $user, 'update_time' => $now, 'update_user' => $user); $upgrade->insert($upgradeData); // 自定义字段 $attrval = new Admin_Model_Formval(); foreach ($request as $field => $value) { if (stripos($field, "intelligenceField") !== false && $value) { $attrId = str_replace("intelligenceField", "", $field); $menu = 'oa_doc_files_' . $id; $formval = array('attrid' => $attrId, 'value' => $value, 'menu' => $menu); $attrval->insert($formval); } } // 操作记录 $data = array('type' => "files", 'table_name' => "oa_doc_files", 'table_id' => $id, 'handle_user' => $user, 'handle_time' => $now, 'action' => "申请", 'ip' => $_SERVER['REMOTE_ADDR']); $record->insert($data); // 审核流程 // 把阶段信息插入review记录 $first = true; foreach ($stepRows as $s) { $plan_user = $s['user']; if ($s['dept']) { $plan_dept = $s['dept']; // 根据角色id和项目号获取用户成员列表 $roleid = $s['dept']; $codeTmp = $employee->getAdapter()->query("select project_no from oa_doc_code where code = '{$code}'")->fetchObject(); $projectno = $codeTmp->project_no; // 如果不存在项目号,则直接取角色中的用户 否则根据角色id和项目号获取roleset id $tmpUser = array(); $tmpBool = true; if ($projectno) { // 根据角色id和项目号获取roleset id $rolesetTmp = $employee->getAdapter()->query("select group_concat(id) as id from oa_product_catalog_roleset where active=1 and catalog_id='{$projectno}' and role_id in ( " . $roleid . ")")->fetchObject(); $rolesetid = $rolesetTmp->id; if ($rolesetid) { $tmpBool = false; $userTmp = $employee->getAdapter()->query("select group_concat(user_id) as ids from oa_product_catalog_roleset_member where roleset_id in ( " . $rolesetid . ")")->fetchObject(); $tmpUser = explode(',', $userTmp->ids); // 如果没有取到用户,还是使用默认用户 if (count($tmpUser) == 0) { $tmpBool = true; } } } if ($tmpBool) { foreach (explode(',', $plan_dept) as $role) { $tmpRole = $member->getMemberWithNoManager($role); foreach ($tmpRole as $m) { $tmpUser[] = $m['user_id']; } } } if (count($tmpUser) == 0 && !$plan_user) { $tmpUser = $member->getUserids("系统管理员"); } // user id 转换成employee id if (count($tmpUser) > 0) { $tmpUser = $employee->getAdapter()->query("select group_concat(employee_id) as users from oa_user where active = 1 and id in ( " . implode(',', $tmpUser) . ")")->fetchObject(); $users = $tmpUser->users; } // 获取角色所有人员 // $tmpUser = $employee->getAdapter()->query("select group_concat(id) as ids from oa_employee where dept_id in ( " . $plan_dept . ")")->fetchObject(); if ($users) { if ($plan_user) { $plan_user .= ","; } $plan_user .= $users; } $repeatUser = explode(',', $plan_user); $repeatUser = array_unique($repeatUser); $plan_user = implode(',', $repeatUser); } $reviewData = array('type' => "files", 'file_id' => $id, 'plan_dept' => $s['dept'], 'plan_user' => $plan_user, 'method' => $s['method'], 'return' => $s['return'], 'step_name' => $s['step_name'], 'step_ename' => $s['step_ename']); $review->insert($reviewData); // 邮件任务 if ($first) { $to = $employee->getAdapter()->query("select group_concat(email) as mail_to from oa_employee where id in ( " . $plan_user . ")")->fetchObject(); $content = "你有文件升版需要审核,<p><b>文件号:</b>" . implode(',', $code_file_code) . "</p><p><b>版本:</b>" . implode(',', $vers) . "</p><p><b>升版原因:</b>" . $val->reason . "</p><p><b>备注:</b>" . $val->remark . "</p><p><b>申请人:</b>" . $user_name . "</p><p><b>申请时间:</b>" . $now . "</p><p>请登录系统查看详情!</p>"; $mailData = array('type' => '升版文件', 'subject' => '升版文件评审', 'to' => $to->mail_to, 'cc' => '', 'content' => $content, 'send_time' => $now, 'add_date' => $now); $mailId = $mail->insert($mailData); if ($mailId) { $mail->send($mailId); } } $first = false; } // 没有审批流程,旧版文件自动作废 if (!isset($state)) { $sids = array($id); if (isset($sids) && count($sids) > 0) { if (count($code_file_code) > 0) { $codes = array(); foreach ($code_file_code as $c) { $codes[] = $c; } } if (isset($codes) && count($codes) > 0) { for ($i = 0; $i < count($codes); $i++) { $codes[$i] = "'" . $codes[$i] . "'"; } } $obsoluteWhere = " id not in (" . implode(',', $sids) . ") and code in (" . implode(',', $codes) . ")"; } $obsoluteData = array("state" => "Obsolete"); if (isset($obsoluteWhere)) { $files->update($obsoluteData, $obsoluteWhere); } // 更改文件状态为归档 $uploadData = array("archive" => 1, "archive_time" => $now); $uploadWhere = "id in (" . implode(',', $code_file_file_id) . ")"; // 更新文件 $upload->update($uploadData, $uploadWhere); } } } catch (Exception $e) { $result['result'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } echo Zend_Json::encode($result); exit; } }
/** * @abstract 添加文件编码 * @return null */ public function saveAction() { // 返回值数组 $result = array('success' => true, 'result' => true, 'info' => '申请成功'); $request = $this->getRequest()->getParams(); $now = date('Y-m-d H:i:s'); $user_session = new Zend_Session_Namespace('user'); $user = $user_session->user_info['employee_id']; $val = (object) $request; $code = new Dcc_Model_Code(); $type = new Dcc_Model_Type(); $db = $code->getAdapter(); if ($val->id) { // 编辑 if (isset($val->code) && $val->code) { $auto_code = $val->code; // 检查是否文件号已经存在 if ($code->fetchAll("id != " . $val->id . " and code = '" . $auto_code . "'")->count() > 0) { $result['result'] = false; $result['info'] = "文件编码“" . $val->code . "”已经存在"; echo Zend_Json::encode($result); exit; } } else { $auto_code = ""; } $data = array('code' => $auto_code, 'active' => isset($val->active) ? 1 : 0, 'project_no' => $val->project_no, 'project_standard_no' => isset($val->project_standard_no) ? $val->project_standard_no : "", 'description' => $val->description, 'remark' => $val->remark, 'update_time' => $now, 'update_user' => $user); try { $code->update($data, "id = " . $val->id); $result['info'] = "修改成功"; } catch (Exception $e) { $result['result'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } else { // 检查是自动生成编码还是手动 $typedata = $db->query("select t2.automethod from oa_doc_type t1 inner join oa_doc_auto t2 on t1.autotype=t2.id where t1.state = 1 and t1.id = " . $val->prefix)->fetchObject(); if ($typedata && $typedata->automethod != 'H' && $typedata->automethod != 'A' && $typedata->automethod != 'F') { $auto_code = $this->getCode($val->prefix, $val->project_no); if (!$auto_code) { $result['result'] = false; $result['info'] = "文件编码获取失败"; echo Zend_Json::encode($result); exit; } } else { if ($typedata && $typedata->automethod == 'A' && (!isset($val->code) || !$val->code)) { $auto_code = ""; // 需发邮件 $mailId = ''; $type = "文件编码申请"; $subject = "文件号分配"; // $to = 文件管理员 $employee = new Hra_Model_Employee(); $member = new Admin_Model_Member(); $role = new Admin_Model_Role(); $toArr = array(); $roleArr = $role->getRoleIdByName('文件管理员'); $roleData = array(); if ($roleArr['role_id']) { $roleData = $member->getMember($roleArr['role_id']); } foreach ($roleData as $r) { if ($r['user_id'] == 1) { continue; } $toArr[] = $r['email']; } $to = implode(',', $toArr); if ($to) { $emp = $employee->getInfoById($user); $userName = ''; if (count($emp) > 0) { $userName = $emp[0]['cname']; } $user_name = $user_session->user_info['user_name']; $content = "<p>你有一个文件编码申请需要分配文件号</p>"; $content .= "<p><b>文件描述:</b>" . $val->description . "</p><p><b>备注:</b>" . $val->remark . "</p><p><b>申请人:</b>" . $user_name . "</p><p><b>申请时间:</b>" . $now . "</p><p>请登录系统查看详情!</p>"; $mailData = array('type' => $type, 'subject' => $subject, 'to' => $to, 'content' => $content, 'send_time' => $now, 'add_date' => $now); $mail = new Application_Model_Log_Mail(); try { $mailId = $mail->insert($mailData); } catch (Exception $e) { } if ($mailId) { $mail->send($mailId); } } } else { if ($typedata && $typedata->automethod == 'F' && (!isset($val->code) || !$val->code)) { // 流程 // 获取当前文件类别对应的流程ID $row = $type->getList("id='{$val->prefix}'"); $flow_id = ''; if ($row && count($row) > 0) { $flow_id = $row[0]['apply_flow_id']; } else { $result['info'] = "文件类型未设置审核流程"; echo Zend_Json::encode($result); exit; } // 根据流程ID获取阶段 $flow = new Admin_Model_Flow(); $step = new Admin_Model_Step(); $member = new Admin_Model_Member(); $employee = new Hra_Model_Employee(); $mail = new Application_Model_Log_Mail(); $record = new Dcc_Model_Record(); $review = new Dcc_Model_Review(); $flowRow = $flow->getRow($flow_id); $step_ids = $flowRow['step_ids']; if ($step_ids) { $data = array('prefix' => $val->prefix, 'code' => '', 'state' => 'Reviewing', 'active' => isset($val->active) ? 1 : 0, 'project_no' => $val->project_no, 'project_standard_no' => isset($val->project_standard_no) ? $val->project_standard_no : "", 'description' => $val->description, 'remark' => $val->remark, 'create_time' => $now, 'create_user' => $user, 'update_time' => $now, 'update_user' => $user); try { $id = $code->insert($data); $inserted = true; // 操作记录 $data = array('type' => "code_apply", 'table_name' => "oa_doc_code", 'table_id' => $id, 'handle_user' => $user, 'handle_time' => $now, 'action' => "申请", 'ip' => $_SERVER['REMOTE_ADDR']); $record->insert($data); } catch (Exception $e) { $result['result'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } $stepRows = $step->getListByFlow($step_ids); $state = "Reviewing"; // 把阶段信息插入review记录 $first = true; foreach ($stepRows as $s) { $plan_user = $s['user']; if ($s['dept']) { $tmpUser = array(); $plan_dept = $s['dept']; foreach (explode(',', $plan_dept) as $role) { $tmpRole = $member->getMemberWithNoManager($role); foreach ($tmpRole as $m) { $tmpUser[] = $m['user_id']; } } if (count($tmpUser) == 0 && !$plan_user) { $tmpUser = $member->getUserids("系统管理员"); } if (count($tmpUser) > 0) { $tmpUser = $employee->getAdapter()->query("select group_concat(employee_id) as users from oa_user where active = 1 and id in ( " . implode(',', $tmpUser) . ")")->fetchObject(); $users = $tmpUser->users; } if ($users) { if ($plan_user) { $plan_user .= ","; } $plan_user .= $users; } } $repeatUser = explode(',', $plan_user); $repeatUser = array_unique($repeatUser); $plan_user = implode(',', $repeatUser); $reviewData = array('type' => "code_apply", 'file_id' => $id, 'plan_user' => $plan_user, 'method' => $s['method'], 'return' => $s['return'], 'step_name' => $s['step_name'], 'step_ename' => $s['step_ename']); $review->insert($reviewData); // 邮件任务 if ($first) { // 需发邮件 $mailId = ''; $type = "文件编码申请"; $subject = "文件编码申请审核"; $user_name = $user_session->user_info['user_name']; $to = $employee->getAdapter()->query("select group_concat(email) as mail_to from oa_employee where id in ( " . $plan_user . ")")->fetchObject(); $content = "<p>你有一个文件编码申请需要审核</p>"; $content .= "<p><b>文件描述:</b>" . $val->description . "</p><p><b>备注:</b>" . $val->remark . "</p><p><b>申请人:</b>" . $user_name . "</p><p><b>申请时间:</b>" . $now . "</p><p>请登录系统查看详情!</p>"; $mailData = array('type' => $type, 'subject' => $subject, 'to' => $to->mail_to, 'content' => $content, 'send_time' => $now, 'add_date' => $now); $mailId = $mail->insert($mailData); if ($mailId) { $mail->send($mailId); } } $first = false; } $result['info'] = "申请成功,已通知相关人员审核"; echo Zend_Json::encode($result); exit; } } else { $auto_code = $val->code; // 检查是否文件号已经存在 if ($auto_code && $code->fetchAll("code = '" . $auto_code . "'")->count() > 0) { $result['result'] = false; $result['info'] = "文件编码“" . $val->code . "”已经存在"; echo Zend_Json::encode($result); exit; } } } } $auto_code = strtoupper($auto_code); $data = array('prefix' => $val->prefix, 'code' => $auto_code, 'state' => isset($state) ? 'Reviewing' : 'Active', 'active' => isset($val->active) ? 1 : 0, 'project_no' => $val->project_no, 'project_standard_no' => isset($val->project_standard_no) ? $val->project_standard_no : "", 'description' => $val->description, 'remark' => $val->remark, 'create_time' => $now, 'create_user' => $user, 'update_time' => $now, 'update_user' => $user); try { $code->insert($data); if ($auto_code) { $result['info'] = "申请成功,文件编码:{$auto_code}"; } else { $result['info'] = "申请成功,请通知管理员分配文件编码"; } } catch (Exception $e) { $result['result'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } echo Zend_Json::encode($result); exit; }
/** * @abstract 保存 * @return null */ public function saveAction() { // 返回值数组 $result = array('success' => true, 'result' => true, 'info' => '提交成功'); $request = $this->getRequest()->getParams(); $now = date('Y-m-d H:i:s'); $user_session = new Zend_Session_Namespace('user'); $user = $user_session->user_info['employee_id']; $user_name = $user_session->user_info['user_name']; $val = (object) $request; $materiel = new Product_Model_Materiel(); $record = new Dcc_Model_Record(); $review = new Dcc_Model_Review(); $employee = new Hra_Model_Employee(); $mail = new Application_Model_Log_Mail(); $member = new Admin_Model_Member(); $fadev = new Product_Model_Fadev(); $faModel = new Product_Model_Fa(); $sondev = new Product_Model_Sondev(); $flow = new Admin_Model_Flow(); $step = new Admin_Model_Step(); $db = $fadev->getAdapter(); $type = $val->upd_type; if ($type == 'new') { $bomModel = new Product_Model_Newbom(); } else { $bomModel = new Product_Model_Updbom(); } // 检查BOM信息是否完整 if (!isset($val->id) || !$val->id) { $result['result'] = false; $result['info'] = "BOM信息不完整,请重新编辑"; echo Zend_Json::encode($result); exit; } $id = $val->id; $ismanager = ""; if (isset($val->ismanager) && $val->ismanager == '1') { $ismanager = "1"; $managerState = $val->state; } // BOM完整:存在上级物料和下级物料,每个上级物料都有下级物料,替代料都存在 $bomFinishFlg = true; $facount = 0; $faData = $fadev->fetchAll("type = '{$type}' and nid = " . $id)->toArray(); if (count($faData) > 0) { $files = new Dcc_Model_Files(); foreach ($faData as $farow) { if ($farow['bom_file']) { $fileArr = explode(',', $farow['bom_file']); foreach ($fileArr as $filecode) { if ($files->fetchAll("code='{$filecode}' and state ='Active'")->count() == 0) { $result['result'] = false; $result['info'] = "BOM " . $farow['code'] . "的关联文件:“<b>" . $filecode . "</b>”不存在!"; echo Zend_Json::encode($result); exit; } } } } } $sonData = $sondev->fetchAll("nid = " . $id)->toArray(); if (count($faData) > 0 && count($sonData) > 0) { foreach ($sonData as $son) { if ($son['replace'] == "") { continue; } $replace = explode(',', $son['replace']); foreach ($replace as $r) { if ($materiel->fetchAll("code='{$r}'")->count() == 0) { $result['result'] = false; $result['info'] = "物料" . $son['code'] . "的替代料:<b>" . $r . "</b>不存在!"; echo Zend_Json::encode($result); exit; } } } foreach ($faData as $fa) { foreach ($sonData as $son) { if ($fa['recordkey'] == $son['recordkey']) { $facount++; break; } } } if ($facount != count($faData)) { $bomFinishFlg = false; } } else { $bomFinishFlg = false; } if (!$bomFinishFlg) { $result['result'] = false; $result['info'] = "BOM信息不完整,请重新编辑"; echo Zend_Json::encode($result); exit; } // 下级BOM未归档 $materielType = new Product_Model_Type(); $bomArr = array(); foreach ($faData as $fa) { if ($type == 'new') { // 检查上级bom是否已经存在,或者正在申请 $join = array(array('type' => INNERJOIN, 'table' => $bomModel->getName(), 'condition' => $fadev->getName() . '.nid = ' . $bomModel->getName() . '.id')); $jwhere = $fadev->getName() . ".code = '" . $fa['code'] . "' and (" . $bomModel->getName() . ".state = 'Active' or " . $bomModel->getName() . ".state = 'Reviewing')"; if ($fadev->getJoinCount($jwhere, $join)) { $result['result'] = false; $result['info'] = "BOM“" . $fa['code'] . "”已存在或正在申请"; echo Zend_Json::encode($result); exit; } // 检查bom的状态,不能是作废或者删除 $bomMateriel = $materiel->getMaterielByCode($fa['code']); if (!$bomMateriel) { $result['result'] = false; $result['info'] = "物料“" . $fa['code'] . "”不存在"; echo Zend_Json::encode($result); exit; } if ($bomMateriel['state'] == 'Obsolete' || $bomMateriel['state'] == 'Deleted') { $result['result'] = false; $result['info'] = "物料“" . $fa['code'] . "”已作废"; echo Zend_Json::encode($result); exit; } } // 检查下级bom是否归档 foreach ($sonData as $son) { if (isset($bomArr[$son['id']]) && $bomArr[$son['id']]) { $isbom = true; } else { if (isset($bomArr[$son['id']]) && !$bomArr[$son['id']]) { $isbom = false; } else { $d = $materiel->fetchRow('id = ' . $son['id']); $d = $materielType->fetchRow('id = ' . $d['type']); $bomArr[$son['id']] = $d['bom']; $isbom = false; } } if ($isbom) { if ($faModel->fetchAll("id = '" . $son['id'] . "'")->count() == 0) { $result['result'] = false; $result['info'] = "子BOM“" . $son['code'] . "”未归档"; echo Zend_Json::encode($result); exit; } } } } // 根据BOM获取审批流 $flow_id = ""; if (isset($val->review_flow)) { $flow_id = $val->review_flow; $flowRow = $db->query("select t1.* from oa_admin_flow t1 where t1.id='{$flow_id}'")->fetchObject(); } if (!$flow_id) { $flowRow = $db->query("select t1.* from oa_admin_flow t1 inner join oa_product_bom_config t2 on t1.flow_name=t2.flow where t2.type='{$type}'")->fetchObject(); if ($flowRow) { $flow_id = $flowRow->id; } } if (!$flow_id) { $result['result'] = false; $result['info'] = "还没有配置BOM审核流程,请联系管理员配置"; echo Zend_Json::encode($result); exit; } // 根据流程ID获取阶段 $step_ids = $flowRow->step_ids; if ($step_ids) { $stepRows = $step->getListByFlow($step_ids); $state = "Reviewing"; } $state = "Reviewing"; if (isset($managerState) && $managerState) { $state = $managerState; } if ($type == 'new') { $data = array("description" => isset($val->description) ? $val->description : "", "state" => $state, "remark" => isset($val->remark) ? $val->remark : "", "update_time" => $now, "update_user" => $user); } else { $data = array("upd_type" => isset($val->upd_type) ? $val->upd_type : "", "replace_flg" => isset($val->replace_flg) ? 1 : 0, "description" => isset($val->description) ? $val->description : "", "upd_reason" => isset($val->upd_reason) ? $val->upd_reason : "", "reason_type" => isset($val->reason_type) ? $val->reason_type : "", "state" => $state, "remark" => isset($val->remark) ? $val->remark : "", "update_time" => $now, "update_user" => $user); } if (isset($managerState) && $managerState == 'Active') { $data['archive_time'] = $now; } try { $bomModel->update($data, "id=" . $id); // 自定义字段 $attrval = new Admin_Model_Formval(); if ($type == 'new') { $table = "oa_product_bom_new"; $recordType = "bom"; } else { if ($type == 'ECO') { $table = "oa_product_bom_eco"; $recordType = "ecobom"; } else { if ($type == 'DEV') { $table = "oa_product_bom_dev"; $recordType = "devbom"; } } } $menu = $table . '_' . $id; $attrval->delete("menu = '" . $menu . "'"); foreach ($request as $field => $value) { if (stripos($field, "intelligenceField") !== false && $value) { $attrId = str_replace("intelligenceField", "", $field); $formval = array('attrid' => $attrId, 'value' => $value, 'menu' => $menu); $attrval->insert($formval); } } $action = "申请"; if ($record->fetchAll("type='{$recordType}' and table_id={$id}")->count() > 0) { $action = "编辑"; } // 操作记录 $data = array('type' => $recordType, 'table_name' => $table, 'table_id' => $id, 'handle_user' => $user, 'handle_time' => $now, 'action' => $action, 'ip' => $_SERVER['REMOTE_ADDR']); $record->insert($data); // 管理员将状态改为审核中也会触发审批流程 if (!$ismanager || isset($managerState) && $managerState == 'Reviewing') { // 审核流程 // 把阶段信息插入review记录 // 删除已有流程 $review->delete("type='{$recordType}' and file_id = {$id}"); $first = true; foreach ($stepRows as $s) { $plan_user = $s['user']; if ($s['dept']) { $tmpUser = array(); $plan_dept = $s['dept']; foreach (explode(',', $plan_dept) as $role) { $tmpRole = $member->getMemberWithNoManager($role); foreach ($tmpRole as $m) { $tmpUser[] = $m['user_id']; } } if (count($tmpUser) > 0) { $tmpUser = $employee->getAdapter()->query("select group_concat(employee_id) as users from oa_user where active = 1 and id in ( " . implode(',', $tmpUser) . ")")->fetchObject(); $users = $tmpUser->users; } if (isset($users) && $users) { if ($plan_user) { $plan_user .= ","; } $plan_user .= $users; } } $repeatUser = explode(',', $plan_user); $repeatUser = array_unique($repeatUser); $plan_user = implode(',', $repeatUser); $reviewData = array('type' => "{$recordType}", 'file_id' => $id, 'plan_user' => $plan_user, 'method' => $s['method'], 'return' => $s['return'], 'step_name' => $s['step_name'], 'step_ename' => $s['step_ename']); $review->insert($reviewData); // 邮件任务 if ($first) { $to = $employee->getAdapter()->query("select group_concat(email) as mail_to from oa_employee where id in ( " . $plan_user . ")")->fetchObject(); $boms = array(); foreach ($faData as $fa) { if ($type == 'new') { $boms[] = $fa['code']; } else { $boms[] = $fa['code'] . " V" . $fa['ver']; } } if ($type == 'new') { $content = "你有新BOM归档申请需要审核,<p>" . "<b>BOM号:</b>" . implode(',', $boms) . "</p>" . "<p><b>描述:</b>" . $val->description . "</p>" . "<p><b>备注:</b>" . $val->remark . "</p>" . "<p><b>申请人:</b>" . $user_name . "</p>" . "<p><b>申请时间:</b>" . $now . "</p>" . "<p>请登录系统查看详情!</p>"; } else { $reson_type = ""; if ($val->reason_type) { $codemaster = new Admin_Model_Codemaster(); $mstData = $codemaster->getList("type=6 and code='" . $val->reason_type . "'"); if ($mstData && count($mstData) > 0) { $reson_type = $mstData[0]['text']; } } $content = "你有新BOM升版申请需要审核,<p>" . "<b>BOM号:</b>" . implode(',', $boms) . "</p>" . "<p><b>升版类型:</b>" . $val->upd_type . "</p>" . "<p><b>升版原因分类:</b>" . $reson_type . "</p>" . "<p><b>升版原因:</b>" . $val->upd_reason . "</p>" . "<p><b>升版描述:</b>" . $val->description . "</p>" . "<p><b>备注:</b>" . $val->remark . "</p>" . "<p><b>申请人:</b>" . $user_name . "</p>" . "<p><b>申请时间:</b>" . $now . "</p>" . "<p>请登录系统查看详情!</p>"; } $mailData = array('type' => 'BOM归档审批', 'subject' => 'BOM归档审批', 'to' => $to->mail_to, 'cc' => '', 'content' => $content, 'send_time' => $now, 'add_date' => $now); $mailId = $mail->insert($mailData); if ($mailId) { $mail->send($mailId); } } $first = false; } } else { if (isset($managerState) && $managerState == 'Active') { $bomfaData = $fadev->fetchAll("type = '{$type}' and nid=" . $id)->toArray(); // 如果是多个BOM,需要拆分 foreach ($bomfaData as $bomfa) { // 升版的情况,旧版作废 $facode = $bomfa['code']; if ($type != 'new') { $obsoleteData = array("state" => "Obsolete"); $obsoleteWhere = "code = '{$facode}'"; $faModel->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) select nid, recordkey, id, code, project_no, bom_file, qty, 'EBOM', ver, type, remark 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); } // 更新所有record的finish_flg为0 $reviewWhere = "type = '{$recordType}' and file_id = {$id}"; // 审核情况 $reviewData = array("actual_user" => $user, "finish_time" => $now, "finish_flg" => '1'); // 更新审核情况 $review->update($reviewData, $reviewWhere); } } } catch (Exception $e) { $result['result'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } echo Zend_Json::encode($result); exit; }