/** * /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 string $params */ public function createUser($params) { list($orgId, $address, $uniqueId, $truename) = explode(':', $params); $daoUser = Tudu_Dao_Manager::getDao('Dao_Md_User_User', Tudu_Dao_Manager::DB_MD); $user = $daoUser->getUser(array('uniqueid' => $uniqueId)); $defaultTime = mktime(0, 0, 0, 11, 23, 2011); if ($user->createTime > $defaultTime) { $daoOrg = Tudu_Dao_Manager::getDao('Dao_Md_Org_Org', Tudu_Dao_Manager::DB_MD); $org = $daoOrg->getOrg(array('orgid' => $orgId)); $tsId = $org->tsid; Tudu_Dao_Manager::setDb(Tudu_Dao_Manager::DB_TS, $this->_tsDbs['ts' . $tsId]); $manager = Tudu_Tudu_Manager::getInstance(Tudu_Dao_Manager::getDb(Tudu_Dao_Manager::DB_TS)); // 系统欢迎公告ID $tuduId = md5($orgId . '-welcome'); // 查看系统欢迎公告是否存在 $tudu = $manager->getTuduById($tuduId, $uniqueId); if (null === $tudu) { $manager->addRecipient($tuduId, $uniqueId); $manager->addLabel($tuduId, $uniqueId, '^all'); $manager->addLabel($tuduId, $uniqueId, '^i'); $manager->addLabel($tuduId, $uniqueId, '^n'); $this->getLogger()->debug("System Welcome Notice Tudu id:{$tuduId} done"); } // 查看图度新手任务是否存在 $newbieTuduId = 'newbie-' . $uniqueId; $newbieTudu = $manager->getTuduById($newbieTuduId, $uniqueId); if (null === $newbieTudu) { $content = file_get_contents($this->_options['data']['path'] . '/templates/tudu/newbie_tudu_task.tpl'); if ($content) { $tudu = array('orgid' => $orgId, 'tuduid' => $newbieTuduId, 'boardid' => '^system', 'uniqueid' => $this->_unId, 'type' => 'task', 'subject' => '图度新手任务', 'email' => '*****@*****.**', 'from' => $this->_unId . ' ' . $this->_unName, 'to' => $address . ' ' . $truename, 'cc' => null, 'priority' => 0, 'privacy' => 0, 'issend' => 1, 'needconfirm' => 0, 'status' => Dao_Td_Tudu_Tudu::STATUS_UNSTART, 'content' => $content, 'starttime' => strtotime(date('Y-m-d', time())), 'endtime' => null, 'totaltime' => 3 * 3600, 'poster' => $this->_unName, 'posterinfo' => '', 'lastposter' => $this->_unName, 'lastposttime' => time(), 'createtime' => time(), 'attachment' => array()); $tudu = new Tudu_Tudu_Storage_Tudu($tudu); $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 newbie Tudu failed id:{$newbieTuduId}"); return; } // 发送新手任务 $ret = $deliver->sendTudu($tudu, array()); if (!$ret) { $this->getLogger()->warn("Send newbie Tudu failed id:{$newbieTuduId}"); return; } $manager->addRecipient($tuduId, $uniqueId, array('role' => 'to')); $manager->addLabel($tuduId, $uniqueId, '^all'); $manager->addLabel($tuduId, $uniqueId, '^i'); $manager->addLabel($tuduId, $uniqueId, '^a'); $this->getLogger()->debug("Newbie Tudu id:{$tuduId} done"); } } } }
/** * 添加接收人 */ public function foreignAddAction() { $tuduId = $this->_request->getPost('tid'); $to = $this->_request->getPost('to'); $cc = $this->_request->getPost('cc'); // 参数:图度ID必须存在 if (!$tuduId) { return $this->json(false, $this->lang['invalid_tuduid']); } $fromTudu = $this->manager->getTuduById($tuduId, $this->_user->uniqueId); // 图度必须存在 if (null === $fromTudu) { return $this->json(false, $this->lang['tudu_not_exists']); } // 必须是发起人才具备此操作 if ($fromTudu->sender != $this->_user->userName) { return $this->json(false, $this->lang['perm_deny_add_foreign']); } // 检查外发用户email格式,外发用户是否存在,不存在则创建 $address = array('to' => $this->_formatRecipients($to), 'cc' => $this->_formatRecipients($cc)); $tuduAddr = array('to' => array(), 'cc' => array()); $sendTo = array(); foreach ($fromTudu->to as $k => $item) { $tuduAddr['to'][] = implode(' ', array(!is_numeric($k) ? $k : '', $item[0])); } foreach ($fromTudu->cc as $k => $item) { $tuduAddr['cc'][] = implode(' ', array(!is_int($k) ? $k : '', $item[0])); } /* @var $addressBook Tudu_AddressBook */ $addressBook = Tudu_AddressBook::getInstance(); $receivers = $this->manager->getTuduUsers($tuduId, array('isforeign' => 1)); foreach ($address as $k => $arr) { foreach ($arr as $email => $name) { if (!$email && !$name) { continue; } $email = preg_replace('/^#+/', '', $email); // 本系统用户不参与外发 if (false !== strpos($email, '@') && null !== $addressBook->searchUser($this->_user->orgId, $email)) { return $this->json(false, $this->lang['deny_add_user_to_foreign']); } // 新添加的外发用户是否已存在 foreach ($receivers as $receiver) { if ($email && $email == $receiver['email']) { $display = $email ? $email : $name; return $this->json(false, sprintf($this->lang['foreign_user_already_exists'], $display)); } } // 不存在联系人时创建 if (!$addressBook->searchContact($this->_user->uniqueId, $email, $name)) { $this->manager->createContact($this->_user->uniqueId, $email, $name); } $sendTo[] = $email; $tuduAddr[$k][] = implode(' ', array($email, $name)); } } /* @var $deliver Tudu_Tudu_Deliver */ $deliver = Tudu_Tudu_Deliver::getInstance(); /* @var $storage Tudu_Tudu_Storage */ $storage = Tudu_Tudu_Storage::getInstance(); $tudu = $storage->prepareTudu(array('to' => $to, 'cc' => $cc), $fromTudu); $recipients = $deliver->prepareRecipients($this->_user->uniqueId, $this->_user->userId, $tudu); // 添加用户 if (!$deliver->sendTudu($tudu, $recipients)) { return $this->json(false, $this->lang['add_foreign_failure']); } // 更新图度用户 $this->manager->updateTudu($tuduId, array('to' => implode("\n", $tuduAddr['to']), 'cc' => implode("\n", $tuduAddr['cc']))); $config = $this->bootstrap->getOption('httpsqs'); // 发送邮件 $httpsqs = new Oray_Httpsqs($config['host'], $config['port'], $config['chartset'], $config['name']); // 发送外部邮件(如果有),处理联系人 $data = implode(' ', array('send', 'tudu', '', http_build_query(array('tsid' => $this->_user->tsId, 'tuduid' => $tuduId, 'uniqueid' => $this->_user->uniqueId, 'to' => implode(',', $sendTo))))); $httpsqs->put($data, 'send'); return $this->json(true, $this->lang['add_foreign_success']); }
/** * 生成周期图度 * * @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"); }