项目增删通知

This commit is contained in:
Pang 2021-06-18 01:02:01 +08:00
parent c3fe7c1f7e
commit 41825ea4d4
6 changed files with 80 additions and 44 deletions

View File

@ -149,8 +149,10 @@ class ProjectController extends AbstractController
$column['project_id'] = $project->id; $column['project_id'] = $project->id;
ProjectColumn::createInstance($column)->save(); ProjectColumn::createInstance($column)->save();
} }
$project->addLog("创建项目"); $data = $project->find($project->id);
return Base::retSuccess('添加成功', $project->find($project->id)); $data->addLog("创建项目");
$data->pushMsg('add', $data->toArray());
return Base::retSuccess('添加成功', $data);
}); });
} }
@ -338,7 +340,7 @@ class ProjectController extends AbstractController
ProjectUser::whereProjectId($project->id)->whereUserid($user->userid)->delete(); ProjectUser::whereProjectId($project->id)->whereUserid($user->userid)->delete();
$project->syncDialogUser(); $project->syncDialogUser();
$project->addLog("会员ID" . $user->userid . " 退出项目"); $project->addLog("会员ID" . $user->userid . " 退出项目");
return Base::retSuccess('退出成功'); return Base::retSuccess('退出成功', ['id' => $project->id]);
}); });
} }
@ -359,7 +361,7 @@ class ProjectController extends AbstractController
} }
// //
if ($project->deleteProject()) { if ($project->deleteProject()) {
return Base::retSuccess('删除成功'); return Base::retSuccess('删除成功', ['id' => $project->id]);
} }
return Base::retError('删除失败'); return Base::retError('删除失败');
} }
@ -462,9 +464,7 @@ class ProjectController extends AbstractController
} }
// //
if ($column->deleteColumn()) { if ($column->deleteColumn()) {
$data = ['id' => $column->id]; return Base::retSuccess('删除成功', ['id' => $column->id]);
$column->pushMsg("delete", $data);
return Base::retSuccess('删除成功', $data);
} }
return Base::retError('删除失败'); return Base::retError('删除失败');
} }

View File

@ -4,6 +4,8 @@ namespace App\Models;
use App\Exceptions\ApiException; use App\Exceptions\ApiException;
use App\Module\Base; use App\Module\Base;
use App\Tasks\PushTask;
use Hhxsv5\LaravelS\Swoole\Task\Task;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
/** /**
@ -262,14 +264,12 @@ class Project extends AbstractModel
WebSocketDialog::whereId($this->dialog_id)->delete(); WebSocketDialog::whereId($this->dialog_id)->delete();
$columns = ProjectColumn::whereProjectId($this->id)->get(); $columns = ProjectColumn::whereProjectId($this->id)->get();
foreach ($columns as $column) { foreach ($columns as $column) {
$column->deleteColumn(); $column->deleteColumn(false);
}
if ($this->delete()) {
$this->addLog("删除项目");
return Base::retSuccess('删除成功', $this->toArray());
} else {
return Base::retError('删除失败', $this->toArray());
} }
$this->pushMsg('delete', $this->toArray());
$this->delete();
$this->addLog("删除项目");
return Base::retSuccess('删除成功', $this->toArray());
}); });
return Base::isSuccess($result); return Base::isSuccess($result);
} }
@ -293,6 +293,25 @@ class Project extends AbstractModel
return $log; return $log;
} }
/**
* 推送消息
* @param string $action
* @param array $data
*/
public function pushMsg($action, $data)
{
$lists = [
'userid' => $this->relationUserids(),
'msg' => [
'type' => 'project',
'action' => $action,
'data' => $data,
]
];
$task = new PushTask($lists, false);
Task::deliver($task);
}
/** /**
* 根据用户获取项目信息(用于判断会员是否存在项目内) * 根据用户获取项目信息(用于判断会员是否存在项目内)
* @param int $project_id * @param int $project_id

View File

@ -60,21 +60,22 @@ class ProjectColumn extends AbstractModel
/** /**
* 删除列表 * 删除列表
* @param bool $pushMsg 是否推送
* @return bool * @return bool
*/ */
public function deleteColumn() public function deleteColumn($pushMsg = true)
{ {
$result = AbstractModel::transaction(function () { $result = AbstractModel::transaction(function () use ($pushMsg) {
$tasks = ProjectTask::whereColumnId($this->id)->get(); $tasks = ProjectTask::whereColumnId($this->id)->get();
foreach ($tasks as $task) { foreach ($tasks as $task) {
$task->deleteTask(); $task->deleteTask($pushMsg);
} }
if ($this->delete()) { if ($pushMsg) {
$this->addLog("删除列表:" . $this->name); $this->pushMsg("delete", $this->toArray());
return Base::retSuccess('删除成功', $this->toArray());
} else {
return Base::retError('删除失败', $this->toArray());
} }
$this->delete();
$this->addLog("删除列表:" . $this->name);
return Base::retSuccess('删除成功', $this->toArray());
}); });
return Base::isSuccess($result); return Base::isSuccess($result);
} }

