whereUserid($user->userid)->exists()) { return Base::retError('不在成员列表内'); } $dialog = WebSocketDialog::whereId($dialog_id)->first(); if (empty($dialog)) { return Base::retError('对话不存在或已被删除'); } // $list = WebSocketDialogMsg::whereDialogId($dialog_id)->orderByDesc('id')->paginate(Base::getPaginate(100, 50)); $list->transform(function (WebSocketDialogMsg $item) { return $item->sendSuccess(); }); // return Base::retSuccess('success', $list); } /** * 发送消息 * * @apiParam {Number} dialog_id 对话ID * @apiParam {Number} [extra_int] 额外参数(数字) * @apiParam {String} [extra_str] 额外参数(字符) * @apiParam {String} text 消息内容 */ public function msg__sendtext() { $user = User::authE(); if (Base::isError($user)) { return $user; } else { $user = User::IDE($user['data']); } // $dialog_id = intval(Request::input('dialog_id')); $extra_int = intval(Request::input('extra_int')); $extra_str = trim(Request::input('extra_str')); $text = trim(Request::input('text')); // if (mb_strlen($text) < 1) { return Base::retError('消息内容不能为空'); } elseif (mb_strlen($text) > 20000) { return Base::retError('消息内容最大不能超过20000字'); } // if (!WebSocketDialogUser::whereDialogId($dialog_id)->whereUserid($user->userid)->exists()) { return Base::retError('不在成员列表内'); } $dialog = WebSocketDialog::whereId($dialog_id)->first(); if (empty($dialog)) { return Base::retError('对话不存在或已被删除'); } // $msg = [ 'text' => $text ]; // if ($dialog->type == 'group') { return WebSocketDialogMsg::addGroupMsg($dialog_id, 'text', $msg, $user->userid, $extra_int, $extra_str); } else { return WebSocketDialogMsg::addUserMsg($dialog_id, 'text', $msg, $user->userid, $extra_int, $extra_str); } } }