同步通知 项目正删改

This commit is contained in:
aipaw 2021-06-18 07:42:14 +08:00
parent 41825ea4d4
commit 867a46a791
8 changed files with 150 additions and 117 deletions

View File

@ -163,7 +163,7 @@ class ProjectController extends AbstractController
* @apiParam {String} name 项目名称
* @apiParam {String} [desc] 项目介绍
*/
public function edit()
public function update()
{
user::auth();
//
@ -193,10 +193,86 @@ class ProjectController extends AbstractController
$project->addLog("修改项目介绍");
}
$project->save();
$project->pushMsg('update', $project->toArray());
//
return Base::retSuccess('修改成功', $project);
}
/**
* 修改项目成员
*
* @apiParam {Number} project_id 项目ID
* @apiParam {Number} userid 成员ID 成员ID组
*/
public function user()
{
user::auth();
//
$project_id = intval(Request::input('project_id'));
$userid = Request::input('userid');
$userid = is_array($userid) ? $userid : [$userid];
//
$project = Project::userProject($project_id);
if (!$project->owner) {
return Base::retError('你不是项目负责人');
}
//
return AbstractModel::transaction(function() use ($project, $userid) {
$array = [];
foreach ($userid as $uid) {
if ($project->joinProject($uid)) {
$array[] = $uid;
}
}
$delete = ProjectUser::whereProjectId($project->id)->whereNotIn('userid', $array);
$deleteUser = $delete->pluck('userid');
$delete->delete();
$project->syncDialogUser();
$project->addLog("修改项目成员");
$project->pushMsg('delete', null, $deleteUser->toArray());
$project->pushMsg('detail');
return Base::retSuccess('修改成功', ['id' => $project->id]);
});
}
/**
* 移交项目
*
* @apiParam {Number} project_id 项目ID
* @apiParam {Number} owner_userid 新的项目负责人ID
*/
public function transfer()
{
user::auth();
//
$project_id = intval(Request::input('project_id'));
$owner_userid = intval(Request::input('owner_userid'));
//
$project = Project::userProject($project_id);
if (!$project->owner) {
return Base::retError('你不是项目负责人');
}
//
if (!User::whereUserid($owner_userid)->exists()) {
return Base::retError('会员不存在');
}
//
return AbstractModel::transaction(function() use ($owner_userid, $project) {
ProjectUser::whereProjectId($project->id)->update(['owner' => 0]);
ProjectUser::updateInsert([
'project_id' => $project->id,
'userid' => $owner_userid,
], [
'owner' => 1,
]);
$project->syncDialogUser();
$project->addLog("移交项目给会员ID" . $owner_userid);
$project->pushMsg('detail');
//
return Base::retSuccess('移交成功', ['id' => $project->id]);
});
}
/**
* 排序任务
*
@ -246,79 +322,10 @@ class ProjectController extends AbstractController
}
$project->addLog("调整任务排序");
}
$project->pushMsg('detail');
return Base::retSuccess('调整成功');
}
/**
* 修改项目成员
*
* @apiParam {Number} project_id 项目ID
* @apiParam {Number} userid 成员ID 成员ID组
*/
public function user()
{
user::auth();
//
$project_id = intval(Request::input('project_id'));
$userid = Request::input('userid');
$userid = is_array($userid) ? $userid : [$userid];
//
$project = Project::userProject($project_id);
if (!$project->owner) {
return Base::retError('你不是项目负责人');
}
//
return AbstractModel::transaction(function() use ($project, $userid) {
$array = [];
foreach ($userid as $uid) {
if ($project->joinProject($uid)) {
$array[] = $uid;
}
}
ProjectUser::whereProjectId($project->id)->whereNotIn('userid', $array)->delete();
$project->syncDialogUser();
$project->addLog("修改项目成员");
return Base::retSuccess('修改成功');
});
}
/**
* 移交项目
*
* @apiParam {Number} project_id 项目ID
* @apiParam {Number} owner_userid 新的项目负责人ID
*/
public function transfer()
{
user::auth();
//
$project_id = intval(Request::input('project_id'));
$owner_userid = intval(Request::input('owner_userid'));
//
$project = Project::userProject($project_id);
if (!$project->owner) {
return Base::retError('你不是项目负责人');
}
//
if (!User::whereUserid($owner_userid)->exists()) {
return Base::retError('会员不存在');
}
//
return AbstractModel::transaction(function() use ($owner_userid, $project) {
ProjectUser::whereProjectId($project->id)->update(['owner' => 0]);
ProjectUser::updateInsert([
'project_id' => $project->id,
'userid' => $owner_userid,
], [
'owner' => 1,
]);
$project->syncDialogUser();
$project->addLog("移交项目给会员ID" . $owner_userid);
//
return Base::retSuccess('移交成功');
});
}
/**
* 退出项目
*
@ -340,6 +347,7 @@ class ProjectController extends AbstractController
ProjectUser::whereProjectId($project->id)->whereUserid($user->userid)->delete();
$project->syncDialogUser();
$project->addLog("会员ID" . $user->userid . " 退出项目");
$project->pushMsg('delete', null, $user->userid);
return Base::retSuccess('退出成功', ['id' => $project->id]);
});
}

View File

@ -266,9 +266,9 @@ class Project extends AbstractModel
foreach ($columns as $column) {
$column->deleteColumn(false);
}
$this->pushMsg('delete', $this->toArray());
$this->delete();
$this->addLog("删除项目");
$this->pushMsg('delete');
return Base::retSuccess('删除成功', $this->toArray());
});
return Base::isSuccess($result);
@ -296,12 +296,19 @@ class Project extends AbstractModel
/**
* 推送消息
* @param string $action
* @param array $data
* @param array $data 发送内容,默认为[id=>项目ID]
* @param array $userid 指定会员,默认为项目所有成员
*/
public function pushMsg($action, $data)
public function pushMsg($action, $data = null, $userid = null)
{
if ($data === null) {
$data = ['id' => $this->id];
}
if ($userid === null) {
$userid = $this->relationUserids();
}
$lists = [
'userid' => $this->relationUserids(),
'userid' => $userid,
'msg' => [
'type' => 'project',
'action' => $action,

View File

@ -70,11 +70,11 @@ class ProjectColumn extends AbstractModel
foreach ($tasks as $task) {
$task->deleteTask($pushMsg);
}
$this->delete();
$this->addLog("删除列表:" . $this->name);
if ($pushMsg) {
$this->pushMsg("delete", $this->toArray());
}
$this->delete();
$this->addLog("删除列表:" . $this->name);
return Base::retSuccess('删除成功', $this->toArray());
});
return Base::isSuccess($result);
@ -102,15 +102,22 @@ class ProjectColumn extends AbstractModel
/**
* 推送消息
* @param string $action
* @param array $data
* @param array $data 发送内容,默认为[id=>列表ID]
* @param array $userid 指定会员,默认为项目所有成员
*/
public function pushMsg($action, $data)
public function pushMsg($action, $data = null, $userid = null)
{
if (!$this->project) {
return;
}
if ($data === null) {
$data = ['id' => $this->id];
}
if ($userid === null) {
$userid = $this->project->relationUserids();
}
$lists = [
'userid' => $this->project->relationUserids(),
'userid' => $userid,
'msg' => [
'type' => 'projectColumn',
'action' => $action,

View File

@ -591,11 +591,11 @@ class ProjectTask extends AbstractModel
if ($this->dialog_id) {
WebSocketDialog::whereId($this->dialog_id)->delete();
}
$this->delete();
$this->addLog("删除{任务}" . $this->name);
if ($pushMsg) {
$this->pushMsg('delete', $this->toArray());
}
$this->delete();
$this->addLog("删除{任务}" . $this->name);
return Base::retSuccess('删除成功', $this->toArray());
});
}
@ -623,15 +623,22 @@ class ProjectTask extends AbstractModel
/**
* 推送消息
* @param string $action
* @param array $data
* @param array $data 发送内容,默认为[id=>任务ID]
* @param array $userid 指定会员,默认为项目所有成员
*/
public function pushMsg($action, $data)
public function pushMsg($action, $data = null, $userid = null)
{
if (!$this->project) {
return;
}
if ($data === null) {
$data = ['id' => $this->id];
}
if ($userid === null) {
$userid = $this->project->relationUserids();
}
$lists = [
'userid' => $this->project->relationUserids(),
'userid' => $userid,
'msg' => [
'type' => 'projectTask',
'action' => $action,

View File

@ -626,7 +626,7 @@ export default {
}).catch(({msg}) => {
$A.modalError(msg);
this.sortDisabled = false;
this.$store.dispatch("getProjectDetail", this.projectDetail.id);
this.$store.dispatch("getProjectDetail", this.projectDetail);
});
},
@ -782,7 +782,7 @@ export default {
$A.messageSuccess(msg);
this.$set(column, 'loading', false);
this.$Modal.remove();
this.$store.commit("columnRemoveSuccess", data);
this.$store.commit("columnDeleteSuccess", data);
}).catch(({msg}) => {
$A.modalError(msg, 301);
this.$set(column, 'loading', false);
@ -869,7 +869,7 @@ export default {
onSetting() {
this.settingLoad++;
this.$store.dispatch("call", {
url: 'project/edit',
url: 'project/update',
data: this.settingData,
}).then(({data, msg}) => {
$A.messageSuccess(msg);
@ -890,11 +890,11 @@ export default {
project_id: this.userData.project_id,
userid: this.userData.userids,
},
}).then(({msg}) => {
}).then(({data, msg}) => {
$A.messageSuccess(msg);
this.userLoad--;
this.userShow = false;
this.$store.dispatch("getProjectDetail", this.userData.project_id);
this.$store.dispatch("getProjectDetail", data);
}).catch(({msg}) => {
$A.modalError(msg);
this.userLoad--;
@ -909,11 +909,11 @@ export default {
project_id: this.transferData.project_id,
owner_userid: this.transferData.owner_userid[0],
},
}).then(({msg}) => {
}).then(({data, msg}) => {
$A.messageSuccess(msg);
this.transferLoad--;
this.transferShow = false;
this.$store.dispatch("getProjectDetail", this.transferData.project_id);
this.$store.dispatch("getProjectDetail", data);
}).catch(({msg}) => {
$A.modalError(msg);
this.transferLoad--;

View File

@ -24,7 +24,7 @@ export default {
this.project_id = route.params.id;
},
project_id(id) {
this.$store.dispatch("getProjectDetail", id);
this.$store.dispatch("getProjectDetail", {id});
}
},
}

View File

@ -314,16 +314,16 @@ export default {
* 获取项目信息
* @param state
* @param dispatch
* @param project_id
* @param data {id}
*/
getProjectBasic({state, dispatch}, project_id) {
if (state.method.runNum(project_id) === 0) {
getProjectBasic({state, dispatch}, data) {
if (state.method.runNum(data.id) === 0) {
return;
}
dispatch("call", {
url: 'project/basic',
data: {
project_id: project_id,
project_id: data.id,
},
}).then(result => {
dispatch("saveProject", result.data);
@ -334,24 +334,24 @@ export default {
* 获取项目详情
* @param state
* @param dispatch
* @param project_id
* @param data {id}
*/
getProjectDetail({state, dispatch}, project_id) {
if (state.method.runNum(project_id) === 0) {
getProjectDetail({state, dispatch}, data) {
if (state.method.runNum(data.id) === 0) {
return;
}
const project = state.cacheProjectList.find(({id}) => id == project_id);
const project = state.cacheProjectList.find(({id}) => id == data.id);
if (project) {
state.projectDetail = Object.assign({project_column: [], project_user: []}, project);
} else {
state.projectDetail.id = project_id;
state.projectDetail.id = data.id;
}
//
state.projectLoad++;
dispatch("call", {
url: 'project/detail',
data: {
project_id: project_id,
project_id: data.id,
},
}).then(result => {
state.projectLoad--;
@ -365,7 +365,7 @@ export default {
/**
* 删除项目信息
* @param state
* @param data
* @param data {id}
*/
removeProject({state}, data) {
let index = state.projectList.findIndex(({id}) => id == data.id);
@ -689,7 +689,7 @@ export default {
dispatch("getTaskBasic", result.data.parent_id);
}
if (typeof post.complete_at !== "undefined") {
dispatch("getProjectBasic", result.data.project_id);
dispatch("getProjectBasic", {id: result.data.project_id});
}
dispatch("saveTask", result.data);
resolve(result)
@ -716,7 +716,7 @@ export default {
task_id,
},
}).then(result => {
commit("taskRemoveSuccess", result.data);
commit("taskDeleteSuccess", result.data);
resolve(result);
}).catch(result => {
reject(result)
@ -1126,8 +1126,12 @@ export default {
const {action, data} = msg;
switch (action) {
case 'add':
case 'update':
dispatch("saveProject", data)
break;
case 'detail':
dispatch("getProjectDetail", data);
break;
case 'delete':
dispatch("removeProject", data);
break;
@ -1146,7 +1150,7 @@ export default {
commit("columnAddSuccess", data)
break;
case 'delete':
commit("columnRemoveSuccess", data)
commit("columnDeleteSuccess", data)
break;
}
})(msgDetail);
@ -1164,7 +1168,7 @@ export default {
break;
case 'archived':
case 'delete':
commit("taskRemoveSuccess", data)
commit("taskDeleteSuccess", data)
break;
}
})(msgDetail);

View File

@ -1,6 +1,6 @@
export default {
/**
* 添加列表成功
* 添加列表
* @param state
* @param data
*/
@ -14,20 +14,20 @@ export default {
},
/**
* 删除列表成功
* 删除列表
* @param state
* @param data
*/
columnRemoveSuccess(state, data) {
columnDeleteSuccess(state, data) {
let index = state.projectDetail.project_column.findIndex(({id}) => id === data.id);
if (index > -1) {
state.projectDetail.project_column.splice(index, 1);
}
this.dispatch("getProjectBasic", data.project_id);
this.dispatch("getProjectBasic", {id: data.project_id});
},
/**
* 添加任务成功
* 添加任务
* @param state
* @param data
*/
@ -51,7 +51,7 @@ export default {
}
}
}
this.dispatch("getProjectBasic", task.project_id);
this.dispatch("getProjectBasic", {id: task.project_id});
} else {
// 添加子任务
if (state.projectDetail.id == task.project_id) {
@ -78,11 +78,11 @@ export default {
},
/**
* 移除任务成功
* 删除任务
* @param state
* @param data
*/
taskRemoveSuccess(state, data) {
taskDeleteSuccess(state, data) {
const column = state.projectDetail.project_column.find(({id}) => id === data.column_id);
if (column) {
let index = column.project_task.findIndex(({id}) => id === data.id);
@ -102,6 +102,6 @@ export default {
if (index > -1) {
state.calendarTask.splice(index, 1)
}
this.dispatch("getProjectBasic", data.project_id);
this.dispatch("getProjectBasic", {id: data.project_id});
}
}