Browse Source

Db查询message改为模型使用软删除

master
wanghongjun 8 months ago
parent
commit
cc68a6b879
  1. 6
      app/enterprise/controller/Im.php
  2. 8
      app/enterprise/model/User.php
  3. 2
      app/manage/controller/Message.php

6
app/enterprise/controller/Im.php

@ -216,7 +216,7 @@ class Im extends BaseController
}
// 如果是查询@数据
if($is_at){
$atList=Db::name('message')->where($map)->where($where)->whereFindInSet('at',$this->userInfo['user_id'])->order('msg_id desc')->select()->toArray();
$atList=(new Message())->where($map)->where($where)->whereFindInSet('at',$this->userInfo['user_id'])->order('msg_id desc')->select()->toArray();
if($atList){
$data = $this->recombileMsg($atList,false);
Message::setAtread($data,$this->userInfo['user_id']);
@ -236,7 +236,7 @@ class Im extends BaseController
// 如果是群聊并且是第一页消息,需要推送@数据给用户
if($param['is_group']==1 && $param['page']==1){
$isPush=Cache::get('atMsgPush'.$chat_identify) ?? '';
$atList=Db::name('message')->where(['chat_identify'=>$chat_identify,'is_group'=>1])->whereFindInSet('at',$this->userInfo['user_id'])->order('msg_id desc')->select()->toArray();
$atList=(new Message())->where(['chat_identify'=>$chat_identify,'is_group'=>1])->whereFindInSet('at',$this->userInfo['user_id'])->order('msg_id desc')->select()->toArray();
$msgIda=array_column($atList,'msg_id');
// 如果两次推送at数据的列表不一样,则推送
if($isPush!=json_encode($msgIda)){
@ -780,7 +780,7 @@ class Im extends BaseController
// 阅读@消息
public function readAtMsg(){
$param = $this->request->param();
$atList=Db::name('message')->where(['chat_identify'=>$param['toContactId'],'is_group'=>1])->whereFindInSet('at',$this->userInfo['user_id'])->order('msg_id desc')->select();
$atList=(new Message())->where(['chat_identify'=>$param['toContactId'],'is_group'=>1])->whereFindInSet('at',$this->userInfo['user_id'])->order('msg_id desc')->select();
$atData=$this->recombileMsg($atList,false);
Message::setAtRead($atData,$this->userInfo['user_id']);
// $message=Message::where('msg_id',$param['msg_id'])->select();

8
app/enterprise/model/User.php

@ -136,7 +136,7 @@ class User extends BaseModel
}
$list_chart = chartSort($list, 'realname', false, 'index');
// 查询未读消息
$unread = Db::name('message')
$unread = (new Message())
->field('from_user,count(msg_id) as unread')
->where([['to_user', '=', $user_id], ['is_read', '=', 0], ['is_group', '=', 0]])
->group('from_user')
@ -145,7 +145,7 @@ class User extends BaseModel
$map1 = [['to_user', '=', $user_id], ['is_last', '=', 1], ['is_group', '=', 0]];
$map2 = [['from_user', '=', $user_id], ['is_last', '=', 1], ['is_group', '=', 0]];
$msgField = 'from_user,to_user,content as lastContent,create_time as lastSendTime,chat_identify,type,del_user';
$lasMsgList = Db::name('message')
$lasMsgList = (new Message())
->field($msgField)
->whereOr([$map1, $map2])
->order('create_time desc')
@ -155,8 +155,8 @@ class User extends BaseModel
if ($group) {
$group = $group->toArray();
$group_ids = arrayToString($group, 'group_id');
$getGroupLastMsg = Db::name('message')->field($msgField)->where([['to_user', 'in', $group_ids], ['is_group', '=', 1], ['is_last', '=', 1]])->select();
$getAtMsg=Db::name('message')->field($msgField)->where([['to_user', 'in', $group_ids], ['is_group', '=', 1]])->whereFindInSet('at',$user_id)->select();
$getGroupLastMsg = (new Message())->field($msgField)->where([['to_user', 'in', $group_ids], ['is_group', '=', 1], ['is_last', '=', 1]])->select();
$getAtMsg=(new Message())->field($msgField)->where([['to_user', 'in', $group_ids], ['is_group', '=', 1]])->whereFindInSet('at',$user_id)->select();
// halt($getAtMsg);
foreach ($group as $k => $v) {

2
app/manage/controller/Message.php

@ -139,7 +139,7 @@ class Message extends BaseController
$map1 = [['to_user', '=', $user_id], ['is_last', '=', 1], ['is_group', '=', 0]];
$map2 = [['from_user', '=', $user_id], ['is_last', '=', 1], ['is_group', '=', 0]];
$msgField = 'from_user,to_user,content as lastContent,create_time as lastSendTime,chat_identify,type,del_user';
$lasMsgList = Db::name('message')
$lasMsgList = (new MessageModel())
->field($msgField)
->whereOr([$map1, $map2])
->order('create_time desc')

Loading…
Cancel
Save