From b21e53f16f228d3192eb54178f081395878b2406 Mon Sep 17 00:00:00 2001
From: chengkun <chengkun@ishangstudy.com>
Date: Fri, 12 Sep 2025 13:13:50 +0800
Subject: [PATCH] 提交
---
app/admin/controller/OnlineMessage.php | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 52 insertions(+), 0 deletions(-)
diff --git a/app/admin/controller/OnlineMessage.php b/app/admin/controller/OnlineMessage.php
index 34124f8..c6a5c1a 100644
--- a/app/admin/controller/OnlineMessage.php
+++ b/app/admin/controller/OnlineMessage.php
@@ -4,6 +4,7 @@
use think\Exception;
use think\facade\Db;
+use think\facade\Request;
use think\facade\View;
use think\response\Json;
@@ -13,11 +14,27 @@
return View::fetch();
}
+ /**
+ * 获取在线留言列表
+ * @return Json
+ */
public function get_online_message_list(): Json {
try {
+ if (!Request::isPost()) {
+ throw new Exception('请求方式错误');
+ }
$page = input('page', 1);
$limit = input('limit', 10);
+ $kw = input('kw', '');
+ $status = input('status', '');
$where = [];
+ if ($kw) {
+ $where[] = ['name|phone|email|subject|message', 'like', "%{$kw}%"];
+ }
+
+ if (in_array($status, [0, 1])) {
+ $where[] = ['status', '=', $status];
+ }
$total = Db::name('online_message')->where($where)->count();
$list = Db::name('online_message')->where($where)->order('id desc')->page($page, $limit)->select()->toArray();
$result = [
@@ -36,4 +53,39 @@
}
return json($result);
}
+
+ /**
+ * 修改留言状态
+ * @return Json
+ */
+ public function change_message_status(): Json {
+ try {
+ if (!Request::isPost()) {
+ throw new Exception('请求方式错误');
+ }
+ $id = input('id', 0);
+ if (!$id || !is_numeric($id)) {
+ throw new Exception('参数错误');
+ }
+ $info = Db::name('online_message')->where('id', $id)->find();
+ if (!$info) {
+ throw new Exception('留言不存在');
+ }
+ $status = $info['status'] ? 0 : 1;
+ $update_result = Db::name('online_message')->where('id', $id)->save(['status' => $status]);
+ if (!$update_result) {
+ throw new Exception('操作失败');
+ }
+ $result = [
+ 'code' => 200,
+ 'message' => '操作成功',
+ ];
+ } catch (Exception $exc) {
+ $result = [
+ 'code' => $exc->getCode(),
+ 'message' => $exc->getMessage(),
+ ];
+ }
+ return json($result);
+ }
}
\ No newline at end of file
--
Gitblit v1.9.0