支持使用@提及任务成员

Signed-off-by: vilson <545522390@qq.com>
This commit is contained in:
vilson 2019-08-17 18:51:40 +08:00
parent c8080c0a1d
commit 5bef4c27cc
3 changed files with 48 additions and 19 deletions

View File

@ -411,12 +411,13 @@ class Task extends CommonModel
/** /**
* @param $taskCode * @param $taskCode
* @param $comment * @param $comment
* @return ProjectLog * @param $mentions
* @return bool
* @throws DataNotFoundException * @throws DataNotFoundException
* @throws ModelNotFoundException
* @throws DbException * @throws DbException
* @throws ModelNotFoundException
*/ */
public function createComment($taskCode, $comment) public function createComment($taskCode, $comment, $mentions = [])
{ {
if (!$taskCode) { if (!$taskCode) {
throw new Exception('请选择任务', 1); throw new Exception('请选择任务', 1);
@ -425,17 +426,19 @@ class Task extends CommonModel
if (!$task) { if (!$task) {
throw new Exception('任务已失效', 2); throw new Exception('任务已失效', 2);
} }
$data = [ // $data = [
'member_code' => getCurrentMember()['code'], // 'member_code' => getCurrentMember()['code'],
'source_code' => $taskCode, // 'source_code' => $taskCode,
'action_type' => 'task', // 'action_type' => 'task',
'code' => createUniqueCode('projectLog'), // 'code' => createUniqueCode('projectLog'),
'create_time' => nowTime(), // 'create_time' => nowTime(),
'is_comment' => 1, // 'is_comment' => 1,
'content' => $comment, // 'content' => $comment,
'type' => 'comment' // 'type' => 'comment'
]; // ];
return ProjectLog::create($data); self::taskHook(getCurrentMember()['code'], $taskCode, 'comment', '', 1, '', $comment, '', $mentions);
return true;
// return ProjectLog::create($data);
} }
/** /**

View File

@ -19,6 +19,7 @@ use app\common\Model\TaskStages;
use app\common\Model\TaskWorkflowRule; use app\common\Model\TaskWorkflowRule;
use message\DingTalk; use message\DingTalk;
use service\MessageService; use service\MessageService;
use think\Db;
use think\db\exception\DataNotFoundException; use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException; use think\db\exception\ModelNotFoundException;
use think\exception\DbException; use think\exception\DbException;
@ -49,6 +50,7 @@ class Task
'type' => 'message', 'type' => 'message',
'action' => 'task', 'action' => 'task',
'terminal' => 'project', 'terminal' => 'project',
'source_code' => $task['code'],
]; ];
$remark = ''; $remark = '';
$content = ''; $content = '';
@ -171,6 +173,11 @@ class Task
$remark = '取消关联文件'; $remark = '取消关联文件';
$content = "<a target=\"_blank\" class=\"muted\" href=\"{$data['data']['url']} \">{$data['data']['title']}</a>"; $content = "<a target=\"_blank\" class=\"muted\" href=\"{$data['data']['url']} \">{$data['data']['title']}</a>";
break; break;
case 'comment':
$icon = 'file-text';
$remark = $data['content'];
$content = $data['content'];
break;
default: default:
$icon = 'plus'; $icon = 'plus';
$remark = ' 创建了任务 '; $remark = ' 创建了任务 ';
@ -224,16 +231,32 @@ class Task
//触发推送的事件 //触发推送的事件
$messageService = new MessageService(); $messageService = new MessageService();
$messageDingTalk = new DingTalk(); $messageDingTalk = new DingTalk();
$notifyActions = ['done', 'redo', 'assign']; $notifyActions = ['done', 'redo', 'assign', 'comment'];
$notifyModel = new Notify(); $notifyModel = new Notify();
$member = Member::where(['code' => $data['memberCode']])->find(); $member = Member::where(['code' => $data['memberCode']])->find();
$notifyData['title'] = $member['name'] . ' ' . $remark; $notifyData['title'] = $member['name'] . ': ' . $remark;
$notifyData['content'] = $task['name']; $notifyData['content'] = $task['name'];
$notifyData['avatar'] = $member['avatar']; $notifyData['avatar'] = $member['avatar'];
$socketMessage = $socketGroupMessage = ['content' => $notifyData['content'], 'title' => $notifyData['title'], 'data' => ['organizationCode' => getCurrentOrganizationCode(), 'projectCode' => $task['project_code'], 'taskCode' => $task['code']]]; $socketMessage = $socketGroupMessage = ['content' => $notifyData['content'], 'title' => $notifyData['title'], 'data' => ['organizationCode' => getCurrentOrganizationCode(), 'projectCode' => $task['project_code'], 'taskCode' => $task['code']]];
$socketAction = $notifyData['action']; $socketAction = $notifyData['action'];
if (in_array($data['type'], $notifyActions)) { if (in_array($data['type'], $notifyActions)) {
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(); $taskMembers = TaskMember::where(['task_code' => $task['code']])->select()->toArray();
}
//todo 短信,消息推送 //todo 短信,消息推送
if ($taskMembers) { if ($taskMembers) {
foreach ($taskMembers as $taskMember) { foreach ($taskMembers as $taskMember) {

View File

@ -263,12 +263,15 @@ class Task extends BasicApi
*/ */
public function createComment(Request $request) public function createComment(Request $request)
{ {
$data = $request::only('taskCode,comment'); $data = $request::only('taskCode,comment,mentions');
if (!$request::post('taskCode')) { if (!$request::post('taskCode')) {
$this->error("请选择任务"); $this->error("请选择任务");
} }
if (isset($data['mentions'])) {
$data['mentions'] = json_decode($data['mentions']);
}
try { try {
$result = $this->model->createComment($data['taskCode'], $data['comment']); $result = $this->model->createComment($data['taskCode'], $data['comment'], $data['mentions']);
} catch (Exception $e) { } catch (Exception $e) {
$this->error($e->getMessage(), $e->getCode());; $this->error($e->getMessage(), $e->getCode());;
} }