From a83639597668e04d467b36d8b880d1a8bcfd3ced Mon Sep 17 00:00:00 2001 From: gzydong <837215079@qq.com> Date: Sun, 23 May 2021 17:28:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Handler/JwtAuthExceptionHandler.php | 5 ++--- .../Handler/WebSocketExceptionHandler.php | 2 +- app/Model/Group/Group.php | 4 ++-- app/Model/Group/GroupMember.php | 6 +++--- app/Model/UsersChatList.php | 16 ++++++++-------- app/Model/UsersFriend.php | 2 +- 6 files changed, 17 insertions(+), 18 deletions(-) diff --git a/app/Exception/Handler/JwtAuthExceptionHandler.php b/app/Exception/Handler/JwtAuthExceptionHandler.php index a24a308..2bf471c 100644 --- a/app/Exception/Handler/JwtAuthExceptionHandler.php +++ b/app/Exception/Handler/JwtAuthExceptionHandler.php @@ -2,12 +2,11 @@ namespace App\Exception\Handler; +use Qbhy\HyperfAuth\Exception\AuthException; use Throwable; use Hyperf\ExceptionHandler\ExceptionHandler; use Hyperf\HttpMessage\Stream\SwooleStream; use Psr\Http\Message\ResponseInterface; -use Phper666\JWTAuth\Exception\TokenValidException; -use Hyperf\WebSocketServer\Exception\WebSocketHandeShakeException; /** * Class JwtAuthExceptionHandler @@ -19,7 +18,7 @@ class JwtAuthExceptionHandler extends ExceptionHandler public function handle(Throwable $throwable, ResponseInterface $response) { // 判断被捕获到的异常是希望被捕获的异常 - if ($throwable instanceof TokenValidException) { + if ($throwable instanceof AuthException) { // 格式化输出 $data = json_encode([ 'code' => $throwable->getCode(), diff --git a/app/Exception/Handler/WebSocketExceptionHandler.php b/app/Exception/Handler/WebSocketExceptionHandler.php index dbb8fe2..85d37a8 100644 --- a/app/Exception/Handler/WebSocketExceptionHandler.php +++ b/app/Exception/Handler/WebSocketExceptionHandler.php @@ -29,7 +29,7 @@ class WebSocketExceptionHandler extends ExceptionHandler public function handle(Throwable $throwable, ResponseInterface $response) { - $stream = new SwooleStream((string)$throwable->getMessage()); + $stream = new SwooleStream($throwable->getMessage()); return $response->withBody($stream); } diff --git a/app/Model/Group/Group.php b/app/Model/Group/Group.php index 71eea82..f765fab 100644 --- a/app/Model/Group/Group.php +++ b/app/Model/Group/Group.php @@ -70,7 +70,7 @@ class Group extends BaseModel */ public static function isManager(int $user_id, int $group_id, $leader = 2) { - return self::where('id', $group_id)->where('creator_id', $user_id)->exists(); + return self::query()->where('id', $group_id)->where('creator_id', $user_id)->exists(); } /** @@ -81,7 +81,7 @@ class Group extends BaseModel */ public static function isDismiss(int $group_id) { - return self::where('id', $group_id)->where('is_dismiss', 1)->exists(); + return self::query()->where('id', $group_id)->where('is_dismiss', 1)->exists(); } /** diff --git a/app/Model/Group/GroupMember.php b/app/Model/Group/GroupMember.php index 15f4333..70dc70e 100644 --- a/app/Model/Group/GroupMember.php +++ b/app/Model/Group/GroupMember.php @@ -52,7 +52,7 @@ class GroupMember extends BaseModel */ public static function getGroupMemberIds(int $group_id) { - return self::where('group_id', $group_id)->where('is_quit', 0)->pluck('user_id')->toArray() ?? []; + return self::query()->where('group_id', $group_id)->where('is_quit', 0)->pluck('user_id')->toArray() ?? []; } /** @@ -64,7 +64,7 @@ class GroupMember extends BaseModel */ public static function visitCard(int $user_id, int $group_id) { - return self::where('group_id', $group_id)->where('user_id', $user_id)->value('user_card') ?? ""; + return self::query()->where('group_id', $group_id)->where('user_id', $user_id)->value('user_card') ?? ""; } /** @@ -75,6 +75,6 @@ class GroupMember extends BaseModel */ public static function getUserGroupIds(int $user_id) { - return self::where('user_id', $user_id)->where('is_quit', 0)->pluck('group_id')->toArray() ?? []; + return self::query()->where('user_id', $user_id)->where('is_quit', 0)->pluck('group_id')->toArray() ?? []; } } diff --git a/app/Model/UsersChatList.php b/app/Model/UsersChatList.php index 4b30aa2..2224dd0 100644 --- a/app/Model/UsersChatList.php +++ b/app/Model/UsersChatList.php @@ -58,7 +58,7 @@ class UsersChatList extends BaseModel */ public static function addItem(int $user_id, int $receive_id, int $type) { - $result = self::where('uid', $user_id)->where('type', $type)->where($type == 1 ? 'friend_id' : 'group_id', $receive_id)->first(); + $result = self::query()->where('uid', $user_id)->where('type', $type)->where($type == 1 ? 'friend_id' : 'group_id', $receive_id)->first(); if ($result) { $result->status = 1; $result->updated_at = date('Y-m-d H:i:s'); @@ -72,7 +72,7 @@ class UsersChatList extends BaseModel ]; } - if (!$result = self::create([ + if (!$result = self::query()->create([ 'type' => $type, 'uid' => $user_id, 'status' => 1, @@ -102,7 +102,7 @@ class UsersChatList extends BaseModel */ public static function topItem(int $user_id, int $list_id, $is_top = true) { - return (bool)self::where('id', $list_id)->where('uid', $user_id)->update([ + return (bool)self::query()->where('id', $list_id)->where('uid', $user_id)->update([ 'is_top' => $is_top ? 1 : 0, 'updated_at' => date('Y-m-d H:i:s') ]); @@ -120,11 +120,11 @@ class UsersChatList extends BaseModel { $data = ['status' => 0, 'updated_at' => date('Y-m-d H:i:s')]; if ($type == 1) { - return (bool)self::where('id', $id)->where('uid', $user_id)->update($data); + return (bool)self::query()->where('id', $id)->where('uid', $user_id)->update($data); } else if ($type == 2) { - return (bool)self::where('uid', $user_id)->where('friend_id', $id)->update($data); + return (bool)self::query()->where('uid', $user_id)->where('friend_id', $id)->update($data); } else { - return (bool)self::where('uid', $user_id)->where('group_id', $id)->update($data); + return (bool)self::query()->where('uid', $user_id)->where('group_id', $id)->update($data); } } @@ -139,11 +139,11 @@ class UsersChatList extends BaseModel */ public static function notDisturbItem(int $user_id, int $receive_id, int $type, int $not_disturb) { - $result = self::where('uid', $user_id)->where($type == 1 ? 'friend_id' : 'group_id', $receive_id)->where('status', 1)->first(['id', 'not_disturb']); + $result = self::query()->where('uid', $user_id)->where($type == 1 ? 'friend_id' : 'group_id', $receive_id)->where('status', 1)->first(['id', 'not_disturb']); if (!$result || $not_disturb == $result->not_disturb) { return false; } - return (bool)self::where('id', $result->id)->update(['not_disturb' => $not_disturb]); + return (bool)self::query()->where('id', $result->id)->update(['not_disturb' => $not_disturb]); } } diff --git a/app/Model/UsersFriend.php b/app/Model/UsersFriend.php index 7767368..6eb4cef 100644 --- a/app/Model/UsersFriend.php +++ b/app/Model/UsersFriend.php @@ -92,7 +92,7 @@ SQL; return true; } - $isTrue = self::where('user1', $user_id1)->where('user2', $user_id2)->where('status', 1)->exists(); + $isTrue = self::query()->where('user1', $user_id1)->where('user2', $user_id2)->where('status', 1)->exists(); if ($isTrue) { redis()->setex($cacheKey, 60 * 5, 1); }