Commit 257f13f3 authored by zw's avatar zw

chat

parent cd4bf09a
......@@ -108,7 +108,7 @@ class AppChat extends Basic
$only_arr = $this->_chat->register($user_id, $mobile, $source, $device_id, $push_id);
if ($only_arr["code"] == 200) {
return $this->response("200", "success", [ "only_id" => $only_arr["only_id"] ]);
return $this->response("200", "success", ["only_id" => $only_arr["only_id"]]);
} else {
return $this->response("101", $only_arr["msg"]);
}
......@@ -151,7 +151,7 @@ class AppChat extends Basic
$only_arr = $this->_chat->register($user_id, $mobile, $source, $device_id, $push_id);
if ($only_arr["code"] == 200) {
return $this->response("200", "success", [ "only_id" => $only_arr["only_id"] ]);
return $this->response("200", "success", ["only_id" => $only_arr["only_id"]]);
} else {
return $this->response("101", $only_arr["msg"]);
}
......@@ -225,9 +225,9 @@ class AppChat extends Basic
$result = $this->_chat->sendMsg($user_name, $target_type, $target, $source, $is_user, $type, $msg_content, $from);
if ($result) {
return $this->response("200", "", [ "msg" => "消息发送成功" ]);
return $this->response("200", "", ["msg" => "消息发送成功"]);
} else {
return $this->response("101", "", [ "msg" => "消息发送失败" ]);
return $this->response("101", "", ["msg" => "消息发送失败"]);
}
}
......@@ -250,13 +250,22 @@ class AppChat extends Basic
if (!isset($params['target_type']) || !isset($params['from']) || !isset($params['target']) || !isset($params['last_msg_id'])) {
return $this->response(ErrorCodeConst::ERROR_CODE_PARAM_NOT_EXIST, "请求参数错误");
}
$msgModel = new ChatMsg();
//进入详情页修改已读消息 只修改自己收到的消息为已读,自己发送的是在对方判断已读未读
if (!empty($params["last_msg_id"]) && $params["last_msg_id"] > 0) {
$where_arr["from"] = $params["from"];
$where_arr["target"] = $params["target"];
$update_arr["is_read"] = 0;
$msgModel->updateIsRead($where_arr, $update_arr);
}
$page_no = empty($params['page_no']) ? 1 : $params['page_no'];
$page_size = empty($params['page_size']) ? 15 : $params['page_size'];
$field = "a.id,a.to_id,a.from_id,a.created_at,b.type,b.body";
$msgModel = new ChatMsg();
$history_result = $msgModel->getChatHistory($params, $field, $page_no, $page_size);
return $this->response("200", "request success", array_reverse($history_result));
......@@ -275,7 +284,7 @@ class AppChat extends Basic
$data = [];
if ($file) {
$path = ROOT_PATH . 'public' . DS . 'static' . DS . 'chat_image';
$info = $file->validate([ 'size' => 10240000, 'ext' => 'jpg,png' ])//限制100m
$info = $file->validate(['size' => 10240000, 'ext' => 'jpg,png'])//限制100m
->move($path);
if ($info) {
$img_path = $info->getSaveName(); //生成的图片路径
......@@ -283,7 +292,7 @@ class AppChat extends Basic
$image = \think\Image::open($static_path);
$image->thumb(500, 500)->save($static_path); //生成缩略图
$data = [ 'name' => $img_path ];
$data = ['name' => $img_path];
} else {
// 上传失败获取错误信息
return $this->response("101", $file->getError());
......@@ -312,7 +321,7 @@ class AppChat extends Basic
if (!isset($params['id']) || !isset($params['from'])) {
return $this->response("300", "参数不全");
}
$conditions['id'] = array( "eq", $params["id"] );
$conditions['id'] = array("eq", $params["id"]);
$gHousesModel = new GHouses();
//external_title c端
if ($params["from"] == "C") {
......@@ -465,7 +474,7 @@ class AppChat extends Basic
//获取此经纪人的所有盘方楼盘id
$param["addressee_id"] = $params["agent_id"];
$param["type"] = array( "in", "1,3" );
$param["type"] = array("in", "1,3");
$msgModel = new MPushMessage();
$history_result = $msgModel->getListByWhere($field, $param, $page_no, $page_size);
......@@ -511,7 +520,8 @@ class AppChat extends Basic
* 获取商铺消息和客户消息的未读消息个数,并修改已读消息状态
* @return \think\Response
*/
public function updateSystemMessageIsRead(){
public function updateSystemMessageIsRead()
{
$params = $this->params;
/* $params = array(
"agent_id" => 1,//经纪人id
......@@ -523,10 +533,10 @@ class AppChat extends Basic
}
$msgModel = new MPushMessage();
//修改已读消息
if(!empty($params['read_ids'])){
$where_arr["id"] = array("in",$params["read_ids"]);
if (!empty($params['read_ids'])) {
$where_arr["id"] = array("in", $params["read_ids"]);
$update_arr["is_read"] = 1;
$msgModel->updateIsRead($where_arr,$update_arr);
$msgModel->updateIsRead($where_arr, $update_arr);
}
$param["addressee_id"] = $params["agent_id"];
......@@ -535,26 +545,35 @@ class AppChat extends Basic
$data["user_count"] = $msgModel->getListCountByWhere($param);
$param["type"] = 1;
$data["shop_count"] = $msgModel->getListCountByWhere($param);
return $this->response("200","success",$data);
return $this->response("200", "success", $data);
}
public function getMessageIsRead(){
public function getMessageIsRead()
{
$params = $this->params;
$params = array(
/* $params = array(
"agent_id" => 1
);
);*/
//todo 先获取是否有店铺或客户修改消息是否为0,大于0返回true,否则查询聊天消息是否有未读
$param["addressee_id"] = $params["agent_id"];
$param["type"] = 2;
//TODO 获取未读个数
$msgModel = new MPushMessage();
$user_count = $msgModel->getListCountByWhere($param);
if($user_count > 0){
return $this->response("200","success",["is_show_red"=>true]);
if ($user_count > 0) {
return $this->response("200", "success", ["is_show_red" => true]);
}
$param["type"] = 1;
$shop_count = $msgModel->getListCountByWhere($param);
if($shop_count > 0){
return $this->response("200","success",["is_show_red"=>true]);
if ($shop_count > 0) {
return $this->response("200", "success", ["is_show_red" => true]);
}
$where["to_id"] = "agent_" . $params["agent_id"];
$chatModel = new ChatMsg();
$msg_count = $chatModel->getTotalByToId($where);
if ($msg_count > 0) {
return $this->response("200", "success", ["is_show_red" => true]);
}
......
......@@ -82,6 +82,36 @@ class ChatMsg extends Model
return $data;
}
/** 批量更新已看记录
* @param array $where_arr
* @param array $update_arr
* @return bool
*/
public function updateIsRead(array $where_arr,array $update_arr){
$where_ = [];
if (isset($where_arr["from"])) {
$where_["from_id"] = $where_arr["from"];
}
if (isset($where_arr["target"])) {
$where_["to_id"] = $where_arr["target"];
}
if(empty($where_)){
return false;
}
try {
$this->db->where($where_)
->update($update_arr);
return true;
} catch (\Exception $e) {
return false;
}
}
/**
* @param $params
* @param $field
* @return mixed
*/
public function getTotalUnread($params, $field)
{
......@@ -96,7 +126,9 @@ class ChatMsg extends Model
}
$where_["a.is_del"] = 0;
$data = $this->db->field($field)
$data = $this->db
->field($field)
->alias("a")
->join('chat_msg_ext b', 'a.id = b.msg_id', 'LEFT')
->where($where_)
......@@ -105,4 +137,11 @@ class ChatMsg extends Model
return $data;
}
public function getTotalByToId($params){
$data = $this->db
->where($params)
->count();
return $data;
}
}
\ No newline at end of file
......@@ -458,6 +458,7 @@ Route::group('chat', [
'getSystemMessageByShop' => ['chat/AppChat/getSystemMessageByShop', ['method' => 'post|get']],
'getSystemMessageByUser' => ['chat/AppChat/getSystemMessageByUser', ['method' => 'post|get']],
'updateSystemMessageIsRead' => ['chat/AppChat/updateSystemMessageIsRead', ['method' => 'post|get']],
'getMessageIsRead' => ['chat/AppChat/getMessageIsRead', ['method' => 'post|get']],
]);
......@@ -668,8 +669,8 @@ Route::group('broker', [
'getSiteListApp' => ['api_broker/Site/getSiteList', ['method' => 'POST|GET']], //获取站点列表
'getAgentSiteList' => [ 'api_broker/Site/getAgentSiteList', [ 'method' => 'POST|GET' ] ], //获取经纪人站点列表
'getPhoneBook' => [ 'api_broker/Agent/getPhoneBook', [ 'method' => 'POST|GET' ] ], //消息页面--通讯录
'getAgentSiteList' => ['api_broker/Site/getAgentSiteList', ['method' => 'POST|GET']], //获取经纪人站点列表
'getPhoneBook' => ['api_broker/Agent/getPhoneBook', ['method' => 'POST|GET']], //消息页面--通讯录
]);
//Route::miss('api/index/miss');//处理错误的url
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment