Commit b9180d50 authored by clone's avatar clone

手机号绑定限制

parent 79fb0406
......@@ -15,6 +15,7 @@ use app\api\untils\MessageUntils;
use app\api_broker\extend\Basic;
use app\api_broker\service\OrderLogService;
use app\model\AAgents;
use app\model\ABindingDevice;
use app\model\GOperatingRecords;
use app\model\NoteLog;
use app\model\UPhoneFollowPp;
......@@ -33,7 +34,7 @@ class Broker extends Basic
/**
* 经纪人登录
*
* 废弃by zw0702
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
......@@ -91,6 +92,108 @@ class Broker extends Basic
return $this->response(200, $data['msg'], $data['data']);
}
/**
* 经纪人登录
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function loginV2()
{
$params = $this->params;
/*$params = array(
"phone" => "15002102357",
"pwd" => "123456",
"device_id" => "qweqweqweqweqw123123",
"model" => "iphone7",//手机型号
);*/
$checkResult = $this->validate($params, "PerformanceValidate.login");
if (true !== $checkResult) {
return $this->response("101", $checkResult);
}
$field = 'id,store_id,auth_group_id,district_id,level,name,phone,password,sex,img,inviter_id,status';
$where['phone'] = $params['phone'];
$where['id'] = [ '<>', 1 ];
$agents_data = $this->a_agents->getAgentInfo($field, '', $where);
if (count($agents_data) <= 0) {
return $this->response(101, '没有该用户');
}
if ($agents_data['status'] == 2) {
return $this->response(101, '您已离职');
}
if ($agents_data['status'] == 1) {
return $this->response(101, '账号已冻结');
}
if ($agents_data['password'] != md5($this->params['pwd'])) {
return $this->response(101, '密码错误');
}
//判断设备id是否存在
$is_login = $this->judgeBand($params["device_id"], $agents_data['id'], $params["model"]);
if (!$is_login) {
return $this->response("101", "该账号没有绑定该手机,请致电人事进行绑定。");
}
$agents_data['last_login_ip'] = ip2long($this->request->ip());
$agents_data['last_login_time'] = date('Y-m-d H:i:s');
$agents_data->allowField(true)->save();
if (!empty($agents_data['img'])) {
$agents_data['img'] = AGENTHEADERIMGURL . $agents_data->img;
}
$jwt_data['id'] = $agents_data['id'];
$jwt_data['name'] = $agents_data['name'];
$jwt_data['phone'] = $agents_data['phone'];
$jwt_data['level'] = $agents_data['level'];
$jwt = new JwtUntils();
$data['data'] = $agents_data->getData();
$data['data']['last_login_ip'] = long2ip($data['data']['last_login_ip']);
$data['data']['AuthToken'] = $jwt->createToken($jwt_data);
$data['msg'] = '登陆成功';
return $this->response(200, $data['msg'], $data['data']);
}
/**
* 判断设备绑定关系
* @param string $device_id
* @param int $agent_id
* @param string $model
* @return bool
*/
private function judgeBand(string $device_id, int $agent_id, string $model): bool
{
//todo 查询是否绑定过设备id,if没有绑定则直接登陆新增绑定关系,if有绑定,则判断登陆的设备id是否存在于关系列表中,存在并且状态正常则登陆,
//todo 否则提示联系管理员开通
$aBD = new ABindingDevice();
$params["agent_id"] = $agent_id;
$result = $aBD->getDeviceByAgentId($params);
if (count($result) <= 0) {
//新增设备绑定关系
$aBD->addDevice([ "device_id" => $device_id, "agent_id" => $agent_id, "model" => $model, "is_forbidden" => 0 ]);
return true;
}
foreach ($result as $item) {
if ($device_id == $item["device_id"] && $item["is_forbidden"] == 0) {
return true;
}
}
//新增申请绑定关系
$aBD->addDevice([ "device_id" => $device_id, "agent_id" => $agent_id, "model" => $model, "is_forbidden" => 1 ]);
return false;
}
/**
* 获取经纪人列表
*
......
......@@ -39,6 +39,7 @@ class Basic extends Controller
protected $timeStamp_;
protected $filterVerify = array(
'broker/login',
'broker/loginV2',
'broker/token',
'broker/getShopList',
'broker/getShopDetail',
......
......@@ -14,19 +14,28 @@ use think\Validate;
class PerformanceValidate extends Validate
{
protected $rule = [
'type' => 'require|number',
'agent_id' => 'require|number',
'type' => 'require|number',
'agent_id' => 'require|number',
'phone' => 'require|number',
'pwd' => 'require|min:6',
'device_id' => 'require',
];
protected $message = [
'type.require' => 'type为必填字段',
'type.number' => 'type只能为数字',
'agent_id.require' => 'agent_id为必填字段',
'agent_id.number' => 'agent_id只能为数字',
'type.require' => 'type为必填字段',
'type.number' => 'type只能为数字',
'agent_id.require' => 'agent_id为必填字段',
'agent_id.number' => 'agent_id只能为数字',
'phone.require' => '手机号不能为空',
'phone.number' => '手机号输入错误',
'pwd.require' => '密码不能为空',
'pwd.min' => '密码小于6位',
'device_id.require' => '设备号获取失败,请联系管理员',
];
protected $scene = [
'verify' => [ 'type', 'agent_id' ],
'verifyOther' => [ 'agent_id' ],
'verify' => [ 'type', 'agent_id' ],
'verifyOther' => [ 'agent_id' ],
'login' => [ 'phone', 'pwd', 'device_id' ],
];
}
\ No newline at end of file
......@@ -631,9 +631,11 @@ class AAgents extends BaseModel
} else {
$where = $params;
}
return $this->field($field)
$result = $this->field($field)
->where($where)
->find();
//echo $this->getLastSql();
return $result;
}
/**
......
<?php
namespace app\model;
use think\Db;
use think\Exception;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/7/2
* Time : 11:31
* Intro:
*/
class ABindingDevice extends BaseModel
{
protected $table = 'a_binding_device';
/**
* @param array $params
* @return int
* @throws \Exception
*/
public function addDevice(array $params): int
{
$bandBin = $this->deviceBin($params);
Db::startTrans();
try {
$id = $this->insertGetId($bandBin);
Db::commit();
return $id;
} catch (Exception $exception) {
Db::rollback();
throw $exception;
}
}
/**
* 修改绑定的设备id
* @param array $params
* @return int
* @throws Exception
*/
public function updateDevice(array $params): int
{
$bandBin = $this->deviceBin($params);
Db::startTrans();
try {
$this->update($bandBin);
Db::commit();
return $params["id"];
} catch (Exception $exception) {
Db::rollback();
throw $exception;
}
}
/**
* 根据经纪人id获取绑定过的设备id
* @param array $params
* @param string $field
* @return false|\PDOStatement|string|\think\Collection
*/
public function getDeviceByAgentId(array $params, string $field = "id,agent_id,device_id,is_forbidden")
{
$where_ = [];
if(isset($params["agent_id"])){
$where_["agent_id"] = $params["agent_id"];
}
if(isset($params["device_id"])){
$where_["device_id"] = $params["device_id"];
}
if(isset($params["is_forbidden"])){
$where_["is_forbidden"] = $params["is_forbidden"];
}
return $this
->field($field)
->where($where_)
->order("create_time desc")
->select();
}
/**
* bin
* @param $params
* @return array
*/
private function deviceBin($params)
{
$arr = [];
if (isset($params["id"])) {
$arr["id"] = $params["id"];
} else {
$arr["create_time"] = date("Y-m-d H:i:s", time());
}
if (isset($params["agent_id"])) {
$arr["agent_id"] = $params["agent_id"];
}
if (isset($params["device_id"])) {
$arr["device_id"] = $params["device_id"];
}
if (isset($params["model"])) {
$arr["model"] = $params["model"];
}
if (isset($params["is_forbidden"])) {
$arr["is_forbidden"] = $params["is_forbidden"];
}
$arr["update_time"] = date("Y-m-d H:i:s", time());
return $arr;
}
}
......@@ -373,7 +373,8 @@ Route::group('broker', [
'statusBargain' => [ 'api_broker/OrderLog/statusBargain', [ 'method' => 'get|post' ] ],
'getIsAccountStatement' => [ 'api_broker/OrderLog/getIsAccountStatement', [ 'method' => 'get|post' ] ],
'login' => [ 'api_broker/Broker/login', [ 'method' => 'post' ] ], //经纪人登陆
'login' => [ 'api_broker/Broker/login', [ 'method' => 'post' ] ], //经纪人登陆 废弃
'loginV2' => [ 'api_broker/Broker/loginV2', [ 'method' => 'post|get' ] ], //经纪人登陆
'editAgent' => [ 'api_broker/Broker/editAgent', [ 'method' => 'post' ] ], //经纪人修改密码
'forgetPwd' => [ 'api_broker/Broker/forgetPwd', [ 'method' => 'post' ] ], //经纪人忘记密码
'uploadHeadImg' => [ 'api_broker/Broker/uploadHeadImg', [ 'method' => 'post' ] ], //经纪人上传头像
......
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