diff --git a/module/task/model.php b/module/task/model.php index c3a4243ac8..357bf90413 100755 --- a/module/task/model.php +++ b/module/task/model.php @@ -649,7 +649,8 @@ class taskModel extends model } /** - * Get team by account from task teams. + * 获取用户所在多人任务的团队工序。 + * Get the team process of the multi-task by account. * * @param array $teams * @param string $account @@ -657,33 +658,37 @@ class taskModel extends model * @access public * @return object */ - public function getTeamByAccount($teams, $account = '', $extra = array('filter' => 'done')) + public function getTeamByAccount(array $teams, string $account = '', array $extra = array('filter' => 'done')) { if(empty($account)) $account = $this->app->user->account; - $filter = zget($extra, 'filter', ''); - $effortID = zget($extra, 'effortID', ''); + $filterStatus = zget($extra, 'filter', ''); + $effortID = zget($extra, 'effortID', ''); - $duplicates = array(); - $members = array(); - $taskID = 0; + $repeatUsers = array(); + $taskID = 0; foreach($teams as $team) { if(isset($extra['order']) and $team->order == $extra['order'] and $team->account == $account) return $team; - if(empty($taskID)) $taskID = $team->task; - if(isset($members[$team->account])) $duplicates[$team->account] = $team->account; - if(!isset($members[$team->account])) $members[$team->account] = 0; - $members[$team->account] += 1; + if(empty($taskID) and $effortID) $taskID = $team->task; + + if(isset($repeatUsers[$team->account])) + { + $repeatUsers[$team->account] = 1; + } + else + { + $repeatUsers[$team->account] = 0; + } } /* - * 1. No duplicate account; - * 2. Account is not duplicate account; - * 3. Not by effort; + * 1. No repeat account or account is not repeat account; + * 2. Not by effort; * Then direct get team by account. */ - if(empty($duplicates) or (!isset($duplicates[$account]))) + if(empty($repeatUsers[$account])) { foreach($teams as $team) { @@ -694,27 +699,25 @@ class taskModel extends model { foreach($teams as $team) { - if($filter and $team->status == $filter) continue; + if($filterStatus and $team->status == $filterStatus) continue; if($team->account == $account) return $team; } } elseif($effortID) { - $efforts = $this->getTaskEfforts($taskID, '', $effortID); - - $prevTeam = null; - $thisTeam = null; + $efforts = $this->getTaskEfforts($taskID, '', $effortID); + $prevTeam = $currentTeam = null; foreach($efforts as $effort) { - $thisTeam = reset($teams); + $currentTeam = reset($teams); if($effort->id == $effortID) { - if($effort->account == $thisTeam->account) return $thisTeam; - if($effort->account == $prevTeam->account) return $prevTeam; + if($effort->account == $currentTeam->account) return $currentTeam; + if($effort->account == $prevTeam->account) return $prevTeam; return false; } - if($effort->left == 0 and $thisTeam->account == $effort->account) $prevTeam = array_shift($teams); + if($effort->left == 0 and $currentTeam->account == $effort->account) $prevTeam = array_shift($teams); } } } diff --git a/module/task/test/model/getteambyaccount.php b/module/task/test/model/getteambyaccount.php index 08e3674c50..53162cf83c 100755 --- a/module/task/test/model/getteambyaccount.php +++ b/module/task/test/model/getteambyaccount.php @@ -7,11 +7,44 @@ su('admin'); /** title=taskModel->getTeamByAccount(); +timeout=0 cid=1 -pid=1 + +- 获取未开始的指定账号的团队信息 @admin_wait + +- 获取进行中的指定账号的团队信息 @admin_doing + +- 过滤已完成的成员获取的指定账号的团队信息 @admin_wait + +- 获取不存在的账号 @_ + +- 不过滤已完成的成员获取的指定账号的团队信息 @admin_done + +- 根据传入的日志ID获取对应成员的团队信息 @dev1_wait */ +$task = zdTable('task'); +$task->id->range('1-5'); +$task->execution->range('1-5'); +$task->name->prefix("任务")->range('1-5'); +$task->left->range('11-15'); +$task->estStarted->range('2022\-01\-01'); +$task->status->range("wait,doing,done,pause,cancel,closed"); +$task->gen(5); + +$effort = zdTable('effort'); +$effort->id->range('1-5'); +$effort->objectID->range('1-5'); +$effort->objectType->range('task'); +$effort->execution->range('1-5'); +$effort->work->prefix("工作内容")->range('1-5'); +$effort->left->range('11-15'); +$effort->consumed->range('11-15'); +$effort->date->range('2022\-01\-01'); +$effort->account->range("admin,dev1,dev2"); +$effort->gen(5); + $user = new stdclass(); $user->task = 1; $user->account = 'admin'; @@ -33,14 +66,28 @@ $user->status = 'wait'; $user->order = '2'; $users[] = $user; +$user = new stdclass(); +$user->task = 1; +$user->account = 'dev2'; +$user->status = 'done'; +$user->order = '3'; +$users[] = $user; + +$user = new stdclass(); +$user->task = 1; +$user->account = 'admin'; +$user->status = 'done'; +$user->order = '4'; +$users[] = $user; + $task = new taskTest(); -r($task->getTeamByAccount($users, 'admin')) && p() && e('admin_wait'); //获取未开始的指定账号的团队信息 +r($task->getTeamByAccountTest($users, 'admin')) && p() && e('admin_wait'); //获取未开始的指定账号的团队信息 $users[0]->status = 'doing'; -r($task->getTeamByAccount($users, 'admin')) && p() && e('admin_doing'); //获取进行中的指定账号的团队信息 +r($task->getTeamByAccountTest($users, 'admin')) && p() && e('admin_doing'); //获取进行中的指定账号的团队信息 $users[0]->status = 'done'; -r($task->getTeamByAccount($users, 'admin')) && p() && e('admin_wait'); //过滤已完成的成员获取的指定账号的团队信息 -r($task->getTeamByAccount($users, 'admin', array('filter' => ''))) && p() && e('admin_done'); //不过滤已完成的成员获取的指定账号的团队信息 - -r($task->getTeamByAccount($users, 'dev')) && p() && e('_'); //获取的不存在账号 +r($task->getTeamByAccountTest($users, 'admin')) && p() && e('admin_wait'); //过滤已完成的成员获取的指定账号的团队信息 +r($task->getTeamByAccountTest($users, 'dev')) && p() && e('_'); //获取不存在的账号 +r($task->getTeamByAccountTest($users, 'admin', array('filter' => ''))) && p() && e('admin_done'); //不过滤已完成的成员获取的指定账号的团队信息 +r($task->getTeamByAccountTest($users, 'dev1', array('filter' => '', 'effortID' => 3))) && p() && e('dev1_wait'); //根据传入的日志ID获取对应成员的团队信息 \ No newline at end of file diff --git a/module/task/test/task.class.php b/module/task/test/task.class.php index 7b40684306..c9712f3c5a 100755 --- a/module/task/test/task.class.php +++ b/module/task/test/task.class.php @@ -1481,7 +1481,7 @@ class taskTest * @access public * @return string */ - public function getTeamByAccount($users, $account, $filter = array('filter' => 'done')) + public function getTeamByAccountTest(array $users, string $account, array $filter = array('filter' => 'done')): string { $object = $this->objectModel->getTeamByAccount($users, $account, $filter); if(empty($object)) return '_';