From 7f85ce33f125230493b80e751350962b90d99c38 Mon Sep 17 00:00:00 2001 From: ZX <903464207@qq.com> Date: Tue, 25 Jul 2023 23:06:35 +0800 Subject: [PATCH] 1 --- laravel/app/Services/Web/MessageService.php | 77 +++++---------------- laravel/resources/views/welcome.blade.php | 4 +- 2 files changed, 21 insertions(+), 60 deletions(-) diff --git a/laravel/app/Services/Web/MessageService.php b/laravel/app/Services/Web/MessageService.php index de9c689..814340c 100644 --- a/laravel/app/Services/Web/MessageService.php +++ b/laravel/app/Services/Web/MessageService.php @@ -3,6 +3,7 @@ namespace App\Services\Web; use App\Models\Message; +use App\Utils\GlobalMsg; use Exception; use App\Utils\GlobalCode; use Illuminate\Support\Carbon; @@ -33,72 +34,32 @@ public static function saveData($where = [], $data = []) $message = new Message(); - $message->real_name = isset($data['real_name']) ? $data['real_name'] : ''; - $message->mobile = isset($data['mobile']) ? $data['mobile'] : ''; - $message->email = isset($data['email']) ? $data['email'] : ''; - $message->title = isset($data['title']) ? htmlspecialchars($data['title']) : ''; - $message->content = isset($data['content']) ? htmlspecialchars($data['content']) : ''; - $message->pics = isset($data['pics']) ? json_encode($data['pics']) : ''; - $message->ip = $data['ip']; - $res = $message->save(); - - - } - - public static function getList($where = [], $data = [], $page = 1, $pageSize = 15) - { - try { - - $query = Message::where('is_delete', 10); - - if (!empty($where['email'])) { - $query->where('email', $where['email']); - } - if (!empty($where['real_name'])) { - $query->where('real_name', 'like', '%' . $where['real_name'] . '%'); - } - if (!empty($where['mobile'])) { - $query->where('mobile', $where['mobile']); - } - $count = $query->count(); - $list = $query->forPage($page, $pageSize)->orderBy('id', 'desc')->get()->toArray(); - foreach ($list as $k => &$v) { - $v['content'] = htmlspecialchars_decode($v['content']); - $v['title'] = htmlspecialchars_decode($v['title']); - } + isset($data['real_name']) && $message->real_name = $data['real_name']; + isset($data['email']) && $message->email = $data['real_name']; + isset($data['title']) && $message->title = $data['real_name']; + isset($data['content']) && $message->content = $data['real_name']; + isset($data['pics']) && $message->pics = implode(',', $data['pics']); + isset($data['ip']) && $message->ip = $data['ip']; - return ['count' => $count, 'list' => $list]; - } catch (Exception $e) { + $res = $message->save(); - throw new Exception($e->getMessage()); + if ($res == false) { + throw new Exception(GlobalMsg::SAVE_FAIL); } + return $res; } - public static function getLatestMessage($where = [], $data = []) + public static function processed($where = []) { - try { - $time = Carbon::parse('-5 days')->toDateTimeString(); -// $count = Message::where('is_delete', 10)->where('create_time', '>=', $time)->where('status', 10)->count(); - $count = Message::where('is_delete', 10)->where('status', 10)->count(); - return $count; - } catch (Exception $e) { - throw new Exception($e->getMessage()); + if (empty($where['id'])) { + throw new Exception('消息ID不存在'); } - } - - public static function processed($where = [], $data = []) - { - try { - - $message = Message::where('is_delete', 10)->where('status', 10)->where('id', $where['id'])->first(); - if (empty($message)) { - throw new Exception('此消息不存在'); - } - $message->status = 20; - $message->save(); - } catch (Exception $e) { - throw new Exception($e->getMessage()); + $message = Message::where('status', 10)->where('id', $where['id'])->first(); + if (empty($message)) { + throw new Exception('此消息不存在'); } + $message->status = 20; + $message->save(); } public static function sendEmail() diff --git a/laravel/resources/views/welcome.blade.php b/laravel/resources/views/welcome.blade.php index 843c660..190430a 100644 --- a/laravel/resources/views/welcome.blade.php +++ b/laravel/resources/views/welcome.blade.php @@ -4,7 +4,7 @@ - 医大医院-API接口 + CMS,企业官网 @@ -17,7 +17,7 @@
- 医大医院-API接口 + CMS,企业官网