Commit 1c6d856c authored by clone's avatar clone

1

parent bf7855b4
...@@ -10,6 +10,7 @@ namespace app\chat\service; ...@@ -10,6 +10,7 @@ namespace app\chat\service;
* Intro: * Intro:
*/ */
use app\api_broker\service\RedisCacheService;
use app\chat\utils\RegisterUtil; use app\chat\utils\RegisterUtil;
use app\chat\utils\RPush; use app\chat\utils\RPush;
use app\model\AAgents; use app\model\AAgents;
...@@ -78,7 +79,7 @@ class ChatService ...@@ -78,7 +79,7 @@ class ChatService
} else { } else {
$only_id = $this->createOnlyId($user_id, $source); $only_id = $this->createOnlyId($user_id, $source);
if (!$only_id) { if (!$only_id) {
return [ "code" => "101", "msg" => "没有找到用户信息" ]; return ["code" => "101", "msg" => "没有找到用户信息"];
} else { } else {
$id = $this->insertChatUser($source, $user_id, $mobile, $only_id); $id = $this->insertChatUser($source, $user_id, $mobile, $only_id);
} }
...@@ -88,7 +89,7 @@ class ChatService ...@@ -88,7 +89,7 @@ class ChatService
if ($id > 0 && $device_id && $push_id) { if ($id > 0 && $device_id && $push_id) {
$this->savePushIdV3($id, $device_id, $push_id, $source); $this->savePushIdV3($id, $device_id, $push_id, $source);
} }
return [ "code" => 200, "only_id" => $only_id ]; return ["code" => 200, "only_id" => $only_id];
} }
/** /**
...@@ -102,11 +103,11 @@ class ChatService ...@@ -102,11 +103,11 @@ class ChatService
private function savePushId($chat_user_id, $device_id, $push_id) private function savePushId($chat_user_id, $device_id, $push_id)
{ {
$where['ext_id'] = $chat_user_id; $where['ext_id'] = $chat_user_id;
$where['device_id'] = $device_id; $where['device_id'] = $device_id;
$where['push_id'] = $push_id; $where['push_id'] = $push_id;
// $where['is_forbidden'] = 0; // $where['is_forbidden'] = 0;
$info = $this->chatUserExtModel->getChatUserExt($where, 'id,ext_id,device_id,push_id,is_forbidden'); $info = $this->chatUserExtModel->getChatUserExt($where, 'id,ext_id,device_id,push_id,is_forbidden');
$result = false; $result = false;
if (count($info) > 0) { if (count($info) > 0) {
...@@ -151,31 +152,31 @@ class ChatService ...@@ -151,31 +152,31 @@ class ChatService
private function savePushIdV2($chat_user_id, $device_id, $push_id, $type) private function savePushIdV2($chat_user_id, $device_id, $push_id, $type)
{ {
//todo 根据设备来判断使用设备用户, //todo 根据设备来判断使用设备用户,
$where['ext_id'] = $chat_user_id; $where['ext_id'] = $chat_user_id;
$where['push_id'] = $push_id; $where['push_id'] = $push_id;
$where['device_id'] = $device_id; $where['device_id'] = $device_id;
$where['type'] = $type; $where['type'] = $type;
$info = $this->chatUserExtModel->getChatUserExtByUserId($where, 'a.id,a.ext_id,a.device_id,a.push_id,a.is_forbidden', 100); $info = $this->chatUserExtModel->getChatUserExtByUserId($where, 'a.id,a.ext_id,a.device_id,a.push_id,a.is_forbidden', 100);
$result = false; $result = false;
if (count($info) > 0) { if (count($info) > 0) {
$where['device_id'] = $device_id; $where['device_id'] = $device_id;
$where['type'] = $type; $where['type'] = $type;
$where['ext_id'] = ['<>', $chat_user_id]; $where['ext_id'] = ['<>', $chat_user_id];
$info = $this->chatUserExtModel->getChatUserExtByUserId($where, 'a.id,a.ext_id,a.device_id,a.push_id,a.is_forbidden', 100); $info = $this->chatUserExtModel->getChatUserExtByUserId($where, 'a.id,a.ext_id,a.device_id,a.push_id,a.is_forbidden', 100);
$current_user_id = 0; $current_user_id = 0;
foreach ($info as $k=>$v) { foreach ($info as $k => $v) {
if ($v['is_forbidden'] == 0) { if ($v['is_forbidden'] == 0) {
if ($v['ext_id'] != $chat_user_id && $push_id == $v['push_id']) { 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 { } 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; $current_user_id = $chat_user_id;
} }
} else { } else {
if ($v['ext_id'] == $chat_user_id && $push_id == $v['push_id']) { 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; $current_user_id = $chat_user_id;
} }
} }
...@@ -218,20 +219,20 @@ class ChatService ...@@ -218,20 +219,20 @@ class ChatService
private function savePushIdV3($chat_user_id, $device_id, $push_id, $type) private function savePushIdV3($chat_user_id, $device_id, $push_id, $type)
{ {
//todo 根据设备来判断使用设备用户, //todo 根据设备来判断使用设备用户,
$where['push_id'] = $push_id; $where['push_id'] = $push_id;
$where['type'] = $type; $where['type'] = $type;
$info = $this->chatUserExtModel->getChatUserExtByUserId($where, 'a.id,b.user_id,a.ext_id,a.device_id,a.push_id,a.is_forbidden', 500); $info = $this->chatUserExtModel->getChatUserExtByUserId($where, 'a.id,b.user_id,a.ext_id,a.device_id,a.push_id,a.is_forbidden', 500);
$result = false; $result = false;
if (count($info) > 0) { if (count($info) > 0) {
$current_user_id = 0; $current_user_id = 0;
foreach ($info as $k=>$v) { foreach ($info as $k => $v) {
if ($v['ext_id'] != $chat_user_id) { 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 { } else {
$current_user_id = $chat_user_id; $current_user_id = $chat_user_id;
if ($current_user_id && $v['is_forbidden'] == 1) { 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']]);
} }
} }
} }
...@@ -244,12 +245,12 @@ class ChatService ...@@ -244,12 +245,12 @@ class ChatService
$params["is_forbidden"] = 0; $params["is_forbidden"] = 0;
$result = $this->chatUserExtModel->addChatUserExt($params); $result = $this->chatUserExtModel->addChatUserExt($params);
} else { } else {
$where2['push_id'] = ['<>', $push_id]; $where2['push_id'] = ['<>', $push_id];
$where2['type'] = $type; $where2['type'] = $type;
$where2['is_forbidden'] = 0; $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); $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) { foreach ($info as $k2 => $v2) {
$this->chatUserExtModel->updateDate(['is_forbidden'=>1], ['id'=>$v2['id']]); $this->chatUserExtModel->updateDate(['is_forbidden' => 1], ['id' => $v2['id']]);
} }
} }
} else { } else {
...@@ -367,27 +368,27 @@ class ChatService ...@@ -367,27 +368,27 @@ class ChatService
} }
} }
$where['is_forbidden'] = 0; $where['is_forbidden'] = 0;
$info = $userExt->getChatUserExtByUserId($where, 'a.id,a.ext_id,a.device_id,a.push_id,b.user_id'); $info = $userExt->getChatUserExtByUserId($where, 'a.id,a.ext_id,a.device_id,a.push_id,b.user_id');
if (count($info) <= 0) { if (count($info) <= 0) {
return false; return false;
} }
if ($user_type == 1) { if ($user_type == 1) {
$user_data = $this->userModel->getUserById('user_phone', $user_id); $user_data = $this->userModel->getUserById('user_phone', $user_id);
$user_info['id'] = $user_id; $user_info['id'] = $user_id;
$user_info['phone'] = $user_data['user_phone']; $user_info['phone'] = $user_data['user_phone'];
} else { } else {
$agent_data = $this->agentsV2Model->getAgentInfo('phone', $user_id); $agent_data = $this->agentsV2Model->getAgentInfo('phone', $user_id);
$user_info['id'] = $user_id; $user_info['id'] = $user_id;
$user_info['phone'] = $agent_data['phone']; $user_info['phone'] = $agent_data['phone'];
} }
$push_id = []; $push_id = [];
foreach ($info as $item) { foreach ($info as $item) {
array_push($push_id, $item["push_id"]); 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; return true;
} }
...@@ -427,7 +428,7 @@ class ChatService ...@@ -427,7 +428,7 @@ class ChatService
$chat_user_arr = []; $chat_user_arr = [];
if ($only_id) { if ($only_id) {
$only_id_arr = explode(",", $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; $where_["status"] = 0;
$field = "type,user_id,phone,only_id"; $field = "type,user_id,phone,only_id";
$chat_user = $this->chatUserModel->getChatUser($where_, $field); $chat_user = $this->chatUserModel->getChatUser($where_, $field);
...@@ -448,7 +449,7 @@ class ChatService ...@@ -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"; $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); $agentsResult = $this->agentsV2Model->getAgentsInfoByAgentId($field, $where_agent);
foreach ($agentsResult as $v) { foreach ($agentsResult as $v) {
...@@ -466,7 +467,7 @@ class ChatService ...@@ -466,7 +467,7 @@ class ChatService
$fields = "id,user_nick,user_phone,user_pic"; $fields = "id,user_nick,user_phone,user_pic";
$param["status"] = 0; $param["status"] = 0;
$param["user_phone"] = [ "in", $user_phone ]; $param["user_phone"] = ["in", $user_phone];
$userResult = $this->userModel->getUserByWhere($param, $fields); $userResult = $this->userModel->getUserByWhere($param, $fields);
foreach ($userResult as $v) { foreach ($userResult as $v) {
...@@ -556,18 +557,31 @@ class ChatService ...@@ -556,18 +557,31 @@ class ChatService
$chatRelationModel = new ChatRelation(); $chatRelationModel = new ChatRelation();
$params["target"] = $target; $params["target"] = $target;
$params["from"] = $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, $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";
$relationList = $chatRelationModel->getChatRelationInfo($params, $field); $relationList = $chatRelationModel->getChatRelationInfo($params, $field);
$result = []; $result = [];
$fields = "a.id,a.from_id,a.to_id,b.body,b.type,a.created_at"; $fields = "a.id,a.from_id,a.to_id,b.body,b.type,a.created_at";
$msgModel = new ChatMsg(); $msgModel = new ChatMsg();
$redis_service = new RedisCacheService();
foreach ($relationList as $key => $item) { foreach ($relationList as $key => $item) {
$result[$key]["id"] = $item["id"];//关系id $result[$key]["id"] = $item["id"];//关系id
$result[$key]["user_id"] = $item["user_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 //对方的only_id
if ($item["from_id"] == $target) { if ($item["from_id"] == $target) {
$result[$key]["relation_id"] = $item["to_id"]; $result[$key]["relation_id"] = $item["to_id"];
...@@ -602,7 +616,7 @@ class ChatService ...@@ -602,7 +616,7 @@ class ChatService
} }
try { 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"); $unread_count = $msgModel->getTotalUnread($where_, "id");
//dump($unread_count); //dump($unread_count);
......
...@@ -80,8 +80,8 @@ class ChatRelation extends Model ...@@ -80,8 +80,8 @@ class ChatRelation extends Model
$date = $this->field($field) $date = $this->field($field)
->alias("a") ->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("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("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("u_users d","b.type =2 and b.user_id=d.id","left")*/
->where($where_) ->where($where_)
->whereOr(function ($query) use ($whereOr_) { ->whereOr(function ($query) use ($whereOr_) {
$query->where($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