From 8f42e2924d6e0929d85f33056090c737ebc61d14 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Fri, 15 Jul 2022 14:47:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=97=A0=E6=B3=95=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E7=A6=BB=E8=81=8C=E7=9A=84=E9=97=AE=E9=A2=98?= 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 | 30 +++++++++++--------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index f98dc1a71..07b5ed42a 100755 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -711,7 +711,7 @@ class UsersController extends AbstractController $userTransfer->start(); // 离职移出全员群组 $dialog = WebSocketDialog::whereGroupType('all')->orderByDesc('id')->first(); - $dialog?->exitGroup($userInfo->userid, 'remove'); + $dialog?->exitGroup($userInfo->userid, 'remove', false); } elseif ($type === 'cleardisable') { // 取消离职重新加入全员群组 $dialog = WebSocketDialog::whereGroupType('all')->orderByDesc('id')->first(); diff --git a/app/Models/WebSocketDialog.php b/app/Models/WebSocketDialog.php index 5b9c4f68b..73b33e4b0 100644 --- a/app/Models/WebSocketDialog.php +++ b/app/Models/WebSocketDialog.php @@ -131,7 +131,7 @@ class WebSocketDialog extends AbstractModel } if ($hasData === true) { $msgBuilder = WebSocketDialogMsg::whereDialogId($this->id); - $this->has_tag = $msgBuilder->clone()->whereMtype('tag')->exists(); + $this->has_tag = $msgBuilder->clone()->where('tag', '>', 0)->exists(); $this->has_image = $msgBuilder->clone()->whereMtype('image')->exists(); $this->has_file = $msgBuilder->clone()->whereMtype('file')->exists(); $this->has_link = $msgBuilder->clone()->whereLink(1)->exists(); @@ -172,30 +172,34 @@ class WebSocketDialog extends AbstractModel /** * 退出聊天室 * @param int|array $userid 退出的会员ID或会员ID组 - * @param $type + * @param string $type exit|remove + * @param bool $checkDelete 是否检查删除 */ - public function exitGroup($userid, $type = 'exit') + public function exitGroup($userid, $type = 'exit', $checkDelete = true) { $typeDesc = $type === 'remove' ? '移出' : '退出'; - AbstractModel::transaction(function () use ($typeDesc, $type, $userid) { + AbstractModel::transaction(function () use ($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 ($typeDesc, $type) { + $builder->chunkById(100, function($list) use ($checkDelete, $typeDesc, $type) { /** @var WebSocketDialogUser $item */ foreach ($list as $item) { - if ($type === 'remove' && !in_array(User::userid(), [$this->owner_id, $item->inviter])) { - throw new ApiException('只有群主或邀请人可以移出成员'); - } - if ($item->userid == $this->owner_id) { - throw new ApiException('群主不可' . $typeDesc); - } - if ($item->important) { - throw new ApiException('项目人员或任务人员不可' . $typeDesc); + if ($checkDelete) { + if ($type === 'remove' && !in_array(User::userid(), [$this->owner_id, $item->inviter])) { + throw new ApiException('只有群主或邀请人可以移出成员'); + } + if ($item->userid == $this->owner_id) { + throw new ApiException('群主不可' . $typeDesc); + } + if ($item->important) { + throw new ApiException('项目人员或任务人员不可' . $typeDesc); + } } + // $item->delete(); // if ($type === 'remove') {