优化归档

This commit is contained in:
kuaifan 2021-12-13 00:27:47 +08:00
parent 28dc314397
commit 7cf76d91a0
3 changed files with 50 additions and 7 deletions

View File

@ -267,7 +267,7 @@ class Project extends AbstractModel
} }
/** /**
* 归档任务、取消归档 * 归档项目、取消归档
* @param Carbon|null $archived_at 归档时间 * @param Carbon|null $archived_at 归档时间
* @return bool * @return bool
*/ */
@ -279,12 +279,20 @@ class Project extends AbstractModel
$this->archived_at = null; $this->archived_at = null;
$this->addLog("项目取消归档"); $this->addLog("项目取消归档");
$this->pushMsg('add', $this); $this->pushMsg('add', $this);
ProjectTask::whereProjectId($this->id)->whereArchivedFollow(1)->update([
'archived_at' => null,
'archived_follow' => 0
]);
} else { } else {
// 归档任务 // 归档项目
$this->archived_at = $archived_at; $this->archived_at = $archived_at;
$this->archived_userid = User::userid(); $this->archived_userid = User::userid();
$this->addLog("项目归档"); $this->addLog("项目归档");
$this->pushMsg('archived'); $this->pushMsg('archived');
ProjectTask::whereProjectId($this->id)->whereArchivedAt(null)->update([
'archived_at' => Carbon::now(),
'archived_follow' => 1
]);
} }
$this->save(); $this->save();
}); });
@ -299,9 +307,7 @@ class Project extends AbstractModel
{ {
AbstractModel::transaction(function () { AbstractModel::transaction(function () {
$dialog = WebSocketDialog::find($this->dialog_id); $dialog = WebSocketDialog::find($this->dialog_id);
if ($dialog) { $dialog?->deleteDialog();
$dialog->deleteDialog();
}
$columns = ProjectColumn::whereProjectId($this->id)->get(); $columns = ProjectColumn::whereProjectId($this->id)->get();
foreach ($columns as $column) { foreach ($columns as $column) {
$column->deleteColumn(false); $column->deleteColumn(false);

View File

@ -12,9 +12,8 @@ use Illuminate\Database\Eloquent\SoftDeletes;
use Request; use Request;
/** /**
* Class ProjectTask * App\Models\ProjectTask
* *
* @package App\Models
* @property int $id * @property int $id
* @property int|null $parent_id 父级任务ID * @property int|null $parent_id 父级任务ID
* @property int|null $project_id 项目ID * @property int|null $project_id 项目ID
@ -27,6 +26,7 @@ use Request;
* @property string|null $end_at 计划结束时间 * @property string|null $end_at 计划结束时间
* @property string|null $archived_at 归档时间 * @property string|null $archived_at 归档时间
* @property int|null $archived_userid 归档会员 * @property int|null $archived_userid 归档会员
* @property int|null $archived_follow 跟随项目归档(项目取消归档时任务也取消归档)
* @property string|null $complete_at 完成时间 * @property string|null $complete_at 完成时间
* @property int|null $userid 创建人 * @property int|null $userid 创建人
* @property int|null $p_level 优先级 * @property int|null $p_level 优先级
@ -58,6 +58,7 @@ use Request;
* @method static \Illuminate\Database\Query\Builder|ProjectTask onlyTrashed() * @method static \Illuminate\Database\Query\Builder|ProjectTask onlyTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|ProjectTask query() * @method static \Illuminate\Database\Eloquent\Builder|ProjectTask query()
* @method static \Illuminate\Database\Eloquent\Builder|ProjectTask whereArchivedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|ProjectTask whereArchivedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|ProjectTask whereArchivedFollow($value)
* @method static \Illuminate\Database\Eloquent\Builder|ProjectTask whereArchivedUserid($value) * @method static \Illuminate\Database\Eloquent\Builder|ProjectTask whereArchivedUserid($value)
* @method static \Illuminate\Database\Eloquent\Builder|ProjectTask whereColor($value) * @method static \Illuminate\Database\Eloquent\Builder|ProjectTask whereColor($value)
* @method static \Illuminate\Database\Eloquent\Builder|ProjectTask whereColumnId($value) * @method static \Illuminate\Database\Eloquent\Builder|ProjectTask whereColumnId($value)
@ -639,6 +640,7 @@ class ProjectTask extends AbstractModel
if ($archived_at === null) { if ($archived_at === null) {
// 取消归档 // 取消归档
$this->archived_at = null; $this->archived_at = null;
$this->archived_follow = 0;
$this->addLog("任务取消归档:" . $this->name); $this->addLog("任务取消归档:" . $this->name);
$this->pushMsg('add', [ $this->pushMsg('add', [
'new_column' => null, 'new_column' => null,
@ -648,6 +650,7 @@ class ProjectTask extends AbstractModel
// 归档任务 // 归档任务
$this->archived_at = $archived_at; $this->archived_at = $archived_at;
$this->archived_userid = User::userid(); $this->archived_userid = User::userid();
$this->archived_follow = 0;
$this->addLog("任务归档:" . $this->name); $this->addLog("任务归档:" . $this->name);
$this->pushMsg('archived'); $this->pushMsg('archived');
} }

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class ProjectTasksAddArchivedFollow extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('project_tasks', function (Blueprint $table) {
if (!Schema::hasColumn('project_tasks', 'archived_follow')) {
$table->tinyInteger('archived_follow')->nullable()->default(0)->after('archived_userid')->comment('跟随项目归档(项目取消归档时任务也取消归档)');
}
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('project_tasks', function (Blueprint $table) {
$table->dropColumn("archived_follow");
});
}
}