正式版不能直接请求地图域名时,由后端转发逆地理。保存区划时带上省的 id,避免同名直辖县挂错省份。 Co-authored-by: Cursor <cursoragent@cursor.com>
79 行
2.3 KiB
PHP
79 行
2.3 KiB
PHP
<?php
|
|
|
|
namespace addons\shopro\controller;
|
|
|
|
use addons\shopro\exception\Exception;
|
|
use addons\shopro\model\UserAddress;
|
|
use addons\shopro\model\Area;
|
|
|
|
class Address extends Base
|
|
{
|
|
|
|
protected $noNeedLogin = ['area'];
|
|
protected $noNeedRight = ['*'];
|
|
|
|
public function index()
|
|
{
|
|
$this->success('收货地址', UserAddress::getUserAddress());
|
|
}
|
|
|
|
public function defaults()
|
|
{
|
|
$this->success('默认收货地址', UserAddress::getUserDefaultAddress());
|
|
}
|
|
|
|
public function area()
|
|
{
|
|
$data['provinceData'] = Area::where('level', 1)->order('id asc')->field('id as value, name as label, pid, level')->select();
|
|
foreach ($data['provinceData'] as $k => $p) {
|
|
$data['cityData'][$k] = Area::where(['level' => 2, 'pid' => $p->value])->order('id asc')->field('id as value, name as label, pid, level')->select();
|
|
foreach ($data['cityData'][$k] as $i => $c) {
|
|
$data['areaData'][$k][$i] = Area::where(['level' => 3, 'pid' => $c->value])->order('id asc')->field('id as value, name as label, pid, level')->select();
|
|
}
|
|
}
|
|
|
|
$this->success('省市区', $data);
|
|
|
|
}
|
|
|
|
public function edit()
|
|
{
|
|
$params = $this->request->post();
|
|
|
|
// 表单验证
|
|
$this->shoproValidate($params, get_class(), 'edit');
|
|
|
|
$this->success('编辑地址', UserAddress::edit($params));
|
|
}
|
|
|
|
public function info()
|
|
{
|
|
$params = $this->request->get();
|
|
$this->success('地址详情', UserAddress::info($params));
|
|
}
|
|
|
|
public function del()
|
|
{
|
|
$params = $this->request->post();
|
|
$this->success('地址详情', UserAddress::del($params));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function regeo()
|
|
{
|
|
$latitude = $this->request->post('latitude');
|
|
$longitude = $this->request->post('longitude');
|
|
if (!is_numeric($latitude) || !is_numeric($longitude) || abs($latitude) < 0.000001 || abs($longitude) < 0.000001) {
|
|
$this->error('请先选择位置');
|
|
}
|
|
try {
|
|
$data = \app\common\library\Tianditu::reverse((float)$longitude, (float)$latitude);
|
|
} catch (\Exception $e) {
|
|
$this->error($e->getMessage() ?: '地址解析失败');
|
|
}
|
|
$this->success('解析成功', $data);
|
|
}
|
|
|
|
} |