|
|
@@ -43,6 +43,12 @@ class Imchat extends ImchatModel
|
|
|
return $this->setListDataFromApi($list);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param int $userId
|
|
|
+ * @param array $param
|
|
|
+ * @param int $listRows
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
public function getListByUser(int $userId, array $param = [], int $listRows = 15)
|
|
|
{
|
|
|
$param = array_merge($param, ['user_id'=> $userId,'data_type'=>'msg']);
|
|
|
@@ -62,8 +68,7 @@ class Imchat extends ImchatModel
|
|
|
})
|
|
|
->field($this->name.".*")
|
|
|
->group($this->name.'.chat_key')
|
|
|
- ->order($this->name.'.sendtime','desc')
|
|
|
- ->order($this->name.'.is_push desc,'.$this->name.'.sendtime','desc')
|
|
|
+ ->order($this->name.'.sendtime desc,'.$this->name.'.is_push desc')
|
|
|
->paginate($listRows);
|
|
|
|
|
|
return $this->setListDataFromApi($list, $param);
|
|
|
@@ -78,6 +83,12 @@ class Imchat extends ImchatModel
|
|
|
{
|
|
|
return $this->setListData($info, function ($data) use ($params){
|
|
|
|
|
|
+ $info = self::getNewMessageByChat($data['chat_key']);
|
|
|
+ $data['message'] = isset($info['message'])? $info['message'] : '';
|
|
|
+ $data['is_push'] = isset($info['is_push'])? $info['is_push'] : 0;
|
|
|
+ $data['sendtime'] = isset($info['sendtime'])? $info['sendtime'] : 0;
|
|
|
+
|
|
|
+
|
|
|
// 统计最新未读消息
|
|
|
$dataType = isset($params['data_type'])? $params['data_type'] : '';
|
|
|
$userId = isset($params['user_id'])? $params['user_id'] : 0;
|
|
|
@@ -116,8 +127,8 @@ class Imchat extends ImchatModel
|
|
|
$data['user_type'] = $info['user_type'];
|
|
|
$data['user_school_id'] = isset($info['info']['school_id'])? $info['info']['school_id'] : 0;
|
|
|
$admissionYear = isset($info['info']['admission_year'])? $info['info']['admission_year'] : '';
|
|
|
- $admissionYear = isset($info['info']['admission_year'])? $info['info']['admission_year'] : '';
|
|
|
$data['user_type_text'] = $data['user_type'] == 3? '招生老师' : ($admissionYear? $admissionYear.'级' : '学生');
|
|
|
+
|
|
|
}
|
|
|
// 用户学校
|
|
|
if($data['user_type'] == 3){
|
|
|
@@ -130,7 +141,7 @@ class Imchat extends ImchatModel
|
|
|
$this->setDataFromApi($data);
|
|
|
|
|
|
// 隐藏冗余的字段
|
|
|
- $this->hidden(array_merge($this->hidden, ['chat_key','sendtime']));
|
|
|
+ $this->hidden(array_merge($this->hidden, ['chat_key']));
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -149,6 +160,23 @@ class Imchat extends ImchatModel
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 获取最新消息
|
|
|
+ * @param $chatKey
|
|
|
+ * @return Imchat|array|mixed|\think\Model|null
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ */
|
|
|
+ public static function getNewMessageByChat($chatKey)
|
|
|
+ {
|
|
|
+ return self::where(['chat_key'=> $chatKey])
|
|
|
+ ->order('sendtime desc')
|
|
|
+ ->field('message,from_user_id,to_user_id,sendtime,is_push')
|
|
|
+ ->find();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 获取未读消息数量
|
|
|
* @param $userId
|
|
|
* @return int
|