perf: 今天任务、我的任务

This commit is contained in:
kuaifan 2021-12-22 22:39:08 +08:00
parent 6d9237c399
commit 6c34f083e3
4 changed files with 11 additions and 7 deletions

View File

@ -38,7 +38,7 @@ class ProjectController extends AbstractController
Carbon::today()->startOfDay(), Carbon::today()->startOfDay(),
Carbon::today()->endOfDay() Carbon::today()->endOfDay()
]; ];
$data['today'] = ProjectTask::authData()->whereParentId(0) $data['today'] = ProjectTask::authData(null, true)->whereParentId(0)
->whereNull('archived_at') ->whereNull('archived_at')
->whereNull('complete_at') ->whereNull('complete_at')
->where(function ($query) use ($between) { ->where(function ($query) use ($between) {
@ -47,7 +47,7 @@ class ProjectController extends AbstractController
->count(); ->count();
// 超期未完成 // 超期未完成
$data['overdue'] = ProjectTask::authData()->whereParentId(0) $data['overdue'] = ProjectTask::authData(null, true)->whereParentId(0)
->whereNull('archived_at') ->whereNull('archived_at')
->whereNull('complete_at') ->whereNull('complete_at')
->whereNotNull('end_at') ->whereNotNull('end_at')

View File

@ -85,7 +85,7 @@ class Project extends AbstractModel
$this->appendattrs['task_complete'] = $builder->whereNotNull('complete_at')->count(); $this->appendattrs['task_complete'] = $builder->whereNotNull('complete_at')->count();
$this->appendattrs['task_percent'] = $this->appendattrs['task_num'] ? intval($this->appendattrs['task_complete'] / $this->appendattrs['task_num'] * 100) : 0; $this->appendattrs['task_percent'] = $this->appendattrs['task_num'] ? intval($this->appendattrs['task_complete'] / $this->appendattrs['task_num'] * 100) : 0;
// //
$builder = ProjectTask::whereProjectId($this->id)->whereParentId(0)->authData(User::userid())->whereNull('archived_at'); $builder = ProjectTask::whereProjectId($this->id)->whereParentId(0)->authData(User::userid(), true)->whereNull('archived_at');
$this->appendattrs['task_my_num'] = $builder->count(); $this->appendattrs['task_my_num'] = $builder->count();
$this->appendattrs['task_my_complete'] = $builder->whereNotNull('complete_at')->count(); $this->appendattrs['task_my_complete'] = $builder->whereNotNull('complete_at')->count();
$this->appendattrs['task_my_percent'] = $this->appendattrs['task_my_num'] ? intval($this->appendattrs['task_my_complete'] / $this->appendattrs['task_my_num'] * 100) : 0; $this->appendattrs['task_my_percent'] = $this->appendattrs['task_my_num'] ? intval($this->appendattrs['task_my_complete'] / $this->appendattrs['task_my_num'] * 100) : 0;

View File

@ -53,7 +53,7 @@ use Request;
* @property-read int|null $task_tag_count * @property-read int|null $task_tag_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ProjectTaskUser[] $taskUser * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ProjectTaskUser[] $taskUser
* @property-read int|null $task_user_count * @property-read int|null $task_user_count
* @method static \Illuminate\Database\Eloquent\Builder|ProjectTask authData($userid = null) * @method static \Illuminate\Database\Eloquent\Builder|ProjectTask authData($userid = null, $owner = false)
* @method static \Illuminate\Database\Eloquent\Builder|ProjectTask newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|ProjectTask newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ProjectTask newQuery() * @method static \Illuminate\Database\Eloquent\Builder|ProjectTask newQuery()
* @method static \Illuminate\Database\Query\Builder|ProjectTask onlyTrashed() * @method static \Illuminate\Database\Query\Builder|ProjectTask onlyTrashed()
@ -268,13 +268,17 @@ class ProjectTask extends AbstractModel
* 查询自己的任务 * 查询自己的任务
* @param self $query * @param self $query
* @param null $userid * @param null $userid
* @param bool $owner
* @return self * @return self
*/ */
public function scopeAuthData($query, $userid = null) public function scopeAuthData($query, $userid = null, $owner = false)
{ {
$userid = $userid ?: User::userid(); $userid = $userid ?: User::userid();
$query->whereIn('id', function ($qy) use ($userid) { $query->whereIn('id', function ($qy) use ($owner, $userid) {
$qy->select('task_pid')->from('project_task_users')->where('userid', $userid); $qy->select('task_pid')->from('project_task_users')->where('userid', $userid);
if ($owner) {
$qy->where('owner', 1);
}
}); });
return $query; return $query;
} }

View File

@ -511,7 +511,7 @@ export default {
return false; return false;
} }
} }
return task.task_user && task.task_user.find(({userid}) => userid == userId); return task.task_user && task.task_user.find(({userid, owner}) => userid == userId && owner == 1);
}); });
return array.sort((a, b) => { return array.sort((a, b) => {
if (a.p_level != b.p_level) { if (a.p_level != b.p_level) {