优化任务项目归档

This commit is contained in:
kuaifan 2021-12-13 12:38:32 +08:00
parent a5b1fec6b1
commit cde6530832
4 changed files with 29 additions and 14 deletions

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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;
@ -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
]);
}
});
}
}
/**