Commit 7868a31c authored by hujun's avatar hujun

设备id绑定表

parent ea26e994
......@@ -19,11 +19,8 @@ use app\model\ChatMsgExt;
use app\model\ChatMsgStatus;
use app\model\ChatRelation;
use app\model\ChatUser;
use app\model\ChatUserExt;
use app\model\HouseInfos;
use app\model\Users;
use http\Exception;
class ChatService
{
......@@ -49,11 +46,11 @@ class ChatService
public function __construct()
{
$this->userModel = new Users();
$this->agentsModel = new Agents();
$this->chatUserModel = new ChatUser();
$this->userModel = new Users();
$this->agentsModel = new Agents();
$this->chatUserModel = new ChatUser();
$this->chatUserExtModel = new ChatUserExt();
$this->agentsV2Model = new AAgents();
$this->agentsV2Model = new AAgents();
}
/**
......@@ -63,36 +60,37 @@ class ChatService
* @param $device_id
* @param $push_id
* @return array
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @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["user_id"] = $user_id;
$params["phone"] = $mobile;
$fields = "id,type,phone,only_id,password";
$id = $only_id = 0;
$chatUser = $this->chatUserModel->getChatUser($params, $fields);
if (count($chatUser) > 0) {
return [ "code" => "200", "only_id" => $chatUser[0]["only_id"] ];
$id = $chatUser[0]["id"];
$only_id = $chatUser[0]["only_id"];
} else {
$only_id = $this->createOnlyId($user_id, $source);
if (!$only_id) {
return [ "code" => "101", "msg" => "没有找到用户信息" ];
} else {
$id = $this->insertChatUser($source, $user_id, $mobile, $only_id);
echo $id;
//todo 保存或更新push_id
if ($id > 0) {
$this->savePushId($id, $device_id, $push_id);
}
}
return [ "code" => 200, "only_id" => $only_id ];
}
//todo 保存或更新push_id
//todo 1.判断设备id +id 的数据是否存在,存在并且push_id和提交的不同则修改,否者新增
if ($id > 0) {
$this->savePushId($id, $device_id, $push_id);
}
return [ "code" => 200, "only_id" => $only_id ];
}
/**
......@@ -100,16 +98,37 @@ class ChatService
* @param $device_id
* @param $push_id
* @return bool
* @throws \think\Exception
* @throws \think\exception\DbException
*/
private function savePushId($chat_user_id, $device_id, $push_id){
//todo 保存或更新push_id
$params["ext_id"] = $chat_user_id;
$params["device_id"] = $device_id;
$params["push_id"] = $push_id;
$params["is_forbidden"] = 0;
$params["create_time"] = date("Y-m-d H:i:s", time());
$params["update_time"] = date("Y-m-d H:i:s", time());
$this->chatUserExtModel->addChatUserExt($params);
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
$params["ext_id"] = $chat_user_id;
$params["device_id"] = $device_id;
$params["push_id"] = $push_id;
$params["is_forbidden"] = 0;
$result = $this->chatUserExtModel->addChatUserExt($params);
}
if (!$result) {
return false;
}
return true;
}
......@@ -226,7 +245,7 @@ class ChatService
$chat_user_arr = [];
if ($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;
$field = "type,user_id,phone,only_id";
$chat_user = $this->chatUserModel->getChatUser($where_, $field);
......@@ -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";
$where_agent["phone"] = array( "in", $agent_phone );
$where_agent["phone"] = [ "in", $agent_phone ];
$agentsResult = $this->agentsV2Model->getAgentsInfoByAgentId($field, $where_agent);
foreach ($agentsResult as $v) {
......@@ -272,7 +291,7 @@ class ChatService
$fields = "id,user_nick,user_phone,user_pic";
$param["status"] = 0;
$param["user_phone"] = array( "in", $user_phone );
$param["user_phone"] = [ "in", $user_phone ];
$userResult = $this->userModel->getUserByWhere($param, $fields);
foreach ($userResult as $v) {
......@@ -325,7 +344,6 @@ class ChatService
}
/**
* 建立聊天关系
* @param $target
......@@ -355,12 +373,13 @@ class ChatService
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getRelationList($target){
public function getRelationList($target)
{
$chatRelationModel = new ChatRelation();
$params["target"] = $target;
$params["from"] = $target;
$field = "id,to_id,from_id,create_time";
return $chatRelationModel->getChatRelation($params,$field);
$field = "id,to_id,from_id,create_time";
return $chatRelationModel->getChatRelation($params, $field);
}
/**
......
......@@ -52,11 +52,18 @@ class ChatUserExt extends BaseModel
* @param $params
* @return false|int
*/
public function addChatUserExt($params)
public function addChatUserExt($params, $v, $k = 'id')
{
Db::startTrans();
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();
} catch (\Exception $e) {
Db::rollback();
......@@ -70,40 +77,33 @@ class ChatUserExt extends BaseModel
* @param $params
* @return array
*/
private function wxInfoBin($params)
private function chatUserExtBin($params)
{
$arr = [];
$array = [];
if (isset($params["id"])) {
$arr["id"] = $params["id"];
$array["id"] = $params["id"];
} else {
$arr["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"];
$array["create_time"] = date("Y-m-d H:i:s", time());
}
if (isset($params["sex"])) {
$arr["sex"] = $params["sex"];
if (isset($params["ext_id"])) {
$array["ext_id"] = $params["ext_id"];
}
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