From b254fd5ce28ad0c2f5c2349ceb1f3bd07fc7171e Mon Sep 17 00:00:00 2001
From: wfs <605403358>
Date: Tue, 12 Mar 2024 23:49:05 +0800
Subject: [PATCH 1/4] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E6=8E=A5?=
=?UTF-8?q?=E9=BE=99=E6=8E=A5=E5=8F=A3=EF=BC=8C=E5=8A=A0=E4=B8=8A=E4=BA=8B?=
=?UTF-8?q?=E5=8A=A1=E9=94=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/Http/Controllers/Api/DialogController.php | 60 ++++++++++---------
1 file changed, 32 insertions(+), 28 deletions(-)
diff --git a/app/Http/Controllers/Api/DialogController.php b/app/Http/Controllers/Api/DialogController.php
index 27f4227d8..26c45ea6a 100755
--- a/app/Http/Controllers/Api/DialogController.php
+++ b/app/Http/Controllers/Api/DialogController.php
@@ -2180,35 +2180,39 @@ class DialogController extends AbstractController
return Base::retError('内容最大不能超过200000字');
}
//
- $userid = $user->userid;
- if ($uuid) {
- $dialogMsg = WebSocketDialogMsg::whereDialogId($dialog_id)
- ->whereType('word-chain')
- ->orderByDesc('created_at')
- ->where('msg', 'like', "%$uuid%")
- ->value('msg');
- $list = array_reverse(array_merge($dialogMsg['list'] ?? [], $list));
- $list = array_reduce($list, function ($result, $item) {
- $fieldValue = $item['id']; // 指定字段名
- if (!isset($result[$fieldValue])) {
- $result[$fieldValue] = $item;
- }
- return $result;
- }, []);
- $list = array_reverse(array_values($list));
- }
- //
- usort($list, function($a, $b) {
- return $a['id'] - $b['id'];
+ return AbstractModel::transaction(function () use ($user, $uuid, $dialog_id, $list, $text) {
+ if ($uuid) {
+ $dialogMsg = WebSocketDialogMsg::whereDialogId($dialog_id)
+ ->lockForUpdate()
+ ->whereType('word-chain')
+ ->orderByDesc('created_at')
+ ->where('msg', 'like', "%$uuid%")
+ ->value('msg');
+ $list = array_reverse(array_merge($dialogMsg['list'] ?? [], $list));
+ $list = array_reduce($list, function ($result, $item) {
+ $fieldValue = $item['id']; // 指定字段名
+ if (!isset($result[$fieldValue])) {
+ $result[$fieldValue] = $item;
+ }
+ return $result;
+ }, []);
+ $list = array_reverse(array_values($list));
+ } else {
+ $uuid = Base::generatePassword(36);
+ }
+ //
+ usort($list, function ($a, $b) {
+ return $a['id'] - $b['id'];
+ });
+ //
+ $msgData = [
+ 'text' => $text,
+ 'list' => $list,
+ 'userid' => $user->userid,
+ 'uuid' => $uuid,
+ ];
+ return WebSocketDialogMsg::sendMsg(null, $dialog_id, 'word-chain', $msgData, $user->userid);
});
- //
- $msgData = [
- 'text' => $text,
- 'list' => $list,
- 'userid' => $userid,
- 'uuid' => $uuid ?: Base::generatePassword(36),
- ];
- return WebSocketDialogMsg::sendMsg(null, $dialog_id, 'word-chain', $msgData, $user->userid);
}
/**
From 5efe659cf5973ac75fdccb8044fcfdd021c1c7cf Mon Sep 17 00:00:00 2001
From: wfs <605403358>
Date: Wed, 13 Mar 2024 00:17:23 +0800
Subject: [PATCH 2/4] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E6=8A=95?=
=?UTF-8?q?=E7=A5=A8=E6=8E=A5=E5=8F=A3=EF=BC=8C=E5=8A=A0=E4=B8=8A=E4=BA=8B?=
=?UTF-8?q?=E5=8A=A1=E9=94=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/Http/Controllers/Api/DialogController.php | 77 ++++++++++---------
1 file changed, 41 insertions(+), 36 deletions(-)
diff --git a/app/Http/Controllers/Api/DialogController.php b/app/Http/Controllers/Api/DialogController.php
index 26c45ea6a..ed5011423 100755
--- a/app/Http/Controllers/Api/DialogController.php
+++ b/app/Http/Controllers/Api/DialogController.php
@@ -2253,8 +2253,6 @@ class DialogController extends AbstractController
WebSocketDialog::checkDialog($dialog_id);
//
$action = null;
- $userid = $user->userid;
- $result = [];
if ($type != 'create') {
if ($type == 'vote' && empty($votes)) {
return Base::retError('参数错误');
@@ -2262,42 +2260,50 @@ class DialogController extends AbstractController
if (empty($uuid)) {
return Base::retError('参数错误');
}
- $dialogMsgs = WebSocketDialogMsg::whereDialogId($dialog_id)
- ->whereType('vote')
- ->orderByDesc('created_at')
- ->where('msg', 'like', "%$uuid%")
- ->get();
- //
- if ($type == 'again') {
- $res = WebSocketDialogMsg::sendMsg(null, $dialog_id, 'vote', $dialogMsgs[0]->msg, $user->userid);
- if (Base::isError($res)) {
- return $res;
- }
- $result[] = $res['data'];
- } else {
- foreach ($dialogMsgs as $dialogMsg) {
- $action = "change-{$dialogMsg->id}";
- $msgData = $dialogMsg->msg;
- if ($type == 'finish') {
- $msgData['state'] = 0;
- } else {
- $msgDataVotes = $msgData['votes'] ?? [];
- if (in_array($userid, array_column($msgDataVotes, 'userid'))) {
- return Base::retError('不能重复投票');
- }
- $msgDataVotes[] = [
- 'userid' => $userid,
- 'votes' => $votes,
- ];
- $msgData['votes'] = $msgDataVotes;
- }
- $res = WebSocketDialogMsg::sendMsg($action, $dialog_id, 'vote', $msgData, $user->userid);
+ return AbstractModel::transaction(function () use ($user, $uuid, $dialog_id, $type, $votes) {
+ //
+ $dialogMsgs = WebSocketDialogMsg::whereDialogId($dialog_id)
+ ->lockForUpdate()
+ ->whereType('vote')
+ ->orderByDesc('created_at')
+ ->where('msg', 'like', "%$uuid%")
+ ->get();
+ //
+ $result = [];
+ if ($type == 'again') {
+ $res = WebSocketDialogMsg::sendMsg(null, $dialog_id, 'vote', $dialogMsgs[0]->msg, $user->userid);
if (Base::isError($res)) {
return $res;
}
$result[] = $res['data'];
+ } else {
+ foreach ($dialogMsgs as $dialogMsg) {
+ $action = "change-{$dialogMsg->id}";
+ $msgData = $dialogMsg->msg;
+ if ($type == 'finish') {
+ $msgData['state'] = 0;
+ } else {
+ $msgDataVotes = $msgData['votes'] ?? [];
+ if (in_array($user->userid, array_column($msgDataVotes, 'userid'))) {
+ return Base::retError('不能重复投票');
+ }
+ $msgDataVotes[] = [
+ 'userid' => $user->userid,
+ 'votes' => $votes,
+ ];
+ $msgData['votes'] = $msgDataVotes;
+ }
+ //
+ $res = WebSocketDialogMsg::sendMsg($action, $dialog_id, 'vote', $msgData, $user->userid);
+ if (Base::isError($res)) {
+ return $res;
+ }
+ $result[] = $res['data'];
+ }
}
- }
+ //
+ return Base::retSuccess('发送成功', $result);
+ });
} else {
$strlen = mb_strlen($text);
$noimglen = mb_strlen(preg_replace("/]*?>/i", "", $text));
@@ -2310,7 +2316,7 @@ class DialogController extends AbstractController
$msgData = [
'text' => $text,
'list' => $list,
- 'userid' => $userid,
+ 'userid' => $user->userid,
'uuid' => $uuid ?: Base::generatePassword(36),
'multiple' => $multiple,
'anonymous' => $anonymous,
@@ -2321,9 +2327,8 @@ class DialogController extends AbstractController
if (Base::isError($res)) {
return $res;
}
- $result[] = $res['data'];
+ return Base::retSuccess('发送成功', [$res['data']]);
}
- return Base::retSuccess('发送成功', $result);
}
/**
From f5b1a6ab05e42ca5988d943ea6bdefdb957d45ea Mon Sep 17 00:00:00 2001
From: wfs <605403358>
Date: Wed, 13 Mar 2024 00:25:10 +0800
Subject: [PATCH 3/4] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=8A=95=E7=A5=A8?=
=?UTF-8?q?=E5=AE=9E=E5=90=8D=E9=80=BB=E8=BE=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
resources/assets/js/pages/manage/components/DialogView.vue | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/resources/assets/js/pages/manage/components/DialogView.vue b/resources/assets/js/pages/manage/components/DialogView.vue
index cc65a0ada..d48c41391 100644
--- a/resources/assets/js/pages/manage/components/DialogView.vue
+++ b/resources/assets/js/pages/manage/components/DialogView.vue
@@ -97,7 +97,7 @@
{{ $L('投票') }}
{{ msgData.msg.multiple == 1 ? $L('多选') : $L('单选')}}
- {{ msgData.msg.multiple == 1 ? $L('匿名') : $L('实名')}}
+ {{ msgData.msg.anonymous == 1 ? $L('匿名') : $L('实名')}}