From aaedc10a73a5074e353a5734f1359951992eb5d6 Mon Sep 17 00:00:00 2001 From: ASUS <515617283@qq.com> Date: Fri, 5 Dec 2025 15:29:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=9A=E8=AF=9D=E5=88=97=E8=A1=A8=E6=8E=92?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chat/controller/MessageController.php | 21 +++++++++++++++++++-- app/functions.php | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/app/chat/controller/MessageController.php b/app/chat/controller/MessageController.php index 766cc3c..8be767e 100644 --- a/app/chat/controller/MessageController.php +++ b/app/chat/controller/MessageController.php @@ -235,12 +235,29 @@ class MessageController extends ApiController } $msg = ''; if($lastMsg) { + switch ($lastMsg['msg_type']) { + case 1: + $content = $lastMsg['content']; + break; + case 2: + $content = '[图片]'; + break; + case 3: + $content = '[订单]'; + break; + case 4: + $content = '[优惠券]'; + break; + case 5: + $content = '[视频]'; + break; + } // 如果是自己发的不显示发送人 if($lastMsg['from_id'] == $this->uid) { - $msg = $lastMsg['content']; + $msg = $content; }else { // 如果是别人发的显示昵称 - $msg = $chat_user['nick_name'] . ':' . $lastMsg['content']; + $msg = $chat_user['nick_name'] . ':' . $content; } $data[$k]['send_time_origin'] = $lastMsg['send_time']; $data[$k]['send_time'] = formatWeChatTime($lastMsg['send_time']); diff --git a/app/functions.php b/app/functions.php index 463f9d1..da789d1 100644 --- a/app/functions.php +++ b/app/functions.php @@ -140,6 +140,25 @@ function simple_decrypt(string $ciphertext, string $key): string|false } } +/** + * 多维数组排序 + */ +function param_sort($chatList, $param) +{ + usort($chatList, function ($a, $b) use($param) { + // 将时间字符串转为时间戳,便于比较 + $timeA = strtotime($a[$param]); + $timeB = strtotime($b[$param]); + + // 倒序:$timeB - $timeA(正序则$timeA - $timeB) + return $timeB - $timeA; + }); + + return $chatList; +} + + + /** * 微信风格时间格式化(仅用原生 date/strtotime 函数,周一为一周起点)