Commit fdb7c606 authored by clone's avatar clone

bug

parent c54d990c
<?php
namespace app\api\controller;
use app\api\extend\Basic;
use app\extra\RedisExt;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/8/13
* Time : 11:31
* Intro:
*/
class Location extends Basic
{
private $redis_;
const CITY_USER = "user_city_";
public function __construct($request = null)
{
parent::__construct($request);
$this->redis_ = RedisExt::getRedis();
}
public function saveSiteCity()
{
$params = $this->params;
/* $params = array(
"user_id" => 1,
"city" => "上海市"
);*/
$checkResult = $this->validate($params, "RegisterValidate.saveSiteCityVerify");
if (true !== $checkResult) {
return $this->response("101", $checkResult);
}
$city = "上海市";
$user_id = $params["user_id"];
if ($params["city"] == "杭州市" || $params["city"] == "杭州") {
$city = "杭州市";
}
if ($this->redis_) {
$this->redis_->set(self::CITY_USER . $user_id, $city);
} else {
return $this->response("101", "redis service not found");
}
return $this->response("200", "success", []);
}
}
\ No newline at end of file
This diff is collapsed.
...@@ -9,8 +9,10 @@ namespace app\api\extend; ...@@ -9,8 +9,10 @@ namespace app\api\extend;
* Time: 9:35 * Time: 9:35
* 基类 * 基类
*/ */
use app\extra\RedisExt;
use app\model\Users; use app\model\Users;
use think\Controller; use think\Controller;
use think\Exception;
use think\Request; use think\Request;
use think\Response; use think\Response;
use Qiniu; use Qiniu;
...@@ -27,6 +29,8 @@ class Basic extends Controller ...@@ -27,6 +29,8 @@ class Basic extends Controller
public $params; public $params;
public $user_city;
protected $authToken; protected $authToken;
/** /**
...@@ -97,7 +101,7 @@ class Basic extends Controller ...@@ -97,7 +101,7 @@ class Basic extends Controller
$this->userNick = isset($result->data->userNick) ? $result->data->userNick : ""; $this->userNick = isset($result->data->userNick) ? $result->data->userNick : "";
$this->timeStamp_ = $result->timeStamp_; $this->timeStamp_ = $result->timeStamp_;
} }
$this->getCity($this->userId);
$requestPath = $this->request->routeInfo()["rule"][0] . "/" . $this->request->routeInfo()["rule"][1]; $requestPath = $this->request->routeInfo()["rule"][0] . "/" . $this->request->routeInfo()["rule"][1];
//过滤掉不需要验证token的接口 //过滤掉不需要验证token的接口
if (!in_array(trim($requestPath), $this->filterVerify)) { if (!in_array(trim($requestPath), $this->filterVerify)) {
...@@ -105,6 +109,27 @@ class Basic extends Controller ...@@ -105,6 +109,27 @@ class Basic extends Controller
} }
} }
/**
* 默认城市选择
* @param $agentId
*/
public function getCity($userId)
{
try {
$redis_ = RedisExt::getRedis();
if ($redis_) {
$city = $redis_->get("user_city_" . $userId);
$this->user_city = empty($city) ? "上海市" : $city;
} else {
$this->user_city = "上海市";
}
} catch (Exception $exception) {
$this->user_city = "上海市";
}
}
/** /**
* token 验证 * token 验证
*/ */
......
...@@ -20,6 +20,7 @@ class RegisterValidate extends Validate ...@@ -20,6 +20,7 @@ class RegisterValidate extends Validate
'code' => 'require|number', 'code' => 'require|number',
'device_id' => 'require', 'device_id' => 'require',
'phone' => [ 'regex' => '/^((13[0-9])|(14[0-9])|(15[0-9])|(18[0-9])|(16[0-9])|(17[0-9])|(19[0-9]))\\d{8}$/i' ], 'phone' => [ 'regex' => '/^((13[0-9])|(14[0-9])|(15[0-9])|(18[0-9])|(16[0-9])|(17[0-9])|(19[0-9]))\\d{8}$/i' ],
'city' => 'require',
]; ];
protected $message = [ protected $message = [
...@@ -32,13 +33,15 @@ class RegisterValidate extends Validate ...@@ -32,13 +33,15 @@ class RegisterValidate extends Validate
'phone.regex' => '手机号格式不正确', 'phone.regex' => '手机号格式不正确',
'device_id.require' => '设备id不能为空', 'device_id.require' => '设备id不能为空',
'code.require' => 'code为必填字段', 'code.require' => 'code为必填字段',
'code.number' => 'code只能为数字' 'code.number' => 'code只能为数字',
'city.require' => 'city为必填字段',
]; ];
protected $scene = [ protected $scene = [
'verify' => [ 'phone', 'device_id' ], 'verify' => [ 'phone', 'device_id' ],
'register' => [ 'phone', 'device_id', 'code' ], 'register' => [ 'phone', 'device_id', 'code' ],
'removeBind' => [ 'user_id', 'buyer_id' ], 'removeBind' => [ 'user_id', 'buyer_id' ],
'bind' => [ 'wx_union_id','phone' ], 'bind' => [ 'wx_union_id', 'phone' ],
'saveSiteCityVerify' => [ 'user_id', 'city' ],
]; ];
} }
\ No newline at end of file
This diff is collapsed.
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