From 2e12809f4d16aa00239b5e2c6a13a9a51842d134 Mon Sep 17 00:00:00 2001
From: chengkun <chengkun@ishangstudy.com>
Date: Thu, 04 Sep 2025 18:20:17 +0800
Subject: [PATCH] 提交
---
app/home/controller/Contact.php | 36 ++++++++++++++++++++++++++++++++++++
1 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/app/home/controller/Contact.php b/app/home/controller/Contact.php
index 7aa63a2..857559c 100644
--- a/app/home/controller/Contact.php
+++ b/app/home/controller/Contact.php
@@ -2,12 +2,48 @@
namespace app\home\controller;
+use think\Exception;
+use think\facade\Db;
use think\facade\View;
use think\facade\Request;
use app\BaseController;
+use think\response\Json;
class Contact extends BaseController {
public function index() {
return View::fetch('index');
}
+
+ /**
+ * 保存留言
+ * @return Json
+ */
+ public function save_message(): Json {
+ try {
+ if (!Request::isPost()) {
+ throw new Exception('请求方式错误');
+ }
+ $data = Request::post();
+ $validate = new \app\home\validate\Contact();
+ $validate_result = $validate->check($data);
+ if (!$validate_result) {
+ throw new Exception($validate->getError());
+ }
+ $data['create_time'] = time();
+ $new_id = Db::name('online_message')->insertGetId($data);
+ if (!$new_id) {
+ 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