コード例 #1
0
ファイル: ApplyController.php プロジェクト: xindalu/evolve
 /**
  * @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();
     // 根据物料类别获取审批流
     $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";
             }
         }
     }
     $ismanager = "";
     // 新增还是编辑
     if (isset($val->id) && $val->id) {
         // 检查物料描述是不是已被使用
         $desc = trim($val->description);
         // 取消描述相同检查
         /*$where = $materiel->getAdapter()->quoteInto("state!= 'Deleted' and state!= 'Return' and id != ".$val->id." and description = ?", $desc);
           if(!$desc || $materiel->fetchAll($where)->count() > 0) {
               $result['success'] = false;
               $result['result'] = false;
               $result['info'] = "物料描述已存在";
               echo Zend_Json::encode($result);
               exit;
           }*/
         $result['info'] = '修改成功';
         if (isset($val->ismanager) && $val->ismanager == '1') {
             $ma = $materiel->getById($val->id);
             $mcode = $ma['code'];
             $mcode1 = $mcode;
             if (isset($val->mcode) && $val->mcode) {
                 $mcode1 = $val->mcode;
             }
             if (isset($val->state) && ($val->state == 'Obsolete' || $val->state == 'Pre-Obsolete' || $val->state == 'Reviewing' || $val->state == 'Return')) {
                 // 检查有没得bom引用
                 $sql = "select count(*) as sum from oa_product_bom_fa fa where fa.state != 'Obsolete' and fa.recordkey in (select recordkey from oa_product_bom_son son where son.code = '{$mcode}' or son.code = '{$mcode1}')";
                 $r = $materiel->getAdapter()->query($sql)->fetchObject();
                 $count = $r->sum;
                 if ($count > 0) {
                     // 有bom在引用,不能修改为这几种状态
                     $result['success'] = false;
                     $result['result'] = false;
                     $result['info'] = "此物料有BOM在引用,不能修改为" . $val->state . "状态";
                     echo Zend_Json::encode($result);
                     exit;
                 }
             }
             $ismanager = "1";
             $data = array('type' => $val->type_id, 'state' => $val->state, 'project_no' => isset($val->project_no) ? $val->project_no : "", 'name' => $val->name, 'description' => $desc, 'remark' => $val->remark, 'update_time' => $now, 'data_file_id' => $val->data_file_id, 'first_report_id' => $val->first_report_id, 'tsr_id' => $val->tsr_id);
             if (isset($val->mcode) && $val->mcode) {
                 $data['code'] = $val->mcode;
             }
         } else {
             $data = array('type' => $val->type_id, 'project_no' => isset($val->project_no) ? $val->project_no : "", 'name' => $val->name, 'description' => $desc, 'remark' => $val->remark, 'state' => isset($state) ? 'Reviewing' : 'Active', 'update_time' => $now, 'data_file_id' => $val->data_file_id, 'first_report_id' => $val->first_report_id, 'tsr_id' => $val->tsr_id);
             if (isset($val->mcode) && $val->mcode) {
                 $data['code'] = $val->mcode;
             }
         }
         $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);
                 if (!$ismanager) {
                     // 审核流程
                     // 删除已存在的审核记录
                     $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 (isset($users) && $users) {
                                 if ($plan_user) {
                                     $plan_user .= ",";
                                 }
                                 $plan_user .= $users;
                             }
                         }
                         $repeatUser = explode(',', $plan_user);
                         $plan_user = array();
                         foreach ($repeatUser as $u) {
                             if ($u && !in_array($u, $plan_user)) {
                                 $plan_user[] = $u;
                             }
                         }
                         $plan_user = implode(',', $plan_user);
                         $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 {
         // 检查物料代码是否已被使用
         if (isset($val->mcode) && $val->mcode) {
             $where = $materiel->getAdapter()->quoteInto("state!= 'Deleted' and state!= 'Return' and code = ?", $val->mcode);
             if ($materiel->fetchAll($where)->count() > 0) {
                 $result['success'] = false;
                 $result['result'] = false;
                 $result['info'] = "物料代码已存在";
                 echo Zend_Json::encode($result);
                 exit;
             }
         }
         // 检查物料描述是不是已被使用
         $desc = trim($val->description);
         /*$where = $materiel->getAdapter()->quoteInto("state!= 'Deleted' and state!= 'Return' and description = ?", $desc);
           if(!$desc || $materiel->fetchAll($where)->count() > 0) {
               $result['success'] = false;
               $result['result'] = false;
               $result['info'] = "物料描述已存在";
               echo Zend_Json::encode($result);
               exit;
           }*/
         $data = array('type' => $val->type_id, 'name' => $val->name, 'project_no' => isset($val->project_no) ? $val->project_no : "", 'code' => isset($val->mcode) && $val->mcode ? $val->mcode : null, 'description' => $desc, 'remark' => $val->remark, 'state' => isset($state) ? 'Reviewing' : 'Active', 'create_user' => $user, 'create_time' => $now, 'update_time' => $now, 'data_file_id' => $val->data_file_id, 'first_report_id' => $val->first_report_id, 'tsr_id' => $val->tsr_id);
         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;
                 if (count($stepRows) > 0) {
                     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 (isset($users) && $users) {
                                 if ($plan_user) {
                                     $plan_user .= ",";
                                 }
                                 $plan_user .= $users;
                             }
                         }
                         $repeatUser = explode(',', $plan_user);
                         $plan_user = array();
                         foreach ($repeatUser as $u) {
                             if ($u && !in_array($u, $plan_user)) {
                                 $plan_user[] = $u;
                             }
                         }
                         $plan_user = implode(',', $plan_user);
                         $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;
                     }
                 } else {
                     // 自动生成物料编码
                     $code = $data['code'];
                     $materielData = $materiel->getById($id);
                     if (!$code) {
                         $code = $this->getCode($materielData->type, $materielData->project_no);
                     }
                     if (!$code) {
                         $result['result'] = false;
                         $result['info'] = "生成物料编码失败";
                         echo Zend_Json::encode($result);
                         exit;
                     } else {
                         $mData = array("state" => "Active", "code" => $code, "archive_time" => $now);
                         $fileWhere = "id = {$id}";
                         // 如果有ds等文件,这些文件也设置为已归档
                         $data_file_id = $materielData->data_file_id;
                         $tsr_id = $materielData->tsr_id;
                         $first_report_id = $materielData->first_report_id;
                         if ($data_file_id || $tsr_id || $first_report_id) {
                             $uploadUpdWhere = " archive = 0 and (1=0 ";
                             if ($data_file_id) {
                                 $uploadUpdWhere .= " or id = " . $data_file_id;
                             }
                             if ($tsr_id) {
                                 $uploadUpdWhere .= " or id = " . $tsr_id;
                             }
                             if ($first_report_id) {
                                 $uploadUpdWhere .= " or id = " . $first_report_id;
                             }
                             $uploadUpdWhere .= ")";
                             $uploadUpdData = array('archive' => 1, 'archive_time' => $now);
                         }
                         try {
                             // 更新文件
                             if (isset($fileWhere)) {
                                 $materiel->update($mData, $fileWhere);
                             }
                             // 更新上传文件
                             if (isset($uploadUpdData)) {
                                 $upload = new Dcc_Model_Upload();
                                 $upload->update($uploadUpdData, $uploadUpdWhere);
                             }
                             $result['info'] .= ",物料代码:" . $code;
                         } catch (Exception $e) {
                             $result['result'] = false;
                             $result['info'] = $e->getMessage();
                             echo Zend_Json::encode($result);
                             exit;
                         }
                     }
                 }
             }
         } catch (Exception $e) {
             $result['result'] = false;
             $result['info'] = $e->getMessage();
             echo Zend_Json::encode($result);
             exit;
         }
         echo Zend_Json::encode($result);
         exit;
     }
 }
