From 6c5f16328798ecf17fb431cb0627b196e4f7d266 Mon Sep 17 00:00:00 2001 From: ZF sun <34314687@qq.com> Date: Mon, 8 Dec 2025 17:12:00 +0800 Subject: [PATCH] =?UTF-8?q?chore(addon/aikefu):=20=E4=BC=9A=E8=AF=9D?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E6=94=AF=E6=8C=81=E6=89=B9=E9=87=8F=E5=88=A0?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/addon/aikefu/shop/controller/Kefu.php | 30 ++++++++----- .../aikefu/shop/view/kefu/conversation.html | 44 ++++++++++++++++++- 2 files changed, 63 insertions(+), 11 deletions(-) diff --git a/src/addon/aikefu/shop/controller/Kefu.php b/src/addon/aikefu/shop/controller/Kefu.php index ebcfef752..f81059656 100644 --- a/src/addon/aikefu/shop/controller/Kefu.php +++ b/src/addon/aikefu/shop/controller/Kefu.php @@ -158,11 +158,18 @@ class Kefu extends BaseShop public function deleteConversation() { $id = input("id/d", ""); + $ids = input("ids/a", []); - if (empty($id)) { + // 验证参数 + if (empty($id) && empty($ids)) { return $this->error('会话ID不能为空'); } + // 处理单个ID或ID数组 + if (!empty($id)) { + $ids = [$id]; + } + $kefu_conversation_model = new KefuConversationModel(); $kefu_message_model = new KefuMessageModel(); @@ -170,22 +177,25 @@ class Kefu extends BaseShop Db::startTrans(); try { - // 删除会话关联的消息 - $conversation_info = $kefu_conversation_model->getConversationInfo([ - ['id', '=', $id], + // 获取所有要删除的会话信息 + $conversations = $kefu_conversation_model->getConversationList([ + ['id', 'in', $ids], ['site_id', '=', $this->site_id] ]); - if (!empty($conversation_info)) { - $kefu_message_model->deleteMessage([ - ['site_id', '=', $this->site_id], - ['conversation_id', '=', $conversation_info['conversation_id']] - ]); + // 删除所有会话关联的消息 + if (!empty($conversations['data'])) { + foreach ($conversations['data'] as $conversation) { + $kefu_message_model->deleteMessage([ + ['site_id', '=', $this->site_id], + ['conversation_id', '=', $conversation['conversation_id']] + ]); + } } // 删除会话 $result = $kefu_conversation_model->deleteConversation([ - ['id', '=', $id], + ['id', 'in', $ids], ['site_id', '=', $this->site_id] ]); diff --git a/src/addon/aikefu/shop/view/kefu/conversation.html b/src/addon/aikefu/shop/view/kefu/conversation.html index 9eb5d3e1d..656767db2 100644 --- a/src/addon/aikefu/shop/view/kefu/conversation.html +++ b/src/addon/aikefu/shop/view/kefu/conversation.html @@ -54,7 +54,7 @@ @@ -82,6 +82,7 @@ title: '会话管理', width: '100%', cols: [[ + {type: 'checkbox', fixed: 'left'}, {field: 'conversation_id', title: '会话ID', width: 200, align: 'center'}, {field: 'user_id', title: '用户ID', width: 150, align: 'center'}, {field: 'name', title: '会话名称', width: 180, align: 'center'}, @@ -192,5 +193,46 @@ }); } }); + + // 批量删除按钮点击事件 + $('#batchDeleteBtn').click(function() { + // 获取选中的行数据 + var checkStatus = table.checkStatus('conversationTable'); + var data = checkStatus.data; + + if (data.length === 0) { + layer.msg('请选择要删除的会话', {icon: 2}); + return; + } + + // 提取选中的会话ID + var ids = []; + for (var i = 0; i < data.length; i++) { + ids.push(data[i].id); + } + + // 确认删除 + layer.confirm('确定要删除选中的 ' + data.length + ' 个会话吗?删除后将无法恢复', function(index) { + $.ajax({ + url: ns.url("aikefu://shop/kefu/deleteConversation"), + type: 'POST', + data: {ids: ids}, + dataType: 'json', + success: function(res) { + if (res.code === 0) { + layer.msg('删除成功', {icon: 1}); + // 重新加载表格数据 + tableIns.reload(); + } else { + layer.msg('操作失败:' + res.message, {icon: 2}); + } + }, + error: function() { + layer.msg('请求失败,请稍后重试', {icon: 2}); + } + }); + layer.close(index); + }); + }); }); \ No newline at end of file