/** * 认领 * * 必要参数 * tuduid|uniqueid|orgid|username|server|postparams|truename */ public function claim(array $params) { if (empty($params['tuduid'])) { require_once 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Missing or invalid value of parameter "tuduid"', self::CODE_INVALID_TUDUID); } $orgId = $this->_user->orgId; $uniqueId = $this->_user->uniqueId; $userName = $this->_user->userName; $tuduId = $params['tuduid']; //$manager = $this->getManager(); /* @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_Flow*/ $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS); // 获取图度信息 $tudu = $daoTudu->getTuduById($uniqueId, $tuduId); // 判读图度是否存在 if (null == $tudu) { require_once 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('This tudu is not exists', self::CODE_TUDU_NOTEXISTS); } // 获取步骤 $flowRecord = $daoFlow->getFlow(array('tuduid' => $tudu->tuduId)); $step = isset($flowRecord->steps[$flowRecord->currentStepId]) ? $flowRecord->steps[$flowRecord->currentStepId] : null; // 判断当前是否为认领操作 if (!$step || $step['type'] != Dao_Td_Tudu_Step::TYPE_CLAIM) { require_once 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('This tudu current step is not claim', self::CODE_STEP_NOTCLAIM); } // 判读图度是否已有user认领 if ($tudu->acceptTime) { require_once 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('This tudu current step is claimed', self::CODE_STEP_CLAIM_FINISH); } $accepters = $daoTudu->getAccepters($tuduId); foreach ($accepters as $accepter) { if ($uniqueId == $accepter['uniqueid']) { $claimAccepter = $accepter; } else { $removeAccepter[] = $accepter; } } require_once 'Model/Tudu/Extension/Flow.php'; $flow = new Model_Tudu_Extension_Flow(); $flow->setAttributes($flowRecord->toArray()); // 插入新的步骤 $stepId = Dao_Td_Tudu_Step::getStepId(); $flow->complete($flow->currentStepId, $this->_user->uniqueId); if ($tudu->flowId && strstr($step['next'], 'ST-')) { $flow->deleteStep($step['next']); } $flow->addStep(array('stepid' => $stepId, 'prev' => $step['stepid'], 'next' => $step['next'], 'type' => 0)); $flow->updateStep($step['stepid'], array('next' => $stepId)); $flow->addStepSection($stepId, array(array('uniqueid' => $this->_user->uniqueId, 'truename' => $this->_user->trueName, 'username' => $this->_user->userName, 'email' => $this->_user->userName, 'status' => 0))); $flow->flowTo($stepId); if (!$daoFlow->updateFlow($flow->tuduId, $flow->toArray())) { require_once 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Tudu flow save failed', self::CODE_SAVE_FAILED); } $ret = $daoTudu->updateTudu($tuduId, array('to' => $claimAccepter['accepterinfo'], 'stepid' => $stepId, 'stepnum' => count($flow->steps), 'acceptmode' => 0)); $params = array('accepttime' => time(), 'tudustatus' => Dao_Td_Tudu_Tudu::STATUS_DOING); // 更新认领人 td_tudu_user $ret = $daoTudu->updateTuduUser($tuduId, $uniqueId, $params); if (!$ret) { require_once 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Claim tudu failed', self::CODE_SAVE_FAILED); } // 更新图度的接受时间 $daoTudu->updateLastAcceptTime($tuduId); // 更新需要移除的执行人及去除“我执行”标签 if (!empty($removeAccepter)) { foreach ($removeAccepter as $rmAccept) { if (!$daoTudu->updateTuduUser($tuduId, $rmAccept['uniqueid'], array('role' => null))) { continue; } if (!$daoTudu->deleteLabel($tuduId, $rmAccept['uniqueid'], '^a')) { continue; } } } /* @var $daoPost Dao_Td_Tudu_Post */ $daoPost = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Post', Tudu_Dao_Manager::DB_TS); $content = sprintf('%s 认领了该图度。', $this->_user->trueName); $header = array('action' => 'claim', 'tudu-claimer' => $this->_user->trueName); $postParams = array('orgid' => $this->_user->orgId, 'boardid' => $tudu->boardId, 'tuduid' => $tudu->tuduId, 'uniqueid' => $this->_user->uniqueId, 'poster' => $this->_user->trueName, 'posterinfo' => $this->_user->position, 'email' => $this->_user->userName, 'postid' => Dao_Td_Tudu_Post::getPostId($tuduId), 'header' => $header, 'content' => $content, 'lastmodify' => implode(chr(9), array($this->_user->uniqueId, time(), $this->_user->trueName))); $postId = $daoPost->createPost($postParams); //发送回复 $daoPost->sendPost($tuduId, $postId); //标记未读 $daoTudu->markAllUnRead($tuduId); // 添加操作日志 $this->_writeLog(Dao_Td_Log_Log::TYPE_TUDU, $tuduId, Dao_Td_Log_Log::ACTION_TUDU_CLAIM, array('orgid' => $orgId, 'uniqueid' => $uniqueId, 'userinfo' => $this->_user->userInfo), array('claimuser' => $this->_user->trueName, 'claimtime' => time(), 'status' => Dao_Td_Tudu_Tudu::STATUS_DOING)); if (Tudu_Model::hasResource(Tudu_Model::RESOURCE_CONFIG)) { $config = Tudu_Model::getResource(Tudu_Model::RESOURCE_CONFIG); if ($config['httpsqs']) { $options = $config['httpsqs']; $charset = isset($config['charset']) ? $config['charset'] : 'utf-8'; $httpsqs = new Oray_Httpsqs($options['host'], $options['port'], $charset, $options['name']); $notifyTo = array($tudu->sender); $notifyTo = array_merge($notifyTo, array_keys($tudu->to)); if ($tudu->notifyAll) { $notifyTo = array_merge($notifyTo, array_keys($tudu->cc)); } $tpl = <<<HTML <strong>您刚收到一个新的回复</strong><br /> <a href="http://{$this->_user->domainName}/frame#m=view&tid=%s&page=1" target="_blank" _tid="{$tuduId}">%s</a><br /> 发起人:{$this->_user->trueName}<br /> 更新日期:%s<br /> {$content} HTML; $data = implode(' ', array('tudu', 'reply', '', http_build_query(array('tuduid' => $tudu->tuduId, 'from' => $userName, 'to' => implode(',', $notifyTo), 'content' => sprintf($tpl, $tudu->tuduId, $tudu->subject, date('Y-m-d H:i:s', time())))))); $httpsqs->put($data); } } }
/** * /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)); }
/** * * @param Model_Tudu_Tudu $tudu * @param Model_Tudu_Extension_Flow $flow */ public function renewTuduFlow(Model_Tudu_Tudu &$tudu, Model_Tudu_Extension_Flow &$flow) { // 手动工作流,可修改当前步骤或不同意的后续步骤 $isExceed = false; $prev = $flow->currentStepId ? $flow->currentStepId : '^head'; $next = '^end'; if ($tudu->operation != 'forward' && ($tudu->reviewer || $tudu->to)) { foreach ($flow->steps as $key => $item) { $stepId = $item['stepid']; foreach ($item['section'] as $idx => $section) { if ($isExceed) { $flow->removeStepSection($stepId, $idx); if (empty($flow->steps[$stepId]['section'])) { $flow->deleteStep($stepId); } continue; } foreach ($section as $k => $u) { if (isset($u['status']) && $u['status'] >= 2 && $item['type'] == 1) { $isExceed = true; $prev = $stepId; } if ($isExceed && $u['status'] < 2) { $flow->removeStepSection($key, $idx); } } } } } if ($tudu->operation == 'forward') { if (isset($flow->steps[$flow->currentStepId])) { $next = $flow->steps[$flow->currentStepId]['next']; } } $flowTo = null; if ($tudu->reviewer) { $reviewer = $tudu->reviewer; $stepId = $flow->addStep(array('type' => Dao_Td_Tudu_Step::TYPE_EXAMINE, 'prev' => $prev, 'next' => $next)); $flowTo = $prev = $stepId; $prev = $stepId; foreach ($reviewer as $item) { $flow->addStepSection($stepId, $item); } $tudu->reviewer = $flow->getStepSection($stepId, 0); } if ($tudu->to) { $to = $tudu->to; $stepId = $flow->addStep(array('type' => $tudu->acceptMode ? Dao_Td_Tudu_Step::TYPE_CLAIM : Dao_Td_Tudu_Step::TYPE_EXECUTE, 'prev' => $prev, 'next' => $next)); foreach ($to as $item) { $flow->addStepSection($stepId, $item); } $to = $flow->getStepSection($stepId, 0); foreach ($to as $k => $t) { if (isset($tudu->to[0][$t['username']]) && isset($tudu->to[0][$t['username']]['percent'])) { $to[$k]['percent'] = $tudu->to[0][$t['username']]['percent']; continue; } } $tudu->to = $to; if (0 !== strpos($prev, '^')) { $flow->updateStep($prev, array('next' => $stepId)); } if (null === $flowTo) { $flowTo = $stepId; } } $isComplete = true; if ($tudu->operation == 'forward') { $flow->complete(); } if ($flow->currentStepId && 0 !== strpos($flow->currentStepId, '^')) { $step = $flow->getStep($flow->currentStepId); $sec = $flow->getStepSection($step['stepid'], $step['currentSection']); if ($sec) { foreach ($sec as $u) { if (!empty($u['status']) && $u['status'] < 2) { $isComplete = false; break; } } } } if ($isComplete) { $flow->flowTo($flowTo); } // 到头了 if (0 === strpos($flow->currentStepId, '^') || !$flow->currentStepId) { return; } $step = $flow->getStep($flow->currentStepId); $su = $flow->getStepSection($flow->currentStepId); $users = array(); $to = $tudu->to; foreach ($su as $k => $u) { $users[$u['username']] = array('uniqueid' => $u['uniqueid'], 'username' => $u['username'], 'truename' => $u['truename'], 'email' => $u['username']); foreach ($to as $t) { if ($t['uniqueid'] == $u['uniqueid'] && !empty($t['percent'])) { $users[$u['username']]['percent'] = $t['percent']; break; } } } if ($step['type'] == 1) { if (!$tudu->reviewer) { $tudu->reviewer = $users; } } else { if ($step['type'] == 2) { $tudu->acceptMode = 1; } if (!$tudu->to) { $tudu->to = $users; } } }