Пример #1
0
 /**
  * @abstract    添加新文件
  * @return      null
  */
 public function saveAction()
 {
     // 返回值数组
     $result = array('success' => true, 'result' => true, 'convert' => 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'];
     if (!$user) {
         $user = $this->getRequest()->getParam('employee_id');
     }
     $val = (object) $request;
     $private = 0;
     if (isset($request['private'])) {
         $private = 1;
     }
     $upload = new Dcc_Model_Upload();
     // 新增还是编辑
     if ($val->id) {
         if (isset($_FILES['file']) && $_FILES['file']['name']) {
             $file = $_FILES['file'];
             $fileSize = $file['size'];
             $fileType = strrchr($file['name'], ".");
             $fname_arr = explode(".", $file['name']);
             $fileName = $file['name'];
             // 检查本人上传的同名文件已存在
             //                if ($upload->fetchAll("id != $val->id and name = '$fileName' and update_user = $user")->count() > 0) {
             //                    $result['result'] = false;
             //                    $result['info'] = '文件已存在';
             //
             //                    echo Zend_Json::encode($result);
             //
             //                    exit;
             //                }
             //		        $savepath = $_SERVER['DOCUMENT_ROOT']."/evolve/upload/files/".date('Y-m-d')."/";
             $savepath = "../upload/files/" . date('Y-m-d') . "/";
             $fujian_name_tmp = $this->randomkeys(15) . strtolower($fileType);
             if (!is_dir($savepath)) {
                 mkdir($savepath);
             }
             $path = $savepath . $fujian_name_tmp;
             move_uploaded_file($file["tmp_name"], $path);
             $fileType = str_replace('.', '', $fileType);
             if (!$fileSize) {
                 $fileSize = $_SERVER['CONTENT_LENGTH'];
             }
             $data = array('category' => $val->category, 'name' => $fileName, 'type' => $fileType, 'size' => $fileSize, 'path' => $path, 'description' => $val->description, 'remark' => $val->remark, 'private' => $private, 'upload_time' => $now, 'update_time' => $now, 'update_user' => $user);
         } else {
             $data = array('category' => $val->category, 'description' => $val->description, 'remark' => $val->remark, 'private' => $private, 'update_time' => $now, 'update_user' => $user);
         }
         $id = $val->id;
         $where = "id = " . $id;
         try {
             $upload->update($data, $where);
             if ($id && ($val->employeeId || $val->deptId)) {
                 $share = new Dcc_Model_Share();
                 $where = "shared_id = " . $id;
                 if ($share->fetchAll($where)->count() > 0) {
                     // 更新
                     $shareData = array('type' => 'upload', 'share_user' => str_replace('E', '', $val->employeeId), 'share_dept' => str_replace('D', '', $val->deptId), 'share_time_begin' => $val->share_time_begin ? $val->share_time_begin : '2013-01-01', 'share_time_end' => $val->share_time_end ? $val->share_time_end : '2099-12-31');
                     $share->update($shareData, $where);
                 } else {
                     // 插入
                     $shareData = array('type' => 'upload', 'shared_id' => $id, 'share_user' => str_replace('E', '', $val->employeeId), 'share_dept' => str_replace('D', '', $val->deptId), 'share_time_begin' => $val->share_time_begin, 'share_time_end' => $val->share_time_end, 'create_user' => $user, 'create_time' => $now);
                     $share->insert($shareData);
                 }
                 // 共享
             }
         } catch (Exception $e) {
             $result['result'] = false;
             $result['info'] = $e->getMessage();
             echo Zend_Json::encode($result);
             exit;
         }
         echo Zend_Json::encode($result);
         exit;
     } else {
         if (!isset($val->uploadedFileIds)) {
             // 没有上传文件
             $result['result'] = false;
             $result['info'] = '没有上传文件';
             echo Zend_Json::encode($result);
             exit;
         }
         $filesarr = explode(',', $val->uploadedFileIds);
         foreach ($filesarr as $id) {
             $data = array('category' => isset($val->category) ? $val->category : null, 'description' => $val->description, 'remark' => $val->remark, 'private' => $private);
             $where = "id = {$id}";
             try {
                 $rows = $upload->update($data, $where);
                 if ($rows && ($val->employeeId || $val->deptId)) {
                     $share = new Dcc_Model_Share();
                     // 共享
                     $shareData = array('type' => 'upload', 'shared_id' => $id, 'share_user' => str_replace('E', '', $val->employeeId), 'share_dept' => str_replace('D', '', $val->deptId), 'share_time_begin' => $val->share_time_begin ? $val->share_time_begin : '2013-01-01', 'share_time_end' => $val->share_time_end ? $val->share_time_end : '2099-12-31', 'create_user' => $user, 'create_time' => $now);
                     $share->insert($shareData);
                 }
             } catch (Exception $e) {
                 $result['result'] = false;
                 $result['info'] = $e->getMessage();
             }
         }
         echo Zend_Json::encode($result);
         exit;
     }
 }
Пример #2
0
 /**
  * 获取文件编码及文件信息
  */
 public function getfilesbyidAction()
 {
     // 获取参数
     $request = $this->getRequest()->getParams();
     $id = $request['id'];
     $user_session = new Zend_Session_Namespace('user');
     $user = $user_session->user_info['employee_id'];
     $myDept = $user_session->user_info['dept_id'];
     $nowDate = date('Y-m-d');
     $files = new Dcc_Model_Files();
     $record = new Dcc_Model_Record();
     $upload = new Dcc_Model_Upload();
     $codeModel = new Dcc_Model_Code();
     $share = new Dcc_Model_Share();
     $review = new Dcc_Model_Review();
     $modelUser = new Application_Model_User();
     $data = $files->getDataById($id);
     // [id, code, ver, file_id, file_name, file_path, file_view_path]
     $result = array();
     $row0 = $data[0];
     $names = explode(',', $row0['name']);
     $codes = explode(',', $row0['code']);
     $vers = explode(',', $row0['ver']);
     $description = explode('|', $row0['description']);
     $project_info = explode(',', $row0['project_info']);
     $final_codes = array();
     $final_vers = array();
     $final_names = array();
     $final_descs = array();
     $final_projs = array();
     $k = 0;
     for ($i = 0; $i < count($names); $i++) {
         $sub_names = explode('|', $names[$i]);
         $final_codes[$k] = $codes[$i];
         $final_vers[$k] = $vers[$i];
         if (isset($description[$i]) && $description[$i]) {
             $final_descs[$k] = $description[$i];
         } else {
             $final_descs[$k] = "";
         }
         if (isset($project_info[$i]) && $project_info[$i]) {
             $final_projs[$k] = $project_info[$i];
         } else {
             $final_projs[$k] = "";
         }
         $final_names[$k] = $sub_names[0];
         $k++;
         for ($j = 1; $j < count($sub_names); $j++) {
             $final_codes[$k] = $codes[$i];
             $final_vers[$k] = $vers[$i];
             $final_names[$k] = $sub_names[$j];
             if (isset($description[$i]) && $description[$i]) {
                 $final_descs[$k] = $description[$i];
             } else {
                 $final_descs[$k] = "";
             }
             if (isset($project_info[$i]) && $project_info[$i]) {
                 $final_projs[$k] = $project_info[$i];
             } else {
                 $final_projs[$k] = "";
             }
             $k++;
         }
     }
     $catalog = new Product_Model_Catalog();
     for ($i = 0; $i < count($data); $i++) {
         $paths = $this->getPathByName($data, trim($final_names[$i]));
         $row = $data[$i];
         $result[$i]['id'] = $row['id'];
         $result[$i]['state'] = $row['state'];
         if ($final_descs[$i]) {
             $result[$i]['description'] = $final_descs[$i];
         } else {
             // 获取描述
             $descData = $codeModel->getJoinList("code = '{$final_codes[$i]}'", array(), array('description', 'project_no'));
             if (count($descData) > 0) {
                 $result[$i]['description'] = $descData[0]['description'];
                 if (!$final_projs[$i]) {
                     $final_projs[$i] = $descData[0]['project_no'];
                 }
             }
         }
         $result[$i]['project_no'] = $final_projs[$i];
         if ($final_projs[$i]) {
             $projData = $catalog->getById($final_projs[$i]);
             if ($projData && $projData['model_internal']) {
                 $result[$i]['project_name'] = $projData['model_internal'];
             }
         }
         $result[$i]['code'] = $final_codes[$i];
         $result[$i]['ver'] = $final_vers[$i];
         $result[$i]['file_id'] = $paths[0];
         $result[$i]['file_name'] = $final_names[$i];
         $result[$i]['file_path'] = $paths[1];
         $result[$i]['file_view_path'] = $paths[2];
         // 权限检查
         // 有权限的情况:1、本人上传的文件 2、本人提交的文件评审 3、本人参与审核的文件评审 4、共享给我的 5、将要审核的审核人 6、文件管理员、BOM管理员、物料管理员
         // 首先检查文件是否存在
         $result[$i]['exists'] = true;
         if (!file_exists($paths[1])) {
             $result[$i]['exists'] = false;
         }
         $role = false;
         if ($modelUser->checkPermissionByRoleName('物料管理员') || $modelUser->checkPermissionByRoleName('文件管理员') || $modelUser->checkPermissionByRoleName('系统管理员') || $modelUser->checkPermissionByRoleName('BOM管理员')) {
             $role = true;
         } else {
             if ($row0['create_user'] == $user || $row0['update_user'] == $user) {
                 $role = true;
             } else {
                 if ($record->fetchAll("table_id = {$id} and handle_user = {$user} and table_name = 'oa_doc_files' and action = '审批'")->count() > 0) {
                     $role = true;
                 } else {
                     if ($upload->fetchAll("id = " . $row['id'] . " and (create_user = {$user} or update_user = {$user})")->count() > 0) {
                         $role = true;
                     } else {
                         if ($share->fetchAll("shared_id = " . $row['id'] . " and type = 'upload' and share_time_begin <= '{$nowDate}' and share_time_end >= '{$nowDate}'  and (FIND_IN_SET({$user}, share_user) or FIND_IN_SET({$myDept}, share_dept))")->count() > 0) {
                             $role = true;
                         } else {
                             if ($review->fetchAll("file_id = {$id} and FIND_IN_SET({$user}, plan_user) and type = 'files'")->count() > 0) {
                                 $role = true;
                             }
                         }
                     }
                 }
             }
         }
         $result[$i]['role'] = $role;
     }
     echo Zend_Json::encode($result);
     exit;
 }
Пример #3
0
 /**
  * @abstract    获取文件JSON数据
  * @return      null
  */
 public function getfilesAction()
 {
     // 请求参数
     $request = $this->getRequest()->getParams();
     $limit = $request['limit'];
     $start = $request['start'];
     $whereSearch = "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");
                 $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] . "%'";
                 }
                 $whereSearch .= " and " . join(' AND ', $arr);
                 //                     $whereSearch .= " 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) {
                     $whereSearch .= " and t.category = '{$v}'";
                 } else {
                     $col = str_replace('search_', '', $k);
                     if ($col != $k) {
                         // 查询条件
                         $whereSearch .= " 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();
     // 我的ID
     $user_session = new Zend_Session_Namespace('user');
     $myId = $user_session->user_info['employee_id'];
     $myDept = $user_session->user_info['dept_id'];
     // 类型
     $myType = "";
     if (isset($request['mytype'])) {
         $myType = $request['mytype'];
     }
     $file_ids = array();
     if ($myType == 4 || $myType == '') {
         // 4、共享给我的
         // 查询共享给我的文件ID
         $share = new Dcc_Model_Share();
         $nowDate = date('Y-m-d');
         $uploadRows = $share->fetchAll("type = 'upload' and share_time_begin <= '{$nowDate}' and share_time_end >= '{$nowDate}'  and (FIND_IN_SET({$myId}, share_user) or FIND_IN_SET({$myDept}, share_dept))")->toArray();
         for ($i = 0; $i < count($uploadRows); $i++) {
             $upload_id = $uploadRows[$i]['shared_id'];
             // 查询使用了此上传文件的文件
             $filesRows = $files->fetchAll("state != 'Deleted' and del_flg = 0 and FIND_IN_SET({$upload_id}, file_ids)")->toArray();
             for ($j = 0; $j < count($filesRows); $j++) {
                 $file_id = $filesRows[$j]['id'];
                 if (!in_array($file_id, $file_ids)) {
                     $file_ids[] = $file_id;
                 }
             }
         }
     }
     //         $datas = $files->getMy($myType, $whereSearch, $myId, $file_ids, $start, $limit);
     $totalData = $files->getMyCount($myType, $whereSearch, $myId, $file_ids);
     $totalCount = count($totalData);
     $datas = array_slice($totalData, $start, $limit);
     $data = array();
     foreach ($datas as $tmp) {
         $mytype = 2;
         if ($tmp['create_user'] == $myId) {
             $mytype = 1;
         } else {
             if (in_array($tmp['id'], $file_ids)) {
                 $mytype = 4;
             }
         }
         $tmp['create_time'] = strtotime($tmp['create_time']);
         $tmp['update_time'] = strtotime($tmp['update_time']);
         $tmp['archive_time'] = strtotime($tmp['archive_time']);
         $tmp['codever'] = $tmp['code'] . ' V' . $tmp['ver'];
         $tmp['send_require'] = $tmp['send_require'] == 1 ? true : false;
         $tmp['description'] = $tmp['code_description'];
         // 增加审核状态
         $reviewState = "";
         $step_name = "";
         if ($tmp['state'] == 'Active') {
             $reviewState = "已发布";
         } else {
             if ($tmp['state'] == 'Reviewing') {
                 // 查询当前审核状态
                 // 查询所有审核阶段
                 $reviewRows = $review->getList("file_id = " . $tmp['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) {
                                 $tmp['review_id'] = $row['id'];
                                 $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();
                                 /* if ($method == 1 && $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 ($planUser)
                                    $planUser .= ",";
                                    $planUser .= $tmpUser->ids;
                                    }
                                    } else if ($method == 2 && $plan_dept) {
                                    $tmpDept = $step->getAdapter()->query("select group_concat(name) as name from oa_employee_dept where id in ( " . $plan_dept . ")")->fetchObject();
                                    $step_dept_name = $tmpDept->name;
                                    if ($step_dept_name) {
                                    $depts = explode(',', $step_dept_name);
                                    }
                                    } */
                                 $plan_user = explode(',', $planUser);
                                 $diff = array_diff($plan_user, $actual_user);
                                 foreach ($diff as $u) {
                                     if (!$u) {
                                         continue;
                                     }
                                     if ($u == $myId) {
                                         $mytype = 3;
                                     }
                                     $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 ($tmp['state'] == 'Obsolete') {
                     $reviewState = "已作废";
                 } else {
                     if ($tmp['state'] == 'Return') {
                         $reviewState = "退回";
                     } else {
                         $reviewState = $tmp['state'];
                     }
                 }
             }
         }
         $tmp['step_name'] = $step_name;
         $tmp['review_state'] = $reviewState;
         if ($tmp['reason_type']) {
             $masterData = $codemaster->fetchRow("type = 5 and code = '" . $tmp['reason_type'] . "'");
             $reason_type_name = $masterData->text;
             $tmp['reason_type_name'] = $reason_type_name;
         }
         // int转换为字符串
         $tmp['mytype'] = " " + $mytype;
         $data[] = $tmp;
     }
     // 排序
     $dataT3 = array();
     $dataT1 = array();
     $dataT2 = array();
     $dataT4 = array();
     for ($i = 0; $i < count($data); $i++) {
         if ($data[$i]['mytype'] == 3) {
             $dataT3[] = $data[$i];
         } else {
             if ($data[$i]['mytype'] == 1) {
                 $dataT1[] = $data[$i];
             } else {
                 if ($data[$i]['mytype'] == 2) {
                     $dataT2[] = $data[$i];
                 } else {
                     $dataT4[] = $data[$i];
                 }
             }
         }
     }
     $data = array_merge($dataT3, $dataT1, $dataT2, $dataT4);
     $resutl = array("totalCount" => $totalCount, "topics" => $data);
     echo Zend_Json::encode($resutl);
     exit;
 }