会话列表 edit
This commit is contained in:
@@ -183,10 +183,43 @@ class MessageController extends ApiController
|
||||
}
|
||||
$list = Redis::get('usermsg:list:' . $this->user_type . ':' . $this->uid);
|
||||
if($list) {
|
||||
return $this->success(['list' => json_decode($list, true)]);
|
||||
$data = json_decode($list, true);
|
||||
}else {
|
||||
return $this->success(['list' => ChatMessage::getconverlist($this->uid, $this->user_type)]);
|
||||
$data = ChatMessage::getconverlist($this->uid, $this->user_type);
|
||||
}
|
||||
// 最新一条消息
|
||||
foreach ($data as $k => $session) {
|
||||
$lastMsg = '';
|
||||
$unreadCount = 0;
|
||||
if(!empty($session['session_id'])) {
|
||||
// 最后一条消息
|
||||
$lastMsg = Db::name('chat_message')
|
||||
->where('session_id', $session['session_id'])
|
||||
->order('send_time', 'desc')
|
||||
->find();
|
||||
// 未读计数
|
||||
$unreadCount = Db::name('chat_unread_count')->where(['user_id' => $this->uid, 'session_id' => $session['session_id']])->value('count')?:0;
|
||||
}
|
||||
if($session['chat_type'] == 2) {
|
||||
if($lastMsg) {
|
||||
$chat_user = Db::name('chat_user')->where(['user_id' => $lastMsg['from_id']])->field('nick_name,avatar')->find();
|
||||
}
|
||||
}
|
||||
$msg = '';
|
||||
if($lastMsg) {
|
||||
// 如果是自己发的不显示发送人
|
||||
if($lastMsg['from_id'] == $this->uid) {
|
||||
$msg = $lastMsg['content'];
|
||||
}else {
|
||||
// 如果是别人发的显示昵称
|
||||
$msg = $chat_user['nick_name'] . ':' . $lastMsg['content'];
|
||||
}
|
||||
$data[$k]['send_time'] = formatWeChatTime($lastMsg['send_time']);
|
||||
}
|
||||
$data[$k]['msg'] = $msg;
|
||||
$data[$k]['unread_count'] = $unreadCount;
|
||||
}
|
||||
return $this->success(['list' => $data]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user