feat(template): 添加跨项目任务模板支持,增加使用统计和搜索功能

This commit is contained in:
kuaifan
2026-05-11 01:13:54 +00:00
parent 18336c870e
commit 7dc641e69e
11 changed files with 776 additions and 17 deletions

View File

@@ -13,6 +13,8 @@ namespace App\Models;
* @property int $sort 排序
* @property int $is_default 是否默认模板
* @property int $userid 创建人
* @property int $use_count 累计使用次数
* @property \Illuminate\Support\Carbon|null $last_used_at 最近一次使用时间
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \App\Models\Project $project
@@ -52,7 +54,18 @@ class ProjectTaskTemplate extends AbstractModel
'content',
'sort',
'is_default',
'userid'
'userid',
'use_count',
'last_used_at'
];
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'last_used_at' => 'datetime',
];
/**
@@ -74,4 +87,17 @@ class ProjectTaskTemplate extends AbstractModel
{
return $this->belongsTo(User::class, 'userid');
}
/**
* 原子递增使用次数并刷新最近使用时间。
*/
public function incrementUsage(): void
{
$this->newQuery()
->where('id', $this->id)
->update([
'use_count' => \DB::raw('use_count + 1'),
'last_used_at' => now(),
]);
}
}