Commit 7868a31c authored by hujun's avatar hujun

设备id绑定表

parent ea26e994
...@@ -19,11 +19,8 @@ use app\model\ChatMsgExt; ...@@ -19,11 +19,8 @@ use app\model\ChatMsgExt;
use app\model\ChatMsgStatus; use app\model\ChatMsgStatus;
use app\model\ChatRelation; use app\model\ChatRelation;
use app\model\ChatUser; use app\model\ChatUser;
use app\model\ChatUserExt; use app\model\ChatUserExt;
use app\model\HouseInfos;
use app\model\Users; use app\model\Users;
use http\Exception;
class ChatService class ChatService
{ {
...@@ -63,53 +60,75 @@ class ChatService ...@@ -63,53 +60,75 @@ class ChatService
* @param $device_id * @param $device_id
* @param $push_id * @param $push_id
* @return array * @return array
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function register($user_id, $mobile, $source,$device_id, $push_id) public function register($user_id, $mobile, $source, $device_id, $push_id)
{ {
$params["type"] = $source; $params["type"] = $source;
$params["user_id"] = $user_id; $params["user_id"] = $user_id;
$params["phone"] = $mobile; $params["phone"] = $mobile;
$fields = "id,type,phone,only_id,password"; $fields = "id,type,phone,only_id,password";
$id = $only_id = 0;
$chatUser = $this->chatUserModel->getChatUser($params, $fields); $chatUser = $this->chatUserModel->getChatUser($params, $fields);
if (count($chatUser) > 0) { if (count($chatUser) > 0) {
return [ "code" => "200", "only_id" => $chatUser[0]["only_id"] ]; $id = $chatUser[0]["id"];
$only_id = $chatUser[0]["only_id"];
} 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);
echo $id; }
}
//todo 保存或更新push_id //todo 保存或更新push_id
//todo 1.判断设备id +id 的数据是否存在,存在并且push_id和提交的不同则修改,否者新增
if ($id > 0) { if ($id > 0) {
$this->savePushId($id, $device_id, $push_id); $this->savePushId($id, $device_id, $push_id);
} }
}
return [ "code" => 200, "only_id" => $only_id ]; return [ "code" => 200, "only_id" => $only_id ];
} }
}
/** /**
* @param $chat_user_id * @param $chat_user_id
* @param $device_id * @param $device_id
* @param $push_id * @param $push_id
* @return bool * @return bool
* @throws \think\Exception
* @throws \think\exception\DbException
*/ */
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['device_id'] = $device_id;
$where['push_id'] = $push_id;
$where['is_forbidden'] = 0;
$info = $this->chatUserExtModel->getChatUserExt($where, 'id,ext_id,device_id,push_id');
$result = false;
if (count($info) > 0) {
if ($info[0]["push_id"] != $push_id) {
//update
$result = $this->chatUserExtModel->addChatUserExt([ 'push_id' => $push_id ], $info[0]['id']);
}
} else {
//todo 保存或更新push_id //todo 保存或更新push_id
$params["ext_id"] = $chat_user_id; $params["ext_id"] = $chat_user_id;
$params["device_id"] = $device_id; $params["device_id"] = $device_id;
$params["push_id"] = $push_id; $params["push_id"] = $push_id;
$params["is_forbidden"] = 0; $params["is_forbidden"] = 0;
$params["create_time"] = date("Y-m-d H:i:s", time()); $result = $this->chatUserExtModel->addChatUserExt($params);
$params["update_time"] = date("Y-m-d H:i:s", time()); }
$this->chatUserExtModel->addChatUserExt($params);
if (!$result) {
return false;
}
return true; return true;
} }
...@@ -226,7 +245,7 @@ class ChatService ...@@ -226,7 +245,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"] = array( "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);
...@@ -254,7 +273,7 @@ class ChatService ...@@ -254,7 +273,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"] = array( "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) {
...@@ -272,7 +291,7 @@ class ChatService ...@@ -272,7 +291,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"] = array( "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) {
...@@ -325,7 +344,6 @@ class ChatService ...@@ -325,7 +344,6 @@ class ChatService
} }
/** /**
* 建立聊天关系 * 建立聊天关系
* @param $target * @param $target
...@@ -355,12 +373,13 @@ class ChatService ...@@ -355,12 +373,13 @@ class ChatService
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function getRelationList($target){ public function getRelationList($target)
{
$chatRelationModel = new ChatRelation(); $chatRelationModel = new ChatRelation();
$params["target"] = $target; $params["target"] = $target;
$params["from"] = $target; $params["from"] = $target;
$field = "id,to_id,from_id,create_time"; $field = "id,to_id,from_id,create_time";
return $chatRelationModel->getChatRelation($params,$field); return $chatRelationModel->getChatRelation($params, $field);
} }
/** /**
......
...@@ -52,11 +52,18 @@ class ChatUserExt extends BaseModel ...@@ -52,11 +52,18 @@ class ChatUserExt extends BaseModel
* @param $params * @param $params
* @return false|int * @return false|int
*/ */
public function addChatUserExt($params) public function addChatUserExt($params, $v, $k = 'id')
{ {
Db::startTrans(); Db::startTrans();
try { try {
$res = $this->save($params); $data = $this->chatUserExtBin($params);
if ($v) {
$this->db->where($k, $v)->update($data);
$res = $v;
} else {
$res = $this->db->insertGetId($data);
}
Db::commit(); Db::commit();
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
...@@ -70,40 +77,33 @@ class ChatUserExt extends BaseModel ...@@ -70,40 +77,33 @@ class ChatUserExt extends BaseModel
* @param $params * @param $params
* @return array * @return array
*/ */
private function wxInfoBin($params) private function chatUserExtBin($params)
{ {
$arr = []; $array = [];
if (isset($params["id"])) { if (isset($params["id"])) {
$arr["id"] = $params["id"]; $array["id"] = $params["id"];
} else { } else {
$arr["create_time"] = date("Y-m-d H:i:s", time()); $array["create_time"] = date("Y-m-d H:i:s", time());
}
if (isset($params["wx_open_id"])) {
$arr["wx_open_id"] = $params["wx_open_id"];
}
if (isset($params["wx_union_id"])) {
$arr["wx_union_id"] = $params["wx_union_id"];
}
if (isset($params["buyer_nick"])) {
$arr["buyer_nick"] = $params["buyer_nick"];
} }
if (isset($params["buyer_img"])) {
$arr["buyer_img"] = $params["buyer_img"]; if (isset($params["ext_id"])) {
} $array["ext_id"] = $params["ext_id"];
if (isset($params["sex"])) {
$arr["sex"] = $params["sex"];
} }
if (isset($params["province"])) {
$arr["province"] = $params["province"]; if (isset($params["device_id"])) {
$array["device_id"] = $params["device_id"];
} }
if (isset($params["city"])) {
$arr["city"] = $params["city"]; if (isset($params["push_id"])) {
$array["push_id"] = $params["push_id"];
} }
if (isset($params["source"])) {
$arr["source"] = $params["source"]; if (isset($params["is_forbidden"])) {
$array["is_forbidden"] = $params["is_forbidden"];
} }
$arr["update_time"] = date("Y-m-d H:i:s", time());
return $arr; $array["update_time"] = date("Y-m-d H:i:s", time());
return $array;
} }
} }
\ 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