From cde65308329fd93a37ec6d5e6b43fabb0aef3572 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Mon, 13 Dec 2021 12:38:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=BB=E5=8A=A1=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=BD=92=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/ProjectController.php | 4 ++-- app/Models/Project.php | 11 +++++------ app/Models/ProjectTask.php | 10 +++++----- ...02344_project_tasks_add_archived_follow.php | 18 +++++++++++++++++- 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/Api/ProjectController.php b/app/Http/Controllers/Api/ProjectController.php index 7c7a9879..a6535a0c 100755 --- a/app/Http/Controllers/Api/ProjectController.php +++ b/app/Http/Controllers/Api/ProjectController.php @@ -648,9 +648,9 @@ class ProjectController extends AbstractController // $task_id = intval(Request::input('task_id')); // - $task = ProjectTask::userTask($task_id, ['taskUser', 'taskTag']); + $task = ProjectTask::userTask($task_id, ['taskUser', 'taskTag'], true, $project); // - $task->project_name = Project::whereId($task->project_id)->value('name'); + $task->project_name = $project?->name; $task->column_name = ProjectColumn::whereId($task->column_id)->value('name'); // return Base::retSuccess('success', $task); diff --git a/app/Models/Project.php b/app/Models/Project.php index 9e27527c..bf84e92b 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -290,7 +290,7 @@ class Project extends AbstractModel $this->addLog("项目归档"); $this->pushMsg('archived'); ProjectTask::whereProjectId($this->id)->whereArchivedAt(null)->update([ - 'archived_at' => Carbon::now(), + 'archived_at' => $archived_at, 'archived_follow' => 1 ]); } @@ -373,14 +373,13 @@ class Project extends AbstractModel */ public static function userProject($project_id, $ignoreArchived = true) { - $builder = self::select(self::projectSelect)->authData()->where('projects.id', intval($project_id)); - if ($ignoreArchived) { - $builder->whereNull('projects.archived_at'); - } - $project = $builder->first(); + $project = self::select(self::projectSelect)->authData()->where('projects.id', intval($project_id))->first(); if (empty($project)) { throw new ApiException('项目不存在或不在成员列表内', [ 'project_id' => $project_id ], -4001); } + if ($ignoreArchived && $project->archived_at != null) { + throw new ApiException('项目已归档', [ 'project_id' => $project_id ], -4001); + } return $project; } } diff --git a/app/Models/ProjectTask.php b/app/Models/ProjectTask.php index 02910ae6..efbdd6bb 100644 --- a/app/Models/ProjectTask.php +++ b/app/Models/ProjectTask.php @@ -744,18 +744,18 @@ class ProjectTask extends AbstractModel * @param int $task_id * @param array $with * @param bool $ignoreArchived 排除已归档 + * @param null $project * @return self */ public static function userTask($task_id, $with = [], $ignoreArchived = true, &$project = null) { - $builder = self::with($with)->whereId(intval($task_id)); - if ($ignoreArchived) { - $builder->whereNull('archived_at'); - } - $task = $builder->first(); + $task = self::with($with)->whereId(intval($task_id))->first(); if (empty($task)) { throw new ApiException('任务不存在', [ 'task_id' => $task_id ], -4002); } + if ($ignoreArchived && $task->archived_at != null) { + throw new ApiException('任务已归档', [ 'task_id' => $task_id ], -4002); + } // try { $project = Project::userProject($task->project_id, $ignoreArchived); diff --git a/database/migrations/2021_12_13_002344_project_tasks_add_archived_follow.php b/database/migrations/2021_12_13_002344_project_tasks_add_archived_follow.php index 2b0d92a0..da29c2fa 100644 --- a/database/migrations/2021_12_13_002344_project_tasks_add_archived_follow.php +++ b/database/migrations/2021_12_13_002344_project_tasks_add_archived_follow.php @@ -1,5 +1,8 @@ tinyInteger('archived_follow')->nullable()->default(0)->after('archived_userid')->comment('跟随项目归档(项目取消归档时任务也取消归档)'); } }); + if ($isAdd) { + // 更新数据 + Project::whereNotNull('archived_at')->chunkById(100, function ($lists) { + foreach ($lists as $item) { + ProjectTask::whereProjectId($item->id)->whereArchivedAt(null)->update([ + 'archived_at' => $item->archived_at, + 'archived_follow' => 1 + ]); + } + }); + } } /**