feat(任务可见性功能、子任务优化):新增任务可见性操作模块、任务详情子任务样式优化
This commit is contained in:
@@ -370,6 +370,18 @@ class ProjectTask extends AbstractModel
|
||||
$p_color = $data['p_color'];
|
||||
$top = intval($data['top']);
|
||||
$userid = User::userid();
|
||||
$visibility_appoint = $data['visibility_appoint'];
|
||||
$visibility_appointor = $data['visibility_appointor'];
|
||||
// 可见性
|
||||
$visibility_userids = [];
|
||||
$is_all_visible = 0;
|
||||
if ($visibility_appoint) {
|
||||
if (in_array(0, $visibility_appointor)) {
|
||||
$is_all_visible = 1;
|
||||
} else {
|
||||
$visibility_userids = $visibility_appointor;
|
||||
}
|
||||
}
|
||||
//
|
||||
if (ProjectTask::whereProjectId($project_id)
|
||||
->whereNull('project_tasks.complete_at')
|
||||
@@ -398,6 +410,7 @@ class ProjectTask extends AbstractModel
|
||||
'p_level' => $p_level,
|
||||
'p_name' => $p_name,
|
||||
'p_color' => $p_color,
|
||||
'is_all_visible' => $is_all_visible
|
||||
]);
|
||||
if ($content) {
|
||||
$task->desc = Base::getHtml($content, 100);
|
||||
@@ -462,7 +475,7 @@ class ProjectTask extends AbstractModel
|
||||
}
|
||||
}
|
||||
//
|
||||
return AbstractModel::transaction(function() use ($assist, $times, $subtasks, $content, $owner, $task) {
|
||||
return AbstractModel::transaction(function() use ($assist, $times, $subtasks, $content, $owner, $task, $visibility_userids) {
|
||||
$task->save();
|
||||
$owner = array_values(array_unique($owner));
|
||||
foreach ($owner as $uid) {
|
||||
@@ -484,6 +497,17 @@ class ProjectTask extends AbstractModel
|
||||
'owner' => 0,
|
||||
])->save();
|
||||
}
|
||||
|
||||
foreach ($visibility_userids as $uid) {
|
||||
ProjectTaskUser::createInstance([
|
||||
'project_id' => $task->project_id,
|
||||
'task_id' => $task->id,
|
||||
'task_pid' => $task->parent_id ?: $task->id,
|
||||
'userid' => $uid,
|
||||
'owner' => 2,
|
||||
])->save();
|
||||
}
|
||||
|
||||
if ($content) {
|
||||
ProjectTaskContent::createInstance([
|
||||
'project_id' => $task->project_id,
|
||||
@@ -691,6 +715,26 @@ class ProjectTask extends AbstractModel
|
||||
$updateMarking['is_update_project'] = true;
|
||||
$this->syncDialogUser();
|
||||
}
|
||||
// 可见性
|
||||
if (Arr::exists($data, 'visibility_appointor')) {
|
||||
if (in_array(0, $data['visibility_appointor'])) {
|
||||
ProjectTask::whereId($data['task_id'])->update(['is_all_visible' => 1]);
|
||||
} else {
|
||||
ProjectTask::whereId($data['task_id'])->update(['is_all_visible' => 0]);
|
||||
// 覆盖
|
||||
ProjectTaskUser::whereTaskId($data['task_id'])->whereOwner(2)->delete();
|
||||
foreach ($data['visibility_appointor'] as $uid) {
|
||||
ProjectTaskUser::createInstance([
|
||||
'project_id' => $this->project_id,
|
||||
'task_id' => $this->id,
|
||||
'task_pid' => $this->parent_id ?: $this->id,
|
||||
'userid' => $uid,
|
||||
'owner' => 2,
|
||||
])->save();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// 计划时间(原则:子任务时间在主任务时间内)
|
||||
if (Arr::exists($data, 'times')) {
|
||||
$oldAt = [Carbon::parse($this->start_at), Carbon::parse($this->end_at)];
|
||||
@@ -1372,6 +1416,8 @@ class ProjectTask extends AbstractModel
|
||||
$userids = $this->project->relationUserids();
|
||||
} elseif (!is_array($userid)) {
|
||||
$userids = [$userid];
|
||||
} elseif (is_array($userid)) {
|
||||
$userids = $userid;
|
||||
}
|
||||
//
|
||||
$array = [];
|
||||
@@ -1391,8 +1437,10 @@ class ProjectTask extends AbstractModel
|
||||
];
|
||||
}
|
||||
// 协助人
|
||||
$assists = $taskUser->pluck('userid')->toArray();
|
||||
$assists = array_intersect($userids, array_diff($assists, $owners));
|
||||
// $assists = $taskUser->pluck('userid')->toArray();
|
||||
// $assists = array_intersect($userids, array_diff($assists, $owners));
|
||||
$assists = $taskUser->where('owner', 0)->pluck('userid')->toArray();
|
||||
$assists = array_intersect($userids, $assists);
|
||||
if ($assists) {
|
||||
$array[] = [
|
||||
'userid' => array_values($assists),
|
||||
@@ -1403,13 +1451,21 @@ class ProjectTask extends AbstractModel
|
||||
];
|
||||
}
|
||||
// 项目成员(其他人)
|
||||
$userids = array_diff($userids, $owners, $assists);
|
||||
if ($data['is_all_visible'] == 1) {
|
||||
// 全部可见
|
||||
$userids = array_diff($userids, $owners, $assists);
|
||||
} else {
|
||||
// 指定可见
|
||||
$visible = $taskUser->where('owner', 2)->pluck('userid')->toArray();
|
||||
$userids = $visible;
|
||||
}
|
||||
$data = array_merge($data, [
|
||||
'owner' => 0,
|
||||
'assist' => 0,
|
||||
]);
|
||||
}
|
||||
}
|
||||
//
|
||||
$array[] = [
|
||||
'userid' => array_values($userids),
|
||||
'data' => $data
|
||||
@@ -1430,6 +1486,116 @@ class ProjectTask extends AbstractModel
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加可见性任务 推送
|
||||
* @param array|self $data 发送内容,默认为[id, parent_id, project_id, column_id, dialog_id]
|
||||
*/
|
||||
public function pushMsgVisibleAdd($data = null)
|
||||
{
|
||||
if (!$this->project) {
|
||||
return;
|
||||
}
|
||||
if ($data === null) {
|
||||
$data = [
|
||||
'id' => $this->id,
|
||||
'parent_id' => $this->parent_id,
|
||||
'project_id' => $this->project_id,
|
||||
'column_id' => $this->column_id,
|
||||
'dialog_id' => $this->dialog_id,
|
||||
];
|
||||
} elseif ($data instanceof self) {
|
||||
$data = $data->toArray();
|
||||
}
|
||||
//
|
||||
$array = [];
|
||||
if ($this->is_all_visible == 0) {
|
||||
$userids = ProjectTaskUser::select(['userid', 'owner'])->whereTaskId($this->id)->pluck('userid')->toArray();
|
||||
} else {
|
||||
$userids = ProjectUser::whereProjectId($this->project_id)->pluck('userid')->toArray(); // 项目成员
|
||||
}
|
||||
//
|
||||
$array[] = [
|
||||
'userid' => array_values($userids),
|
||||
'data' => $data
|
||||
];
|
||||
//
|
||||
foreach ($array as $item) {
|
||||
$params = [
|
||||
// 'ignoreFd' => Request::header('fd'),
|
||||
'ignoreFd' => '0',
|
||||
'userid' => array_values($item),
|
||||
'msg' => [
|
||||
'type' => 'projectTask',
|
||||
'action' => 'add',
|
||||
'data' => $item['data'],
|
||||
]
|
||||
];
|
||||
$task = new PushTask($params, false);
|
||||
Task::deliver($task);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除可见性任务 推送
|
||||
* @param string $action
|
||||
* @param array|self $data 发送内容,默认为[id, parent_id, project_id, column_id, dialog_id]
|
||||
*/
|
||||
public function pushMsgVisibleRemove($data = null)
|
||||
{
|
||||
if (!$this->project) {
|
||||
return;
|
||||
}
|
||||
if ($data === null) {
|
||||
$data = [
|
||||
'id' => $this->id,
|
||||
'parent_id' => $this->parent_id,
|
||||
'project_id' => $this->project_id,
|
||||
'column_id' => $this->column_id,
|
||||
'dialog_id' => $this->dialog_id,
|
||||
];
|
||||
} elseif ($data instanceof self) {
|
||||
$data = $data->toArray();
|
||||
}
|
||||
//
|
||||
$array = [];
|
||||
// 项目成员 与 项目负责人,任务负责人、协助人的差集
|
||||
$projectUserids = ProjectUser::whereProjectId($this->project_id)->pluck('userid')->toArray(); // 项目成员
|
||||
$projectOwner = Project::whereId($this->project_id)->pluck('userid')->toArray(); // 项目负责人
|
||||
$taskOwnerAndAssists = ProjectTaskUser::select(['userid', 'owner'])->whereIn('owner', [0, 1])->whereTaskId($this->id)->pluck('userid')->toArray();
|
||||
$userids = array_diff($projectUserids, $projectOwner, $taskOwnerAndAssists);
|
||||
//
|
||||
$array[] = [
|
||||
'userid' => array_values($userids),
|
||||
'data' => $data
|
||||
];
|
||||
//
|
||||
foreach ($array as $item) {
|
||||
$params = [
|
||||
// 'ignoreFd' => Request::header('fd'),
|
||||
'ignoreFd' => '0',
|
||||
'userid' => array_values($item),
|
||||
'msg' => [
|
||||
'type' => 'projectTask',
|
||||
'action' => 'delete',
|
||||
'data' => $item['data'],
|
||||
]
|
||||
];
|
||||
$task = new PushTask($params, false);
|
||||
Task::deliver($task);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新可见性任务 推送
|
||||
* @param array|self $data 发送内容,默认为[id, parent_id, project_id, column_id, dialog_id]
|
||||
*/
|
||||
public function pushMsgVisibleUpdate($data)
|
||||
{
|
||||
$this->pushMsgVisibleRemove();
|
||||
usleep(300);
|
||||
$this->pushMsgVisibleAdd($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 任务提醒
|
||||
* @param $userids
|
||||
|
||||
Reference in New Issue
Block a user