Merge pull request '用户列表最后消息更新' (#59) from zhangwei into dev

Reviewed-on: #59
This commit is contained in:
weiz 2023-10-08 14:51:19 +08:00
commit 376c4c4d01

View File

@ -275,11 +275,13 @@ class ImController extends BaseLikeAdminController
return $this->fail('接收者信息错误');
}
//将消息设置为已读
UserImMessage::where([['from_user_id','=',$params['from_user_id']],['to_user_id','=',$params['to_user_id']]])->update(['is_read' => 1]);
UserImMessage::where([['from_user_id','=',$params['to_user_id']],['to_user_id','=',$params['from_user_id']]])->update(['is_read' => 1]);
//获取用户消息
$params['page_no'] -= 1;
$sql = "SELECT id,from_user_id,to_user_id,content,type,is_read,create_time,extends FROM la_user_im_message WHERE (from_user_id = {$params['from_user_id']} AND to_user_id = {$params['to_user_id']}) OR (from_user_id = {$params['to_user_id']} AND to_user_id = {$params['from_user_id']}) ORDER BY create_time DESC LIMIT {$params['page_no']},{$params['page_size']}";
$msgData = Db::query($sql);
$msgData = Db::name('user_im_message')->field('id,from_user_id,to_user_id,content,type,is_read,create_time,extends')
->whereRaw("(from_user_id = {$params['from_user_id']} AND to_user_id = {$params['to_user_id']}) OR (from_user_id = {$params['to_user_id']} AND to_user_id = {$params['from_user_id']})")
->order('create_time desc')
->page($params['page_no'],$params['page_size'])
->select()->toArray();
foreach($msgData as $k=>$v){
if($v['from_user_id'] == $params['from_user_id']){
$msgData[$k]['from_user_name'] = $fromUserInfo['name'];
@ -327,9 +329,12 @@ class ImController extends BaseLikeAdminController
$users = User::field('id,nickname as name,avatar')->where('company_id','in',$company)->select()->each(function($item) use($params) {
//获取消息
$msg_no_read = UserImMessage::field('id')->where('from_user_id',$item['id'])->where('to_user_id',$params['user_id'])->where('is_read',0)->count();
$last_msg = UserImMessage::field('id,content,create_time')->where('from_user_id',$item['id'])->where('to_user_id',$params['user_id'])->where('is_read',0)->order('create_time desc')->limit(1)->findOrEmpty();
$last_msg = Db::name('user_im_message')->field('id,content,type,create_time')
->whereRaw("(from_user_id = {$item['id']} AND to_user_id = {$params['user_id']}) OR (from_user_id = {$params['user_id']} AND to_user_id = {$item['id']})")
->order('create_time desc')->limit(1)->findOrEmpty();
$item['no_read_num'] = $msg_no_read;
$item['last_msg_content'] = $last_msg['content'];
$item['last_msg_type'] = $last_msg['type'];
$item['last_msg_time'] = $last_msg['create_time'];
})->toArray();
$key = array_column($users,'last_msg_time');
@ -363,7 +368,9 @@ class ImController extends BaseLikeAdminController
if($params['user_id'] == $companyInfo['area_manager']){
return $this->fail('用户身份错误错误');
}
//获取用户信息
$adminInfo = Admin::field('id,name,avatar')->where('id',$companyInfo['area_manager'])->findOrEmpty();
//返回
return $this->success('请求成功',['to_user_id'=>$companyInfo['area_manager']]);
return $this->success('请求成功',['to_user_id'=>$adminInfo['id'],'manager_name'=>$adminInfo['name'],'manager_avatar'=>$adminInfo['avatar']]);
}
}