Commit 1c6d856c authored by clone's avatar clone

1

parent bf7855b4
......@@ -10,6 +10,7 @@ namespace app\chat\service;
* Intro:
*/
use app\api_broker\service\RedisCacheService;
use app\chat\utils\RegisterUtil;
use app\chat\utils\RPush;
use app\model\AAgents;
......@@ -78,7 +79,7 @@ class ChatService
} else {
$only_id = $this->createOnlyId($user_id, $source);
if (!$only_id) {
return [ "code" => "101", "msg" => "没有找到用户信息" ];
return ["code" => "101", "msg" => "没有找到用户信息"];
} else {
$id = $this->insertChatUser($source, $user_id, $mobile, $only_id);
}
......@@ -88,7 +89,7 @@ class ChatService
if ($id > 0 && $device_id && $push_id) {
$this->savePushIdV3($id, $device_id, $push_id, $source);
}
return [ "code" => 200, "only_id" => $only_id ];
return ["code" => 200, "only_id" => $only_id];
}
/**
......@@ -165,17 +166,17 @@ class ChatService
$info = $this->chatUserExtModel->getChatUserExtByUserId($where, 'a.id,a.ext_id,a.device_id,a.push_id,a.is_forbidden', 100);
$current_user_id = 0;
foreach ($info as $k=>$v) {
foreach ($info as $k => $v) {
if ($v['is_forbidden'] == 0) {
if ($v['ext_id'] != $chat_user_id && $push_id == $v['push_id']) {
$this->chatUserExtModel->updateDate(['is_forbidden'=>1], ['id'=>$v['id']]);
$this->chatUserExtModel->updateDate(['is_forbidden' => 1], ['id' => $v['id']]);
} else {
$this->chatUserExtModel->updateDate(['update_time'=>date('Y-m-d H:i:s')], ['id'=>$v['id']]);
$this->chatUserExtModel->updateDate(['update_time' => date('Y-m-d H:i:s')], ['id' => $v['id']]);
$current_user_id = $chat_user_id;
}
} else {
if ($v['ext_id'] == $chat_user_id && $push_id == $v['push_id']) {
$this->chatUserExtModel->updateDate(['is_forbidden'=>0], ['id'=>$v['id'], 'ext_id'=>$chat_user_id]);
$this->chatUserExtModel->updateDate(['is_forbidden' => 0], ['id' => $v['id'], 'ext_id' => $chat_user_id]);
$current_user_id = $chat_user_id;
}
}
......@@ -225,13 +226,13 @@ class ChatService
$result = false;
if (count($info) > 0) {
$current_user_id = 0;
foreach ($info as $k=>$v) {
foreach ($info as $k => $v) {
if ($v['ext_id'] != $chat_user_id) {
$this->chatUserExtModel->updateDate(['is_forbidden'=>1], ['id'=>$v['id']]);
$this->chatUserExtModel->updateDate(['is_forbidden' => 1], ['id' => $v['id']]);
} else {
$current_user_id = $chat_user_id;
if ($current_user_id && $v['is_forbidden'] == 1) {
$this->chatUserExtModel->updateDate(['is_forbidden'=>0], ['id'=>$v['id']]);
$this->chatUserExtModel->updateDate(['is_forbidden' => 0], ['id' => $v['id']]);
}
}
}
......@@ -248,8 +249,8 @@ class ChatService
$where2['type'] = $type;
$where2['is_forbidden'] = 0;
$info = $this->chatUserExtModel->getChatUserExtByUserId($where2, 'a.id,b.user_id,a.ext_id,a.device_id,a.push_id,a.is_forbidden', 500);
foreach ($info as $k2=>$v2) {
$this->chatUserExtModel->updateDate(['is_forbidden'=>1], ['id'=>$v2['id']]);
foreach ($info as $k2 => $v2) {
$this->chatUserExtModel->updateDate(['is_forbidden' => 1], ['id' => $v2['id']]);
}
}
} else {
......@@ -387,7 +388,7 @@ class ChatService
foreach ($info as $item) {
array_push($push_id, $item["push_id"]);
}
$rPush->send($user_name, $target_type, $target, $msg_content, $from, $user_type, $type, [ $this, 'saveSendStatus' ], $push_id, $msg_id, $user_info);
$rPush->send($user_name, $target_type, $target, $msg_content, $from, $user_type, $type, [$this, 'saveSendStatus'], $push_id, $msg_id, $user_info);
return true;
}
......@@ -427,7 +428,7 @@ class ChatService
$chat_user_arr = [];
if ($only_id) {
$only_id_arr = explode(",", $only_id);
$where_["only_id"] = [ "in", $only_id_arr ];
$where_["only_id"] = ["in", $only_id_arr];
$where_["status"] = 0;
$field = "type,user_id,phone,only_id";
$chat_user = $this->chatUserModel->getChatUser($where_, $field);
......@@ -448,7 +449,7 @@ class ChatService
$field = "a.id,a.name as user_nick,a.phone as user_phone,a.img as user_pic,CONCAT(c.district_name,'-',b.store_name) as shop_name";
$where_agent["phone"] = [ "in", $agent_phone ];
$where_agent["phone"] = ["in", $agent_phone];
$agentsResult = $this->agentsV2Model->getAgentsInfoByAgentId($field, $where_agent);
foreach ($agentsResult as $v) {
......@@ -466,7 +467,7 @@ class ChatService
$fields = "id,user_nick,user_phone,user_pic";
$param["status"] = 0;
$param["user_phone"] = [ "in", $user_phone ];
$param["user_phone"] = ["in", $user_phone];
$userResult = $this->userModel->getUserByWhere($param, $fields);
foreach ($userResult as $v) {
......@@ -556,18 +557,31 @@ class ChatService
$chatRelationModel = new ChatRelation();
$params["target"] = $target;
$params["from"] = $target;
$field = "a.id,a.to_id,a.from_id,a.create_time,b.type,b.user_id,b.id as user_or_agent_id,b.only_id,
c.name as agent_name,c.img,c.phone,d.user_name,d.user_phone,d.user_nick,d.user_pic,d.other_pic";
$field = "a.id,a.to_id,a.from_id,a.create_time,b.type,b.user_id,b.id as user_or_agent_id,b.only_id";
$relationList = $chatRelationModel->getChatRelationInfo($params, $field);
$result = [];
$fields = "a.id,a.from_id,a.to_id,b.body,b.type,a.created_at";
$msgModel = new ChatMsg();
$redis_service = new RedisCacheService();
foreach ($relationList as $key => $item) {
$result[$key]["id"] = $item["id"];//关系id
$result[$key]["user_id"] = $item["user_id"];//关系id
//拆分查询
$info = $redis_service->agentCache($item["user_id"]);
if ($item["type"] == 1) { //经纪人
$result[$key]["agent_name"] = $info["name"];
$result[$key]["img"] = $info["img"];
$result[$key]["phone"] = $info["phone"];
} elseif ($item["type"] == 2) { //用户
$result[$key]["user_name"] = $info["user_name"];
$result[$key]["user_phone"] = $info["user_phone"];
$result[$key]["user_nick"] = $info["user_nick"];
$result[$key]["user_pic"] = $info["user_pic"];
$result[$key]["other_pic"] = $info["other_pic"];
}
//对方的only_id
if ($item["from_id"] == $target) {
$result[$key]["relation_id"] = $item["to_id"];
......@@ -602,7 +616,7 @@ class ChatService
}
try {
$where_["id"] = [ "between", [ $relation_list[$item["id"]][0]["msg_id"], $chat_info[0]["id"] ] ];
$where_["id"] = ["between", [$relation_list[$item["id"]][0]["msg_id"], $chat_info[0]["id"]]];
//计算未读消息个数
$unread_count = $msgModel->getTotalUnread($where_, "id");
//dump($unread_count);
......
......@@ -80,8 +80,8 @@ class ChatRelation extends Model
$date = $this->field($field)
->alias("a")
->join("chat_user b","b.only_id != '".$only_id."' and (a.to_id=b.only_id or a.from_id=b.only_id)","left")
->join("a_agents c","b.type = 1 and b.user_id = c.id","left")
->join("u_users d","b.type =2 and b.user_id=d.id","left")
/* ->join("a_agents c","b.type = 1 and b.user_id = c.id","left")
->join("u_users d","b.type =2 and b.user_id=d.id","left")*/
->where($where_)
->whereOr(function ($query) use ($whereOr_) {
$query->where($whereOr_);
......
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