Commit 5c8bf6e9 authored by clone's avatar clone

默认城市

parent 4a7eb351
<?php
namespace app\api_broker\controller;
use app\api_broker\extend\Basic;
use app\extra\RedisExt;
use think\Request;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/8/7
* Time : 11:31
* Intro:
*/
class Location extends Basic
{
private $redis_;
const CITY_AGENTS = "agent_city_";
public function __construct($request = null)
{
parent::__construct($request);
$this->redis_ = RedisExt::getRedis();
}
public function saveSiteCity()
{
$params = $this->params;
/* $params = array(
"agent_id" => 1,
"city" => "上海"
);*/
$checkResult = $this->validate($params, "LocationValidate.saveSiteCityVerify");
if (true !== $checkResult) {
return $this->response("101", $checkResult);
}
$city = "上海";
$agent_id = $params["agent_id"];
if ($params["city"] == "杭州") {
$city = "杭州";
}
$this->redis_->set(self::CITY_AGENTS . $agent_id, $city);
}
}
\ No newline at end of file
......@@ -9,6 +9,7 @@ namespace app\api_broker\extend;
* Time: 9:35
* 基类
*/
use app\extra\RedisExt;
use app\model\AAgents;
use app\model\GOperatingRecords;
use UnexpectedValueException;
......@@ -25,9 +26,8 @@ class Basic extends Controller
* @var Request
*/
public $request;
public $params;
public $city;
protected $authToken;
/**
......@@ -65,6 +65,7 @@ class Basic extends Controller
*/
public function __construct(Request $request = null)
{
// CORS 跨域 Options 检测响应
$this->corsOptionsHandler();
// 输入对象
......@@ -76,7 +77,6 @@ class Basic extends Controller
$this->params = $this->request->param() != null ? $this->request->param() : null;
}
if (isset($this->params['AuthToken']) && $this->params['AuthToken'] != 'null' && !empty($this->params['AuthToken'])) {
$jwt = new \Firebase\JWT\JWT();
......@@ -96,6 +96,9 @@ class Basic extends Controller
$this->agentName = isset($result->data->name) ? $result->data->name : "";
$this->timeStamp_ = $result->timeStamp_;
}
//获取默认城市
$this->getCity($this->agentId);
$requestPath = $this->request->routeInfo()["rule"][0] . "/" . $this->request->routeInfo()["rule"][1];
//过滤掉不需要验证token的接口
if (!in_array(trim($requestPath), $this->filterVerify)) {
......@@ -105,6 +108,20 @@ class Basic extends Controller
unset($this->params["AuthToken"]);
}
/**
* 默认城市选择
* @param $agentId
*/
public function getCity($agentId){
$redis_ = RedisExt::getRedis();
if($redis_){
$this->city = $redis_->get("agent_city_".$agentId);
}else{
$this->city = "上海";
}
}
/**
* token 验证
*/
......
<?php
namespace app\api_broker\validate;
use think\Validate;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/8/7
* Time : 13:17
* Intro:
*/
class LocationValidate extends Validate
{
protected $rule = [
'city' => 'require',
'agent_id' => 'require|number',
];
protected $message = [
'city.require' => 'city为必填字段',
'agent_id.require' => '经纪人id为必填字段',
'agent_id.number' => '经纪人id只能为数字',
];
protected $scene = [
'saveSiteCityVerify' => [ 'city', 'agent_id' ],
];
}
\ No newline at end of file
......@@ -536,6 +536,9 @@ Route::group('broker', [
'getCollectHouseList' => [ 'api_broker/CollectHouse/getCollectHouseList', [ 'method' => 'POST|GET' ] ], //查询收藏数据 朱伟 2018-07-04
'saveSiteCity' => [ 'api_broker/Location/saveSiteCity', [ 'method' => 'POST|GET' ] ], //保存默认城市选择
]);
//Route::miss('api/index/miss');//处理错误的url
\ 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