|
|
@@ -133,7 +133,8 @@ class Chat extends BaseController
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取聊天记录
|
|
|
+ * 获取聊天记录(分页)
|
|
|
+ * page=1 为最新的一批消息,页码递增则获取更早的消息
|
|
|
*/
|
|
|
public function recordList(Request $request)
|
|
|
{
|
|
|
@@ -147,15 +148,19 @@ class Chat extends BaseController
|
|
|
return app('json')->fail('对方用户ID错误');
|
|
|
}
|
|
|
|
|
|
+ if ($page < 1) $page = 1;
|
|
|
+ if ($limit < 1) $limit = 20;
|
|
|
+ if ($limit > 100) $limit = 100;
|
|
|
+
|
|
|
$result = ChatRecord::getChatRecords($userId, $toUserId, $page, $limit);
|
|
|
|
|
|
- // 处理消息类型文本
|
|
|
+ // 处理附加字段
|
|
|
foreach ($result['list'] as &$item) {
|
|
|
$item['type_text'] = ChatRecord::getTypeText($item['type']);
|
|
|
$item['form_type_text'] = ChatRecord::getFormTypeText($item['form_type'] ?? 0);
|
|
|
- // 判断是否是自己发送的
|
|
|
$item['is_mine'] = $item['user_id'] == $userId;
|
|
|
}
|
|
|
+ unset($item);
|
|
|
|
|
|
return app('json')->success('获取成功', $result);
|
|
|
}
|
|
|
@@ -172,8 +177,8 @@ class Chat extends BaseController
|
|
|
if ($fromUserId <= 0) {
|
|
|
return app('json')->fail('用户ID错误');
|
|
|
}
|
|
|
- @file_put_contents('quanju.txt', $userId."-何意啊111\r\n", 8);
|
|
|
- @file_put_contents('quanju.txt', $fromUserId."-何意啊222\r\n", 8);
|
|
|
+// @file_put_contents('quanju.txt', $userId."-何意啊111\r\n", 8);
|
|
|
+// @file_put_contents('quanju.txt', $fromUserId."-何意啊222\r\n", 8);
|
|
|
|
|
|
ChatRecord::markAsRead($userId, $fromUserId);
|
|
|
|
|
|
@@ -188,8 +193,8 @@ class Chat extends BaseController
|
|
|
$data = $request->get();
|
|
|
$fromUserId = $data['from_user_id'] ?? null;
|
|
|
$userId = $request->user['uid'];
|
|
|
- @file_put_contents('quanju.txt', $userId."-何意啊111444\r\n", 8);
|
|
|
- @file_put_contents('quanju.txt', $fromUserId."-何意啊222555\r\n", 8);
|
|
|
+// @file_put_contents('quanju.txt', $userId."-何意啊111444\r\n", 8);
|
|
|
+// @file_put_contents('quanju.txt', $fromUserId."-何意啊222555\r\n", 8);
|
|
|
|
|
|
// 处理空字符串等无效值
|
|
|
if ($fromUserId !== null && $fromUserId !== '' && (int)$fromUserId > 0) {
|