项目增删通知

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;
ProjectColumn::createInstance($column)->save();
}
$project->addLog("创建项目");
return Base::retSuccess('添加成功', $project->find($project->id));
$data = $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();
$project->syncDialogUser();
$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()) {
return Base::retSuccess('删除成功');
return Base::retSuccess('删除成功', ['id' => $project->id]);
}
return Base::retError('删除失败');
}
@ -462,9 +464,7 @@ class ProjectController extends AbstractController
}
//
if ($column->deleteColumn()) {
$data = ['id' => $column->id];
$column->pushMsg("delete", $data);
return Base::retSuccess('删除成功', $data);
return Base::retSuccess('删除成功', ['id' => $column->id]);
}
return Base::retError('删除失败');
}

View File

@ -4,6 +4,8 @@ namespace App\Models;
use App\Exceptions\ApiException;
use App\Module\Base;
use App\Tasks\PushTask;
use Hhxsv5\LaravelS\Swoole\Task\Task;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
@ -262,14 +264,12 @@ class Project extends AbstractModel
WebSocketDialog::whereId($this->dialog_id)->delete();
$columns = ProjectColumn::whereProjectId($this->id)->get();
foreach ($columns as $column) {
$column->deleteColumn();
}
if ($this->delete()) {
$this->addLog("删除项目");
return Base::retSuccess('删除成功', $this->toArray());
} else {
return Base::retError('删除失败', $this->toArray());
$column->deleteColumn(false);
}
$this->pushMsg('delete', $this->toArray());
$this->delete();
$this->addLog("删除项目");
return Base::retSuccess('删除成功', $this->toArray());
});
return Base::isSuccess($result);
}
@ -293,6 +293,25 @@ class Project extends AbstractModel
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

View File

@ -60,21 +60,22 @@ class ProjectColumn extends AbstractModel
/**
* 删除列表
* @param bool $pushMsg 是否推送
* @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();
foreach ($tasks as $task) {
$task->deleteTask();
$task->deleteTask($pushMsg);
}
if ($this->delete()) {
$this->addLog("删除列表:" . $this->name);
return Base::retSuccess('删除成功', $this->toArray());
} else {
return Base::retError('删除失败', $this->toArray());
if ($pushMsg) {
$this->pushMsg("delete", $this->toArray());
}
$this->delete();
$this->addLog("删除列表:" . $this->name);
return Base::retSuccess('删除成功', $this->toArray());
});
return Base::isSuccess($result);
}

View File

@ -582,17 +582,20 @@ class ProjectTask extends AbstractModel
/**
* 删除任务
* @param bool $pushMsg 是否推送
* @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) {
WebSocketDialog::whereId($this->dialog_id)->delete();
}
if ($pushMsg) {
$this->pushMsg('delete', $this->toArray());
}
$this->delete();
$this->addLog("删除{任务}" . $this->name);
$this->pushMsg('delete', $this->toArray());
return Base::retSuccess('删除成功', $this->toArray());
});
}

View File

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

View File

@ -365,14 +365,22 @@ export default {
/**
* 删除项目信息
* @param state
* @param project_id
* @param data
*/
removeProject({state}, project_id) {
let index = state.projectList.findIndex(({id}) => id == project_id);
removeProject({state}, data) {
let index = state.projectList.findIndex(({id}) => id == data.id);
if (index > -1) {
state.projectList.splice(index, 1);
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);
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;
/**
* 任务列表消息
*/