From 5bef4c27cc52a30c4605e9f83784fe64cd99180e Mon Sep 17 00:00:00 2001 From: vilson <545522390@qq.com> Date: Sat, 17 Aug 2019 18:51:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BD=BF=E7=94=A8@=E6=8F=90?= =?UTF-8?q?=E5=8F=8A=E4=BB=BB=E5=8A=A1=E6=88=90=E5=91=98?= 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/Task.php | 31 ++++++++++++++----------- application/project/behavior/Task.php | 29 ++++++++++++++++++++--- application/project/controller/Task.php | 7 ++++-- 3 files changed, 48 insertions(+), 19 deletions(-) diff --git a/application/common/Model/Task.php b/application/common/Model/Task.php index 24d7f30..5f634bc 100644 --- a/application/common/Model/Task.php +++ b/application/common/Model/Task.php @@ -411,12 +411,13 @@ class Task extends CommonModel /** * @param $taskCode * @param $comment - * @return ProjectLog + * @param $mentions + * @return bool * @throws DataNotFoundException - * @throws ModelNotFoundException * @throws DbException + * @throws ModelNotFoundException */ - public function createComment($taskCode, $comment) + public function createComment($taskCode, $comment, $mentions = []) { if (!$taskCode) { throw new Exception('请选择任务', 1); @@ -425,17 +426,19 @@ class Task extends CommonModel if (!$task) { throw new Exception('任务已失效', 2); } - $data = [ - 'member_code' => getCurrentMember()['code'], - 'source_code' => $taskCode, - 'action_type' => 'task', - 'code' => createUniqueCode('projectLog'), - 'create_time' => nowTime(), - 'is_comment' => 1, - 'content' => $comment, - 'type' => 'comment' - ]; - return ProjectLog::create($data); +// $data = [ +// 'member_code' => getCurrentMember()['code'], +// 'source_code' => $taskCode, +// 'action_type' => 'task', +// 'code' => createUniqueCode('projectLog'), +// 'create_time' => nowTime(), +// 'is_comment' => 1, +// 'content' => $comment, +// 'type' => 'comment' +// ]; + self::taskHook(getCurrentMember()['code'], $taskCode, 'comment', '', 1, '', $comment, '', $mentions); + return true; +// return ProjectLog::create($data); } /** diff --git a/application/project/behavior/Task.php b/application/project/behavior/Task.php index 5c401c7..4b82e97 100644 --- a/application/project/behavior/Task.php +++ b/application/project/behavior/Task.php @@ -19,6 +19,7 @@ use app\common\Model\TaskStages; use app\common\Model\TaskWorkflowRule; use message\DingTalk; use service\MessageService; +use think\Db; use think\db\exception\DataNotFoundException; use think\db\exception\ModelNotFoundException; use think\exception\DbException; @@ -49,6 +50,7 @@ class Task 'type' => 'message', 'action' => 'task', 'terminal' => 'project', + 'source_code' => $task['code'], ]; $remark = ''; $content = ''; @@ -171,6 +173,11 @@ class Task $remark = '取消关联文件'; $content = "{$data['data']['title']}"; break; + case 'comment': + $icon = 'file-text'; + $remark = $data['content']; + $content = $data['content']; + break; default: $icon = 'plus'; $remark = ' 创建了任务 '; @@ -224,16 +231,32 @@ class Task //触发推送的事件 $messageService = new MessageService(); $messageDingTalk = new DingTalk(); - $notifyActions = ['done', 'redo', 'assign']; + $notifyActions = ['done', 'redo', 'assign', 'comment']; $notifyModel = new Notify(); $member = Member::where(['code' => $data['memberCode']])->find(); - $notifyData['title'] = $member['name'] . ' ' . $remark; + $notifyData['title'] = $member['name'] . ': ' . $remark; $notifyData['content'] = $task['name']; $notifyData['avatar'] = $member['avatar']; $socketMessage = $socketGroupMessage = ['content' => $notifyData['content'], 'title' => $notifyData['title'], 'data' => ['organizationCode' => getCurrentOrganizationCode(), 'projectCode' => $task['project_code'], 'taskCode' => $task['code']]]; $socketAction = $notifyData['action']; if (in_array($data['type'], $notifyActions)) { - $taskMembers = TaskMember::where(['task_code' => $task['code']])->select()->toArray(); + if ($data['type'] == 'comment') { + $taskMembers = []; + $notifyData['type'] = 'notice'; + if ($data['data']) { + $prefix = config('database.prefix'); + $taskCode = $task['code']; + foreach ($data['data'] as $item) { + $sql = "select tm.member_code from {$prefix}task_member as tm join {$prefix}member as m on tm.member_code = m.code where tm.task_code = '{$taskCode}' and name = '{$item}'"; + $memberCurr = Db::query($sql); + if ($memberCurr) { + $taskMembers[] = $memberCurr[0]; + } + } + } + }else{ + $taskMembers = TaskMember::where(['task_code' => $task['code']])->select()->toArray(); + } //todo 短信,消息推送 if ($taskMembers) { foreach ($taskMembers as $taskMember) { diff --git a/application/project/controller/Task.php b/application/project/controller/Task.php index 0885db4..f28f052 100644 --- a/application/project/controller/Task.php +++ b/application/project/controller/Task.php @@ -263,12 +263,15 @@ class Task extends BasicApi */ public function createComment(Request $request) { - $data = $request::only('taskCode,comment'); + $data = $request::only('taskCode,comment,mentions'); if (!$request::post('taskCode')) { $this->error("请选择任务"); } + if (isset($data['mentions'])) { + $data['mentions'] = json_decode($data['mentions']); + } try { - $result = $this->model->createComment($data['taskCode'], $data['comment']); + $result = $this->model->createComment($data['taskCode'], $data['comment'], $data['mentions']); } catch (Exception $e) { $this->error($e->getMessage(), $e->getCode());; }