Skip to content

Commit

Permalink
优化归档
Browse files Browse the repository at this point in the history
  • Loading branch information
kuaifan committed Dec 12, 2021
1 parent 28dc314 commit 7cf76d9
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
16 changes: 11 additions & 5 deletions app/Models/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public function useridInTheProject($userid)
}

/**
* 归档任务、取消归档
* 归档项目、取消归档
* @param Carbon|null $archived_at 归档时间
* @return bool
*/
Expand All @@ -279,12 +279,20 @@ public function archivedProject($archived_at)
$this->archived_at = null;
$this->addLog("项目取消归档");
$this->pushMsg('add', $this);
ProjectTask::whereProjectId($this->id)->whereArchivedFollow(1)->update([
'archived_at' => null,
'archived_follow' => 0
]);
} else {
// 归档任务
// 归档项目
$this->archived_at = $archived_at;
$this->archived_userid = User::userid();
$this->addLog("项目归档");
$this->pushMsg('archived');
ProjectTask::whereProjectId($this->id)->whereArchivedAt(null)->update([
'archived_at' => Carbon::now(),
'archived_follow' => 1
]);
}
$this->save();
});
Expand All @@ -299,9 +307,7 @@ public function deleteProject()
{
AbstractModel::transaction(function () {
$dialog = WebSocketDialog::find($this->dialog_id);
if ($dialog) {
$dialog->deleteDialog();
}
$dialog?->deleteDialog();
$columns = ProjectColumn::whereProjectId($this->id)->get();
foreach ($columns as $column) {
$column->deleteColumn(false);
Expand Down
7 changes: 5 additions & 2 deletions app/Models/ProjectTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
use Request;

/**
* Class ProjectTask
* App\Models\ProjectTask
*
* @package App\Models
* @property int $id
* @property int|null $parent_id 父级任务ID
* @property int|null $project_id 项目ID
Expand All @@ -27,6 +26,7 @@
* @property string|null $end_at 计划结束时间
* @property string|null $archived_at 归档时间
* @property int|null $archived_userid 归档会员
* @property int|null $archived_follow 跟随项目归档(项目取消归档时任务也取消归档)
* @property string|null $complete_at 完成时间
* @property int|null $userid 创建人
* @property int|null $p_level 优先级
Expand Down Expand Up @@ -58,6 +58,7 @@
* @method static \Illuminate\Database\Query\Builder|ProjectTask onlyTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|ProjectTask query()
* @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 whereColor($value)
* @method static \Illuminate\Database\Eloquent\Builder|ProjectTask whereColumnId($value)
Expand Down Expand Up @@ -639,6 +640,7 @@ public function archivedTask($archived_at)
if ($archived_at === null) {
// 取消归档
$this->archived_at = null;
$this->archived_follow = 0;
$this->addLog("任务取消归档:" . $this->name);
$this->pushMsg('add', [
'new_column' => null,
Expand All @@ -648,6 +650,7 @@ public function archivedTask($archived_at)
// 归档任务
$this->archived_at = $archived_at;
$this->archived_userid = User::userid();
$this->archived_follow = 0;
$this->addLog("任务归档:" . $this->name);
$this->pushMsg('archived');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
});
}
}

0 comments on commit 7cf76d9

Please sign in to comment.