/**
  * 更改任务状态
  */
 public function check()
 {
     $data['noset']['task_id'] = $this->isP('task_id', '请选择任务');
     $task = $this->db('task AS t')->field("t.*, group_concat(tc.check_user_id) AS check_user_id ")->join("{$this->prefix}task_check AS tc ON tc.task_id = t.task_id")->where('t.task_id = :task_id ')->group('t.task_id')->find(array('task_id' => $data['noset']['task_id']));
     if (empty($task) || $task['task_delete'] == '1') {
         $this->error('任务不存在');
     }
     $checker = explode(',', $task['check_user_id']);
     $data['task_status'] = empty($_POST['task_status']) ? '2' : $this->p('task_status');
     $this->db()->transaction();
     switch ($data['task_status']) {
         case '2':
             if ($_SESSION['team']['user_id'] != $task['task_user_id']) {
                 $this->error('您不是本任务执行人');
             }
             $noticeUser = $checker;
             $noticeType = '3';
             $dynamicType = '3';
             //提交审核,增加EY值
             \Model\User::setEy($_SESSION['team']['user_id'], '1');
             break;
         case '3':
         case '4':
             if (!in_array($_SESSION['team']['user_id'], $checker)) {
                 $this->error('您没有权限处理本任务');
             }
             $noticeUser = array($task['task_user_id']);
             $noticeType = $data['task_status'] == '3' ? '4' : '6';
             $dynamicType = $data['task_status'] == '3' ? '' : '4';
             $eyValue = $data['task_status'] == '3' ? '-2' : '1';
             \Model\User::setEy($task['task_user_id'], $eyValue);
             break;
         default:
             $this->error('未知的任务状态');
     }
     //每个状态变更,都表示一个完成时间
     $data['task_completetime'] = time();
     $updateResultt = $this->db('task')->where('task_id = :task_id')->update($data);
     if (empty($updateResultt)) {
         $this->db()->rollBack();
         $this->error('提交任务失败');
     }
     //状态为3需要判断是否有任务补充说明提交
     if ($data['task_status'] == 3) {
         $supplement['task_id'] = $data['noset']['task_id'];
         $supplement['task_supplement_content'] = $this->p('content');
         $supplement['task_supplement_file'] = !empty($_POST['file']) && is_array($_POST['file']) ? implode(',', $_POST['file']) : '';
         $supplement['task_supplement_time'] = time();
         if (!empty($supplement['task_supplement_content']) || !empty($supplement['task_supplement_file'])) {
             $addSupplement = $this->db('task_supplement')->insert($supplement);
             if (empty($addSupplement)) {
                 $this->db()->rollBack();
                 $this->error('添加任务补充说明失败');
             }
         }
     }
     //生成系统消息
     foreach ($noticeUser as $value) {
         $sendNotice = \Model\Notice::addNotice($value, $data['noset']['task_id'], $noticeType, $task['task_mail']);
         if (empty($sendNotice)) {
             $this->db()->rollBack();
             $this->error('生成系统消息出错!');
         }
     }
     //生成个人动态
     if (!empty($dynamicType)) {
         $addDynamic = \Model\Dynamic::addDynamic($task['task_user_id'], $data['noset']['task_id'], $dynamicType);
         if (empty($addDynamic)) {
             $this->db()->rollBack();
             $this->error('更新用户动态失败');
         }
     }
     $this->db()->commit();
     $this->success('任务状态已更新!', $this->url('Team-Task-view', array('id' => $data['noset']['task_id'])));
 }
 public function action()
 {
     //创建任务的uid,此处必须注意,$_POST的信息必定是字符串
     $_POST['create_id'] = (string) $_SESSION['team']['user_id'];
     //进行一些基础表单信息入库
     $this->db()->transaction();
     $addResult = \Model\Content::addContent();
     if ($addResult['status'] == false) {
         $this->db()->rollBack();
         $this->error($addResult['mes']);
     }
     //生成任务站内通知,accept_id为1表示本部门,反之需要部门责任人审核任务
     if ($_POST['accept_id'] == '1') {
         $sendNoticeResult = \Model\Notice::addNotice($_POST['user_id'], $addResult['mes'], '1', $_POST['mail']);
         if ($sendNoticeResult == false) {
             $this->db()->rollBack();
             $this->error('生成新任务通知失败');
         }
     } else {
         $department = \Model\Content::findContent('department', $_POST['department_id'], 'department_id');
         if (empty($department['department_header'])) {
             $this->db()->rollBack();
             $this->error('该部门没有负责人,无法创建任务');
         }
         $department_header = explode(',', $department['department_header']);
         foreach ($department_header as $v) {
             $sendNoticeResult = \Model\Notice::addNotice($v, $addResult['mes'], '5', $_POST['mail']);
             if ($sendNoticeResult == false) {
                 $this->db()->rollBack();
                 $this->error('生成部门审核通知失败');
             }
         }
     }
     //添加任务审核人,不论是否设置对应的审核人,部门审核人都将成为审核人之一。
     $checkUserList = empty($department_header) ? explode(',', $_POST['check_user_id']) : array_unique(array_merge_recursive(explode(',', $_POST['check_user_id']), $department_header));
     foreach ($checkUserList as $v) {
         $addCheckResult = $this->db('task_check')->insert(array('task_id' => $addResult['mes'], 'check_user_id' => $v));
         if ($addCheckResult == false) {
             $this->db()->rollBack();
             $this->error('添加审核人失败');
         }
         $sendNoticeResult = \Model\Notice::addNotice($v, $addResult['mes'], '2', $_POST['mail']);
         if ($sendNoticeResult == false) {
             $this->db()->rollBack();
             $this->error('生成指派通知失败');
         }
         \Model\User::setEy($v, '1');
     }
     $addDynamic = \Model\Dynamic::addDynamic($_SESSION['team']['user_id'], $addResult['mes'], '1');
     if (empty($addDynamic)) {
         $this->db()->rollBack();
         $this->error('更新用户动态失败');
     }
     $this->db()->commit();
     if (!empty($_POST['back_url'])) {
         $url = $_POST['back_url'];
     } else {
         $url = $this->url('Team-' . MODULE . '-index');
     }
     $this->success($GLOBALS['_LANG']['CONTENT']['ADD_CONTENT_SUCCESS'], $url);
 }