代码同步提交
This commit is contained in:
72
Server/application/chukebao/controller/MessageController.php
Normal file
72
Server/application/chukebao/controller/MessageController.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace app\chukebao\controller;
|
||||
|
||||
use library\ResponseHelper;
|
||||
use think\Db;
|
||||
|
||||
class MessageController extends BaseController
|
||||
{
|
||||
|
||||
public function getList(){
|
||||
$page = $this->request->param('page', 1);
|
||||
$limit = $this->request->param('limit', 10);
|
||||
$accountId = $this->getUserInfo('s2_accountId');
|
||||
if (empty($accountId)){
|
||||
return ResponseHelper::error('请先登录');
|
||||
}
|
||||
|
||||
$chatroomList = Db::table('s2_wechat_chatroom')->alias('wc')
|
||||
->join(['s2_wechat_message' => 'm'], 'wc.id = m.wechatChatroomId', 'LEFT')
|
||||
->where(['wc.accountId' => $accountId,'m.type' => 2,' wc.isDeleted' => 0])
|
||||
->order('m.id desc')
|
||||
->group('m.wechatChatroomId')
|
||||
->page($page, $limit)
|
||||
->select();
|
||||
$friendIds = Db::table('s2_wechat_friend')
|
||||
->where(['accountId' => $accountId,' isDeleted' => 0])
|
||||
->group('id')
|
||||
->column('id');
|
||||
$friendList = Db::table('s2_wechat_message')
|
||||
->where(['type' => 1])
|
||||
->whereIn('wechatFriendId',$friendIds)
|
||||
->order('id desc')
|
||||
->group('wechatFriendId')
|
||||
->page($page, $limit)
|
||||
->select();
|
||||
|
||||
$list = array_merge($chatroomList,$friendList);
|
||||
|
||||
// 按createTime字段从大到小排序
|
||||
usort($list, function($a, $b) {
|
||||
return $b['createTime'] <=> $a['createTime'];
|
||||
});
|
||||
|
||||
|
||||
foreach ($list as $k=>&$v){
|
||||
$v['createTime'] = !empty($v['createTime']) ? date('Y-m-d H:i:s',$v['createTime']) : '';
|
||||
$v['wechatTime'] = !empty($v['wechatTime']) ? date('Y-m-d H:i:s',$v['wechatTime']) : '';
|
||||
|
||||
if (!empty($v['wechatFriendId'])){
|
||||
$friend = Db::table('s2_wechat_friend')
|
||||
->where(['id'=>$v['wechatFriendId']])
|
||||
->field('id,nickname,avatar')
|
||||
->find();
|
||||
$v['msgInfo'] = $friend;
|
||||
}
|
||||
|
||||
if (!empty($v['wechatChatroomId'])){
|
||||
$chatroom = Db::table('s2_wechat_chatroom')
|
||||
->where(['id'=>$v['wechatChatroomId']])
|
||||
->field('id,nickname,chatroomAvatar as avatar')
|
||||
->find();
|
||||
$v['msgInfo'] = $chatroom;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
unset($v);
|
||||
|
||||
return ResponseHelper::success($list);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user