Commit 51874410 authored by hujun's avatar hujun

设备id绑定

parent 900ca3c1
...@@ -20,6 +20,7 @@ use app\model\ChatMsgStatus; ...@@ -20,6 +20,7 @@ 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\HouseInfos; use app\model\HouseInfos;
use app\model\Users; use app\model\Users;
use http\Exception; use http\Exception;
...@@ -51,6 +52,7 @@ class ChatService ...@@ -51,6 +52,7 @@ class ChatService
$this->userModel = new Users(); $this->userModel = new Users();
$this->agentsModel = new Agents(); $this->agentsModel = new Agents();
$this->chatUserModel = new ChatUser(); $this->chatUserModel = new ChatUser();
$this->chatUserExtModel = new ChatUserExt();
$this->agentsV2Model = new AAgents(); $this->agentsV2Model = new AAgents();
} }
...@@ -80,16 +82,34 @@ class ChatService ...@@ -80,16 +82,34 @@ class ChatService
if (!$only_id) { if (!$only_id) {
return [ "code" => "101", "msg" => "没有找到用户信息" ]; return [ "code" => "101", "msg" => "没有找到用户信息" ];
} else { } else {
$this->insertChatUser($source, $user_id, $mobile, $only_id); $id = $this->insertChatUser($source, $user_id, $mobile, $only_id);
}
//todo 保存或更新push_id //todo 保存或更新push_id
if ($id > 0) {
$this->savePushId($id, $device_id, $push_id);
}
}
return [ "code" => 200, "only_id" => $only_id ]; return [ "code" => 200, "only_id" => $only_id ];
} }
} }
private function savePushId(){
//todo /**
* @param $chat_user_id
* @param $device_id
* @param $push_id
* @return bool
*/
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["updated_at"] = date("Y-m-d H:i:s", time());
$this->chatUserExtModel->addChatUserExt($params);
return true;
} }
/** /**
...@@ -381,8 +401,7 @@ class ChatService ...@@ -381,8 +401,7 @@ class ChatService
$params["last_login_time"] = date("Y-m-d H:i:s", time()); $params["last_login_time"] = date("Y-m-d H:i:s", time());
$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());
$this->chatUserModel->addChatUser($params); return $this->chatUserModel->addChatUser($params);
return true;
} }
......
...@@ -35,12 +35,13 @@ class ChatUser extends Model ...@@ -35,12 +35,13 @@ class ChatUser extends Model
{ {
Db::startTrans(); Db::startTrans();
try { try {
$this->save($params); $res = $this->save($params);
Db::commit(); Db::commit();
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
$res = 0;
} }
return $res;
} }
} }
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: fuju
* Date: 2018/7/7
* Time: 11:28
*/
namespace app\model;
class ChatUserExt extends BaseModel
{
// 设置当前模型对应的完整数据表名称
protected $table = 'chat_user_ext';
protected $db;
public function __construct()
{
$this->db = Db($this->table);
}
/**
* @param $params
* @param string $field
* @return mixed
* @throws \think\Exception
* @throws \think\exception\DbException
*/
public function getChatUserExt($params, $field = "id,ext_id,push_id,is_forbidden")
{
$where_ = [];
if (isset($params['is_forbidden'])) {
$where_['is_forbidden'] = $params['is_forbidden'];
} else {
$where_['is_forbidden'] = 0;
}
if (isset($params['ext_id'])) {
$where_['ext_id'] = $params['ext_id'];
}
$data = $this->db->field($field)
->where($where_)
->select();
return $data;
}
/**
* @param $params
* @return false|int
*/
public function addChatUserExt($params)
{
Db::startTrans();
try {
$res = $this->save($params);
Db::commit();
} catch (\Exception $e) {
Db::rollback();
$res = 0;
}
return $res;
}
}
\ 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