diff --git a/app/Http/Controllers/Api/DialogController.php b/app/Http/Controllers/Api/DialogController.php index f41f9a084..a65cff46d 100755 --- a/app/Http/Controllers/Api/DialogController.php +++ b/app/Http/Controllers/Api/DialogController.php @@ -672,15 +672,18 @@ class DialogController extends AbstractController } /** - * @api {get} api/dialog/msg/search 14. 搜索消息位置 + * @api {get} api/dialog/msg/search 14. 搜索消息 * * @apiDescription 需要token身份 * @apiVersion 1.0.0 * @apiGroup dialog * @apiName msg__search * - * @apiParam {Number} dialog_id 对话ID * @apiParam {String} key 搜索关键词 + * @apiParam {Number} [dialog_id] 对话ID(存在则搜索消息在对话的位置) + * @apiParam {Number} [take] 搜索数量 + * - dialog_id > 0, 默认:200,最大:200 + * - dialog_id <= 0, 默认:20,最大:50 * * @apiSuccess {Number} ret 返回状态码(1正确、0错误) * @apiSuccess {String} msg 返回信息(错误描述) @@ -688,59 +691,38 @@ class DialogController extends AbstractController */ public function msg__search() { - User::auth(); + $user = User::auth(); // - $dialog_id = intval(Request::input('dialog_id')); $key = trim(Request::input('key')); + $dialogId = intval(Request::input('dialog_id')); // if (empty($key)) { return Base::retError('关键词不能为空'); } // - WebSocketDialog::checkDialog($dialog_id); - // - $data = WebSocketDialogMsg::whereDialogId($dialog_id) - ->where('key', 'LIKE', "%{$key}%") - ->take(200) - ->pluck('id'); - return Base::retSuccess('success', compact('data')); - } - - /** - * @api {get} api/dialog/msg/esearch 15. 搜索消息 - * - * @apiDescription 需要token身份 - * @apiVersion 1.0.0 - * @apiGroup dialog - * @apiName msg__esearch - * - * @apiParam {String} key 搜索关键词 - * @apiParam {Number} [pagesize] 每页显示数量,默认:20,最大:50 - * - * @apiSuccess {Number} ret 返回状态码(1正确、0错误) - * @apiSuccess {String} msg 返回信息(错误描述) - * @apiSuccess {Object} data 返回数据 - */ - public function msg__esearch() - { - $user = User::auth(); - // - $key = trim(Request::input('key')); - $list = []; - // - $searchResults = ZincSearchDialogMsg::search($user->userid, $key, 0, Base::getPaginate(50, 20)); - if ($searchResults) { - foreach ($searchResults as $item) { - if ($dialog = WebSocketDialog::find($item['id'])) { - $dialog = array_merge($dialog->toArray(), $item); - $list[] = WebSocketDialog::synthesizeData($dialog, $user->userid); + if ($dialogId > 0) { + // 搜索位置 + WebSocketDialog::checkDialog($dialogId); + // + $data = WebSocketDialogMsg::whereDialogId($dialogId) + ->where('key', 'LIKE', "%{$key}%") + ->take(Base::getPaginate(200, 200, 'take')) + ->pluck('id'); + return Base::retSuccess('success', compact('data')); + } else { + // 搜索消息 + $list = []; + $searchResults = ZincSearchDialogMsg::search($user->userid, $key, 0, Base::getPaginate(50, 20, 'take')); + if ($searchResults) { + foreach ($searchResults as $item) { + if ($dialog = WebSocketDialog::find($item['id'])) { + $dialog = array_merge($dialog->toArray(), $item); + $list[] = WebSocketDialog::synthesizeData($dialog, $user->userid); + } } } + return Base::retSuccess('success', ['data' => $list]); } - // - return Base::retSuccess('success', [ - 'data' => $list, - ]); } /** diff --git a/app/Models/UserDelete.php b/app/Models/UserDelete.php index 47e85ebdb..a87239aba 100644 --- a/app/Models/UserDelete.php +++ b/app/Models/UserDelete.php @@ -37,11 +37,6 @@ use App\Module\Base; */ class UserDelete extends AbstractModel { - /** - * 昵称 - * @param $value - * @return string - */ public function getCacheAttribute($value) { if (!is_array($value)) { @@ -65,13 +60,25 @@ class UserDelete extends AbstractModel */ public static function userid2basic($userid) { - $row = self::whereUserid($userid)->first(); - if (empty($row) || empty($row->cache)) { - return null; - } - $cache = $row->cache; - $cache = array_intersect_key($cache, array_flip(array_merge(User::$basicField, ['department_name']))); - $cache['delete_at'] = $row->created_at->toDateTimeString(); - return $cache; + return \Cache::remember("UserDelete:{$userid}", now()->addDays(3), function () use ($userid) { + $row = self::whereUserid($userid)->first(); + if (empty($row) || empty($row->cache)) { + return null; + } + $cache = $row->cache; + $cache = array_intersect_key($cache, array_flip(array_merge(User::$basicField, ['department_name']))); + $cache['delete_at'] = $row->created_at->toDateTimeString(); + return $cache; + }); + } + + /** + * userid 获取 昵称 + * @param $userid + * @return string + */ + public static function userid2nickname($userid) + { + return self::userid2basic($userid)['nickname'] ?? ''; } } diff --git a/app/Models/WebSocketDialog.php b/app/Models/WebSocketDialog.php index 2d0ff27f9..839cffa17 100644 --- a/app/Models/WebSocketDialog.php +++ b/app/Models/WebSocketDialog.php @@ -298,7 +298,8 @@ class WebSocketDialog extends AbstractModel $data['is_disable'] = $basic->isDisable(true); $data['quick_msgs'] = UserBot::quickMsgs($basic->email); } else { - $data['name'] = 'non-existent'; + $data['name'] = UserDelete::userid2nickname($dialog_user->userid) ?: '[Delete]'; + $data['is_disable'] = 1; $data['dialog_delete'] = 1; } $data['dialog_user'] = $dialog_user; diff --git a/resources/assets/js/components/SearchBox.vue b/resources/assets/js/components/SearchBox.vue index 576ea1349..a86422085 100755 --- a/resources/assets/js/components/SearchBox.vue +++ b/resources/assets/js/components/SearchBox.vue @@ -50,7 +50,7 @@
- +