From a4b719641ba2c2f6b562751ad5a72186078b6a41 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Sun, 18 Sep 2022 21:44:57 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=93=8D=E4=BD=9C=E7=A6=BB=E8=81=8C?= =?UTF-8?q?=E9=9A=90=E8=97=8F=E9=80=80=E5=87=BA=E7=BE=A4=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/UsersController.php | 2 +- app/Models/WebSocketDialog.php | 23 +++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index cfbe925bb..f00082be2 100755 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -720,7 +720,7 @@ class UsersController extends AbstractController $userTransfer->start(); // 离职移出全员群组 $dialog = WebSocketDialog::whereGroupType('all')->orderByDesc('id')->first(); - $dialog?->exitGroup($userInfo->userid, 'remove', false); + $dialog?->exitGroup($userInfo->userid, 'remove', false, false); } elseif ($type === 'cleardisable') { // 取消离职重新加入全员群组 $dialog = WebSocketDialog::whereGroupType('all')->orderByDesc('id')->first(); diff --git a/app/Models/WebSocketDialog.php b/app/Models/WebSocketDialog.php index dfff82b21..52a87cbd0 100644 --- a/app/Models/WebSocketDialog.php +++ b/app/Models/WebSocketDialog.php @@ -175,18 +175,19 @@ class WebSocketDialog extends AbstractModel * @param int|array $userid 退出的会员ID或会员ID组 * @param string $type exit|remove * @param bool $checkDelete 是否检查删除 + * @param bool $pushMsg 是否推送消息 */ - public function exitGroup($userid, $type = 'exit', $checkDelete = true) + public function exitGroup($userid, $type = 'exit', $checkDelete = true, $pushMsg = true) { $typeDesc = $type === 'remove' ? '移出' : '退出'; - AbstractModel::transaction(function () use ($checkDelete, $typeDesc, $type, $userid) { + AbstractModel::transaction(function () use ($pushMsg, $checkDelete, $typeDesc, $type, $userid) { $builder = WebSocketDialogUser::whereDialogId($this->id); if (is_array($userid)) { $builder->whereIn('userid', $userid); } else { $builder->whereUserid($userid); } - $builder->chunkById(100, function($list) use ($checkDelete, $typeDesc, $type) { + $builder->chunkById(100, function($list) use ($pushMsg, $checkDelete, $typeDesc, $type) { /** @var WebSocketDialogUser $item */ foreach ($list as $item) { if ($checkDelete) { @@ -203,14 +204,16 @@ class WebSocketDialog extends AbstractModel // $item->delete(); // - if ($type === 'remove') { - $notice = User::nickname() . " 将 " . User::userid2nickname($item->userid) . " 移出群组"; - } else { - $notice = User::userid2nickname($item->userid) . " 退出群组"; + if ($pushMsg) { + if ($type === 'remove') { + $notice = User::nickname() . " 将 " . User::userid2nickname($item->userid) . " 移出群组"; + } else { + $notice = User::userid2nickname($item->userid) . " 退出群组"; + } + WebSocketDialogMsg::sendMsg(null, $this->id, 'notice', [ + 'notice' => $notice + ], User::userid(), true, true); } - WebSocketDialogMsg::sendMsg(null, $this->id, 'notice', [ - 'notice' => $notice - ], User::userid(), true, true); } }); });