sth
This commit is contained in:
parent
2b8cb7150b
commit
bf418b8e3a
|
|
@ -194,4 +194,51 @@ if (!function_exists('build_heading')) {
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function getLocation($address){
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 百度地图 API 的 URL 和 API Key
|
||||||
|
$apiKey = config('map.baidu_app_key'); // 替换为您的 API Key
|
||||||
|
|
||||||
|
// 构建请求 URL
|
||||||
|
$url = "http://api.map.baidu.com/geocoding/v3/?address=" . urlencode($address) . "&output=json&ak=" . $apiKey;
|
||||||
|
|
||||||
|
// 使用 cURL 请求接口
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
$response = curl_exec($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
// 解析返回的 JSON 数据
|
||||||
|
$data = json_decode($response, true);
|
||||||
|
|
||||||
|
// 获取经纬度
|
||||||
|
if ($data['status'] == 0) {
|
||||||
|
$latitude = $data['result']['location']['lat']; // 纬度
|
||||||
|
$longitude = $data['result']['location']['lng']; // 经度
|
||||||
|
|
||||||
|
|
||||||
|
return [
|
||||||
|
'lat' => $latitude,
|
||||||
|
'lng' => $longitude,
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
return [];
|
||||||
|
//echo "地址解析失败: " . $data['msg'] . "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch (Exception $exception){
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace app\admin\controller\workers;
|
namespace app\admin\controller\workers;
|
||||||
|
|
||||||
|
use app\admin\model\Area;
|
||||||
use app\admin\model\AuthGroup;
|
use app\admin\model\AuthGroup;
|
||||||
use app\admin\model\Item;
|
use app\admin\model\Item;
|
||||||
use app\admin\model\Order;
|
use app\admin\model\Order;
|
||||||
|
|
@ -158,6 +159,18 @@ class Worker extends Backend
|
||||||
$this->model->validateFailException()->validate($validate);
|
$this->model->validateFailException()->validate($validate);
|
||||||
}
|
}
|
||||||
$params['admin_id'] = $this->auth->id;
|
$params['admin_id'] = $this->auth->id;
|
||||||
|
|
||||||
|
if(!empty($params['area_id'])){
|
||||||
|
|
||||||
|
$area = Area::getByCode($params['area_id']);
|
||||||
|
if($area){
|
||||||
|
$location = getLocation($area->merge_name);
|
||||||
|
if(!empty($location)){
|
||||||
|
$params['lng'] = $location['lng'];
|
||||||
|
$params['lat'] = $location['lat'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
$result = $this->model->allowField(true)->save($params);
|
$result = $this->model->allowField(true)->save($params);
|
||||||
$item_map = model('item')->getAll();
|
$item_map = model('item')->getAll();
|
||||||
$item_map = array_column($item_map, 'level', 'id');
|
$item_map = array_column($item_map, 'level', 'id');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user