コード例 #2
0
ファイル: DescController.php プロジェクト: eoasoft/evolve
 public function getoneAction()
 {
     $request = $this->getRequest()->getParams();
     $data = "";
     if (isset($request['id']) && $request['id']) {
         $id = $request['id'];
         $materiel = new Product_Model_Materiel();
         $data = $materiel->getById($id);
     }
     // 转为json格式并输出
     echo Zend_Json::encode($data);
     exit;
 }
コード例 #3
0
ファイル: BomController.php プロジェクト: xindalu/evolve
 public function autosaveAction()
 {
     // 返回值数组
     $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;
     $fas = array();
     if ($val->fa) {
         $fas = Zend_Json::decode($val->fa);
     }
     $sons = array();
     if ($val->son) {
         $sons = Zend_Json::decode($val->son);
     }
     $type = $val->type;
     if ($type == 'edit') {
         $fadev = new Product_Model_Fa();
         $sondev = new Product_Model_Son();
     } else {
         $fadev = new Product_Model_Fadev();
         $sondev = new Product_Model_Sondev();
     }
     $materiel = new Product_Model_Materiel();
     $db = $fadev->getAdapter();
     // 保存数据到临时表
     $id = $val->nid;
     $recordkey = "";
     if (isset($val->recordkey)) {
         $recordkey = $val->recordkey;
     }
     if ($type == 'edit' && !$recordkey) {
         $result['result'] = false;
         $result['info'] = "参数错误,保存失败";
         echo Zend_Json::encode($result);
         exit;
     }
     if (!$id && $type != 'edit') {
         // 如果不存在表单数据,则创建一条
         if ($type == 'new') {
             $bomModel = new Product_Model_Newbom();
         } else {
             $bomModel = new Product_Model_Updbom();
         }
         // 保存数据
         $data = array("state" => 'Draft', "create_time" => $now, "create_user" => $user, "update_time" => $now, "update_user" => $user);
         try {
             $id = $bomModel->insert($data);
         } catch (Exception $e) {
             $result['result'] = false;
             $result['info'] = $e->getMessage();
             echo Zend_Json::encode($result);
             exit;
         }
     }
     if ($type == 'edit') {
         // 2 保存fa数据
         $faDatas = array();
         $keyArr = array();
         // 清除原先的数据
         $where = "recordkey=" . $recordkey;
         $sondev->delete($where);
         // 3 保存son数据
         $fa = $fas[0];
         $faData = array("project_no" => isset($fa['project_no']) ? $fa['project_no'] : 0, "bom_file" => isset($fa['bom_file']) ? $fa['bom_file'] : "", "remark" => isset($fa['remark']) ? $fa['remark'] : "");
         $sonDatas = array();
         foreach ($sons as $son) {
             if (!$son['id']) {
                 continue;
             }
             $row = $materiel->getById($son['id']);
             if (!$row['id']) {
                 continue;
             }
             $sonData = array("nid" => 0, "recordkey" => $recordkey, "pid" => $son['pid'], "id" => $row['id'], "code" => $row['code'], "qty" => isset($son['qty']) ? $son['qty'] : 1, "remark" => isset($son['remark']) ? $son['remark'] : "", "partposition" => isset($son['partposition']) ? $son['partposition'] : "", "replace" => isset($son['replace']) ? $son['replace'] : "");
             $sonDatas[] = $sonData;
         }
         $db->beginTransaction();
         try {
             $fadev->update($faData, $where);
             foreach ($sonDatas as $sonData) {
                 $sondev->insert($sonData);
             }
             $db->commit();
             //执行commit
             $result['info'] = "编辑成功";
         } catch (Exception $e) {
             $db->rollBack();
             //如果出现错误,执行回滚操作
             $result['result'] = false;
             $result['info'] = $e->getMessage();
             echo Zend_Json::encode($result);
             exit;
         }
     } else {
         // 2 保存fa数据
         $faDatas = array();
         $keyArr = array();
         // 清除原先的数据
         $delWhere = "nid=" . $id;
         $fadev->delete($delWhere);
         $sondev->delete($delWhere);
         // 只取一次最大值,可能遇到重号
         $maxkeys1 = $db->query("select ifnull(max(recordkey),0) + 1 as maxkey from oa_product_bom_fa_dev")->fetchObject();
         $maxkeys2 = $db->query("select ifnull(max(recordkey),0) + 1 as maxkey from oa_product_bom_fa")->fetchObject();
         $recordkey1 = $maxkeys1->maxkey;
         $recordkey2 = $maxkeys2->maxkey;
         $recordkey = max($recordkey1, $recordkey2);
         $faArr = array();
         foreach ($fas as $fa) {
             $fastate = "EBOM";
             if (!$fa['id']) {
                 continue;
             }
             $row = $materiel->getById($fa['id']);
             if (!$row['id']) {
                 continue;
             }
             $ver = "";
             if ($type == 'new') {
                 $ver = "1.0";
             } else {
                 // 获取最新版本
                 $vers = $db->query("select (max(ver) + 0.1) as ver, state from oa_product_bom_fa where code = '" . $row['code'] . "'")->fetchObject();
                 if ($vers && $vers->ver) {
                     $ver = round($vers->ver, 1);
                 }
                 if ($vers && $vers->state && ($vers->state == 'EBOM' || $vers->state == 'MBOM')) {
                     $fastate = $vers->state;
                 }
                 if (!$ver) {
                     $result['result'] = false;
                     $result['info'] = "BOM:" . $row['code'] . "版本错误!";
                     echo Zend_Json::encode($result);
                     exit;
                 }
             }
             $keyArr[$row['id']] = $recordkey;
             $faArr[] = $row['id'];
             if ($type == 'MBOM') {
                 $fastate = 'MBOM';
             }
             if (!$fastate) {
                 $fastate = 'EBOM';
             }
             $faData = array("nid" => $id, "recordkey" => $recordkey, "id" => $row['id'], "code" => $row['code'], "project_no" => isset($fa['project_no']) ? $fa['project_no'] : 0, "bom_file" => isset($fa['bom_file']) ? $fa['bom_file'] : "", "qty" => 1, "state" => $fastate, "ver" => $ver, "type" => $type, "remark" => isset($fa['remark']) ? $fa['remark'] : "");
             $faDatas[] = $faData;
             $recordkey++;
         }
         // 3 保存son数据
         $sonDatas = array();
         foreach ($sons as $son) {
             if (!$son['id'] || !$son['pid']) {
                 continue;
             }
             $row = $materiel->getById($son['id']);
             if (!$row['id']) {
                 continue;
             }
             if (!in_array($son['pid'], $faArr) || !$keyArr[$son['pid']]) {
                 continue;
             }
             $sonData = array("nid" => $id, "recordkey" => $keyArr[$son['pid']], "pid" => $son['pid'], "id" => $row['id'], "code" => $row['code'], "qty" => isset($son['qty']) ? $son['qty'] : 1, "remark" => isset($son['remark']) ? $son['remark'] : "", "partposition" => isset($son['partposition']) ? $son['partposition'] : "", "replace" => isset($son['replace']) ? $son['replace'] : "");
             $sonDatas[] = $sonData;
         }
         $db->beginTransaction();
         try {
             foreach ($faDatas as $faData) {
                 $fadev->insert($faData);
             }
             foreach ($sonDatas as $sonData) {
                 $sondev->insert($sonData);
             }
             $db->commit();
             //执行commit
             $result['info'] = $id;
         } catch (Exception $e) {
             $db->rollBack();
             //如果出现错误,执行回滚操作
             $result['result'] = false;
             $result['info'] = $e->getMessage();
             echo Zend_Json::encode($result);
             exit;
         }
     }
     echo Zend_Json::encode($result);
     exit;
 }