<?php
|
|
namespace app\api\model\plus\release;
|
|
use app\common\model\plus\release\Chat as ChatModel;
|
use app\common\model\plus\release\ChatRelation as ChatRelationModel;
|
use app\api\model\user\User as UserModel;
|
|
/**
|
* 消息模型类
|
*/
|
class Chat extends ChatModel
|
{
|
|
/**
|
* 隐藏字段
|
*/
|
protected $hidden = [
|
'app_id',
|
'update_time'
|
];
|
|
//消息列表
|
public function myList($user)
|
{
|
$ChatRelation = new ChatRelation();
|
$list = $ChatRelation->with(['user'])
|
->where(['user_id' => $user['user_id']])
|
->whereOr(['other_user_id' => $user['user_id']])
|
->order('update_time desc')
|
->select();
|
foreach ($list as $key => &$value) {
|
$where['relation_id'] = $value['relation_id'];
|
if($value['user_id'] == $user['user_id']){
|
$where['user_id']= $other_user_id = $value['other_user_id'];
|
}else{
|
$where['user_id']= $other_user_id = $value['user_id'];
|
}
|
$where['status'] = 0;
|
$value['num'] = $this->where($where)->count();
|
unset($where['status']);
|
$value['newMessage'] = $this->where($where)->order('chat_id desc')->field('content,create_time')->find();
|
$value['user'] = UserModel::detail($other_user_id);
|
}
|
return $list;
|
}
|
|
//获取聊天信息
|
public function getMessage($data, $user)
|
{
|
$relation_id = ChatRelationModel::getRelationId($user['user_id'],$data['you_user_id']);
|
$list = $this->where("relation_id","=",$relation_id)
|
->with(['user'])
|
->order('chat_id desc')
|
->paginate($data);
|
$where['relation_id'] = $relation_id;
|
$where['user_id'] = $data['you_user_id'];
|
$this->where($where)->update(['status' => 1]);
|
return $list;
|
}
|
|
//获取消息条数
|
public function mCount($user)
|
{
|
$num = 0;
|
if ($user) {
|
$num = $this->where('user_id', '=', $user['user_id'])->whereOr('user_id', '=', $user['user_id'])->count();
|
}
|
return $num;
|
}
|
|
//获取用户信息
|
public function getInfo($user_id)
|
{
|
$userInfo = UserModel::detail($user_id);
|
$data['avatarUrl'] = $userInfo['avatarUrl'];
|
return $data;
|
}
|
|
public static function getNoReadCount($user_id){
|
return self::where('user_id', '=', $user_id)->whereOr('user_id', '=', $user_id)
|
//->where('status', '=', 0)
|
->count();
|
}
|
|
}
|