Commit eda14bde by 朱继来

Merge branch 'zjl_export_20191209'

parents e8f4edcc bbec3030
...@@ -3,6 +3,8 @@ namespace App\Http\Controllers; ...@@ -3,6 +3,8 @@ namespace App\Http\Controllers;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use DB; use DB;
use Illuminate\Support\Facades\Redis as Redis;
use App\Model\RegionModel;
class RegionController extends Controller class RegionController extends Controller
{ {
...@@ -38,11 +40,47 @@ class RegionController extends Controller ...@@ -38,11 +40,47 @@ class RegionController extends Controller
); );
} }
//获取省市县名称 //获取省市县名称
public function getRegionName($region_id){ public function getRegionName($region_id)
{
if (empty($region_id)){ if (empty($region_id)){
return ""; return "";
} }
$list = DB::connection('order')->table('lie_region')->select("region_name")->where("region_id",$region_id)->get(); $list = DB::connection('order')->table('lie_region')->select("region_name")->where("region_id",$region_id)->get();
return !$list ? "" : current(objectToArray($list))['region_name']; return !$list ? "" : current(objectToArray($list))['region_name'];
} }
// 初始化地址缓存
public function cache()
{
$RegionModel = new RegionModel();
$province = $RegionModel->getRegion(1); // 获取省
S_str('oms:province', json_encode($province));
$city = $RegionModel->getRegion(2); // 获取城市
foreach($city as $c) {
S_hash('oms:city:'.$c['parent_id'], $c['region_id'], json_encode($c));
}
$district = $RegionModel->getRegion(3); // 获取区
foreach($district as $d) {
S_hash('oms:district:'.$d['parent_id'], $d['region_id'], json_encode($d));
}
echo '设置地址缓存成功';
}
// 清除缓存
public function clear()
{
Redis::del('oms:province');
Redis::del(Redis::keys('oms:city:*'));
Redis::del(Redis::keys('oms:district:*'));
echo '清除地址缓存成功';
}
} }
\ No newline at end of file
...@@ -444,4 +444,42 @@ function Autograph(){ ...@@ -444,4 +444,42 @@ function Autograph(){
// // Session::forget($token); // 验证完毕后删除token // // Session::forget($token); // 验证完毕后删除token
// // return true; // // return true;
// } // }
\ No newline at end of file
// 读取Redis缓存
function S_str($key, $value='')
{
static $redis = null;
if ($redis == null) $redis = new \App\Model\RedisModel();
if ($value === '') return json_decode($redis->get($key), true);
return $redis->set($key, $value);
}
function S_hash($key, $field='', $value='')
{
static $redis = null;
if ($redis == null) $redis = new \App\Model\RedisModel();
if ($value === '') {
$data = $field === '' ? $redis->hgetAll($key) : $redis->hget($key, $field);
$datas = [];
if (is_array($data)) {
foreach ($data as $v) {
$datas[] = json_decode($v, true);
}
} else {
$datas = json_decode($data, true);
}
return $datas;
}
return $redis->hset($key, $field, $value);
}
\ No newline at end of file
...@@ -39,9 +39,10 @@ class CheckLogin ...@@ -39,9 +39,10 @@ class CheckLogin
$cookie = 'oa_user_id=' . $userId . '; oa_skey=' . $skey; $cookie = 'oa_user_id=' . $userId . '; oa_skey=' . $skey;
$client = new \GuzzleHttp\Client(); $client = new \GuzzleHttp\Client();
$rsp = $client->request('GET', $login['check'], [ $rsp = $client->request('GET', $login['check'], [
'headers' => ['Cookie' => $cookie], 'headers' => ['Cookie' => $cookie],
'connect_timeout' => 1, 'connect_timeout' => 1,
'timeout' => 3 'timeout' => 10,
'verify' => false,
]); ]);
if ($rsp->getStatusCode() != 200) { if ($rsp->getStatusCode() != 200) {
......
...@@ -54,6 +54,8 @@ Route::group(['middleware' => 'web'], function () { ...@@ -54,6 +54,8 @@ Route::group(['middleware' => 'web'], function () {
Route::match(['get', 'post'], '/changeShipping/{id?}', 'OrderController@changeShipping'); Route::match(['get', 'post'], '/changeShipping/{id?}', 'OrderController@changeShipping');
Route::post('/region/getAll', 'RegionController@getAll'); Route::post('/region/getAll', 'RegionController@getAll');
Route::get('/region/cache', 'RegionController@cache');
Route::get('/region/clear', 'RegionController@clear');
Route::match(['get', 'post'], '/changeInvoice/{id?}', 'OrderController@changeInvoice'); Route::match(['get', 'post'], '/changeInvoice/{id?}', 'OrderController@changeInvoice');
......
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class OrderAddressModel extends Model
{
protected $connection = 'order';
protected $table = 'lie_order_address';
protected $primaryKey = 'order_address_id';
public $timestamps = false;
}
\ No newline at end of file
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class OrderShippingModel extends Model
{
protected $connection = 'order';
protected $table = 'lie_order_shipping';
protected $primaryKey = 'order_shipping_id';
public $timestamps = false;
}
\ No newline at end of file
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class RegionModel extends Model
{
protected $connection = 'order';
protected $table = 'lie_region';
protected $primaryKey = 'region_id';
public $timestamps = false;
// 获取地址
public function getRegion($region_type=1)
{
$map['region_type'] = $region_type;
return $this->where($map)->select('region_id', 'parent_id', 'region_name')->get()->toArray();
}
}
\ 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 sign in to comment