/** * 认领 * * 必要参数 * 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); } } }
/** * 生成周期图度 * * @param $params */ public function cycle($params) { if (empty($params['tuduid']) || empty($params['cycleid']) || empty($params['tsid'])) { return; } $tuduId = $params['tuduid']; $cycleId = $params['cycleid']; $tsId = $params['tsid']; $daoUser = Tudu_Dao_Manager::getDao('Dao_Md_User_User', Tudu_Dao_Manager::DB_MD); $daoCycle = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Cycle', Tudu_Dao_Manager::DB_TS); $manager = Tudu_Tudu_Manager::getInstance(Tudu_Dao_Manager::getDb(Tudu_Dao_Manager::DB_TS)); $tudu = $manager->getTuduById($tuduId, $this->_unId); $fromTuduId = $tudu->tuduId; $acceptMode = $tudu->acceptMode; $isAuth = $tudu->isAuth; if (null === $tudu) { $this->getLogger()->warn("Tudu id: {$tuduId} is not exists"); return; } $cycle = $daoCycle->getCycle(array('cycleid' => $cycleId)); if (null === $cycle) { $this->getLogger()->warn("Tudu Cycle id: {$cycleId} is not exists"); return; } // 已经失效的周期设置 if ($cycle->isValid == 0) { return; } if (Dao_Td_Tudu_Cycle::END_TYPE_COUNT == $cycle->endType && $cycle->count >= $cycle->endCount) { $daoCycle->deleteCycle($cycle->cycleId); return; } if (Dao_Td_Tudu_Cycle::END_TYPE_DATE == $cycle->endType && time() >= $cycle->endDate) { $daoCycle->deleteCycle($cycle->cycleId); return; } $time = $daoCycle->getCycleTime($cycle, $tudu->startTime, $tudu->endTime); $recipients = array(); $to = array(); $fromUnId = null; $u = $daoUser->getUserByAddress($tudu->sender); if ($u) { $recipients[$u->uniqueId] = array('uniqueid' => $u->uniqueId, 'role' => 'from'); $fromUnId = $u->uniqueId; } if (!$acceptMode) { $accepters = $manager->getTuduAccepters($tudu->tuduId); foreach ($accepters as $a) { $recipients[$a['uniqueid']] = array('accepterinfo' => $a['accepterinfo'], 'uniqueid' => $a['uniqueid'], 'role' => Dao_Td_Tudu_Tudu::ROLE_ACCEPTER, 'tudustatus' => Dao_Td_Tudu_Tudu::STATUS_UNSTART, 'isforeign' => (int) $a['isforeign'], 'percent' => 0, 'authcode' => (int) $a['isforeign'] && $tudu->isAuth ? Oray_Function::randKeys(4) : null); if ($tudu->isAuth) { $recipients[$a['uniqueid']]['authcode'] = $a['authcode']; } $to[] = $a['accepterinfo']; } } // 公共周期任务图度数据 $params = $this->getCycleTuduParams($tudu, $cycle, $to, $fromUnId, $time); // 抄送 if (!empty($tudu->cc)) { $cc = array(); $sendCc = array(); foreach ($tudu->cc as $userName => $item) { $cc[] = $userName . ' ' . $item[0]; } $params['cc'] = implode("\n", $cc); $sendCc = $this->formatRecipients($params['cc']); $addressBook = Tudu_AddressBook::getInstance(); foreach ($sendCc as $key => $item) { if (isset($item['groupid'])) { if (0 === strpos($item['groupid'], 'XG')) { $users = $addressBook->getGroupContacts($tudu->orgId, $fromUnId, $item['groupid']); } else { $users = $addressBook->getGroupUsers($tudu->orgId, $item['groupid']); } $recipients = array_merge($users, $recipients); } else { $user = $addressBook->searchUser($tudu->orgId, $item['email']); if (null === $user) { $user = $addressBook->searchContact($fromUnId, $item['email'], $item['truename']); if (null === $user) { $user = $addressBook->prepareContact($item['email'], $item['truename']); } } if (!isset($recipients[$user['uniqueid']])) { $recipients[$user['uniqueid']] = $user; } } } } // 密送 if (!empty($tudu->bcc)) { $bcc = array(); $sendBcc = array(); foreach ($tudu->bcc as $userName => $item) { $bcc[] = $userName . ' ' . $item[0]; } $params['bcc'] = implode("\n", $bcc); $sendBcc = $this->formatRecipients($params['bcc']); $addressBook = Tudu_AddressBook::getInstance(); foreach ($sendBcc as $key => $item) { if (isset($item['groupid'])) { if (0 === strpos($item['groupid'], 'XG')) { $users = $addressBook->getGroupContacts($tudu->orgId, $fromUnId, $item['groupid']); } else { $users = $addressBook->getGroupUsers($tudu->orgId, $item['groupid']); } $recipients = array_merge($users, $recipients); } else { $user = $addressBook->searchUser($tudu->orgId, $item['email']); if (null === $user) { $user = $addressBook->searchContact($fromUnId, $item['email'], $item['truename']); if (null === $user) { $user = $addressBook->prepareContact($item['email'], $item['truename']); } } if (!isset($recipients[$user['uniqueid']])) { $recipients[$user['uniqueid']] = $user; } } } } // 会议数据 if ($tudu->type == 'meeting') { $daoMeeting = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Meeting', Tudu_Dao_Manager::DB_TS); $meeting = $daoMeeting->getMeeting(array('tuduid' => $tudu->tuduId)); if ($meeting) { $params['meeting'] = array('notifytype' => $meeting->notifyType, 'location' => $meeting->location, 'isallday' => $meeting->isAllday); $params['meeting']['notifytime'] = Dao_Td_Tudu_Meeting::calNotifyTime($params['starttime'], $meeting->notifyType); } } // 保留周期任务的附件 if ($cycle->isKeepAttach) { $daoAttach = Tudu_Dao_Manager::getDao('Dao_Td_Attachment_File', Tudu_Dao_Manager::DB_TS); $attaches = $daoAttach->getFiles(array('tuduid' => $tudu->tuduId, 'postid' => $tudu->postId))->toArray(); $attachNum = 0; foreach ($attaches as $attach) { if ($attach['isattach']) { $params['attachment'][] = $attach['fileid']; } else { $params['file'][] = $attach['fielid']; } } } $stepId = $params['stepid']; $tudu = new Tudu_Tudu_Storage_Tudu($params); $storage = Tudu_Tudu_Storage::getInstance(Tudu_Dao_Manager::getDb(Tudu_Dao_Manager::DB_TS)); $deliver = Tudu_Tudu_Deliver::getInstance(); $tuduId = $storage->createTudu($tudu); if (!$tuduId) { $this->getLogger()->warn("Create Cycle Tudu failed id:{$tuduId}"); return; } if ($params['type'] == 'task' && $tuduId) { $daoFlow = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Flow', Tudu_Dao_Manager::DB_TS); $flow = $daoFlow->getFlow(array('tuduid' => $fromTuduId)); $steps = $flow->steps; $step = reset($steps); $modelFlow = new Model_Tudu_Extension_Flow(array('orgid' => $tudu->orgId, 'tuduid' => $tuduId)); /*$step = $daoStep->getStep(array('tuduid' => $fromTuduId, 'prevstepid' => '^head')); $orderNum = 1;*/ $prevStepId = '^head'; $addressBook = Tudu_AddressBook::getInstance(); // 认领 if ($step && $step['type'] == Dao_Td_Tudu_Step::TYPE_CLAIM) { $modelFlow->addStep(array('stepid' => $step['stepid'], 'prev' => $step['prev'], 'next' => '^end', 'type' => $step['type'])); $acceptMode = true; $to = array(); foreach ($step['section'] as $idx => $sec) { $section = array(); foreach ($sec as $user) { $section[] = array('uniqueid' => $user['uniqueid'], 'username' => $user['username'], 'truename' => $user['truename']); if ($idx == 0) { $to[] = $user['username'] . ' ' . $user['truename']; $recipient = array('uniqueid' => $user['uniqueid'], 'userinfo' => $user['username'] . ' ' . $user['truename'], 'role' => Dao_Td_Tudu_Tudu::ROLE_ACCEPTER, 'tudustatus' => Dao_Td_Tudu_Tudu::STATUS_UNSTART, 'percent' => 0); $u = $addressBook->searchUser($fromUnId, $user['username']); if (!$u) { $recipient['isforeign'] = 1; if ($isAuth) { $recipient['auth'] = Oray_Function::randKeys(4); } } $recipients[$recipient['uniqueid']] = $recipient; } } $modelFlow->addStepSection($step['stepid'], $sec); } $modelFlow->stepNum = 1; $modelFlow->flowTo($step['stepid']); $daoFlow->createFlow($modelFlow->toArray()); // 更新to字段 $manager->updateTudu($tuduId, array('to' => implode("\n", $to), 'acceptmode' => 1, 'accepttime' => null)); } else { // 审批 $nextId = $step['next']; $modelFlow->addStep(array('stepid' => $step['stepid'], 'prev' => $step['prev'], 'next' => $step['next'], 'type' => $step['type'])); foreach ($step['section'] as $idx => $sec) { $section = array(); foreach ($sec as $user) { $section[] = array('uniqueid' => $user['uniqueid'], 'username' => $user['username'], 'truename' => $user['truename']); if ($idx == 0) { $to[] = $user['username'] . ' ' . $user['truename']; $recipient = array('uniqueid' => $user['uniqueid'], 'userinfo' => $user['username'] . ' ' . $user['truename'], 'role' => isset($recipients[$user['uniqueid']]) ? $recipients[$user['uniqueid']]['role'] : null, 'isreview' => true, 'tudustatus' => Dao_Td_Tudu_Tudu::STATUS_UNSTART); $recipients[$recipient['uniqueid']] = $recipient; } } $modelFlow->addStepSection($step['stepid'], $sec); } if (isset($flow->steps[$nextId])) { $next = $flow->steps[$nextId]; $modelFlow->addStep(array('stepid' => $next['stepid'], 'prev' => $next['prev'], 'next' => '^end', 'type' => $next['type'])); foreach ($next['section'] as $idx => $sec) { $section = array(); foreach ($sec as $user) { $section[] = array('uniqueid' => $user['uniqueid'], 'username' => $user['username'], 'truename' => $user['truename']); } $modelFlow->addStepSection($next['stepid'], $sec); } } $modelFlow->stepNum = count($modelFlow->steps); $modelFlow->flowTo($step['stepid']); $daoFlow->createFlow($modelFlow->toArray()); } } $sendParams = array(); if ($tudu->type == 'meeting') { $sendParams['meeting'] = true; } if (empty($reviewer)) { $ret = $deliver->sendTudu($tudu, $recipients, $sendParams); if (!$ret) { $this->getLogger()->warn("Send Tudu failed id:{$tuduId}"); return; } if (!$acceptMode) { foreach ($recipients as $unId => $recipient) { if (isset($recipient['role']) && $recipient['role'] == Dao_Td_Tudu_Tudu::ROLE_ACCEPTER) { $manager->acceptTudu($tuduId, $unId, null); } } } } else { $rev = array_shift($reviewer); $ret = $deliver->sendTudu($tudu, array($rev['uniqueid'] => array('tuduid' => $tuduId, 'uniqueid' => $rev['uniqueid']), $fromUnId => array('tuduid' => $tuduId, 'uniqueid' => $fromUnId)), null); if (!$ret) { $this->getLogger()->warn("Send Tudu failed id:{$tuduId}"); return; } $manager->addLabel($tuduId, $rev['uniqueid'], '^e'); } // 发起人的 if (null !== $fromUnId) { $manager->addLabel($tuduId, $fromUnId, '^f'); $manager->addLabel($tuduId, $fromUnId, '^i'); } $daoCycle->increment($cycle->cycleId); // 收发规则过滤 $data = implode(' ', array('tudu', 'filter', '', http_build_query(array('tsid' => $tsId, 'tuduid' => $tuduId)))); $this->_httpsqs->put($data, $this->_options['httpsqs']['names']['tudu']); // 外发请求 $data = implode(' ', array('send', 'tudu', '', http_build_query(array('tsid' => $tsId, 'tuduid' => $tuduId, 'uniqueid' => $fromUnId, 'to' => '')))); $this->_httpsqs->put($data, $this->_options['httpsqs']['names']['send']); $this->getLogger()->debug("Tudu id:{$tuduId} done"); }
/** * 拒绝图度 */ 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']); }
/** * * @param MOdel_Tudu_Tudu $tudu */ public function createFlow(Model_Tudu_Extension_Flow $flow) { /* @var $daoFlow Dao_Td_Tudu_Flow */ $daoFlow = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Flow', Tudu_Dao_Manager::DB_TS); if (!$daoFlow->createFlow($flow->toArray())) { require_once 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Tudu flow save failed', Model_Tudu_Exception::SAVE_FAILED); } }