/** * /compose/send * * 图度发送统一接口 * 接管保存,发送,更新,转发,申请审批等操作 * */ public function sendAction() { $post = $this->_request->getPost(); // 当前操作类型 $action = self::ACTION_SEND; // 图度类型 $type = isset($post['type']) ? $post['type'] : 'task'; // 操作的保存图度列表 // array('tuduid' => $params ...) $tuduList = array(); // 提交主任务ID $tuduId = isset($post['ftid']) ? $post['ftid'] : null; // 图度组根任务ID $rootId = null; // 是否包含分工 $hasDivide = isset($post['chidx']) && is_array($post['chidx']); // 日志详细信息 $logDetails = array(); // 返回数据 $returnData = array(); // 是否重开讨论 $isReopen = isset($post['isclose']) && $type == 'discuss'; if (!empty($post['action']) && $post['action'] == 'save') { $action = self::ACTION_SAVE; } if (!empty($post['forward'])) { $action = self::ACTION_FORWARD; } elseif (!empty($post['invite'])) { $action = self::ACTION_INVITE; } elseif (!empty($post['divide'])) { $action = self::ACTION_DIVIDE; } elseif (!empty($post['review'])) { $action = self::ACTION_REVIEW; } elseif (!empty($post['apply'])) { $action = self::ACTION_APPLY; } /* @var $manager Tudu_Tudu_Manager */ $manager = Tudu_Tudu_Manager::getInstance(); /* @var $storage Tudu_Tudu_Storage */ $storage = Tudu_Tudu_Storage::getInstance(); $Indexes = array(''); if ($type == 'task' && $hasDivide && $action != self::ACTION_FORWARD && $action != self::ACTION_APPLY) { $Indexes = array_merge($Indexes, $post['chidx']); } // 周期任务 if (($type == 'task' || $type == 'meeting') && $tuduId && !Tudu_Tudu_Extension::isRegistered('cycle')) { Tudu_Tudu_Extension::registerExtension('cycle', 'Tudu_Tudu_Extension_Cycle'); } // 需要图度组 if ($type == 'task') { Tudu_Tudu_Extension::registerExtension('group', 'Tudu_Tudu_Extension_Group'); } // 需要流程 if (($type == 'task' || $type == 'notice') && !Tudu_Tudu_Extension::isRegistered('flow')) { Tudu_Tudu_Extension::registerExtension('flow', 'Tudu_Tudu_Extension_Flow'); } // 版块列表 $boards = $this->getBoards(false); // 遍历提交图度参数,填充图度列表 $children = array(); foreach ($Indexes as $suffix) { if ('' !== $suffix) { $suffix = '-' . $suffix; } // 获取已存在图度数据 $fromTudu = null; if (!empty($post['ftid' . $suffix])) { $tid = $post['ftid' . $suffix]; $fromTudu = $manager->getTuduById($tid, $this->_user->uniqueId); if (null === $fromTudu) { return $this->json(false, $this->lang['tudu_not_exists']); } } // 创建图度 if (null === $fromTudu) { // 转发、分工等图度不存在 if ($action != self::ACTION_SEND && $action != self::ACTION_SAVE && $action != self::ACTION_DIVIDE || $action == self::ACTION_DIVIDE && '' === $suffix) { return $this->json(false, $this->lang['tudu_not_exists']); } // 创建权限 if (!$this->_user->getAccess()->isAllowed(Tudu_Access::PERM_CREATE_TUDU)) { return $this->json(false, $this->lang['perm_deny_create_tudu']); } } else { // 非草稿状态下的分工,没有修改则不进行后续更新操作 if (!empty($suffix) && empty($post['ismodified' . $suffix]) && !($fromTudu->isDraft && $action != self::ACTION_SAVE)) { $idx = str_replace('-', '', $suffix); $children[$idx] = $fromTudu->tuduId; continue; } // 保存草稿,图度必须为草稿状态 if ($action == self::ACTION_SAVE) { if (!$fromTudu->isDraft) { return $this->json(false, $this->lang['forbid_save_sent']); } } else { $isSender = true; $isAccepter = in_array($this->_user->address, $fromTudu->accepter, true) || in_array($this->_user->userName, $fromTudu->accepter, true); switch ($action) { // 更新,权限,发起人/版主/分区负责人 case self::ACTION_SEND: // 更新权限 if ($fromTudu && !$fromTudu->isDraft && !$this->_user->getAccess()->isAllowed(Tudu_Access::PERM_UPDATE_TUDU)) { return $this->json(false, $this->lang['perm_deny_update_tudu']); } // 权限 $board = $boards[$fromTudu->boardId]; $isModerator = array_key_exists($this->_user->userId, $board['moderators']); $isSuperModerator = !empty($board['parentid']) && array_key_exists($this->_user->userId, $boards[$board['parentid']]['moderators']); if (!$isSender && !$isModerator && !$isSuperModerator) { return $this->json(false, $this->lang['perm_deny_update_tudu']); } break; // 转发,权限,任务,已发送,执行人,非图度组 // 转发,权限,任务,已发送,执行人,非图度组 case self::ACTION_FORWARD: // 转发权限 if (!$this->_user->getAccess()->isAllowed(Tudu_Access::PERM_FORWARD_TUDU)) { return $this->json(false, $this->lang['perm_deny_forward_tudu']); } // 图度组 if ($fromTudu->isTuduGroup) { return $this->json(false, $this->lang['deny_forward_tudugroup']); } // 不是执行人 if (!$isAccepter) { return $this->json(false, $this->lang['forbid_non_accepter_forward']); } $isSender = $fromTudu->sender == $this->_user->userName; break; // 分工,任务,已发送,执行人,有分工 // 分工,任务,已发送,执行人,有分工 case self::ACTION_DIVIDE: if (empty($post['chidx'])) { return $this->json(false, $this->lang['no_divide_tudu']); } if ($fromTudu->isDraft) { return $this->json(false, $this->lang['tudu_not_exists']); } $isSender = $fromTudu->sender == $this->_user->userName; break; // 邀请,必须为会议,已经发送 // 邀请,必须为会议,已经发送 case self::ACTION_INVITE: if ($fromTudu->type != 'meeting') { return $this->json(false, null); } if ($fromTudu->isDraft) { return $this->json(false, $this->lang['tudu_not_exists']); } $isSender = $fromTudu->sender == $this->_user->userName; break; // 申请审批,必须为任务,已发送,执行人,非图度组 // 申请审批,必须为任务,已发送,执行人,非图度组 case self::ACTION_APPLY: // 图度组不能参与审批 if ($fromTudu->isTuduGroup) { return $this->json(false, $this->lang['tudu_group_review']); } // 非图度执行人不能进行申请审批操作 if (!$isAccepter) { return $this->json(false, $this->lang['no_accepter_apply']); } // 审批人为空 if (empty($post['reviewer' . $suffix])) { return $this->json(false, $this->lang['no_reviewer']); } $isSender = $fromTudu->sender == $this->_user->userName; break; // 审批,审批步骤,审批人是当前用户 // 审批,审批步骤,审批人是当前用户 case self::ACTION_REVIEW: if (!$fromTudu->stepId || false !== strpos('^', $fromTudu->stepId)) { return $this->json(false, $this->lang['disable_review']); } $flow = Tudu_Tudu_Extension::getExtension('flow'); $reviewer = $flow->getStepUser($fromTudu->tuduId, $fromTudu->stepId, $this->_user->uniqueId); if (!$reviewer || $reviewer['type'] != Dao_Td_Tudu_Step::TYPE_EXAMINE || $reviewer['status'] != 1) { return $this->json(false, $this->lang['disable_review']); } $isSender = $fromTudu->sender == $this->_user->userName; break; } if ($action != self::ACTION_SEND && $fromTudu->isDraft) { return $this->json(false, $this->lang['forbid_save_sent']); } } } $params = $this->_formatTuduParams($post, $suffix); $params['action'] = $action; if (null === $fromTudu) { // 发起人参数 $params['from'] = $this->_user->userName . ' ' . $this->_user->trueName; $params['email'] = $this->_user->userName; $params['sender'] = $this->_user->userName; } else { if (!empty($params['flowid']) && $action != self::ACTION_REVIEW && $action != self::ACTION_FORWARD) { unset($params['to']); } if (!$fromTudu->isDraft) { $params['lastmodify'] = implode(chr(9), array($this->_user->uniqueId, time(), $this->_user->trueName)); } } // 创建时间 if (null === $fromTudu || $fromTudu->isDraft) { $params['createtime'] = time(); } // 转发,没有编辑权限,去除保存参数 $isClearModify = false; if ($action == self::ACTION_FORWARD) { // 权限 $board = $boards[$fromTudu->boardId]; $isModerator = array_key_exists($this->_user->userId, $board['moderators']); $isSuperModerator = !empty($board['parentid']) && array_key_exists($this->_user->userId, $boards[$board['parentid']]['moderators']); if (!$this->_user->getAccess()->isAllowed(Tudu_Access::PERM_UPDATE_TUDU) || !$isSender && !$isModerator && !$isSuperModerator) { $isClearModify = true; } } if ($action == self::ACTION_REVIEW || $action == self::ACTION_APPLY) { $isClearModify = true; } if ($isClearModify) { unset($params['classid'], $params['subject'], $params['privacy'], $params['password'], $params['priority'], $params['isauth'], $params['needconfirm'], $params['notifyall']); } try { $tudu = $storage->prepareTudu($params, $fromTudu); } catch (Tudu_Tudu_Exception $e) { switch ($e->getCode()) { case Tudu_Tudu_Exception::CODE_FLOW_STEP_NULL: $this->json(false, $this->lang['missing_flow_steps']); break; case Tudu_Tudu_Exception::CODE_NOT_EXISTS_UPPER: $this->json(false, $this->lang['missing_flow_steps_upper_reviewer']); break; case Tudu_Tudu_Exception::CODE_NOT_EXISTS_USER: $this->json(false, $this->lang['missing_flow_steps_receiver']); break; /* case Tudu_Tudu_Exception::MISSING_VOTE_TITLE: $this->json(false, $this->lang['missing_vote_title']); break; case Tudu_Tudu_Exception::MISSING_VOTE_OPTIONS: $this->json(false, $this->lang['missing_vote_option']); break; */ } } if ('' === $suffix) { $tuduId = $tudu->tuduId; $rootId = $tudu->rootId ? $tudu->rootId : $tudu->tuduId; } // 返回投票数据参数 if ($tudu->type == 'discuss' && $tudu->vote) { $vote = $tudu->vote; if ($vote && !empty($vote['newoptions'])) { foreach ($vote['newoptions'] as $item) { $returnData['votes'][$item['index']] = $item['optionid']; } } } // 部分操作不需要继承原文内容 if ('' == $suffix && $action != self::ACTION_REVIEW && $action != self::ACTION_FORWARD && $action != self::ACTION_INVITE) { if ($fromTudu && !$fromTudu->isDraft) { $tudu->boardId = $tudu->boardId ? $tudu->boardId : $fromTudu->boardId; $tudu->content = $tudu->content ? $tudu->content : $fromTudu->content; $tudu->startTime = isset($post['starttime' . $suffix]) ? $tudu->startTime : $fromTudu->startTime; $tudu->endTime = isset($post['endtime' . $suffix]) ? $tudu->endTime : $fromTudu->endTime; } } // 设置子任务的父级ID if ('' !== $suffix && $type == 'task') { $tudu->parentId = $tuduId; $tudu->rootId = $rootId; $tudu->nodeType = $tudu->nodeType ? $tudu->nodeType : Dao_Td_Tudu_Group::TYPE_LEAF; $parent = $tuduList[$tuduId]; if (!$fromTudu) { $tudu->boardId = $tudu->boardId ? $tudu->boardId : $parent->boardId; $tudu->classId = $tudu->classId ? $tudu->classId : $parent->classId; //$tudu->content = $tudu->content ? $tudu->content : $parent->content; $tudu->startTime = $tudu->startTime ? $tudu->startTime : $parent->startTime; $tudu->endTime = $tudu->endTime ? $tudu->endTime : $parent->endTime; $content = trim(strip_tags($tudu->content, 'img')); if (!$content) { $tudu->content = $parent->content; } } else { $tudu->boardId = $tudu->boardId ? $tudu->boardId : $fromTudu->boardId; $tudu->content = $tudu->content ? $tudu->content : $fromTudu->content; $tudu->startTime = $tudu->startTime ? $tudu->startTime : $fromTudu->startTime; $tudu->endTime = $tudu->endTime ? $tudu->endTime : $fromTudu->endTime; } $returnData['children'][(string) str_replace('-', '', $suffix)] = $tudu->tuduId; $idx = str_replace('-', '', $suffix); $children[$idx] = $tudu->tuduId; } if ('' === $suffix && $hasDivide && $type == 'task') { $tudu->rootId = $rootId; $tudu->nodeType = Dao_Td_Tudu_Group::TYPE_NODE; } // 没有分工 if (!$hasDivide && $tuduId == $tudu->tuduId && $fromTudu && $fromTudu->nodeType && $manager->getChildrenCount($tudu->tuduId) <= 0) { $tudu->nodeType = Dao_Td_Tudu_Group::TYPE_LEAF; } // 未发送,更新创建时间 /*if (!$fromTudu || $fromTudu->isDraft) { $tudu->createTime = time(); }*/ // 空内容 if ($action != self::ACTION_REVIEW && $action != self::ACTION_SAVE && !$tudu->content) { return $this->json(false, $this->lang['params_invalid_content']); } // 转发 if ($action == self::ACTION_FORWARD || $action == self::ACTION_INVITE) { // 输入用户已经是执行人 $to = $tudu->to; foreach ($to as $k => $item) { /*if (is_string($item['email']) && in_array($item['email'], $fromTudu->accepter, true)) { return $this->json(false, sprintf($this->lang['user_is_accepter'], $item['truename'])); }*/ if ($action == self::ACTION_FORWARD && $fromTudu->selfPercent < 100) { $to[$k]['percent'] = $fromTudu->selfPercent; } } $tudu->to = $to; $to = array(); foreach ($fromTudu->to as $k => $item) { if ($k != $this->_user->userName) { $to[] = $k . ' ' . $item[0]; } } $tudu->to = array_merge($tudu->to, Tudu_Tudu_Storage::formatRecipients(implode("\n", $to))); } // 邀请 || 100% 转发 加上自己 if ($action == self::ACTION_INVITE || $action == self::ACTION_FORWARD && $fromTudu->selfPercent >= 100) { $tudu->to = array_merge($tudu->to, array($this->_user->userName => array('email' => $this->_user->userName, 'truename' => $this->_user->trueName, 'percent' => $fromTudu->selfPercent))); } // 执行人 -- 自己 if ($action == self::ACTION_APPLY) { $tudu->to = Tudu_Tudu_Storage::formatRecordRecipients($fromTudu->to); } // 暂时不能输入自己 - 界面交互有问题不能支持 if ($action == self::ACTION_REVIEW && $tudu->reviewer) { if (array_key_exists($this->_user->address, $tudu->reviewer) || array_key_exists($this->_user->userName, $tudu->reviewer)) { return $this->json(false, $this->lang['add_reviewer_self']); } } $tuduList[$tudu->tuduId] = $tudu; $act = $tudu->tuduId == $tuduId ? $action : 'send'; if ($act == 'send') { $act = $fromTudu && !$fromTudu->isDraft ? 'update' : 'send'; } $detail = $this->_getLogDetail($params, $fromTudu); if (in_array($action, array(self::ACTION_REVIEW, self::ACTION_APPLY, self::ACTION_FORWARD, self::ACTION_INVITE))) { unset($detail['content']); } $logDetails[$tudu->tuduId] = array('action' => $act, 'detail' => $detail); } foreach ($tuduList as $tid => $item) { $prevId = $item->prevTuduId; if ($prevId && strpos($prevId, 'child-') !== false) { $prevId = (int) str_replace('child-', '', $prevId); if (isset($children[$prevId])) { $item->prevTuduId = $children[$prevId]; } } } // 遍历图度列表保存 foreach ($tuduList as $tid => $tudu) { // 主任务按照操作处理 // 处理审批流程 if ($action == self::ACTION_REVIEW) { $agree = $this->_request->getPost('agree'); $storage->reviewTudu($tudu, $agree); // 其他操作 } else { if ($tid == $tuduId) { $func = $action == 'send' ? 'save' : $action; $func .= 'Tudu'; } else { $func = 'saveTudu'; } $ret = $storage->{$func}($tudu); if (!$ret) { return $this->json(false, $this->lang['save_failure']); } } $returnData['tuduid'] = $tuduId; } //Tudu_Tudu_Deliver::initAddressBook($this->multidb->getDefaultDb()); $deliver = Tudu_Tudu_Deliver::getInstance(); // 遍历图度列表发送图度 if ($action !== self::ACTION_SAVE) { $config = $this->bootstrap->getOption('httpsqs'); $httpsqs = new Oray_Httpsqs($config['host'], $config['port'], $config['chartset'], $config['name']); foreach ($tuduList as $tid => $tudu) { // 发送到接收人 $recipients = $deliver->prepareRecipients($this->_user->uniqueId, $this->_user->userId, $tudu); if ($action == self::ACTION_REVIEW && $tudu->type == 'notice' && !$this->_request->getPost('agree')) { $recipients = array(); $addressBook = $deliver->getAddressBook(); $fromSender = $addressBook->searchUser($tudu->orgId, $tudu->sender); if (!empty($fromSender)) { $fromSender['accepterinfo'] = $fromSender['email'] . ' ' . $fromSender['truename']; $fromSender['issender'] = $fromSender['email'] == $tudu->sender; $recipients[$fromSender['uniqueid']] = $fromSender; } } // 公告(含审批时),过滤接收人 if ($tudu->type == 'notice' && $tudu->reviewer) { $users = array(); foreach ($tudu->reviewer as $item) { foreach ($item as $reviewer) { $users[] = $reviewer['email']; } } // 过滤非审批人的接收用户 foreach ($recipients as $uniqueId => $recipient) { if (!in_array($recipient['email'], $users)) { unset($recipients[$uniqueId]); } } } // 移除原执行人 if (($tudu->type == 'meeting' || $tudu->type == 'task' && !$tudu->reviewer) && !$tudu->isDraft()) { $accepters = $manager->getTuduAccepters($tudu->tuduId); $to = $tudu->to; foreach ($accepters as $item) { list($email, ) = explode(' ', $item['accepterinfo'], 2); // 移除执行人角色,我执行标签 if (!empty($to) && !array_key_exists($email, $to) && $manager->getChildrenCount($tudu->tuduId, $item['uniqueid']) <= 0) { $deliver->removeAccepter($tudu->tuduId, $item['uniqueid']); $manager->deleteLabel($tudu->tuduId, $item['uniqueid'], '^a'); $manager->deleteLabel($tudu->tuduId, $item['uniqueid'], '^td'); } // 过滤外发执行人 避免重复发送 if ($action != self::ACTION_SEND) { foreach ($recipients as $uniqueId => $recipient) { if (!empty($recipient['isforeign']) && !empty($to) && array_key_exists($recipient['email'], $to)) { unset($recipients[$uniqueId]); } } } // 转发,继续之前的用户进度 if ($action == self::ACTION_FORWARD && isset($recipients[$item['uniqueid']])) { $recipients[$item['uniqueid']]['tudustatus'] = (int) $item['tudustatus']; } // 审批,继续之前的用户进度 if ($action == self::ACTION_REVIEW && isset($recipients[$item['uniqueid']])) { $recipients[$item['uniqueid']]['percent'] = (int) $item['percent']; } } } foreach ($recipients as $key => $recipient) { // 需要验证 if (!empty($recipient['isforeign'])) { $recipients[$key]['authcode'] = $tudu->isAuth ? Oray_Function::randKeys(4) : null; } // 标记转发 // 进度小于 100%是继承进度,100%时为0 if ($action == self::ACTION_FORWARD || $action == self::ACTION_INVITE) { $newAccepter = $this->_getReceiver($post, 'to'); $fromTudu = $tudu->getFromTudu(); if (isset($recipient['role']) && $recipient['role'] == 'to' && array_key_exists($recipient['email'], $newAccepter)) { $recipients[$key]['forwardinfo'] = $this->_user->trueName . "\n" . time(); $recipients[$key]['percent'] = $fromTudu->selfPercent < 100 ? $fromTudu->selfPercent : 0; $recipients[$key]['tudustatus'] = $fromTudu->selfTuduStatus < 2 ? $fromTudu->selfTuduStatus : 0; } } if ($tudu->flowId && isset($recipient['role']) && $recipient['role'] == 'to') { $recipients[$key]['tudustatus'] = 1; $recipients[$key]['percent'] = 0; } } // 过滤外发人 避免重复发送 /*if ($action != self::ACTION_SEND) { $fromTudu = $tudu->getFromTudu(); foreach ($recipients as $uniqueId => $recipient) { if (!empty($recipient['isforeign']) && (($fromTudu->to && array_key_exists($recipient['email'], $fromTudu->to)) || ($fromTudu->cc && array_key_exists($recipient['email'], $fromTudu->cc)) || ($fromTudu->bcc && array_key_exists($recipient['email'], $fromTudu->bcc)))) { unset($recipients[$uniqueId]); } } }*/ // 标记当前用户已转发 if ($action == self::ACTION_FORWARD) { $manager->markForward($tudu->tuduId, $this->_user->uniqueId); } // 加上当前用户(发起人) if ((!$tudu->isFromTudu() || $tudu->isDraft()) && !isset($recipients[$this->_user->uniqueId])) { $recipients[$this->_user->uniqueId] = array('uniqueid' => $this->_user->uniqueId, 'role' => 'from', 'issender' => true); } // 发送图度到接收人 $deliver->sendTudu($tudu, $recipients); $flowPercent = null; // 计算进度 if ($tudu->flowId) { if ($tudu->isChange('stepid')) { $progress = $manager->updateFlowProgress($tudu->tuduId, null, $tudu->stepId, null, $flowPercent); } } else { $progress = $manager->updateProgress($tudu->tuduId, null, null); } // 需要计算父任务进度 if ($tudu->parentId) { $manager->calParentsProgress($tudu->tuduId); // 小于100%的分工从图度箱移除 if (!$tudu->flowId) { if ($progress < 100 && !array_key_exists($this->_user->address, $tudu->to)) { $manager->deleteLabel($tudu->tuduId, $this->_user->uniqueId, '^i'); $manager->deleteLabel($tudu->tuduId, $this->_user->uniqueId, '^td'); $manager->deleteLabel($tudu->tuduId, $this->_user->uniqueId, '^c'); } } } // 自己接受当前任务 if ($action == self::ACTION_SEND || $action == self::ACTION_DIVIDE) { if (($tudu->type == 'task' || $tudu->type == 'meeting') && !$tudu->flowId) { if ($tudu->to && array_key_exists($this->_user->userName, $tudu->to) || $recipients && array_key_exists($this->_user->uniqueId, $recipients) && !$tudu->acceptMode) { $manager->acceptTudu($tudu->tuduId, $this->_user->uniqueId, null); } } } // 转发操作,添加我转发标签,其他则添加到已发送 if ($action == self::ACTION_FORWARD) { $manager->addLabel($tuduId, $this->_user->uniqueId, '^w'); } else { if ($action != self::ACTION_REVIEW) { $manager->addLabel($tuduId, $this->_user->uniqueId, '^f'); } } // 审批标签 if ($action == self::ACTION_REVIEW) { $manager->deleteLabel($tuduId, $this->_user->uniqueId, '^e'); $manager->deleteLabel($tuduId, $this->_user->uniqueId, '^td'); $manager->addLabel($tuduId, $this->_user->uniqueId, '^v'); $fromTudu = $tudu->getFromTudu(); if (null != $fromTudu) { if (is_array($tudu->to) && array_key_exists($fromTudu->sender, $tudu->to) && $tudu->stepId != '^head' && $tudu->stepId != '^break' && !$tudu->flowId && !$tudu->acceptMode) { $addressBook = Tudu_AddressBook::getInstance(); $user = $addressBook->searchUser($this->_user->orgId, $fromTudu->sender); if (null !== $user) { $manager->acceptTudu($tudu->tuduId, $user['uniqueid'], null); } } } } // 移除草稿 if ($tudu->isDraft()) { $manager->deleteLabel($tuduId, $this->_user->uniqueId, '^r'); } if (isset($logDetails[$tid])) { // 图度日志 $this->_writeLog(Dao_Td_Log_Log::TYPE_TUDU, $tid, $logDetails[$tid]['action'], $logDetails[$tid]['detail'], 0); } // 记录私密密码 if ($tudu->password) { $this->session->privacy[$tudu->tuduId] = $tudu->password; } // 标记所有人未读状态 $manager->markAllUnRead($tudu->tuduId); // 重开讨论 if ($isReopen) { $manager->closeTudu($tudu->tuduId, 0); } // 工作流执行人自动接受任务 if ($tudu->flowId) { $daoStep = $this->getDao('Dao_Td_Tudu_Step'); $step = $daoStep->getStep(array('tuduid' => $tudu->tuduId, 'stepid' => $tudu->stepId)); if (null !== $step) { $stepUsers = $daoStep->getUsers($tudu->tuduId, $tudu->stepId); if ($step->type == Dao_Td_Tudu_Step::TYPE_EXECUTE && !empty($stepUsers) && $tudu->stepId != '^head' && $tudu->stepId != '^break') { foreach ($stepUsers as $item) { $manager->acceptTudu($tudu->tuduId, $item['uniqueid'], null); } $manager->updateTudu($tudu->tuduId, array('acceptmode' => 0)); // 认领模式 } else { if ($step->type == Dao_Td_Tudu_Step::TYPE_CLAIM) { $manager->updateTudu($tudu->tuduId, array('acceptmode' => 1, 'accepttime' => null)); } } } if ($flowPercent == 100 && !$tudu->needConfirm) { $manager->doneTudu($tudu->tuduId, true, 0); // 添加操作日志 $this->_writeLog(Dao_Td_Log_Log::TYPE_TUDU, $tudu->tuduId, Dao_Td_Log_Log::ACTION_TUDU_DONE, array('percent' => $flowPercent), false, true); } } // 记录外发人员 $contacts = array(); foreach ($recipients as $item) { if (!empty($item['isforeign'])) { $contacts[] = $item['uniqueid']; } } if ($contacts) { $this->session->tuduContact[$tudu->tuduId] = $contacts; } $sqsAction = !$tudu->isFromTudu() || $tudu->isDraft() ? 'create' : 'update'; $isChangedCc = $tudu->isChange('cc') || $tudu->isChange('bcc'); $sqsParam = array('tsid' => $this->_user->tsId, 'tuduid' => $tid, 'from' => $this->_user->userName, 'uniqueid' => $this->_user->uniqueId, 'server' => $this->_request->getServer('HTTP_HOST'), 'type' => $type, 'ischangedCc' => $sqsAction == 'update' && $isChangedCc ? $isChangedCc : false); if ($action == self::ACTION_SEND && $tudu->flowId && $sqsAction == 'create') { $sqsParam['nstepid'] = $tudu->stepId; $sqsParam['flowid'] = $tudu->flowId; } if ($action == self::ACTION_REVIEW) { $sqsAction = 'review'; $sqsParam['stepid'] = $tudu->getFromTudu()->stepId; $sqsParam['agree'] = $this->_request->getPost('agree'); if ($tudu->flowId) { $sqsParam['nstepid'] = $tudu->stepId; $sqsParam['flowid'] = $tudu->flowId; $sqsParam['stepstatus'] = $tudu->currentStepStatus; } if ($tudu->type == 'notice' && ($tudu->stepId = '^end')) { $sqsAction = 'create'; } } $httpsqs->put(implode(' ', array('tudu', $sqsAction, '', http_build_query($sqsParam))), 'tudu'); } // 保存到发起人草稿箱 } else { foreach ($tuduList as $tid => $tudu) { if (!$tudu->parentId) { $deliver->saveDraft($tudu); } } } $message = $action !== self::ACTION_SAVE ? $this->lang['send_success'] : $this->lang['save_success']; Tudu_Tudu_Extension::unRegisterAll(); return $this->json(true, $message, $returnData); }