public function getRelatedUsers($numberArr) { $userInfo = array(); $review = new Dcc_Model_Review(); $userIdsAdded = array(); foreach ($numberArr as $number) { // 获取申请人 $sql = $this->select()->setIntegrityCheck(false)->from(array('t1' => $this->_name), array('id', 'create_user', 'apply_user'))->joinLeft(array('t2' => $this->_dbprefix . 'user'), "t1.create_user = t2.id", array())->joinLeft(array('t3' => $this->_dbprefix . 'employee'), "t2.employee_id = t3.id", array('creater_email' => 'email'))->joinLeft(array('t4' => $this->_dbprefix . 'user'), "t1.apply_user = t4.id", array())->joinLeft(array('t5' => $this->_dbprefix . 'employee'), "t4.employee_id = t5.id", array('applier_email' => 'email'))->where("t1.number = '" . $number . "'"); //echo $sql.'<br><br>'; $data = $this->fetchRow($sql)->toArray(); array_push($userInfo, array('user_id' => $data['create_user'], 'email' => $data['creater_email'])); array_push($userIdsAdded, $data['create_user']); if ($data['apply_user'] && !in_array($data['apply_user'], $userIdsAdded)) { array_push($userInfo, array('user_id' => $data['apply_user'], 'email' => $data['applier_email'])); } // 获取审核人 $reviewerInfo = $review->getReviewUserInfo('purchse_req_add', $data['id']); foreach ($reviewerInfo as $info) { if (!in_array($info['user_id'], $userIdsAdded)) { array_push($userInfo, $info); } } } return $userInfo; }
public function getReqRelatedUsers($numberArr) { $userInfo = array(); $userIdsAdded = array(); $review = new Dcc_Model_Review(); $employee = new Hra_Model_Employee(); $i = 0; foreach ($numberArr as $order) { $i++; $sql = $this->select()->setIntegrityCheck(false)->from(array('t1' => $this->_name), array())->joinLeft(array('t2' => $this->_dbprefix . "erp_pur_order_items"), "t1.order_item_id = t2.id", array())->joinLeft(array('t3' => $this->_dbprefix . "erp_pur_order"), "t1.order_number = t3.number", array('order_create_user' => 'create_user'))->joinLeft(array('t4' => $this->_dbprefix . "erp_pur_req"), "t2.req_number = t4.number", array('id', 'create_user', 'apply_user'))->joinLeft(array('t5' => $this->_dbprefix . 'user'), "t4.create_user = t5.id", array())->joinLeft(array('t6' => $this->_dbprefix . 'employee'), "t5.employee_id = t6.id", array('creater_email' => 'email'))->joinLeft(array('t7' => $this->_dbprefix . 'user'), "t4.apply_user = t7.id", array())->joinLeft(array('t8' => $this->_dbprefix . 'employee'), "t7.employee_id = t8.id", array('applier_email' => 'email'))->joinLeft(array('t9' => $this->_dbprefix . 'user'), "t3.create_user = t9.id", array())->joinLeft(array('t10' => $this->_dbprefix . 'employee'), "t9.employee_id = t10.id", array('order_creater_email' => 'email'))->where("t1.order_number = '" . $order . "'"); $data = $this->fetchRow($sql)->toArray(); array_push($userInfo, array('user_id' => $data['order_create_user'], 'email' => $data['order_creater_email'])); array_push($userIdsAdded, $data['order_create_user']); if ($data['applier_email'] != '' && $data['apply_user'] && !in_array($data['apply_user'], $userIdsAdded)) { array_push($userInfo, array('user_id' => $data['apply_user'], 'email' => $data['applier_email'])); } // 添加采购申请人:直接主管 if ($data['create_user'] != '') { array_push($userInfo, array('user_id' => $data['create_user'], 'email' => $data['creater_email'])); array_push($userIdsAdded, $data['create_user']); $managerInfo = $employee->getManagerByUserId($data['create_user']); if (isset($managerInfo['email']) && $managerInfo['email'] != '' && !in_array($managerInfo['user_id'], $userIdsAdded)) { array_push($userInfo, array('user_id' => $managerInfo['user_id'], 'email' => $managerInfo['email'])); } // 添加采购申请人:部门主管 $deptManagerInfo = $employee->getDeptManagerByUserId($data['create_user']); if (isset($deptManagerInfo['email']) && $deptManagerInfo['email'] != '' && !in_array($deptManagerInfo['user_id'], $userIdsAdded)) { array_push($userInfo, array('user_id' => $deptManagerInfo['user_id'], 'email' => $deptManagerInfo['email'])); } } // 获取审核人 if ($data['id'] != '') { $reviewerInfo = $review->getReviewUserInfo('purchse_req_add', $data['id']); foreach ($reviewerInfo as $info) { if (!in_array($info['user_id'], $userIdsAdded)) { array_push($userInfo, $info); } } } } $data = array(); $ids = array(); foreach ($userInfo as $user) { if (!in_array($user['user_id'], $ids)) { array_push($data, $user); array_push($ids, $user['user_id']); } } return $data; }
public function editcatalogAction() { // 返回值数组 $result = array('success' => true, 'info' => '编辑成功'); $now = date('Y-m-d H:i:s'); $user_session = new Zend_Session_Namespace('user'); $user_id = $user_session->user_info['user_id']; $request = $this->getRequest()->getParams(); $attribute = isset($request['attribute']) ? $request['attribute'] : false; $catalog = new Product_Model_Catalog(); if ($attribute) { $catalog_id = isset($request['id']) ? $request['id'] : null; $code = isset($request['code']) ? $request['code'] : null; $code_old = isset($request['code_old']) ? $request['code_old'] : null; $stage_id = isset($request['stage_id']) && $request['stage_id'] != '' ? $request['stage_id'] : null; $remark = isset($request['remark']) ? $request['remark'] : null; $date_dvt = isset($request['date_dvt']) && $request['date_dvt'] != '' ? $request['date_dvt'] : null; $qa1_date = isset($request['qa1_date']) && $request['qa1_date'] != '' ? $request['qa1_date'] : null; $qa2_date = isset($request['qa2_date']) && $request['qa2_date'] != '' ? $request['qa2_date'] : null; $evt_date = isset($request['evt_date']) && $request['evt_date'] != '' ? $request['evt_date'] : null; $mass_production_date = isset($request['mass_production_date']) && $request['mass_production_date'] != '' ? $request['mass_production_date'] : null; if ($catalog_id && $code) { if ($catalog->fetchAll("id != " . $catalog_id . " and code = '" . $code . "'")->count() == 0) { $data = array('code' => $code, 'code_old' => $code_old, 'stage_id' => $stage_id, 'remark' => $remark, 'date_dvt' => $date_dvt, 'qa1_date' => $qa1_date, 'qa2_date' => $qa2_date, 'evt_date' => $evt_date, 'mass_production_date' => $mass_production_date, 'update_time' => $now, 'update_user' => $user_id); $where = "id = " . $catalog_id; try { $catalog->update($data, $where); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } else { $result['success'] = false; $result['info'] = '代码重复,请重新分配'; echo Zend_Json::encode($result); exit; } } else { $result['success'] = false; $result['info'] = '信息不完整,编辑失败!'; } } else { $operate = isset($request['operate']) ? $request['operate'] : null; $review = isset($request['review']) ? $request['review'] : null; $id = isset($request['id']) ? $request['id'] : null; $ids = isset($request['ids']) ? $request['ids'] : null; $active = isset($request['active']) ? $request['active'] : null; $active = $active == 'on' ? 1 : 0; $description = isset($request['description']) ? $request['description'] : null; $remark = isset($request['remark']) ? $request['remark'] : null; $code_customer = isset($request['code_customer']) ? trim($request['code_customer']) : null; $model_customer = isset($request['model_customer']) ? trim($request['model_customer']) : null; $description_customer = isset($request['description_customer']) ? $request['description_customer'] : null; $type_id = isset($request['type_id']) ? $request['type_id'] : null; $type_id = isset($request['type_id']) ? $request['type_id'] : null; $series_id = isset($request['series_id']) ? $request['series_id'] : null; $series_id = isset($request['series_id']) ? $request['series_id'] : null; $developmode_id = isset($request['developmode_id']) ? $request['developmode_id'] : null; $model_standard = isset($request['model_standard']) ? trim($request['model_standard']) : null; $model_internal = isset($request['model_internal']) ? trim($request['model_internal']) : null; if ($operate == 'delete' && $id) { // 删除 try { if ($catalog->fetchAll("id = " . $id . " and auditor_id is not null")->count() == 1) { $catalogData = $catalog->fetchRow("id = " . $id)->toArray(); $catalog->update(array('delete' => 1, 'review_info' => $catalogData['review_info'] . '<br>' . $now . ': ' . $user_session->user_info['user_name'] . ' [删除]'), "id = " . $id); } else { $catalog->delete("id = " . $id); $review = new Dcc_Model_Review(); $review->delete("type = 'product_add' and file_id = " . $id); } } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } else { if ($operate == 'disable' && $ids) { // 作废 $idArr = explode(',', $ids); foreach ($idArr as $id) { try { if ($catalog->fetchAll("id = " . $id . " and active = 1")->count() == 1) { $catalogData = $catalog->fetchRow("id = " . $id)->toArray(); $catalog->update(array('active' => 0, 'review_info' => $catalogData['review_info'] . '<br>' . $now . ': ' . $user_session->user_info['user_name'] . ' [作废]'), "id = " . $id); } } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } } else { if ($operate == 'enable' && $ids) { // 启用 $idArr = explode(',', $ids); foreach ($idArr as $id) { try { if ($catalog->fetchAll("id = " . $id . " and active = 0")->count() == 1) { $catalogData = $catalog->fetchRow("id = " . $id)->toArray(); $catalog->update(array('active' => 1, 'review_info' => $catalogData['review_info'] . '<br>' . $now . ': ' . $user_session->user_info['user_name'] . ' [启用]'), "id = " . $id); } } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } } else { if ($operate == 'edit' && $id) { // 判断是否重复 if ($catalog->fetchAll("id != " . $id . " and model_internal = '" . $model_internal . "'")->count() == 0) { //type_id = ".$type_id." and series_id = ".$series_id." and $catalogData = $catalog->fetchRow("id = " . $id)->toArray(); $data = array('active' => $active, 'type_id' => $type_id, 'series_id' => $series_id, 'developmode_id' => $developmode_id, 'model_standard' => $model_standard, 'model_internal' => $model_internal, 'description' => $description, 'remark' => $remark, 'review' => $review == 1 ? 0 : 2, 'code_customer' => $code_customer, 'model_customer' => $model_customer, 'description_customer' => $description_customer, 'update_time' => $now, 'update_user' => $user_id, 'review_info' => $catalogData['review_info'] . '<br>' . $now . ': ' . $user_session->user_info['user_name'] . ' [修改]'); $where = "id = " . $id; try { $catalog->update($data, $where); if ($catalogData['review'] == 1) { // 修改 $member = new Admin_Model_Member(); $user = new Application_Model_User(); $employee = new Hra_Model_Employee(); $flow = new Admin_Model_Flow(); $step = new Admin_Model_Step(); $review = new Dcc_Model_Review(); $flowData = $flow->fetchRow("flow_name = '产品中心-审核'")->toArray(); // 获取审核阶段 $stepIds = $flowData['step_ids']; $stepArr = explode(',', $stepIds); $i = 0; foreach ($stepArr as $s) { $stepData = $step->fetchRow("id = " . $s)->toArray(); $step_user = $stepData['user'] != '' ? $stepData['user'] : null; $step_role = $stepData['dept'] != '' ? $stepData['dept'] : null; $reviewData = array('type' => 'product_add', 'file_id' => $id, 'step_name' => $stepData['step_name'], 'plan_user' => $step_user, 'plan_dept' => $step_role, 'method' => $stepData['method'], 'return' => $stepData['return']); $review->delete("type = 'product_add' AND file_id = " . $id); $review->insert($reviewData); // 第一阶段发送邮件通知 if ($i == 0) { $employeeIdArr = array(); if ($step_user) { $tmpArr = explode(',', $stepData['user']); foreach ($tmpArr as $t) { if (!in_array($t, $employeeIdArr)) { array_push($employeeIdArr, $t); } } } if ($step_role) { $tmpArr = $member->getMember($stepData['dept']); foreach ($tmpArr as $t) { if (!in_array($t, $employeeIdArr)) { array_push($employeeIdArr, $t['employee_id']); } } } $toAddress = array(); $toIds = array(); foreach ($employeeIdArr as $employeeId) { $em = $employee->getInfoById($employeeId); array_push($toAddress, $em['email']); $u = $user->fetchRow("employee_id = " . $employeeId)->toArray(); array_push($toIds, $u['id']); } $mail = new Application_Model_Log_Mail(); $mailContent = '<div>产品中心-修改产品信息,请登录系统审核:</div> <div> <p><b>标准型号:</b>' . $catalogData['model_standard'] . ' -> ' . $model_standard . '</p> <p><b>内部型号:</b>' . $catalogData['model_internal'] . ' -> ' . $model_internal . '</p> <p><b>描述:</b>' . $description . '</p> <p><b>申请人:</b>' . $user_session->user_info['user_name'] . '</p> <p><b>申请时间:</b>' . $now . '</p> </div>'; $mailData = array('type' => '消息', 'subject' => '产品中心-修改', 'to' => implode(',', $toAddress), 'cc' => $user_session->user_info['user_email'], 'user_id' => implode(',', $toIds), 'content' => $mailContent, 'add_date' => $now); try { // 记录邮件日志并发送邮件 $mail->send($mail->insert($mailData)); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } $i++; } } else { // 变更 $noticeMails = array(); $noticeUsers = array(); $user = new Application_Model_User(); $employee = new Hra_Model_Employee(); $member = new Admin_Model_Member(); $reviewModel = new Dcc_Model_Review(); $reviewerInfo = $reviewModel->getReviewUserInfo('product_add', $id); // 审核人 $applyEmployeeData = $user->fetchRow("id = " . $catalogData['create_user'])->toArray(); $applyEmployee = $employee->fetchRow("id = " . $applyEmployeeData['employee_id'])->toArray(); // 申请人 $noticeTo = $member->getMemberWithManagerByName('产品中心-PM'); // 管理员 foreach ($noticeTo as $n) { if ($n['email'] != '' && !in_array($n['user_id'], $noticeUsers)) { array_push($noticeMails, $n['email']); array_push($noticeUsers, $n['user_id']); } } foreach ($reviewerInfo as $r) { if ($r['email'] != '' && !in_array($r['user_id'], $noticeUsers)) { array_push($noticeMails, $r['email']); array_push($noticeUsers, $r['user_id']); } } if (!in_array($catalogData['create_user'], $noticeUsers)) { array_push($noticeMails, $applyEmployee['email']); array_push($noticeUsers, $catalogData['create_user']); } $mail = new Application_Model_Log_Mail(); $mailContent = '<div>产品中心产品信息变更,请登录系统查看:</div> <div> <p><b>标准型号:</b>' . $catalogData['model_standard'] . ' -> ' . $model_standard . '</p> <p><b>内部型号:</b>' . $catalogData['model_internal'] . ' -> ' . $model_internal . '</p> <p><b>描述:</b>' . $description . '</p> <p><b>申请人:</b>' . $user_session->user_info['user_name'] . '</p> <p><b>申请时间:</b>' . $now . '</p> </div>'; $mailData = array('type' => '消息', 'subject' => '产品中心-变更', 'cc' => $user_session->user_info['user_email'], 'to' => implode(',', $noticeMails), 'user_id' => $user_id, 'content' => $mailContent, 'add_date' => $now); try { // 记录邮件日志并发送邮件 $mail->send($mail->insert($mailData)); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } else { $result['success'] = false; $result['info'] = '当前型号已存在,请勿重复添加!'; echo Zend_Json::encode($result); exit; } } else { if ($operate == 'add') { if ($catalog->fetchAll("model_internal = '" . $model_internal . "'")->count() == 0) { //type_id = ".$type_id." and series_id = ".$series_id." and $data = array('active' => $active, 'type_id' => $type_id, 'series_id' => $series_id, 'developmode_id' => $developmode_id, 'model_standard' => $model_standard, 'model_internal' => $model_internal, 'remark' => $remark, 'description' => $description, 'code_customer' => $code_customer, 'model_customer' => $model_customer, 'description_customer' => $description_customer, 'create_time' => $now, 'create_user' => $user_id, 'update_time' => $now, 'update_user' => $user_id, 'review_info' => $now . ': ' . $user_session->user_info['user_name'] . ' [添加]'); try { $catalog_id = $catalog->insert($data); $member = new Admin_Model_Member(); $user = new Application_Model_User(); $employee = new Hra_Model_Employee(); $flow = new Admin_Model_Flow(); $step = new Admin_Model_Step(); $review = new Dcc_Model_Review(); $flowData = $flow->fetchRow("flow_name = '产品中心-审核'")->toArray(); // 获取审核阶段 $stepIds = $flowData['step_ids']; $stepArr = explode(',', $stepIds); $i = 0; foreach ($stepArr as $s) { $stepData = $step->fetchRow("id = " . $s)->toArray(); $step_user = $stepData['user'] != '' ? $stepData['user'] : null; $step_role = $stepData['dept'] != '' ? $stepData['dept'] : null; $reviewData = array('type' => 'product_add', 'file_id' => $catalog_id, 'step_name' => $stepData['step_name'], 'plan_user' => $step_user, 'plan_dept' => $step_role, 'method' => $stepData['method'], 'return' => $stepData['return']); $review->insert($reviewData); // 第一阶段发送邮件通知 if ($i == 0) { $employeeIdArr = array(); if ($step_user) { $tmpArr = explode(',', $stepData['user']); foreach ($tmpArr as $t) { if (!in_array($t, $employeeIdArr)) { array_push($employeeIdArr, $t); } } } if ($step_role) { $tmpArr = $member->getMember($stepData['dept']); foreach ($tmpArr as $t) { if (!in_array($t, $employeeIdArr)) { array_push($employeeIdArr, $t['employee_id']); } } } $toAddress = array(); $toIds = array(); foreach ($employeeIdArr as $employeeId) { $em = $employee->getInfoById($employeeId); array_push($toAddress, $em['email']); $u = $user->fetchRow("employee_id = " . $employeeId)->toArray(); array_push($toIds, $u['id']); } $mail = new Application_Model_Log_Mail(); $mailContent = '<div>产品中心新增产品型号,请登录系统审核:</div> <div> <p><b>标准型号:</b>' . $model_standard . '</p> <p><b>内部型号:</b>' . $model_internal . '</p> <p><b>描述:</b>' . $description . '</p> <p><b>申请人:</b>' . $user_session->user_info['user_name'] . '</p> <p><b>申请时间:</b>' . $now . '</p> </div>'; $mailData = array('type' => '消息', 'subject' => '产品中心-新建', 'to' => implode(',', $toAddress), 'user_id' => implode(',', $toIds), 'content' => $mailContent, 'add_date' => $now); try { // 记录邮件日志并发送邮件 $mail->send($mail->insert($mailData)); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } $i++; } } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } else { $result['success'] = false; $result['info'] = '当前型号已存在,请勿重复添加!'; echo Zend_Json::encode($result); exit; } } } } } } } echo Zend_Json::encode($result); exit; }