diff --git a/app/Services/WebSocketService.php b/app/Services/WebSocketService.php index 330f87a04..8b9d47ee4 100644 --- a/app/Services/WebSocketService.php +++ b/app/Services/WebSocketService.php @@ -125,8 +125,14 @@ class WebSocketService implements WebSocketHandlerInterface * 已阅消息 */ case 'readMsg': - $dialogMsg = WebSocketDialogMsg::whereId(intval($data['id']))->first(); - $dialogMsg && $dialogMsg->readSuccess($this->getUserid($frame->fd)); + $ids = is_array($data['id']) ? $data['id'] : [$data['id']]; + $userid = $this->getUserid($frame->fd); + $list = WebSocketDialogMsg::whereIn('id', $ids)->get(); + if ($list->isNotEmpty()) { + foreach ($list as $item) { + $item->readSuccess($userid); + } + } return; } // diff --git a/app/Tasks/LineTask.php b/app/Tasks/LineTask.php index 9e132109f..78852aa41 100644 --- a/app/Tasks/LineTask.php +++ b/app/Tasks/LineTask.php @@ -36,7 +36,7 @@ class LineTask extends AbstractTask $fd[] = $ws->fd; } if ($fd) { - PushTask::pushIgnoreFail([ + PushTask::push([ 'fd' => $fd, 'msg' => [ 'type' => 'line', diff --git a/app/Tasks/PushTask.php b/app/Tasks/PushTask.php index b2034f2b6..0f1f3f51a 100644 --- a/app/Tasks/PushTask.php +++ b/app/Tasks/PushTask.php @@ -69,21 +69,19 @@ class PushTask extends AbstractTask */ public static function resendTmpMsgForUserid($userid) { - - $lists = WebSocketTmpMsg::whereCreateId($userid) + WebSocketTmpMsg::whereCreateId($userid) ->whereSend(0) ->where('created_at', '>', Carbon::now()->subMinute()) // 1分钟内添加的数据 ->orderBy('id') - ->get(); - if ($lists->isNotEmpty()) { - foreach ($lists as $item) { - self::push([ - 'tmp_msg_id' => $item->id, - 'userid' => $userid, - 'msg' => Base::json2array($item->msg), - ]); - } - } + ->chunk(100, function($list) use ($userid) { + foreach ($list as $item) { + self::push([ + 'tmp_msg_id' => $item->id, + 'userid' => $userid, + 'msg' => Base::json2array($item->msg), + ]); + } + }); } /** @@ -93,7 +91,7 @@ class PushTask extends AbstractTask * @param int $delay 延迟推送时间,默认:1秒($key填写时有效) * @param bool $addFail 失败后是否保存到临时表,等上线后继续发送 */ - public static function push(array $lists, $key = '', $delay = 1, $addFail = true) + public static function push(array $lists, $key = '', $delay = 1, $addFail = false) { if (!is_array($lists) || empty($lists)) { return; @@ -169,11 +167,11 @@ class PushTask extends AbstractTask } /** - * 推送消息(忽略错误) + * 推送消息(出错后保存临时表,上线后尝试重新发送) * @param array $lists 消息列表 */ - public static function pushIgnoreFail(array $lists) + public static function pushR(array $lists) { - self::push($lists, '', 1, false); + self::push($lists, '', 1, true); } } diff --git a/resources/assets/js/pages/manage/components/DialogView.vue b/resources/assets/js/pages/manage/components/DialogView.vue index c5d721d0f..592362099 100644 --- a/resources/assets/js/pages/manage/components/DialogView.vue +++ b/resources/assets/js/pages/manage/components/DialogView.vue @@ -79,7 +79,7 @@ export default { }, mounted() { - this.parsingData() + this.parsingRead() }, computed: { @@ -96,7 +96,7 @@ export default { watch: { msgData() { - this.parsingData() + this.parsingRead() } }, @@ -115,14 +115,11 @@ export default { }); }, - parsingData() { + parsingRead() { const {userid, r, id} = this.msgData; if (userid == this.userId) return; if ($A.isJson(r) && r.read_at) return; - this.$store.commit('wsSend', { - type: 'readMsg', - data: {id} - }); + this.$store.commit('wsMsgRead', id); }, formatTime(date) { diff --git a/resources/assets/js/pages/manage/components/DialogWrapper.vue b/resources/assets/js/pages/manage/components/DialogWrapper.vue index 6522eff2a..230110847 100644 --- a/resources/assets/js/pages/manage/components/DialogWrapper.vue +++ b/resources/assets/js/pages/manage/components/DialogWrapper.vue @@ -24,7 +24,7 @@ -
+
{{$L('有' + msgNew + '条新消息')}}
{ + this.commit('wsSend', { + type: 'readMsg', + data: { + id: $A.cloneJSON(state.wsReadWaitList) + } + }); + state.wsReadWaitList = []; + }, 10); + }, + /** * 监听消息 * @param state diff --git a/resources/assets/js/store/state.js b/resources/assets/js/store/state.js index 71bf53327..8f6d5a58a 100644 --- a/resources/assets/js/store/state.js +++ b/resources/assets/js/store/state.js @@ -172,6 +172,8 @@ state.wsMsg = {}; state.wsCall = {}; state.wsTimeout = null; state.wsListener = {}; +state.wsReadTimeout = null; +state.wsReadWaitList = []; // 项目信息 state.projectLoad = 0; diff --git a/resources/assets/sass/main.scss b/resources/assets/sass/main.scss index 1f2c137f0..fd82731f2 100755 --- a/resources/assets/sass/main.scss +++ b/resources/assets/sass/main.scss @@ -1119,8 +1119,8 @@ body { } .dialog-num { position: absolute; - top: 12px; - left: 38px; + top: 10px; + left: 42px; font-size: 12px; .ivu-badge-count { height: 18px;