/** * 处理审批流程 */ public function reviewAction() { $tuduId = $this->_request->getPost('tid'); $isAgree = (bool) $this->_request->getPost('agree'); $content = $this->_request->getPost('content'); $params = array('orgid' => $this->_user->orgId, 'boardid' => '^app-attend', 'poster' => $this->_user->trueName, 'posterinfo' => $this->_user->posotion, 'email' => $this->_user->userName, 'tuduid' => $tuduId, 'agree' => $isAgree, 'content' => $content, 'uniqueid' => $this->_user->uniqueId); $tudu = new Model_Tudu_Tudu($params); $tudu->setExtension(new Model_App_Attend_Tudu_Apply()); $tudu->setExtension(new Model_Tudu_Extension_Flow()); $tudu->setAttributes(array('operation' => 'review')); try { $model = new Model_Tudu_Compose_Review(); $model->execute('compose', array(&$tudu)); $config = $this->_this->bootstrap->getOption('httpsqs'); $modelSend = new Model_Tudu_Send_Common(array('httpsqs' => $config)); $modelSend->send(&$tudu); } catch (Model_Tudu_Exception $e) { $message = $this->lang['review_failure']; /*switch ($e->getCode()) { case Model_App_Attend_Exception::APPLY_MISSING_CATEGORYID: $message = $this->lang['invalid_categoryid']; break ; case Model_App_Attend_Exception::APPLY_INVALID_ENDTIME: $message = $this->lang['invalid_endtime']; break ; case Model_App_Attend_Exception::APPLY_INVALID_STARTTIME: $message = $this->lang['invalid_starttime']; break ; case Model_App_Attend_Exception::CATEGORY_NOT_EXISTS: $this->lang['category_not_exists']; break; }*/ return $this->json(false, $message); } return $this->_this->json(true, $this->lang['review_apply_success']); }
/** * /compose/reply * * 回覆 */ public function replyAction() { $tuduId = $this->_request->getPost('tid'); $action = $this->_request->getPost('action'); $type = $this->_request->getPost('type'); $post = $this->_request->getPost(); $uniqueId = $this->_user->uniqueId; $fromPost = null; $fromPostId = trim($this->_request->getPost('fpid')); $isDoneTudu = false; /* @var $manager Tudu_Tudu_Manager */ $manager = Tudu_Tudu_Manager::getInstance(); /* @var $storage Tudu_Tudu_Storage */ $storage = Tudu_Tudu_Storage::getInstance(); $tudu = $manager->getTuduById($tuduId, $uniqueId); if (null === $tudu) { return $this->json(false, $this->lang['tudu_not_exists']); } // 编辑回复的权限判断 if ($this->_user->orgId != $tudu->orgId) { return $this->json(false, $this->lang['tudu_not_exists']); } // 已确认图度 if ($tudu->isDone) { return $this->json(false, $this->lang['tudu_is_done']); } if ($fromPostId) { $fromPost = $manager->getPostById($tuduId, $fromPostId); } $isReceiver = $this->_user->uniqueId == $tudu->uniqueId && count($tudu->labels); $isAccepter = in_array($this->_user->userName, $tudu->accepter, true); $isSender = in_array($tudu->sender, array($this->_user->address, $this->_user->account)); $sendParam = array(); if ('modify' == $action) { if (null == $fromPost) { return $this->json(false, $this->lang['post_not_exists']); } // 编辑回复的权限判断 if (!$this->_user->getAccess()->isAllowed(Tudu_Access::PERM_UPDATE_POST) && $fromPost->isSend) { return $this->json(false, $this->lang['perm_deny_update_post']); } // 非回复者时,需要判断版主的权限 if ($fromPost->uniqueId != $this->_user->uniqueId) { $boards = $this->getBoards(false); $board = $boards[$tudu->boardId]; $isModerators = array_key_exists($this->_user->userId, $board['moderators']); if (!$isModerators) { return $this->json(false, $this->lang['perm_deny_update_post']); } } if (!$fromPost->isSend) { $sendParam['remind'] = true; } } else { // 发表回复的权限判断 - 参与人员或回复权限 if (!$isReceiver && !$this->_user->getAccess()->isAllowed(Tudu_Access::PERM_CREATE_POST)) { return $this->json(false, $this->lang['perm_deny_create_post']); } // 需要发送提醒 $sendParam['remind'] = true; } // 空内容 if ($type != 'save' && empty($post['content'])) { return $this->json(false, $this->lang['missing_content']); } // 构造参数 $params = array('orgid' => $tudu->orgId, 'boardid' => $tudu->boardId, 'tuduid' => $tudu->tuduId, 'uniqueid' => $uniqueId, 'email' => $this->_user->userName, 'poster' => $this->_user->trueName, 'posterinfo' => $this->_user->position, 'content' => $post['content'], 'attachment' => !empty($post['attach']) ? array_unique((array) $post['attach']) : array(), 'file' => !empty($post['file']) ? array_unique((array) $post['file']) : array()); $elapsedtime = round((double) $this->_request->getPost('elapsedtime'), 2) * 3600; $percent = min(100, (int) $this->_request->getPost('percent')); if ($fromPost && $fromPost->isSend) { $isLog = $fromPost->isLog; $params['elapsedtime'] = $fromPost->elapsedtime; $params['percent'] = $fromPost->percent; } else { if (isset($post['percent'])) { $isLog = $percent != $tudu->selfPercent || $elapsedtime > 0; } else { $isLog = $elapsedtime > 0; } } $params['islog'] = $isLog; if ($isLog && $tudu->selfPercent < 100) { $params['elapsedtime'] = $elapsedtime; $params['percent'] = $percent; } // 处理网盘附件 if (!empty($post['nd-attach'])) { $params['attachment'] = array_diff($params['attachment'], $post['nd-attach']); $daoNdFile = $this->getDao('Dao_Td_Netdisk_File'); $daoAttachment = $this->getDao('Dao_Td_Attachment_File'); foreach ($post['nd-attach'] as $ndfileId) { $fileId = $ndfileId; $attach = $daoAttachment->getFile(array('fileid' => $fileId)); if (null !== $attach) { $params['attachment'][] = $fileId; continue; } $file = $daoNdFile->getFile(array('uniqueid' => $this->_user->uniqueId, 'fileid' => $ndfileId)); if ($file->fromFileId) { $fileId = $file->fromFileId; } if ($file->attachFileId) { $fileId = $file->attachFileId; } $ret = $daoAttachment->createFile(array('uniqueid' => $this->_user->uniqueId, 'fileid' => $fileId, 'orgid' => $this->_user->orgId, 'filename' => $file->fileName, 'path' => $file->path, 'type' => $file->type, 'size' => $file->size, 'createtime' => time())); if ($ret) { $params['attachment'][] = $fileId; } } } if (!$fromPost) { $postId = $storage->createPost($params); if (!$postId) { return $this->json(false, $this->lang['post_send_failure']); } // 添加操作日志 $this->_writeLog(Dao_Td_Log_Log::TYPE_POST, $postId, Dao_Td_Log_Log::ACTION_CREATE, $params); } else { $postId = $fromPost->postId; // 增加最后编辑信息 if ($fromPost->isSend) { $params['lastmodify'] = implode(chr(9), array($uniqueId, $this->_timestamp, $this->_user->trueName)); } else { $params['createtime'] = time(); } $storage->updatePost($tuduId, $postId, $params); // 记录更新内容 $arrFromPost = $fromPost->toArray(); $updates = array(); foreach ($params as $key => $val) { if (in_array($key, array('file', 'attachment'))) { continue; } if ($val != $arrFromPost[$key]) { $updates[$key] = $val; } } // 添加操作日志 $this->_writeLog(Dao_Td_Log_Log::TYPE_POST, $postId, Dao_Td_Log_Log::ACTION_CREATE, $updates); } if ($type != 'save') { // 未读 if (!$fromPost || !$fromPost->isSend) { $manager->markAllUnread($tudu->tuduId); } // 标记已经读 // 加入了批量更新和回复,所以在更新时就需要标示已读 if ($tudu->isRead) { $manager->markRead($tudu->tuduId, $this->_user->uniqueId, true); } $config = $this->bootstrap->getOption('httpsqs'); // 插入消息队列 $httpsqs = new Oray_Httpsqs($config['host'], $config['port'], $config['chartset'], $config['name']); $tuduPercent = $tudu->percent; $flowPercent = null; if ($isLog && $tudu->selfPercent < 100) { if ($tudu->flowId) { $tuduPercent = $manager->updateFlowProgress($tudu->tuduId, $tudu->uniqueId, $tudu->stepId, (int) $params['percent'], $flowPercent); } else { $tuduPercent = $manager->updateProgress($tudu->tuduId, $tudu->uniqueId, (int) $params['percent']); } if (!$fromPost || !$fromPost->isSend) { // 添加操作日志 $this->_writeLog(Dao_Td_Log_Log::TYPE_TUDU, $tudu->tuduId, Dao_Td_Log_Log::ACTION_TUDU_PROGRESS, array('percent' => $params['percent'], 'elapsedtime' => $tudu->elapsedTime + (int) $post['elapsedtime'])); } } // 自动确认 if ($isLog && $tuduPercent == 100 && null === $flowPercent || $isLog && $flowPercent == 100) { if ($isSender && $isAccepter || !$tudu->needConfirm) { $isDoneTudu = true; $doneParams = array('tuduid' => $tudu->tuduId, 'percent' => $params['percent'], 'elapsedtime' => $tudu->elapsedTime + (int) $post['elapsedtime']); // 添加到发起人图度箱 -- 待确认中 } else { /* @var $addressBook Tudu_AddressBook */ $addressBook = Tudu_AddressBook::getInstance(); $sender = $addressBook->searchUser($this->_user->orgId, $tudu->sender); $manager->addLabel($tudu->tuduId, $sender['uniqueid'], '^i'); } } // 计算父级图度进度 及 图度组达到100%时,确认 if ($tudu->parentId) { $parentPercent = $manager->calParentsProgress($tudu->parentId); if ($parentPercent >= 100) { $sendParam['confirm'] = true; } } // 发送回复 $manager->sendPost($tuduId, $postId); // 统计时间 if ($isLog) { $manager->calcElapsedTime($tuduId); } // 周期任务 if ($isLog && $tudu->cycleId && $tuduPercent >= 100) { $daoCycle = $this->getDao('Dao_Td_Tudu_Cycle'); $cycle = $daoCycle->getCycle(array('cycleid' => $tudu->cycleId)); if ($cycle->count == $tudu->cycleNum) { $sendParam['cycle'] = true; } } $sendParam['tuduid'] = $tudu->tuduId; $sendParam['from'] = $this->_user->userName; $sendParam['sender'] = $this->_user->trueName; $sendParam['uniqueid'] = $this->_user->uniqueId; $sendParam['postid'] = $postId; $sendParam['tsid'] = $this->_user->tsId; $sendParam['server'] = $this->_request->getServer('HTTP_HOST'); // 处理工作流 // 处理流程发送过程 if ($tudu->type == 'task' && $percent >= 100) { /* @var $daoFlow Dao_Td_Tudu_Flow */ $daoFlow = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Flow', Tudu_Dao_Manager::DB_TS); $flowData = $daoFlow->getFlow(array('tuduid' => $tudu->tuduId)); if (null !== $flowData) { /* @var $flow Model_Tudu_Extension_Flow */ $flow = new Model_Tudu_Extension_Flow($flowData->toArray()); $isCurrentUser = $flow->isCurrentUser($this->_user->uniqueId); $isComplete = false; if ($isCurrentUser) { $flow->complete($this->_user->uniqueId); if ($flow->isStepComplete()) { $isComplete = true; $flow->flowTo(); } } $modelFlow = $flow->getHandler($flow->getHandlerClass()); $modelFlow->updateFlow($flow); if ($flow->currentStepId != '^end') { $isDoneTudu = false; } // 发送下一步 if (false === strpos($flow->currentStepId, '^') && $isComplete) { $section = $flow->getStepSection($flow->currentStepId); $tuduParams = array('tuduid' => $tudu->tuduId, 'type' => $tudu->type, 'fromtudu' => $tudu); $users = array(); foreach ($section as $sec) { $users[$sec['username']] = array('uniqueid' => $sec['uniqueid'], 'truename' => $sec['truename'], 'username' => $sec['username'], 'email' => $sec['username']); } $step = $flow->getStep($flow->currentStepId); if ($step['type'] == 1) { $tuduParams['reviewer'] = $users; } else { $tuduParams['to'] = $users; if ($step['type'] == 2) { $tuduParams['acceptmode'] = 1; } } $sendTudu = new Model_Tudu_Tudu($tuduParams); $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS); $params = $sendTudu->getStorageParams(); if (!empty($params['to'])) { $accepters = $daoTudu->getAccepters($tudu->tuduId); foreach ($accepters as $item) { $daoTudu->removeAccepter($tudu->tuduId, $item['uniqueid']); } } $daoTudu->updateTudu($tudu->tuduId, $params); $modelTudu = new Model_Tudu_Send_Common(); $modelTudu->send($sendTudu); // 更新进度 $manager->updateProgress($tudu->tuduId, $this->_user->uniqueId); if ($tudu->parentId) { $manager->calParentsProgress($tudu->parentId); } } } } // 自动确认 if ($isDoneTudu && isset($doneParams)) { $manager->doneTudu($doneParams['tuduid'], true, 0); // 添加操作日志 $this->_writeLog(Dao_Td_Log_Log::TYPE_TUDU, $doneParams['tuduid'], Dao_Td_Log_Log::ACTION_TUDU_DONE, array('percent' => $doneParams['percent'], 'elapsedtime' => $doneParams['elapsedtime']), false, true); } // 回复消息 $data = implode(' ', array('tudu', 'reply', '', http_build_query($sendParam))); $httpsqs->put($data, 'tudu'); } return $this->json(true, $this->lang['post_send_success'], array('postid' => $postId)); }
/** * 拒绝图度 */ public function rejectAction() { $tuduIds = explode(',', $this->_request->getParam('tid')); // 参数:图度ID必须存在 if (!count($tuduIds)) { return $this->json(false, $this->lang['invalid_tuduid']); } /* @var $daoTudu Dao_Td_Tudu_Tudu */ $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS); /* @var $daoFlow Dao_Td_Tudu_Flow */ $daoFlow = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Flow', Tudu_Dao_Manager::DB_TS); /* @var $daoTudu Dao_Td_Tudu_Group */ $daoTuduGroup = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Group', Tudu_Dao_Manager::DB_TS); $resourceManager = new Tudu_Model_ResourceManager_Registry(); $resourceManager->setResource(Tudu_Model::RESOURCE_CONFIG, $this->bootstrap->getOptions()); Tudu_Model::setResourceManager($resourceManager); $success = 0; //用于计数操作成功个数 foreach ($tuduIds as $tuduId) { // 获得图度数据 $tudu = $daoTudu->getTuduById($this->_user->uniqueId, $tuduId); // 图度必须存在 if (null == $tudu) { continue; } // 图度不能是已确定状态 if ($tudu->isDone) { continue; } // 图度不能是“已完成”,“已拒绝”, “已取消”状态 if ($tudu->selfTuduStatus > Dao_Td_Tudu_Tudu::STATUS_DOING) { continue; } // 操作人必须为图度执行人 $isAccepter = in_array($this->_user->userName, $tudu->accepter); // 会议执行人有群组 if ($tudu->type == 'meeting') { foreach ($tudu->accepter as $item) { if ($isAccepter) { break; } if (strpos($item, '^') == 0) { $isAccepter = in_array($item, $this->_user->groups, true); } } } if (!$isAccepter) { continue; } $isFlow = !empty($tudu->flowId) ? true : false; $tuduStatus = $daoTudu->rejectTudu($tuduId, $this->_user->uniqueId, $isFlow); if (false !== $tuduStatus) { $success++; //记录次数 $updateTudu = array(); /*if ($tudu->type == 'task' && empty($tudu->flowId)) { //任务拒绝步骤的指向 $updateTudu = array('stepid' => '^head'); }*/ // 拒绝后任务状态为完成的,生成周期任务 if ($tudu->cycleId && $tuduStatus >= Dao_Td_Tudu_Tudu::STATUS_DONE) { $config = $this->bootstrap->getOption('httpsqs'); // 插入消息队列 $httpsqs = new Oray_Httpsqs($config['host'], $config['port'], $config['chartset'], $config['name']); $updateTudu = array('cycleid' => null); $data = implode(' ', array('tudu', 'cycle', '', http_build_query(array('tuduid' => $tudu->tuduId, 'tsid' => $this->_user->tsId, 'cycleid' => $tudu->cycleId)))); $httpsqs->put($data, 'tudu'); } if (!empty($updateTudu)) { $daoTudu->updateTudu($tuduId, $updateTudu); } $tudu = $tudu->toArray(); // 工作流 拒绝 步骤就拒绝 if ($tudu['flowid']) { $tudu['cc'] = null; $flowRecord = $daoFlow->getFlow(array('tuduid' => $tudu['tuduid'])); $flow = new Model_Tudu_Extension_Flow($flowRecord->toArray()); $composeTudu = new Model_Tudu_Tudu(array('tuduid' => $tudu['tuduid'], 'status' => 1, 'type' => $tudu['type'], 'flowid' => $tudu['flowid'])); if (isset($flow->steps[$flow->currentStepId])) { $step = $flow->steps[$flow->currentStepId]; $prevId = $step['prev']; $isFrowardStep = false; // 工作流中转发的步骤 // 如果所有人拒绝,则删除 if (0 !== strpos($tudu['stepid'], 'F-')) { $flow->deleteStep($flow->currentStepId); $isFrowardStep = true; } else { // 更新当前步骤状态 $flow->reject($flow->currentStepId, $this->_user->userName); } if (isset($flow->steps[$prevId])) { $prev = $flow->steps[$prevId]; $updateStatus = $isFrowardStep; $nextIndex = null; // 上一步骤系审批 if ($prev['type'] == Dao_Td_Tudu_Step::TYPE_EXAMINE) { $reviewer = array(); $flow->resetStep($prevId); foreach ($prev['section'] as $idx => $sec) { foreach ($sec as $i => $u) { if ($idx == 0) { $reviewer[$u['username']] = array('username' => $u['username'], 'truename' => $u['truename'], 'uniqueid' => $u['uniqueid']); } } } $composeTudu->reviewer = $reviewer; // 上一步骤系执行 } else { $to = array(); $flow->resetStep($prevId); foreach ($prev['section'] as $idx => $sec) { foreach ($sec as $i => $u) { if ($idx == 0) { $to[$u['username']] = array('username' => $u['username'], 'truename' => $u['truename'], 'uniqueid' => $u['uniqueid']); } } } $composeTudu->reviewer = null; $composeTudu->to = $to; } $stepId = $prev['stepid']; } else { $stepId = $prevId; } } else { $stepId = '^break'; } $flow->flowTo($stepId); $composeTudu->stepId = $stepId; if ($stepId == '^break' || $stepId == '^head') { $composeTudu->to = array($tudu['from'][3] => array('username' => $tudu['from'][3], 'truename' => $tudu['from'][0])); } // 准备发送 //$modelCompose = new Model_Tudu_Compose_Save($tudu); $modelSend = new Model_Tudu_Send_Common(); //$recipients = $deliver->prepareRecipients($this->_user->uniqueId, $this->_user->userId, $tudu); // 移除原执行人 if ($composeTudu->to && !$composeTudu->reviewer) { $accepters = $daoTudu->getAccepters($tudu['tuduid']); $to = $composeTudu->to; foreach ($accepters as $item) { list($email, ) = explode(' ', $item['accepterinfo'], 2); // 移除执行人角色,我执行标签 if (!empty($to) && !array_key_exists($email, $to) && $daoTuduGroup->getChildrenCount($tudu['tuduid'], $item['uniqueid']) <= 0) { $daoTudu->removeAccepter($tudu['tuduid'], $item['uniqueid']); $this->manager->deleteLabel($tudu['tuduid'], $item['uniqueid'], '^a'); } } } // 执行人自动接受图度 $currentStep = $flow->getStep($flow->currentStepId); if ($stepId != '^break' && $stepId != '^head' && isset($steps[$stepId]) && $currentStep['type'] != Dao_Td_Tudu_Step::TYPE_EXAMINE) { if ($currentStep['type'] == Dao_Td_Tudu_Step::TYPE_EXECUTE) { foreach ($currentStep['section'][0] as $item) { $daoTudu->acceptTudu($tudu['tuduid'], $item['uniqueid'], null); } $updateParams['acceptmode'] = 0; } else { if ($currentStep['type'] == Dao_Td_Tudu_Step::TYPE_CLAIM) { $composeTudu->acceptMode = 1; $composeTudu->acceptTime = null; } } } //$this->manager->updateTudu($tudu->tuduId, $updateParams); $daoFlow->updateFlow($flow->tuduId, $flow->toArray()); //$modelCompose->compose($composeTudu); $params = $composeTudu->getStorageParams(); $daoTudu->updateTudu($tudu['tuduid'], $params); $modelSend->send($composeTudu, true); $daoTudu->markAllUnRead($tudu['tuduid']); $daoTudu->updateFlowProgress($tudu['tuduid'], null, $flow->currentStepId); // 不是自动工作流,回到发起 } else { $flowRecord = $daoFlow->getFlow(array('tuduid' => $tudu['tuduid'])); $flow = new Model_Tudu_Extension_Flow($flowRecord->toArray()); $flow->flowTo('^head'); $daoFlow->updateFlow($tudu['tuduid'], $flow->toArray()); } if ($tudu['parentid']) { $daoTudu->calParentsProgress($tudu['parentid']); } // 添加操作日志 $this->_writeLog(Dao_Td_Log_Log::TYPE_TUDU, $tuduId, Dao_Td_Log_Log::ACTION_TUDU_DECLINE, array('selfstatus' => Dao_Td_Tudu_Tudu::STATUS_REJECT, 'status' => $tuduStatus)); } } if ($success <= 0) { return $this->json(false, $this->lang['reject_failure']); } return $this->json(true, $this->lang['reject_success']); }