diff --git a/application/common/Model/Task.php b/application/common/Model/Task.php index cb90c9f..aca9c09 100644 --- a/application/common/Model/Task.php +++ b/application/common/Model/Task.php @@ -353,18 +353,6 @@ class Task extends CommonModel $result = self::update(['done' => $done], ['code' => $taskCode]); //todo 添加任务动态,编辑权限检测 Db::commit(); - $project = Project::where(['code' => $task['project_code']])->field('auto_update_schedule,schedule')->find(); - if ($project['auto_update_schedule']) { - $taskCount = \app\common\Model\Task::where(['project_code' => $task['project_code']])->count('code'); - if ($taskCount) { - $doneTaskCount = \app\common\Model\Task::where(['project_code' => $task['project_code'], 'done' => 1])->count('code'); - $schedule = $doneTaskCount / $taskCount * 100; - $project->schedule = $schedule; - $project->save(); - } - - } - $projectAutoUpdateSchedule = 1; } catch (Exception $e) { Db::rollback(); throw new Exception($e->getMessage()); diff --git a/application/project/behavior/Task.php b/application/project/behavior/Task.php index 5a82552..67e9a56 100644 --- a/application/project/behavior/Task.php +++ b/application/project/behavior/Task.php @@ -199,6 +199,21 @@ class Task $logData['content'] = $content; } ProjectLog::create($logData); + + $scheduleActions = ['create', 'done', 'redo', 'recycle', 'recovery', 'redoChild', 'doneChild', 'createChild']; + if (in_array($data['type'], $scheduleActions)) { + $project = \app\common\Model\Project::where(['code' => $task['project_code']])->field('auto_update_schedule,schedule')->find(); + if ($project['auto_update_schedule']) { + $taskCount = \app\common\Model\Task::where(['project_code' => $task['project_code']])->count('code'); + if ($taskCount) { + $doneTaskCount = \app\common\Model\Task::where(['project_code' => $task['project_code'], 'done' => 1])->count('code'); + $schedule = $doneTaskCount / $taskCount * 100; + $project->schedule = $schedule; + $project->save(); + } + } + } + //工作流事件 if (!$isRobot && !$task['pcode']) {//子任务不触发 $workflowActions = ['create', 'move', 'done', 'redo', 'assign', 'setEndTime', 'pri'];