Commit 52d1871e authored by clone's avatar clone

聊天

parent 14250637
...@@ -205,7 +205,19 @@ class ChatService ...@@ -205,7 +205,19 @@ class ChatService
$rPush = new RPush(); $rPush = new RPush();
// 消息接收人必须是数组 // 消息接收人必须是数组
$rPush->send($user_name, $target_type, [ $target ], $msg_content, $from, $type, $accessToken, [ $this, 'saveSendStatus' ]); $userExt = new ChatUserExt();
$where['only_id'] = $target;
$info = $userExt->getChatUserExtByUserId($where, 'a.id,a.ext_id,a.device_id,a.push_id');
if (count($info) <= 0) {
return false;
}
$target = [];
foreach ($info as $item) {
array_push($target, $item["push_id"]);
}
$rPush->send($user_name, $target_type, $target, $msg_content, $from, $type, $accessToken, [ $this, 'saveSendStatus' ]);
return true; return true;
} }
...@@ -329,7 +341,7 @@ class ChatService ...@@ -329,7 +341,7 @@ class ChatService
$params["is_user"] = $is_user; $params["is_user"] = $is_user;
$params["created_at"] = date("Y-m-d H:i:s", time()); $params["created_at"] = date("Y-m-d H:i:s", time());
$params["updated_at"] = date("Y-m-d H:i:s", time()); $params["updated_at"] = date("Y-m-d H:i:s", time());
//dump($params);
$msgModel = new ChatMsg(); $msgModel = new ChatMsg();
$id = $msgModel->addChatMsg($params); $id = $msgModel->addChatMsg($params);
...@@ -381,7 +393,16 @@ class ChatService ...@@ -381,7 +393,16 @@ class ChatService
$field = "a.id,a.to_id,a.from_id,a.create_time,b.type,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.id as user_or_agent_id,b.only_id,
c.name as agent_name,c.img,d.user_name,d.user_phone,d.user_nick,d.user_pic,d.other_pic"; c.name as agent_name,c.img,d.user_name,d.user_phone,d.user_nick,d.user_pic,d.other_pic";
return $chatRelationModel->getChatRelationInfo($params, $field); $relationList = $chatRelationModel->getChatRelationInfo($params, $field);
dump($relationList);
$fields = "a.id,a.from_id,a.to_id,b.body,a.created_at";
$msgModel = new ChatMsg();
foreach ($relationList as $key=> $item) {
$select_["from"] = $item["from_id"];
$select_["target"] = $item["to_id"];
$relationList[$key]["chat_info"] = $msgModel->getChatHistory($select_, $fields, 1, 1);
}
return $relationList;
} }
/** /**
......
...@@ -37,24 +37,24 @@ class GeTuiUtils ...@@ -37,24 +37,24 @@ class GeTuiUtils
* @param $data * @param $data
* @return array * @return array
*/ */
public function pushMessageToIgt($push_id, $type = 'other', $title, $data) public function pushMessageToIgt($push_id, $type = 'other', $title, $payload)
{ {
$igt = new \IGeTui(self::IGT_HOST, self::IGT_APP_KEY, self::IGT_MASTER_SECRET); $igt = new \IGeTui(self::IGT_HOST, self::IGT_APP_KEY, self::IGT_MASTER_SECRET);
$payload['title'] = $title; /* $payload['title'] = $title;
$payload['type'] = $type; //0系统,1用户消息 $payload['type'] = $type; //0系统,1用户消息
$payload['msg_content'] = $data['msg_content']; $payload['msg_content'] = $data['msg_content'];
$payload['to_id'] = $data['to_id']; //接收人 $payload['to_id'] = $data['to_id']; //接收人
$payload['from_id'] = $data['from_id']; //发送人 $payload['from_id'] = $data['from_id']; //发送人
$payload['to_name'] = $data['to_name'];//接收人名字 $payload['to_name'] = $data['to_name'];//接收人名字
$payload['from_name'] = $data['from_name'];//发送人名字 $payload['from_name'] = $data['from_name'];//发送人名字
$payload['target_type'] = $data['target_type']; //1文字,2.图片 3.楼盘 $payload['target_type'] = $data['target_type']; //1文字,2.图片 3.楼盘*/
$payload = json_encode($payload);
try { try {
//模板 //模板
$template = $this->onlineAllTemplate($payload, $title, $data['msg_content']); $template = $this->onlineAllTemplate($payload, $title, "1231231");
} catch (\Exception $e) { } catch (\Exception $e) {
$result['code'] = 'failed'; $result['code'] = 'failed';
$result['msg'] = '字数超过限制'; $result['msg'] = '字数超过限制';
...@@ -75,7 +75,9 @@ class GeTuiUtils ...@@ -75,7 +75,9 @@ class GeTuiUtils
$result = []; $result = [];
foreach ($push_id as $k => $v) { foreach ($push_id as $k => $v) {
echo $v;
$target->set_clientId($v); $target->set_clientId($v);
dump($target);
$res = $igt->pushMessageToSingle($message, $target); $res = $igt->pushMessageToSingle($message, $target);
if ($res['result'] == 'ok') { if ($res['result'] == 'ok') {
......
...@@ -45,7 +45,6 @@ class RPush ...@@ -45,7 +45,6 @@ class RPush
} }
$response = $this->sendRequestByCurl($user_name, $target_type, $target, $msg_content, $from, $type, $access_token); $response = $this->sendRequestByCurl($user_name, $target_type, $target, $msg_content, $from, $type, $access_token);
call_user_func_array([ $callback[0], $callback[1] ], [ $response, $target, $from, $msg_content ]); call_user_func_array([ $callback[0], $callback[1] ], [ $response, $target, $from, $msg_content ]);
} }
...@@ -55,27 +54,31 @@ class RPush ...@@ -55,27 +54,31 @@ class RPush
* @param $target_type users 给用户发消息。chatgroups: 给群发消息,chatrooms: 给聊天室发消息 * @param $target_type users 给用户发消息。chatgroups: 给群发消息,chatrooms: 给聊天室发消息
* @param $target 注意这里需要用数组,数组长度建议不大于20,即使只有一个用户,也要用数组 ['u1'],给用户发送时数组元素是用户名, * @param $target 注意这里需要用数组,数组长度建议不大于20,即使只有一个用户,也要用数组 ['u1'],给用户发送时数组元素是用户名,
* 给群组发送时数组元素是groupid * 给群组发送时数组元素是groupid
* @param $type //目前只有文本的消息
* @param $msg_content * @param $msg_content
* @param $from * @param $from
* @param $type //目前只有文本的消息
* @param $access_token * @param $access_token
* @return \app\chat\utils\CurlResponse|bool * @return \app\chat\utils\CurlResponse|bool
*/ */
public function sendRequestByCurl($user_name, $target_type, $target, $msg_content, $from, $type, $access_token) public function sendRequestByCurl($user_name, $target_type, $target, $msg_content, $from, $type, $access_token)
{ {
$title = "收到一条消息";
$arr = array( $arr = array(
'target_type' => $target_type, 'target_type' => $target_type,
'target' => $target,//[1,2,3] 'target' => $target,
'msg' => [ "type" => "txt", "msg" => $msg_content ], 'msg' => [ "type" => "txt", "msg" => $msg_content ],
'from' => $from, 'from' => $from,
'ext' => [ "msg_type" => $type, "user_name" => $user_name ] 'ext' => [ "msg_type" => $type, "user_name" => $user_name ]
); );
$data = json_encode($arr);
$pushMessageToIgt = new GeTuiUtils();
$push_arr = $target;
$response_ = new GeTuiUtils();
$response_->pushMessageToIgt();
/* $data = json_encode($arr); $response = $pushMessageToIgt->pushMessageToIgt($push_arr, $type = 'other', $title, $data);
$curl = new \app\chat\utils\CurlUtil(); /* $curl = new \app\chat\utils\CurlUtil();
$curl->headers = [ $curl->headers = [
"Accept" => "application/json", "Accept" => "application/json",
"Content-Type" => "application/json;charset=utf-8", "Content-Type" => "application/json;charset=utf-8",
...@@ -87,8 +90,8 @@ class RPush ...@@ -87,8 +90,8 @@ class RPush
]; ];
$url = $this->buildSendUrl(); $url = $this->buildSendUrl();
$response = $curl->post($url, $data); $response = $curl->post($url, $data);
Log::record('info -------------' . json_encode($response), "info");*/ Log::record('info -------------' . json_encode($response), "info");
return $response; return $response;*/
} }
/** /**
......
...@@ -26,16 +26,15 @@ class ChatMsg extends Model ...@@ -26,16 +26,15 @@ class ChatMsg extends Model
public function addChatMsg($params) public function addChatMsg($params)
{ {
Db::startTrans(); Db::startTrans();
$id = 0;
try { try {
$this->save($params); $id = $this->db->insertGetId($params);
$id = $this->id;
Db::commit(); Db::commit();
return $id; return $id;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
} }
return 0; return $id;
} }
/** /**
...@@ -64,7 +63,7 @@ class ChatMsg extends Model ...@@ -64,7 +63,7 @@ class ChatMsg extends Model
} }
$where_["a.is_del"] = 0; $where_["a.is_del"] = 0;
$data = $this->field($field) $data = $this->db->field($field)
->alias("a") ->alias("a")
->join('chat_msg_ext b', 'a.id = b.msg_id', 'LEFT') ->join('chat_msg_ext b', 'a.id = b.msg_id', 'LEFT')
->where($where_) ->where($where_)
...@@ -75,6 +74,7 @@ class ChatMsg extends Model ...@@ -75,6 +74,7 @@ class ChatMsg extends Model
->limit($page_size) ->limit($page_size)
->page($page_no) ->page($page_no)
->select(); ->select();
//echo $this->getLastSql();
return $data; return $data;
} }
......
...@@ -42,18 +42,19 @@ class ChatRelation extends Model ...@@ -42,18 +42,19 @@ class ChatRelation extends Model
$whereOr_["from_id"] = $params["target"]; $whereOr_["from_id"] = $params["target"];
} }
if (isset($params["from"])) { if (isset($params["from"])) {
$where_["to_id"] = $params["from"]; $where_["from_id"] = $params["from"];
$whereOr_["from_id"] = $params["from"]; $whereOr_["to_id"] = $params["from"];
} }
$where_["disable"] = 0; $where_["disable"] = 0;
$whereOr_["disable"] = 0; $whereOr_["disable"] = 0;
return $this->field($field) $data = $this->field($field)
->where($where_) ->where($where_)
->whereOr(function ($query) use ($whereOr_) { ->whereOr(function ($query) use ($whereOr_) {
$query->where($whereOr_); $query->where($whereOr_);
}) })
->select(); ->select();
// echo $this->getLastSql();
return $data;
} }
/** /**
...@@ -76,7 +77,7 @@ class ChatRelation extends Model ...@@ -76,7 +77,7 @@ class ChatRelation extends Model
} }
$where_["disable"] = 0; $where_["disable"] = 0;
$whereOr_["disable"] = 0; $whereOr_["disable"] = 0;
return $this->field($field) $date = $this->field($field)
->alias("a") ->alias("a")
->join("chat_user b","a.to_id != '".$only_id."' and a.to_id=b.only_id or a.from_id=b.only_id","left") ->join("chat_user b","a.to_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.id = c.id","left") ->join("a_agents c","b.type = 1 and b.id = c.id","left")
...@@ -86,9 +87,15 @@ class ChatRelation extends Model ...@@ -86,9 +87,15 @@ class ChatRelation extends Model
$query->where($whereOr_); $query->where($whereOr_);
}) })
->select(); ->select();
// echo $this->getLastSql();
return $date;
} }
/**
* 新增联系人
* @param $params
*/
public function addChatRelation($params) public function addChatRelation($params)
{ {
$where_ = []; $where_ = [];
......
...@@ -48,6 +48,30 @@ class ChatUserExt extends BaseModel ...@@ -48,6 +48,30 @@ class ChatUserExt extends BaseModel
return $data; return $data;
} }
/**
* @param $params
* @param string $field
* @return mixed
* @throws \think\Exception
* @throws \think\exception\DbException
*/
public function getChatUserExtByUserId($params, $field)
{
$where_ = [];
if (isset($params['only_id'])) {
$where_['b.only_id'] = $params['only_id'];
$where_['a.is_forbidden'] = 0;
}
$data = $this->db->field($field)
->alias("a")
->join("chat_user b", "a.ext_id = b.id", "right")
->where($where_)
->select();
//echo $this->getLastSql();
return $data;
}
/** /**
* @param $params * @param $params
* @param $v * @param $v
......
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