From 3dd962df4a1d40a2044e09b612ee40ead97207e3 Mon Sep 17 00:00:00 2001 From: vilson <545522390@qq.com> Date: Sun, 23 Jun 2019 08:39:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=89=88=E6=9C=AC=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: vilson <545522390@qq.com> --- application/common/Model/ProjectVersion.php | 23 ++++ application/project/behavior/Project.php | 2 +- application/project/behavior/Task.php | 2 +- application/project/behavior/Version.php | 116 ++++++++++++++++++ .../project/controller/ProjectVersion.php | 69 ++++++++++- application/project/tags.php | 3 + 6 files changed, 209 insertions(+), 6 deletions(-) create mode 100644 application/project/behavior/Version.php diff --git a/application/common/Model/ProjectVersion.php b/application/common/Model/ProjectVersion.php index 561bd92..e5343b0 100644 --- a/application/common/Model/ProjectVersion.php +++ b/application/common/Model/ProjectVersion.php @@ -7,6 +7,7 @@ use think\db\exception\ModelNotFoundException; use think\Exception; use think\exception\DbException; use think\exception\PDOException; +use think\facade\Hook; /** * 版本 @@ -71,6 +72,7 @@ class ProjectVersion extends CommonModel if (!$versionCode) { return error(1, '请选择一个版本'); } + ProjectVersion::versionHook(getCurrentMember()['code'], $versionCode, 'delete'); self::where(['code' => $versionCode])->delete(); Task::update(['features_code' => '', 'version_code' => ''], ['version_code' => $versionCode]); return true; @@ -79,13 +81,17 @@ class ProjectVersion extends CommonModel public function changeStatus($versionCode, $status, $publishTime = '') { if (!$versionCode) { + return error(1, '请选择一个版本'); } $updateData = ['status' => $status]; + $logType = 'status'; if ($status == 3) { $updateData['publish_time'] = $publishTime; + $logType = 'publish'; } self::update($updateData, ['code' => $versionCode]); + ProjectVersion::versionHook(getCurrentMember()['code'], $versionCode, $logType); return true; } @@ -106,6 +112,23 @@ class ProjectVersion extends CommonModel return '已发布'; } + } + + /** + * 版本变动钩子 + * @param $memberCode + * @param $versionCode + * @param string $type + * @param string $remark + * @param string $content + * @param array $data + * @param string $tag + */ + public static function versionHook($memberCode, $versionCode, $type = 'create', $remark = '', $content = '', $data = [], $tag = 'version') + { + $data = ['memberCode' => $memberCode, 'versionCode' => $versionCode, 'remark' => $remark, 'type' => $type, 'content' => $content, 'data' => $data, 'tag' => $tag]; + Hook::listen($tag, $data); } + } diff --git a/application/project/behavior/Project.php b/application/project/behavior/Project.php index 30f015c..db7f702 100644 --- a/application/project/behavior/Project.php +++ b/application/project/behavior/Project.php @@ -28,7 +28,7 @@ class Project public function run($data) { Log::init(['path' => 'log/project']); - $logData = ['member_code' => $data['memberCode'], 'source_code' => $data['sourceCode'], 'remark' => $data['remark'], 'type' => $data['type'], 'content' => $data['content'], 'is_comment' => $data['isComment'], 'to_member_code' => $data['toMemberCode'], 'create_time' => nowTime(), 'code' => createUniqueCode('collection'), 'action_type' => 'project']; + $logData = ['member_code' => $data['memberCode'], 'source_code' => $data['sourceCode'], 'remark' => $data['remark'], 'type' => $data['type'], 'content' => $data['content'], 'is_comment' => $data['isComment'], 'to_member_code' => $data['toMemberCode'], 'create_time' => nowTime(), 'code' => createUniqueCode('projectLog'), 'action_type' => 'project']; $project = \app\common\Model\Project::where(['code' => $data['sourceCode']])->find(); $logData['project_code'] = $project['code']; $toMember = []; diff --git a/application/project/behavior/Task.php b/application/project/behavior/Task.php index ee8c185..e2859f6 100644 --- a/application/project/behavior/Task.php +++ b/application/project/behavior/Task.php @@ -29,7 +29,7 @@ class Task public function run($data) { Log::init(['path' => 'log/task']); - $logData = ['member_code' => $data['memberCode'], 'source_code' => $data['taskCode'], 'remark' => $data['remark'], 'type' => $data['type'], 'content' => $data['content'], 'is_comment' => $data['isComment'], 'to_member_code' => $data['toMemberCode'], 'create_time' => nowTime(), 'code' => createUniqueCode('collection'), 'action_type' => 'task']; + $logData = ['member_code' => $data['memberCode'], 'source_code' => $data['taskCode'], 'remark' => $data['remark'], 'type' => $data['type'], 'content' => $data['content'], 'is_comment' => $data['isComment'], 'to_member_code' => $data['toMemberCode'], 'create_time' => nowTime(), 'code' => createUniqueCode('projectLog'), 'action_type' => 'task']; $task = \app\common\Model\Task::where(['code' => $data['taskCode']])->find(); $logData['project_code'] = $task['project_code']; $toMember = []; diff --git a/application/project/behavior/Version.php b/application/project/behavior/Version.php new file mode 100644 index 0000000..57085e9 --- /dev/null +++ b/application/project/behavior/Version.php @@ -0,0 +1,116 @@ + 'log/task']); + $logData = ['member_code' => $data['memberCode'], 'source_code' => $data['versionCode'], 'remark' => $data['remark'], 'type' => $data['type'], 'content' => $data['content'], 'create_time' => nowTime(), 'code' => createUniqueCode('projectVersionLog')]; + $version = ProjectVersion::where(['code' => $data['versionCode']])->find(); + $logData['features_code'] = $version['features_code']; + $remark = ''; + $content = ''; + switch ($data['type']) { + case 'create': + $icon = 'plus'; + $remark = '创建了版本 '; + $content = $version['name']; + break; + case 'status': + $icon = 'check-square'; + $remark = '更新了状态为 ' . $version['statusText']; + break; + case 'publish': + $icon = 'check-square'; + $remark = '完成版本时间为 ' . date('m月d日 H:i', strtotime($version['publish_time'])); + break; + case 'name': + $icon = 'edit'; + $remark = '更新了版本名 '; + $content = $version['name']; + break; + case 'content': + $icon = 'file-text'; + $remark = '更新了备注 '; + $content = $version['description']; + break; + case 'clearContent': + $icon = 'file-text'; + $remark = '清空了备注 '; + break; + case 'setStartTime': + $icon = 'calendar'; + $remark = '更新开始时间为 ' . date('m月d日 H:i', strtotime($version['start_time'])); + break; + case 'clearStartTime': + $icon = 'calendar'; + $remark = '清除了开始时间 '; + break; + case 'setPlanPublishTime': + $icon = 'calendar'; + $remark = '更新计划发布时间为 ' . date('m月d日 H:i', strtotime($version['plan_publish_time'])); + break; + case 'clearPlanPublishTime': + $icon = 'calendar'; + $remark = '清除了计划发布时间 '; + break; + case 'delete': + $icon = 'delete'; + $remark = '删除了版本 '; + break; + case 'linkFile': + $icon = 'link'; + $remark = ' 添加了 2 项发布内容 '; + $content = "{$data['data']['title']}"; + + break; + case 'unlinkFile': + $icon = 'disconnect'; + $remark = '移除了发布内容'; + $content = "{$data['data']['title']}"; + break; + default: + $icon = 'plus'; + $remark = ' 创建了版本 '; + break; + } + $logData['icon'] = $icon; + if (!$data['remark']) { + $logData['remark'] = $remark; + } + if (!$data['content']) { + $logData['content'] = $content; + } + ProjectVersionLog::create($logData); + } +} diff --git a/application/project/controller/ProjectVersion.php b/application/project/controller/ProjectVersion.php index f46279a..83dec29 100644 --- a/application/project/controller/ProjectVersion.php +++ b/application/project/controller/ProjectVersion.php @@ -3,6 +3,7 @@ namespace app\project\controller; use app\common\Model\Member; +use app\common\Model\ProjectLog; use app\common\Model\ProjectVersionLog; use controller\BasicApi; use think\db\exception\DataNotFoundException; @@ -59,6 +60,7 @@ class ProjectVersion extends BasicApi } $result = $this->model->createData($data['featuresCode'], $data['name'], $data['description'], getCurrentOrganizationCode(), $data['startTime'], $data['planPublishTime']); if (!isError($result)) { + \app\common\Model\ProjectVersion::versionHook(getCurrentMember()['code'], $result['code'], 'create'); $this->success('添加成功', $result); } $this->error($result['msg']); @@ -94,6 +96,30 @@ class ProjectVersion extends BasicApi } $result = $this->model->_edit($data, ['code' => $versionCode]); if ($result) { + $member = getCurrentMember(); + $type = 'name'; + if (isset($data['name'])) { + $type = 'name'; + } + if (isset($data['description'])) { + $type = 'content'; + if (!$data['description']) { + $type = 'clearContent'; + } + } + if (isset($data['start_time'])) { + $type = 'setStartTime'; + if (!$data['start_time']) { + $type = 'clearStartTime'; + } + } + if (isset($data['plan_publish_time'])) { + $type = 'setPlanPublishTime'; + if (!$data['plan_publish_time']) { + $type = 'clearPlanPublishTime'; + } + } + \app\common\Model\ProjectVersion::versionHook($member['code'], $versionCode, $type); $this->success(''); } $this->error("操作失败,请稍候再试!"); @@ -131,6 +157,12 @@ class ProjectVersion extends BasicApi $this->success('', $version); } + /** + * 关联任务 + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ public function _getVersionTask() { $code = Request::post('versionCode'); @@ -138,18 +170,47 @@ class ProjectVersion extends BasicApi $this->success('', $taskList); } + /** + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ public function _getVersionLog() { +// $code = Request::post('versionCode'); +// $logList = ProjectVersionLog::where(['source_code' => $code])->field('id', true)->select(); +// if ($logList) { +// foreach ($logList as &$item) { +// $member = Member::where(['code' => $item['member_code']])->field('id,name,avatar,code')->find(); +// !$member && $member = []; +// $item['member'] = $member; +// } +// } +// $this->success('', $logList); + $code = Request::post('versionCode'); - $logList = ProjectVersionLog::where(['source_code' => $code])->field('id', true)->select(); - if ($logList) { - foreach ($logList as &$item) { + $showAll = Request::post('all', 0); + $where = []; + $where[] = ['source_code', '=', $code]; + $projectVersionModel = new ProjectVersionLog(); + if ($showAll) { + $list = []; + $list['list'] = $projectVersionModel->where($where)->order('id asc')->select()->toArray(); + $list['total'] = count($list['list']); + } else { + $list = $projectVersionModel->_list($where, 'id desc'); + if ($list['list']) { + $list['list'] = array_reverse($list['list']); + } + } + if ($list['list']) { + foreach ($list['list'] as &$item) { $member = Member::where(['code' => $item['member_code']])->field('id,name,avatar,code')->find(); !$member && $member = []; $item['member'] = $member; } } - $this->success('', $logList); + $this->success('', $list); } /** diff --git a/application/project/tags.php b/application/project/tags.php index 7a6879a..773c829 100644 --- a/application/project/tags.php +++ b/application/project/tags.php @@ -6,4 +6,7 @@ return [ 'project' => [ 'app\\project\\behavior\\Project' ], + 'version' => [ + 'app\\project\\behavior\\Version' + ], ];