自动识别
This commit is contained in:
parent
5d50a0f5a1
commit
66c9dcdc7d
|
|
@ -44,8 +44,8 @@ class Index extends Controller
|
|||
{
|
||||
$config = get_addon_config('address');
|
||||
$zoom = (int)$this->request->get('zoom', $config['zoom']);
|
||||
$lng = (float)$this->request->get('lng');
|
||||
$lat = (float)$this->request->get('lat');
|
||||
$lng = $this->request->get('lng');
|
||||
$lat = $this->request->get('lat');
|
||||
$address = $this->request->get('address');
|
||||
$city_code = $this->request->get('city_code');
|
||||
$lng = $lng ?: $config['lng'];
|
||||
|
|
|
|||
|
|
@ -23,10 +23,7 @@ class Address
|
|||
$type = self::extractServiceTypes($string,$titles)[0] ?? '';
|
||||
|
||||
|
||||
$type_arr = explode('__',$type);
|
||||
$type = $type_arr[0] ?? '';
|
||||
$str = $type_arr[1] ?? '';
|
||||
$string = str_replace($str,'',$string);
|
||||
$string = str_replace($type,'',$string);
|
||||
if ($user) {
|
||||
$decompose = self::decompose($string);
|
||||
$re = $decompose;
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ use app\admin\model\OrderDispatch;
|
|||
use app\admin\model\OrderReview;
|
||||
use app\admin\model\Worker;
|
||||
use app\admin\model\WorkerItem;
|
||||
use app\admin\controller\AmapTrait;
|
||||
use think\Collection;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
|
|
@ -24,7 +25,7 @@ use function Symfony\Component\Clock\now;
|
|||
|
||||
class Test extends Command
|
||||
{
|
||||
|
||||
use AmapTrait;
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
|
|
@ -34,13 +35,9 @@ class Test extends Command
|
|||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$dispatch = OrderDispatch::where('id',177)->get();
|
||||
$hookParams2 = [
|
||||
'dispatch' => $dispatch,
|
||||
'remark' => '手动派单给师傅:' . '老师傅' .'(123)',
|
||||
];
|
||||
Hook::listen('order_dispatch_change', $hookParams2);
|
||||
|
||||
$key = 'ae0ab397a2febfa1ce0a2c780f3f23a3';
|
||||
$res = $this->getAddressByKeyword('重庆武隆区凤山街道锦江竹苑6幢31-4');
|
||||
dd($res);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
48
application/admin/controller/AmapTrait.php
Normal file
48
application/admin/controller/AmapTrait.php
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
namespace app\admin\controller;;
|
||||
|
||||
use fast\Http;
|
||||
use think\Env;
|
||||
|
||||
trait AmapTrait
|
||||
{
|
||||
/**
|
||||
* 高德API Key,使用时请赋值或者在类中覆盖此属性
|
||||
* @var string
|
||||
*/
|
||||
protected $amapKey = null;
|
||||
|
||||
/**
|
||||
* 调用高德逆地理编码 获取地址信息
|
||||
*
|
||||
* @param string $location 经纬度,格式 "经度,纬度"
|
||||
* @param bool $returnAll 是否返回全部结果,默认false只返回地址字符串
|
||||
* @return array|string|false 返回数组全部数据,或字符串详细地址,失败返回false
|
||||
*/
|
||||
public function getAddressByKeyword(string $keyword)
|
||||
{
|
||||
$this->amapKey = Env::get('amap_key');
|
||||
$url = 'https://restapi.amap.com/v5/place/text';
|
||||
$params = [
|
||||
'key' => $this->amapKey,
|
||||
'keywords' => $keyword,
|
||||
'page_size' => 1,
|
||||
];
|
||||
|
||||
try {
|
||||
$response = Http::get($url, $params);
|
||||
$data = json_decode($response, true);
|
||||
|
||||
if (isset($data['status']) && $data['status'] == '1') {
|
||||
return $data['pois']['0'] ?? false;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// 这里可以做日志记录
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 还可以封装更多高德API调用方法
|
||||
*/
|
||||
}
|
||||
|
|
@ -325,7 +325,6 @@ class Order extends Backend
|
|||
$params['source_shop'] = $sources[$params['source']] ?? null;
|
||||
|
||||
$sources = $this->sources;
|
||||
$items = $this->items;
|
||||
|
||||
$sources = array_column($sources, 'title', 'id');
|
||||
|
||||
|
|
@ -393,14 +392,35 @@ class Order extends Backend
|
|||
return $orderNumber;
|
||||
}
|
||||
|
||||
|
||||
use AmapTrait;
|
||||
public function smart()
|
||||
{
|
||||
// $titles = Item::where('status',1)->column('title');
|
||||
// $res = $this->extractCustomerInfo(request()->post('str'),$titles);
|
||||
// dd($res);
|
||||
$data = Address::smart(request()->post('str'));
|
||||
|
||||
$this->success(data: Address::smart(request()->post('str')));
|
||||
if ($data['item']['id'] ?? 0){
|
||||
$data['item']['item'] = $this->findElementByValue($this->itemsformattedTree, $data['item']['id'] ?? null);
|
||||
}
|
||||
preg_match('/\b(1[3-9]\d{9})\b/',$data['mobile'],$match);
|
||||
$data['mobile'] = $match[0] ?? $data['mobile'];
|
||||
|
||||
if ($data['addr'] && $data['addr']!=''){
|
||||
$address = $this->getAddressByKeyword($data['addr']);
|
||||
if ($address){
|
||||
$data['area_id'] = $address['adcode'];
|
||||
$location = explode(',',$address['location']);
|
||||
$data['lng'] = $location[0];
|
||||
$data['lat'] = $location[1];
|
||||
}else{
|
||||
$data['addr'] ='';
|
||||
}
|
||||
}
|
||||
// dd($data);
|
||||
|
||||
|
||||
$this->success(data: $data);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -53,13 +53,13 @@
|
|||
data-lat-id="lat">地图查找</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class='address'>
|
||||
<textarea id="c-address"
|
||||
class="form-control form-textarea"
|
||||
readonly
|
||||
<div class='address line'>
|
||||
<input id="c-address"
|
||||
class="form-control"
|
||||
placeholder="请通过地图查找选择"
|
||||
readonly
|
||||
name="row[address]"
|
||||
type="text"></textarea>
|
||||
type="text" />
|
||||
<input type="text" style="display: none"
|
||||
name="row[lng]" id="lng" >
|
||||
<input type="text" style="display: none"
|
||||
|
|
|
|||
|
|
@ -435,17 +435,15 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'cascader'], function
|
|||
});
|
||||
|
||||
$("#smart").on("click", function () {
|
||||
$.ajax({
|
||||
Fast.api.ajax({
|
||||
url: "order/smart", // 你的 API 地址
|
||||
type: "post",
|
||||
contentType: 'application/json',
|
||||
dataType: "json",
|
||||
data: JSON.stringify({
|
||||
str: $('#smart_text').val()
|
||||
}),
|
||||
success: function (data) {
|
||||
if (data.code === 1) {
|
||||
data = data.data;
|
||||
})
|
||||
}, function (data) {
|
||||
if (data.mobile !== '') {
|
||||
$('#c-tel').val(data.mobile);
|
||||
}
|
||||
|
|
@ -459,24 +457,29 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'cascader'], function
|
|||
if (data.idn) {
|
||||
$('#c-source-id').val(data.idn);
|
||||
}
|
||||
let citypicker = $('#c-city');
|
||||
// $city.citypicker({
|
||||
// province: data.province,
|
||||
// city: data.city,
|
||||
// district: data.region
|
||||
// });
|
||||
citypicker.val(data.province + '/' + data.city + '/' + data.region);
|
||||
citypicker = citypicker.data("citypicker");
|
||||
citypicker.refresh();
|
||||
var code = citypicker.getCode("district") || citypicker.getCode("city") || citypicker.getCode("province");
|
||||
$("#area_id").val(code);
|
||||
$("#area_name").val(citypicker.getVal());
|
||||
if (data.area_id) {
|
||||
$("#area_id").val(data.area_id);
|
||||
}
|
||||
|
||||
},
|
||||
error: function () {
|
||||
console.error("请求失败");
|
||||
if (data.lat) {
|
||||
$("#lat").val(data.lat);
|
||||
}
|
||||
if (data.lng) {
|
||||
$("#lng").val(data.lng);
|
||||
}
|
||||
if (data.area_id) {
|
||||
$("#area_id").val(data.area_id);
|
||||
}
|
||||
if (data.addr && data.addr !== '') {
|
||||
$("#c-address").val(data.addr);
|
||||
$("#area_name").val(data.addr);
|
||||
}
|
||||
Toastr.info('识别成功');
|
||||
return false;
|
||||
});
|
||||
});
|
||||
Controller.api.bindevent();
|
||||
|
|
@ -561,9 +564,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'cascader'], function
|
|||
var zoom_id = $(that).data("zoom-id") ? $(that).data("zoom-id") : "";
|
||||
var lat = lat_id ? $("#" + lat_id).val() : '';
|
||||
var lng = lng_id ? $("#" + lng_id).val() : '';
|
||||
var city_code = $("#c-city").val();
|
||||
var city_code = $("#area_id").val();
|
||||
var zoom = zoom_id ? $("#" + zoom_id).val() : '';
|
||||
var url = "/addons/address/index/select?a=1";
|
||||
var url = "/addons/address/index/select?";
|
||||
url += (lat && lng) ? 'lat=' + lat + '&lng=' + lng +
|
||||
(input_id ? "&address=" + $("#" + input_id).val() : "")
|
||||
+ (zoom ? "&zoom=" + zoom : "") : ''
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user