Skip to content

Commit

Permalink
优化任务项目归档
Browse files Browse the repository at this point in the history
  • Loading branch information
kuaifan committed Dec 13, 2021
1 parent a5b1fec commit cde6530
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app/Http/Controllers/Api/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -648,9 +648,9 @@ public function task__one()
//
$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);
Expand Down
11 changes: 5 additions & 6 deletions app/Models/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public function archivedProject($archived_at)
$this->addLog("项目归档");
$this->pushMsg('archived');
ProjectTask::whereProjectId($this->id)->whereArchivedAt(null)->update([
'archived_at' => Carbon::now(),
'archived_at' => $archived_at,
'archived_follow' => 1
]);
}
Expand Down Expand Up @@ -373,14 +373,13 @@ public function pushMsg($action, $data = null, $userid = null)
*/
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;
}
}
10 changes: 5 additions & 5 deletions app/Models/ProjectTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -744,18 +744,18 @@ public function pushMsg($action, $data = null, $userid = null)
* @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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

use App\Models\Project;
use App\Models\ProjectTask;
use Carbon\Carbon;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
Expand All @@ -13,11 +16,24 @@ class ProjectTasksAddArchivedFollow extends Migration
*/
public function up()
{
Schema::table('project_tasks', function (Blueprint $table) {
$isAdd = false;
Schema::table('project_tasks', function (Blueprint $table) use (&$isAdd) {
if (!Schema::hasColumn('project_tasks', 'archived_follow')) {
$isAdd = true;
$table->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
]);
}
});
}
}

/**
Expand Down

0 comments on commit cde6530

Please sign in to comment.