优化任务项目归档
This commit is contained in:
parent
a5b1fec6b1
commit
cde6530832
@ -648,9 +648,9 @@ class ProjectController extends AbstractController
|
|||||||
//
|
//
|
||||||
$task_id = intval(Request::input('task_id'));
|
$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');
|
$task->column_name = ProjectColumn::whereId($task->column_id)->value('name');
|
||||||
//
|
//
|
||||||
return Base::retSuccess('success', $task);
|
return Base::retSuccess('success', $task);
|
||||||
|
@ -290,7 +290,7 @@ class Project extends AbstractModel
|
|||||||
$this->addLog("项目归档");
|
$this->addLog("项目归档");
|
||||||
$this->pushMsg('archived');
|
$this->pushMsg('archived');
|
||||||
ProjectTask::whereProjectId($this->id)->whereArchivedAt(null)->update([
|
ProjectTask::whereProjectId($this->id)->whereArchivedAt(null)->update([
|
||||||
'archived_at' => Carbon::now(),
|
'archived_at' => $archived_at,
|
||||||
'archived_follow' => 1
|
'archived_follow' => 1
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@ -373,14 +373,13 @@ class Project extends AbstractModel
|
|||||||
*/
|
*/
|
||||||
public static function userProject($project_id, $ignoreArchived = true)
|
public static function userProject($project_id, $ignoreArchived = true)
|
||||||
{
|
{
|
||||||
$builder = self::select(self::projectSelect)->authData()->where('projects.id', intval($project_id));
|
$project = self::select(self::projectSelect)->authData()->where('projects.id', intval($project_id))->first();
|
||||||
if ($ignoreArchived) {
|
|
||||||
$builder->whereNull('projects.archived_at');
|
|
||||||
}
|
|
||||||
$project = $builder->first();
|
|
||||||
if (empty($project)) {
|
if (empty($project)) {
|
||||||
throw new ApiException('项目不存在或不在成员列表内', [ 'project_id' => $project_id ], -4001);
|
throw new ApiException('项目不存在或不在成员列表内', [ 'project_id' => $project_id ], -4001);
|
||||||
}
|
}
|
||||||
|
if ($ignoreArchived && $project->archived_at != null) {
|
||||||
|
throw new ApiException('项目已归档', [ 'project_id' => $project_id ], -4001);
|
||||||
|
}
|
||||||
return $project;
|
return $project;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -744,18 +744,18 @@ class ProjectTask extends AbstractModel
|
|||||||
* @param int $task_id
|
* @param int $task_id
|
||||||
* @param array $with
|
* @param array $with
|
||||||
* @param bool $ignoreArchived 排除已归档
|
* @param bool $ignoreArchived 排除已归档
|
||||||
|
* @param null $project
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public static function userTask($task_id, $with = [], $ignoreArchived = true, &$project = null)
|
public static function userTask($task_id, $with = [], $ignoreArchived = true, &$project = null)
|
||||||
{
|
{
|
||||||
$builder = self::with($with)->whereId(intval($task_id));
|
$task = self::with($with)->whereId(intval($task_id))->first();
|
||||||
if ($ignoreArchived) {
|
|
||||||
$builder->whereNull('archived_at');
|
|
||||||
}
|
|
||||||
$task = $builder->first();
|
|
||||||
if (empty($task)) {
|
if (empty($task)) {
|
||||||
throw new ApiException('任务不存在', [ 'task_id' => $task_id ], -4002);
|
throw new ApiException('任务不存在', [ 'task_id' => $task_id ], -4002);
|
||||||
}
|
}
|
||||||
|
if ($ignoreArchived && $task->archived_at != null) {
|
||||||
|
throw new ApiException('任务已归档', [ 'task_id' => $task_id ], -4002);
|
||||||
|
}
|
||||||
//
|
//
|
||||||
try {
|
try {
|
||||||
$project = Project::userProject($task->project_id, $ignoreArchived);
|
$project = Project::userProject($task->project_id, $ignoreArchived);
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Project;
|
||||||
|
use App\Models\ProjectTask;
|
||||||
|
use Carbon\Carbon;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
@ -13,11 +16,24 @@ class ProjectTasksAddArchivedFollow extends Migration
|
|||||||
*/
|
*/
|
||||||
public function up()
|
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')) {
|
if (!Schema::hasColumn('project_tasks', 'archived_follow')) {
|
||||||
|
$isAdd = true;
|
||||||
$table->tinyInteger('archived_follow')->nullable()->default(0)->after('archived_userid')->comment('跟随项目归档(项目取消归档时任务也取消归档)');
|
$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
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user