示例#1
0
 public function getlistAction()
 {
     $request = $this->getRequest()->getParams();
     $limit = $request['limit'];
     $start = $request['start'];
     $desc = new Product_Model_Desc();
     $descName = $desc->getName();
     $whereSearch = "1=1";
     $mytype = $this->getRequest()->getParam('mytype');
     if ($mytype == 3) {
         $whereSearch = "{$descName}.state = 'Reviewing'";
     }
     foreach ($request as $k => $v) {
         if ($v) {
             if ($k == 'search_tag') {
                 $whereSearch .= " and (ifnull({$descName}.remark,'') like '%{$v}%' or ifnull({$descName}.manufacturers_before,'') like '%{$v}%' or ifnull({$descName}.manufacturers_after,'') like '%{$v}%' or ifnull({$descName}.desc_before,'') like '%{$v}%' or ifnull({$descName}.desc_after,'') like '%{$v}%')";
             } else {
                 $col = str_replace('search_', '', $k);
                 if ($col != $k) {
                     // 查询条件
                     $whereSearch .= " and ifnull({$descName}." . $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();
     $review = new Dcc_Model_Review();
     $employee = new Hra_Model_Employee();
     // 查询条件
     // 供应商
     $supply = new Product_Model_Bpartner();
     $supplyData = $supply->getJoinList(array(), array(), array('id', 'code', 'cname', 'ename'));
     // 审核中
     $reviewingData = $review->getJoinList("finish_flg = 0 and type = 'materiel_desc' and (actual_user is null or !(FIND_IN_SET({$user},actual_user))) and (FIND_IN_SET({$user}, plan_user))", array(), array('table_id'));
     $reviewingIds = array();
     foreach ($reviewingData as $r) {
         if (!in_array($r['id'], $reviewingIds)) {
             $reviewingIds[] = $r['id'];
         }
     }
     // 审核过
     $reviewedData = $review->getJoinList("finish_flg = 1 and type = 'materiel_desc' and (FIND_IN_SET({$user},actual_user))", array(), array('table_id'));
     $reviewedIds = array();
     foreach ($reviewedData as $r) {
         if (!in_array($r['id'], $reviewedIds)) {
             $reviewedIds[] = $r['id'];
         }
     }
     $join = array(array('type' => INNERJOIN, 'table' => $employee->getName(), 'condition' => $employee->getName() . '.id = ' . $desc->getName() . '.create_user'));
     $myType = "";
     if (isset($request['mytype'])) {
         $myType = $request['mytype'];
     }
     if ($myType == 1) {
         $whereSearch .= " and {$descName}.create_user = {$user}";
     } else {
         if ($myType == 2 && count($reviewedIds) > 0) {
             $whereSearch .= " and {$descName}.id in (" . implode(',', $reviewedIds) . ")";
         } else {
             if ($myType == 3 && count($reviewingIds) > 0) {
                 $whereSearch .= " and {$descName}.id in (" . implode(',', $reviewingIds) . ")";
             } else {
                 //            $whereSearch .= " and ($descName.create_user = $user ";
                 $whereSearch .= " and (1=1 ";
                 if (count($reviewedIds) > 0) {
                     $whereSearch .= " or {$descName}.id in (" . implode(',', $reviewedIds) . ")";
                 }
                 if (count($reviewingIds) > 0) {
                     $whereSearch .= " or {$descName}.id in (" . implode(',', $reviewingIds) . ")";
                 }
                 $whereSearch .= ")";
             }
         }
     }
     $total = $desc->getJoinCount($whereSearch);
     if ($total > 0) {
         $join = array(array('type' => INNERJOIN, 'table' => $employee->getName(), 'condition' => $employee->getName() . '.id = ' . $desc->getName() . '.create_user', 'cols' => array('creater' => 'cname')));
         $data = $desc->getJoinList($whereSearch, $join, null, array($desc->getName() . '.state desc', $desc->getName() . '.create_time desc'), $start, $limit);
     } else {
         $data = array();
     }
     $fileIds = array();
     // 获取物料数据
     for ($i = 0; $i < count($data); $i++) {
         $mytype = 2;
         if ($data[$i]['create_user'] == $user) {
             $mytype = 1;
         }
         if (($typeId = $data[$i]['type_before']) != '') {
             $typeName = $type->getTypeByConnect($typeId, '');
             $data[$i]['type_name'] = $typeName;
         }
         $data[$i]['create_time'] = strtotime($data[$i]['create_time']);
         $data[$i]['archive_time'] = strtotime($data[$i]['archive_time']);
         // files
         if ($data[$i]['data_file_id_before'] && !in_array($data[$i]['data_file_id_before'], $fileIds)) {
             $fileIds[] = $data[$i]['data_file_id_before'];
         }
         if ($data[$i]['data_file_id_after'] && !in_array($data[$i]['data_file_id_after'], $fileIds)) {
             $fileIds[] = $data[$i]['data_file_id_after'];
         }
         if ($data[$i]['tsr_id_before'] && !in_array($data[$i]['tsr_id_before'], $fileIds)) {
             $fileIds[] = $data[$i]['tsr_id_before'];
         }
         if ($data[$i]['tsr_id_after'] && !in_array($data[$i]['tsr_id_after'], $fileIds)) {
             $fileIds[] = $data[$i]['tsr_id_after'];
         }
         if ($data[$i]['first_report_id_before'] && !in_array($data[$i]['first_report_id_before'], $fileIds)) {
             $fileIds[] = $data[$i]['first_report_id_before'];
         }
         if ($data[$i]['first_report_id_after'] && !in_array($data[$i]['first_report_id_after'], $fileIds)) {
             $fileIds[] = $data[$i]['first_report_id_after'];
         }
         // 增加审核状态
         $reviewState = "";
         $step_name = "";
         if ($data[$i]['state'] == 'Active') {
             $reviewState = "已归档";
         } else {
             if ($data[$i]['state'] == 'Reviewing') {
                 // 查询当前审核状态
                 // 查询所有审核阶段
                 $reviewRows = $review->getList("file_id = " . $data[$i]['id'], "materiel_desc");
                 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 {
                         $reviewState = $data[$i]['state'];
                     }
                 }
             }
         }
         $data[$i]['step_name'] = $step_name;
         $data[$i]['review_state'] = $reviewState;
         $data[$i]['mytype'] = $mytype;
         $data[$i]['record'] = $record->getHis($data[$i]['id'], 'materiel_desc');
     }
     // get file names
     if (count($fileIds) > 0) {
         $upload = new Dcc_Model_Upload();
         $fileData = $upload->getJoinList("id in (" . implode(',', $fileIds) . ")", array(), array('id', 'name'));
         $files = array();
         foreach ($fileData as $f) {
             $files[$f['id']] = $f['name'];
         }
         // data rebuild
         for ($i = 0; $i < count($data); $i++) {
             if ($data[$i]['data_file_id_before'] && in_array($data[$i]['data_file_id_before'], $fileIds)) {
                 $data[$i]['data_file_before'] = $files[$data[$i]['data_file_id_before']];
             }
             if ($data[$i]['data_file_id_after'] && in_array($data[$i]['data_file_id_after'], $fileIds)) {
                 $data[$i]['data_file_after'] = $files[$data[$i]['data_file_id_after']];
             }
             if ($data[$i]['tsr_id_before'] && in_array($data[$i]['tsr_id_before'], $fileIds)) {
                 $data[$i]['tsr_before'] = $files[$data[$i]['tsr_id_before']];
             }
             if ($data[$i]['tsr_id_after'] && in_array($data[$i]['tsr_id_after'], $fileIds)) {
                 $data[$i]['tsr_after'] = $files[$data[$i]['tsr_id_after']];
             }
             if ($data[$i]['first_report_id_before'] && in_array($data[$i]['first_report_id_before'], $fileIds)) {
                 $data[$i]['first_report_before'] = $files[$data[$i]['first_report_id_before']];
             }
             if ($data[$i]['first_report_id_after'] && in_array($data[$i]['first_report_id_after'], $fileIds)) {
                 $data[$i]['first_report_after'] = $files[$data[$i]['first_report_id_after']];
             }
         }
     }
     // 转为json格式并输出
     $resutl = array("totalCount" => $total, "topics" => $data);
     echo Zend_Json::encode($resutl);
     exit;
 }