Commit 2dd72272 authored by clone's avatar clone

app绑定逻辑判断放到service

parent 2230b89b
...@@ -13,6 +13,7 @@ use app\api\untils\GenerateCodeUntils; ...@@ -13,6 +13,7 @@ use app\api\untils\GenerateCodeUntils;
use app\api\untils\JwtUntils; use app\api\untils\JwtUntils;
use app\api\untils\MessageUntils; use app\api\untils\MessageUntils;
use app\api_broker\extend\Basic; use app\api_broker\extend\Basic;
use app\api_broker\service\BrokerService;
use app\api_broker\service\OrderLogService; use app\api_broker\service\OrderLogService;
use app\model\AAgents; use app\model\AAgents;
use app\model\ABindingDevice; use app\model\ABindingDevice;
...@@ -28,12 +29,14 @@ class Broker extends Basic ...@@ -28,12 +29,14 @@ class Broker extends Basic
{ {
protected $a_agents; protected $a_agents;
protected $aBD; protected $aBD;
protected $brokerService;
public function __construct(Request $request = null) public function __construct(Request $request = null)
{ {
parent::__construct($request); parent::__construct($request);
$this->a_agents = new AAgents(); $this->a_agents = new AAgents();
$this->aBD = new ABindingDevice(); $this->aBD = new ABindingDevice();
$this->brokerService = new BrokerService();
} }
/** /**
...@@ -138,7 +141,7 @@ class Broker extends Basic ...@@ -138,7 +141,7 @@ class Broker extends Basic
return $this->response(101, '密码错误'); return $this->response(101, '密码错误');
} }
//判断设备id是否存在 //判断设备id是否存在
$is_login = $this->judgeBand($params["device_id"], $agents_data['id'], $params["model"], 0, $params["push_id"]); $is_login = $this->brokerService->judgeBand($params["device_id"], $agents_data['id'], $params["model"], 0, $params["push_id"]);
if (!$is_login) { if (!$is_login) {
return $this->response("102", "该账号没有绑定该手机,请致电人事进行绑定。"); return $this->response("102", "该账号没有绑定该手机,请致电人事进行绑定。");
} }
...@@ -181,7 +184,7 @@ class Broker extends Basic ...@@ -181,7 +184,7 @@ class Broker extends Basic
return $this->response("101", $checkResult); return $this->response("101", $checkResult);
} }
$is_visit = $this->judgeBand($params["device_id"], $params["agent_id"], "", 1, ""); $is_visit = $this->brokerService->judgeBand($params["device_id"], $params["agent_id"], "", 1, "");
if ($is_visit) { if ($is_visit) {
return $this->response("200", "success", []); return $this->response("200", "success", []);
} else { } else {
...@@ -189,57 +192,6 @@ class Broker extends Basic ...@@ -189,57 +192,6 @@ class Broker extends Basic
} }
} }
/**
* 判断设备绑定关系
* @param string $device_id
* @param int $agent_id
* @param string $model
* @param int $type 0提交记录到后台, 1仅仅判断
* @param string $push_id
* @return bool
*/
private function judgeBand(string $device_id, int $agent_id, string $model, int $type, string $push_id): bool
{
$params["agent_id"] = $agent_id;
$result = $this->aBD->getDeviceByAgentId($params);
if (count($result) <= 0) {
//新增设备绑定关系 默认直接登陆
if ($type == 0)
$this->aBD->addDevice([ "device_id" => $device_id,
"agent_id" => $agent_id,
"model" => $model,
"push_id" => $push_id,
"is_forbidden" => 0 ]);
return true;
}
$is_exits = false;
foreach ($result as $item) {
if ($device_id == $item["device_id"]) {
//当个推返回的id改变时则更新记录
if (!empty($push_id) && $push_id != $item["push_id"]){
$this->aBD->updateDevice([ "id" => $item["id"], "push_id" => $push_id ]);
}
if ($item["is_forbidden"] == 0) {
return true;
} elseif ($item["is_forbidden"] == 1) { //已存在申请关系
$is_exits = true;
}
}
}
if (!$is_exits && $type == 0)
//新增申请绑定关系,需要后台同意登陆
$this->aBD->addDevice([ "device_id" => $device_id,
"agent_id" => $agent_id,
"model" => $model,
"push_id" => $push_id,
"is_forbidden" => 1 ]);
return false;
}
/** /**
* 绑定或者解绑 * 绑定或者解绑
* @return \think\Response * @return \think\Response
...@@ -417,7 +369,6 @@ class Broker extends Basic ...@@ -417,7 +369,6 @@ class Broker extends Basic
} }
/** /**
* 客户动态展示加搜索加客户详情 * 客户动态展示加搜索加客户详情
* *
...@@ -465,7 +416,7 @@ class Broker extends Basic ...@@ -465,7 +416,7 @@ class Broker extends Basic
}*/ }*/
$user = new Users(); $user = new Users();
$user_res = $user->useraction_search_user_res($user_id,1); $user_res = $user->useraction_search_user_res($user_id, 1);
$user_res['user_pic'] = HEADERIMGURL . $user_res['user_pic']; $user_res['user_pic'] = HEADERIMGURL . $user_res['user_pic'];
...@@ -483,12 +434,12 @@ class Broker extends Basic ...@@ -483,12 +434,12 @@ class Broker extends Basic
//是否被收藏 //是否被收藏
$data["is_collect"] = 2; $data["is_collect"] = 2;
//先判断是否已经存在数据 //先判断是否已经存在数据
$field = 'id,status'; $field = 'id,status';
$get_params['agents_id'] = $params["agent_id"]; $get_params['agents_id'] = $params["agent_id"];
$get_params['user_id'] = $params["user_id"]; $get_params['user_id'] = $params["user_id"];
$collect_house = new ACollectUser(); $collect_house = new ACollectUser();
$res = $collect_house->getCollectUser($field,$get_params); $res = $collect_house->getCollectUser($field, $get_params);
if($res && ($res[0]['status'] == 1)){//如果存在 if ($res && ($res[0]['status'] == 1)) {//如果存在
$data["is_collect"] = 1; $data["is_collect"] = 1;
} }
return $this->response("200", "success!", $data); return $this->response("200", "success!", $data);
......
<?php
namespace app\api_broker\service;
use app\model\ABindingDevice;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/7/18
* Time : 18:37
* Intro:
*/
class BrokerService
{
protected $aBD;
public function __construct()
{
$this->aBD = new ABindingDevice();
}
/**
* 判断设备绑定关系
* @param string $device_id
* @param int $agent_id
* @param string $model
* @param int $type 0提交记录到后台, 1仅仅判断
* @param string $push_id
* @return bool
*/
public function judgeBand(string $device_id, int $agent_id, string $model, int $type, string $push_id): bool
{
$params["agent_id"] = $agent_id;
$result = $this->aBD->getDeviceByAgentId($params);
if (count($result) <= 0) {
//新增设备绑定关系 默认直接登陆
if ($type == 0)
$this->aBD->addDevice([ "device_id" => $device_id,
"agent_id" => $agent_id,
"model" => $model,
"push_id" => $push_id,
"is_forbidden" => 0 ]);
return true;
}
$is_exits = false;
foreach ($result as $item) {
if ($device_id == $item["device_id"]) {
//当个推返回的id改变时则更新记录
if (!empty($push_id) && $push_id != $item["push_id"]) {
$this->aBD->updateDevice([ "id" => $item["id"], "push_id" => $push_id ]);
}
if ($item["is_forbidden"] == 0) {
return true;
} elseif ($item["is_forbidden"] == 1) { //已存在申请关系
$is_exits = true;
}
}
}
if (!$is_exits && $type == 0)
//新增申请绑定关系,需要后台同意登陆
$this->aBD->addDevice([ "device_id" => $device_id,
"agent_id" => $agent_id,
"model" => $model,
"push_id" => $push_id,
"is_forbidden" => 1 ]);
return false;
}
}
\ No newline at end of file
...@@ -127,6 +127,11 @@ class Login extends Basic ...@@ -127,6 +127,11 @@ class Login extends Basic
return ; return ;
} }
public function userVerify(){
//todo
}
/** /**
* 退出 * 退出
* *
......
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