View File

@ -582,17 +582,20 @@ class ProjectTask extends AbstractModel
/** /**
* 删除任务 * 删除任务
* @param bool $pushMsg 是否推送
* @return array|bool * @return array|bool
*/ */
public function deleteTask() public function deleteTask($pushMsg = true)
{ {
return AbstractModel::transaction(function () { return AbstractModel::transaction(function () use ($pushMsg) {
if ($this->dialog_id) { if ($this->dialog_id) {
WebSocketDialog::whereId($this->dialog_id)->delete(); WebSocketDialog::whereId($this->dialog_id)->delete();
} }
if ($pushMsg) {
$this->pushMsg('delete', $this->toArray());
}
$this->delete(); $this->delete();
$this->addLog("删除{任务}" . $this->name); $this->addLog("删除{任务}" . $this->name);
$this->pushMsg('delete', $this->toArray());
return Base::retSuccess('删除成功', $this->toArray()); return Base::retSuccess('删除成功', $this->toArray());
}); });
} }

View File

@ -931,16 +931,10 @@ export default {
data: { data: {
project_id: this.projectDetail.id, project_id: this.projectDetail.id,
}, },
}).then(({msg}) => { }).then(({data, msg}) => {
$A.messageSuccess(msg); $A.messageSuccess(msg);
this.$Modal.remove(); this.$Modal.remove();
this.$store.dispatch("removeProject", this.projectDetail.id); this.$store.dispatch("removeProject", data);
const project = this.projectList.find(({id}) => id);
if (project) {
this.goForward({path: '/manage/project/' + project.id}, true);
} else {
this.goForward({path: '/manage/dashboard'}, true);
}
}).catch(({msg}) => { }).catch(({msg}) => {
$A.modalError(msg, 301); $A.modalError(msg, 301);
this.$Modal.remove(); this.$Modal.remove();
@ -960,16 +954,10 @@ export default {
data: { data: {
project_id: this.projectDetail.id, project_id: this.projectDetail.id,
}, },
}).then(({msg}) => { }).then(({data, msg}) => {
$A.messageSuccess(msg); $A.messageSuccess(msg);
this.$Modal.remove(); this.$Modal.remove();
this.$store.dispatch("removeProject", this.projectDetail.id); this.$store.dispatch("removeProject", data);
const project = this.projectList.find(({id}) => id);
if (project) {
this.goForward({path: '/manage/project/' + project.id}, true);
} else {
this.goForward({path: '/manage/dashboard'}, true);
}
}).catch(({msg}) => { }).catch(({msg}) => {
$A.modalError(msg, 301); $A.modalError(msg, 301);
this.$Modal.remove(); this.$Modal.remove();

View File

@ -365,14 +365,22 @@ export default {
/** /**
* 删除项目信息 * 删除项目信息
* @param state * @param state
* @param project_id * @param data
*/ */
removeProject({state}, project_id) { removeProject({state}, data) {
let index = state.projectList.findIndex(({id}) => id == project_id); let index = state.projectList.findIndex(({id}) => id == data.id);
if (index > -1) { if (index > -1) {
state.projectList.splice(index, 1); state.projectList.splice(index, 1);
state.method.setStorage("cacheProjectList", state.cacheProjectList = state.projectList); state.method.setStorage("cacheProjectList", state.cacheProjectList = state.projectList);
} }
if (state.projectDetail.id == data.id) {
const project = state.projectList.find(({id}) => id && id != data.id);
if (project) {
$A.goForward({path: '/manage/project/' + project.id});
} else {
$A.goForward({path: '/manage/dashboard'});
}
}
}, },
/** /**
@ -1110,6 +1118,23 @@ export default {
})(msgDetail); })(msgDetail);
break; break;
/**
* 项目消息
*/
case "project":
(function (msg) {
const {action, data} = msg;
switch (action) {
case 'add':
dispatch("saveProject", data)
break;
case 'delete':
dispatch("removeProject", data);
break;
}
})(msgDetail);
break;
/** /**
* 任务列表消息 * 任务列表消息
*/ */