示例#1
0
 /**
  * 接受任务
  */
 public function acceptAction()
 {
     $tuduIds = explode(',', $this->_request->getParam('tid'));
     // 参数:图度ID必须存在
     if (!count($tuduIds)) {
         return $this->json(false, $this->lang['invalid_tuduid']);
     }
     $success = 0;
     //用于计数操作成功个数
     foreach ($tuduIds as $tuduId) {
         // 获得图度数据
         $tudu = $this->manager->getTuduById($tuduId, $this->_user->uniqueId);
         // 图度必须存在
         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;
         }
         $ret = $this->manager->acceptTudu($tuduId, $this->_user->uniqueId, (int) $tudu->selfPercent);
         // 更新任务进度
         $this->manager->updateProgress($tuduId, $this->_user->uniqueId, $tudu->selfPercent);
         // 计算图度已耗时
         $this->manager->calcElapsedTime($tuduId);
         // 移除待办
         if (in_array('^td', $tudu->labels)) {
             $this->manager->deleteLabel($tudu->tuduId, $this->_user->uniqueId, '^td');
             $this->manager->deleteLabel($tudu->tuduId, $tudu->uniqueId, '^td');
         }
         if ($ret) {
             $success++;
             //记录次数
             // 添加操作日志
             $this->_writeLog(Dao_Td_Log_Log::TYPE_TUDU, $tuduId, Dao_Td_Log_Log::ACTION_TUDU_ACCEPT, array('accepttime' => time(), 'status' => Dao_Td_Tudu_Tudu::STATUS_DOING));
         }
     }
     if ($success <= 0) {
         return $this->json(false, $this->lang['accept_failure']);
     }
     return $this->json(true, $this->lang['accept_success']);
 }