Commit bdc525c9 authored by zhuwei's avatar zhuwei

批量设置商圈的经纬度

parent c141c95d
<?php
namespace app\index\controller;
use app\index\extend\Basic;
use app\model\GBusinessDistrict;
use think\Log;
/**
* 批量处理控制器(数据库一些数据需要批量处理下)
* Class BatchProcessing
* @package app\index\controller
*/
class BatchProcessing extends Basic
{
public function __construct($request = null)
{
parent::__construct($request);
}
/**
* 批量设置商圈的经纬度
*/
public function getCityLatAadLng(){
$model = new GBusinessDistrict();
$field = 'id,name,city';
$get_params = '';
$model_res = $model->getBusinessDistrict($field, $get_params);
$success_num = 0;
$fail = 0;
foreach ($model_res as $key => $v) {
//dump($v['name']);
//dump($v['city']);
$id = $v['id'];
$address = $v['name'];
$city = $v['city'];
$res = $this->getLatLng($address, $city);
if($res){
$success_num ++;
$longitude = $res['lng'];//'经度'
$latitude = $res['lat'];//'维度'
}else{
$fail ++;
$longitude = '';//'经度'
$latitude = '';//'维度'
$log_text = '商圈:'.$v['name'].' 城市: '.$v['city'].' 数据库ID: '.$id;
Log::write($log_text, '获取商圈经纬度-失败'); //记录日志
}
$insert=[];
$insert["id"] = $id;
$insert["longitude"] = $longitude;
$insert["latitude"] = $latitude;
$res = $model->updateBusinessDistrict($insert);//int(1)
$log_text = '商圈:'.$v['name'].' 城市: '.$v['city'].' 经度: '.$longitude.' 纬度: '.$latitude.' 数据库写入返回值: '.$res;
Log::write($log_text, '获取商圈经纬度'); //记录日志
}
return $this->response("200", "处理完成",['成功数'=>$success_num,'失败数'=>$fail]);
}
/**
* @param string $address 地址
* @param string $city 城市名
* @return array
*/
function getLatLng($address='',$city='')
{
$result = array();
$ak = 'eqkGg4WQehHn4k7ssWZTv8RPvydUm35s';//您的百度地图ak,可以去百度开发者中心去免费申请
$url ="http://api.map.baidu.com/geocoder/v2/?callback=renderOption&output=json&address=".$address."&city=".$city."&ak=".$ak;
$data = file_get_contents($url);
$data = str_replace('renderOption&&renderOption(', '', $data);
$data = str_replace(')', '', $data);
$data = json_decode($data,true);
if (!empty($data) && $data['status'] == 0) {
$result['lat'] = $data['result']['location']['lat'];
$result['lng'] = $data['result']['location']['lng'];
return $result;//返回经纬度结果
}else{
return null;
}
}
}
...@@ -5,7 +5,9 @@ namespace app\index\controller; ...@@ -5,7 +5,9 @@ namespace app\index\controller;
use app\index\extend\Basic; use app\index\extend\Basic;
use app\index\service\ImageDepotService; use app\index\service\ImageDepotService;
use app\index\service\UserService; use app\index\service\UserService;
use app\model\GBusinessDistrict;
use app\model\GImageDepot; use app\model\GImageDepot;
use think\Log;
/** /**
* zhuwei * zhuwei
...@@ -177,14 +179,12 @@ class ImageDepot extends Basic ...@@ -177,14 +179,12 @@ class ImageDepot extends Basic
$user_service = new UserService(); $user_service = new UserService();
$is_outstrip_twenty_four_hours = $user_service->isUserProtect(1); $is_outstrip_twenty_four_hours = $user_service->isUserProtect(1);
dump($is_outstrip_twenty_four_hours); dump($is_outstrip_twenty_four_hours);
if($is_outstrip_twenty_four_hours == 0){ if ($is_outstrip_twenty_four_hours == 0) {
dump('保护器内'); dump('保护器内');
}else{ } else {
dump('超过保护期'); dump('超过保护期');
} }
} }
} }
...@@ -7,4 +7,31 @@ use think\Model; ...@@ -7,4 +7,31 @@ use think\Model;
class GBusinessDistrict extends BaseModel class GBusinessDistrict extends BaseModel
{ {
protected $table = 'g_business_district'; protected $table = 'g_business_district';
/**
* 查询数据
* 朱伟 2018-10-17 14:58:36
*/
public function getBusinessDistrict($field,$params)
{
$result = $this
->field($field)
//->alias('a')
->where($params)
->select();
//dump($this->getLastSql());
return $result;
}
/**
* 更新数据
* 朱伟 2018-10-17 14:58:36
*/
public function updateBusinessDistrict($params)
{
$result = $this->update($params);
//dump($this->getLastSql());
return $result;
}
} }
...@@ -330,6 +330,10 @@ Route::group('index', [ ...@@ -330,6 +330,10 @@ Route::group('index', [
'getPerformanceReportList' => [ 'index/PerformanceReport/getPerformanceReportList', [ 'method' => 'get | post' ] ], 'getPerformanceReportList' => [ 'index/PerformanceReport/getPerformanceReportList', [ 'method' => 'get | post' ] ],
'delPerformanceReport' => [ 'index/PerformanceReport/delPerformanceReport', [ 'method' => 'get | post' ] ],//删除 'delPerformanceReport' => [ 'index/PerformanceReport/delPerformanceReport', [ 'method' => 'get | post' ] ],//删除
//批量处理控制器
'getCityLatAadLng' => [ 'index/BatchProcessing/getCityLatAadLng', [ 'method' => 'get | 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