作者 李忠强

更新

{"files":[],"license":"regular","licenseto":"10789","licensekey":"89rbzyMwR7egBFAo EyUfEJxJ9VFzYuZOURRwgg==","domains":[],"licensecodes":[],"validations":[]}
\ No newline at end of file
... ...
<?php
namespace addons\address;
use think\Addons;
/**
* 地址选择
* @author [MiniLing] <[laozheyouxiang@163.com]>
*/
class Address extends Addons
{
/**
* 插件安装方法
* @return bool
*/
public function install()
{
return true;
}
/**
* 插件卸载方法
* @return bool
*/
public function uninstall()
{
return true;
}
}
... ...
require([], function () {
//绑定data-toggle=addresspicker属性点击事件
$(document).on('click', "[data-toggle='addresspicker']", function () {
var that = this;
var callback = $(that).data('callback');
var input_id = $(that).data("input-id") ? $(that).data("input-id") : "";
var lat_id = $(that).data("lat-id") ? $(that).data("lat-id") : "";
var lng_id = $(that).data("lng-id") ? $(that).data("lng-id") : "";
var lat = lat_id ? $("#" + lat_id).val() : '';
var lng = lng_id ? $("#" + lng_id).val() : '';
var url = "/addons/address/index/select";
url += (lat && lng) ? '?lat=' + lat + '&lng=' + lng : '';
Fast.api.open(url, '位置选择', {
callback: function (res) {
input_id && $("#" + input_id).val(res.address).trigger("change");
lat_id && $("#" + lat_id).val(res.lat).trigger("change");
lng_id && $("#" + lng_id).val(res.lng).trigger("change");
try {
//执行回调函数
if (typeof callback === 'function') {
callback.call(that, res);
}
} catch (e) {
}
}
});
});
});
... ...
<?php
return array(
array(
'name' => 'maptype',
'title' => '默认地图类型',
'type' => 'radio',
'content' =>
array(
'baidu' => '百度地图',
'amap' => '高德地图',
'tencent' => '腾讯地图',
),
'value' => 'baidu',
'rule' => 'required',
'msg' => '',
'tip' => '',
'ok' => '',
'extend' => '',
),
array(
'name' => 'location',
'title' => '默认检索城市',
'type' => 'string',
'content' =>
array(),
'value' => '北京',
'rule' => 'required',
'msg' => '',
'tip' => '',
'ok' => '',
'extend' => '',
),
array(
'name' => 'zoom',
'title' => '默认缩放级别',
'type' => 'string',
'content' =>
array(),
'value' => '12',
'rule' => 'required',
'msg' => '',
'tip' => '',
'ok' => '',
'extend' => '',
),
array(
'name' => 'lat',
'title' => '默认Lat',
'type' => 'string',
'content' =>
array(),
'value' => '39.919990',
'rule' => 'required',
'msg' => '',
'tip' => '',
'ok' => '',
'extend' => '',
),
array(
'name' => 'lng',
'title' => '默认Lng',
'type' => 'string',
'content' =>
array(),
'value' => '116.456270',
'rule' => 'required',
'msg' => '',
'tip' => '',
'ok' => '',
'extend' => '',
),
array(
'name' => 'baidukey',
'title' => '百度地图KEY',
'type' => 'string',
'content' =>
array(),
'value' => 'hAeMFHmpyHa2ZjaCH9VVridl',
'rule' => 'required',
'msg' => '',
'tip' => '',
'ok' => '',
'extend' => '',
),
array(
'name' => 'amapkey',
'title' => '高德地图KEY',
'type' => 'string',
'content' =>
array(),
'value' => '608d75903d29ad471362f8c58c550daf',
'rule' => 'required',
'msg' => '',
'tip' => '',
'ok' => '',
'extend' => '',
),
array(
'name' => 'tencentkey',
'title' => '腾讯地图KEY',
'type' => 'string',
'content' =>
array(),
'value' => '608d75903d29ad471362f8c58c550daf',
'rule' => 'required',
'msg' => '',
'tip' => '',
'ok' => '',
'extend' => '',
),
array(
'name' => '__tips__',
'title' => '温馨提示',
'type' => '',
'content' =>
array(),
'value' => '请先申请对应地图的Key,配置后再使用',
'rule' => '',
'msg' => '',
'tip' => '',
'ok' => '',
'extend' => 'alert-danger-light',
),
);
... ...
<?php
namespace addons\address\controller;
use think\addons\Controller;
use think\Config;
use think\Hook;
class Index extends Controller
{
public function index()
{
// 语言检测
$lang = strip_tags($this->request->langset());
$site = Config::get("site");
// 配置信息
$config = [
'site' => array_intersect_key($site, array_flip(['name', 'cdnurl', 'version', 'timezone', 'languages'])),
'upload' => null,
'modulename' => 'addons',
'controllername' => 'index',
'actionname' => 'index',
'jsname' => 'addons/address',
'moduleurl' => '',
'language' => $lang
];
$config = array_merge($config, Config::get("view_replace_str"));
// 配置信息后
Hook::listen("config_init", $config);
// 加载当前控制器语言包
$this->view->assign('site', $site);
$this->view->assign('config', $config);
return $this->view->fetch();
}
/**
* 选择地址
* @return string
* @throws \think\Exception
*/
public function select()
{
$config = get_addon_config('address');
$lat = $this->request->get('lat', $config['lat']);
$lng = $this->request->get('lng', $config['lng']);
$this->view->assign('lat', $lat);
$this->view->assign('lng', $lng);
$this->view->assign('location', $config['location']);
return $this->view->fetch('index/' . $config['maptype']);
}
}
... ...
name = address
title = 地址选择
intro = 地图位置选择插件,可返回地址和经纬度
author = FastAdmin
website = https://www.fastadmin.net
version = 1.0.5
state = 1
url = /addons/address
license = regular
licenseto = 10789
... ...
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>地址选择器</title>
<link rel="stylesheet" href="__CDN__/assets/css/bootstrap.min.css"/>
<link rel="stylesheet" href="__CDN__/assets/css/fastadmin.min.css"/>
<link rel="stylesheet" href="__CDN__/assets/libs/font-awesome/css/font-awesome.min.css"/>
<style type="text/css">
body {
margin: 0;
padding: 0;
}
#container {
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
}
.confirm {
position: absolute;
bottom: 30px;
right: 4%;
z-index: 99;
height: 50px;
width: 50px;
line-height: 50px;
font-size: 15px;
text-align: center;
background-color: white;
background: #1ABC9C;
color: white;
border: none;
cursor: pointer;
border-radius: 50%;
}
.search {
position: absolute;
width: 400px;
top: 0;
left: 50%;
padding: 5px;
margin-left: -200px;
}
.amap-marker-label {
border: 0;
background-color: transparent;
}
.info {
padding: .75rem 1.25rem;
margin-bottom: 1rem;
border-radius: .25rem;
position: fixed;
top: 2rem;
background-color: white;
width: auto;
min-width: 22rem;
border-width: 0;
left: 1.8rem;
box-shadow: 0 2px 6px 0 rgba(114, 124, 245, .5);
}
</style>
</head>
<body>
<div class="search">
<div class="input-group">
<input type="text" id="place" name="q" class="form-control" placeholder="输入地点"/>
<span class="input-group-btn">
<button type="submit" name="search" id="search-btn" class="btn btn-success">
<i class="fa fa-search"></i>
</button>
</span>
</div>
</div>
<div class="confirm">确定</div>
<div id="container"></div>
<script type="text/javascript" src="//webapi.amap.com/maps?v=1.4.11&key={$config.amapkey|default=''}&plugin=AMap.ToolBar,AMap.Autocomplete,AMap.PlaceSearch,AMap.Geocoder"></script>
<!-- UI组件库 1.0 -->
<script src="//webapi.amap.com/ui/1.0/main.js?v=1.0.11"></script>
<script src="__CDN__/assets/libs/jquery/dist/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
var as, address, map, lat, lng, geocoder;
var init = function () {
AMapUI.loadUI(['misc/PositionPicker', 'misc/PoiPicker'], function (PositionPicker, PoiPicker) {
//加载PositionPicker,loadUI的路径参数为模块名中 'ui/' 之后的部分
map = new AMap.Map('container', {
zoom: parseInt('{$config.zoom}')
});
geocoder = new AMap.Geocoder({
radius: 1000 //范围,默认:500
});
var positionPicker = new PositionPicker({
mode: 'dragMarker',//设定为拖拽地图模式,可选'dragMap'、'dragMarker',默认为'dragMap'
map: map//依赖地图对象
});
//输入提示
var autoOptions = {
input: "place"
};
var relocation = function (lnglat) {
lng = lnglat.lng;
lat = lnglat.lat;
map.panTo([lng, lat]);
positionPicker.start(lnglat);
geocoder.getAddress(lng + ',' + lat, function (status, result) {
if (status === 'complete' && result.regeocode) {
var address = result.regeocode.formattedAddress;
var label = '<div class="info">地址:' + address + '<br>经度:' + lng + '<br>纬度:' + lat + '</div>';
positionPicker.marker.setLabel({
content: label //显示内容
});
} else {
console.log(JSON.stringify(result));
}
});
};
var auto = new AMap.Autocomplete(autoOptions);
//构造地点查询类
var placeSearch = new AMap.PlaceSearch({
map: map
});
//注册监听,当选中某条记录时会触发
AMap.event.addListener(auto, "select", function (e) {
placeSearch.setCity(e.poi.adcode);
placeSearch.search(e.poi.name); //关键字查询查询
});
AMap.event.addListener(map, 'click', function (e) {
relocation(e.lnglat);
});
//加载工具条
var tool = new AMap.ToolBar();
map.addControl(tool);
var poiPicker = new PoiPicker({
input: 'place',
placeSearchOptions: {
map: map,
pageSize: 6 //关联搜索分页
}
});
poiPicker.on('poiPicked', function (poiResult) {
poiPicker.hideSearchResults();
$('.poi .nearpoi').text(poiResult.item.name);
$('.address .info').text(poiResult.item.address);
$('#address').val(poiResult.item.address);
$("#place").val(poiResult.item.name);
relocation(poiResult.item.location);
});
positionPicker.on('success', function (positionResult) {
as = positionResult.position;
address = positionResult.address;
lat = as.lat;
lng = as.lng;
});
positionPicker.on('fail', function (positionResult) {
address = '';
});
positionPicker.start();
});
};
//点击确定后执行回调赋值
var close = function (data) {
var index = parent.Layer.getFrameIndex(window.name);
var callback = parent.$("#layui-layer" + index).data("callback");
//再执行关闭
parent.Layer.close(index);
//再调用回传函数
if (typeof callback === 'function') {
callback.call(undefined, data);
}
};
//点击搜索按钮
$(document).on('click', '.confirm', function () {
var zoom = map.getZoom();
var data = {lat: lat, lng: lng, zoom: zoom, address: address};
close(data);
});
init();
});
</script>
</body>
</html>
\ No newline at end of file
... ...
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>地址选择器</title>
<link rel="stylesheet" href="__CDN__/assets/css/bootstrap.min.css"/>
<link rel="stylesheet" href="__CDN__/assets/css/fastadmin.min.css"/>
<link rel="stylesheet" href="__CDN__/assets/libs/font-awesome/css/font-awesome.min.css"/>
<style type="text/css">
body {
margin: 0;
padding: 0;
}
#container {
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
}
.confirm {
position: absolute;
bottom: 30px;
right: 4%;
z-index: 99;
height: 50px;
width: 50px;
line-height: 50px;
font-size: 15px;
text-align: center;
background-color: white;
background: #1ABC9C;
color: white;
border: none;
cursor: pointer;
border-radius: 50%;
}
.search {
position: absolute;
width: 400px;
top: 0;
left: 50%;
padding: 5px;
margin-left: -200px;
}
label.BMapLabel {
max-width: inherit;
padding: .75rem 1.25rem;
margin-bottom: 1rem;
background-color: white;
width: auto;
min-width: 22rem;
border: none;
box-shadow: 0 2px 6px 0 rgba(114, 124, 245, .5);
}
</style>
</head>
<body>
<div class="search">
<div class="input-group">
<input type="text" id="place" name="q" class="form-control" placeholder="输入地点"/>
<div id="searchResultPanel" style="border:1px solid #C0C0C0;width:150px;height:auto; display:none;"></div>
<span class="input-group-btn">
<button type="button" name="search" id="address" class="btn btn-success">
<i class="fa fa-search"></i>
</button>
</span>
</div>
</div>
<div class="confirm">确定</div>
<div id="container"></div>
<script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak={$config.baidukey|default=''}"></script>
<script src="__CDN__/assets/libs/jquery/dist/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
// 百度地图API功能
function G(id) {
return document.getElementById(id);
}
var map, marker, searchService, address = null, lng, lat;
var init = function () {
map = new BMap.Map("container"); // 创建地图实例
var point = new BMap.Point({$lng}, {$lat}); // 创建点坐标
map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
map.centerAndZoom(point, parseInt("{$config.zoom}")); // 初始化地图,设置中心点坐标和地图级别
var size = new BMap.Size(10, 20);
map.addControl(new BMap.CityListControl({
anchor: BMAP_ANCHOR_TOP_LEFT,
offset: size,
}));
var geoc = new BMap.Geocoder();
var addpoint = function (point) {
//通过点击百度地图,可以获取到对应的point, 由point的lng、lat属性就可以获取对应的经度纬度
var pt = point;
geoc.getLocation(pt, function (rs) {
//对象可以获取到详细的地址信息
address = rs.address;
deletePoint();
var mk = new BMap.Marker(pt);
map.addOverlay(mk);
map.panTo(pt);
var label = new BMap.Label('<div class="info">地址:' + address + '<br>经度:' + pt.lng + '<br>纬度:' + pt.lat + '</div>', {offset: new BMap.Size(16, 20)});
label.setStyle({
border: 'none',
padding: '.75rem 1.25rem'
});
mk.setLabel(label);
//将对应的HTML元素设置值
lng = pt.lng;
lat = pt.lat;
});
};
if ("{$lng}" != '' && "{$lat}" != '') {
addpoint(point);
}
ac = new BMap.Autocomplete({"input": "place", "location": map}); //建立一个自动完成的对象
ac.addEventListener("onhighlight", function (e) { //鼠标放在下拉列表上的事件
var str = "";
var _value = e.fromitem.value;
var value = "";
if (e.fromitem.index > -1) {
value = _value.province + _value.city + _value.district + _value.street + _value.business;
}
str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;
value = "";
if (e.toitem.index > -1) {
_value = e.toitem.value;
value = _value.province + _value.city + _value.district + _value.street + _value.business;
}
str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
G("searchResultPanel").innerHTML = str;
});
ac.addEventListener("onconfirm", function (e) { //鼠标点击下拉列表后的事件
var _value = e.item.value;
myValue = _value.province + _value.city + _value.district + _value.street + _value.business;
G("searchResultPanel").innerHTML = "onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;
setPlace();
});
function setPlace() {
map.clearOverlays(); //清除地图上所有覆盖物
function myFun() {
var result = local.getResults().getPoi(0);
var pp = result.point; //获取第一个智能搜索的结果
map.centerAndZoom(pp, 18);
map.addOverlay(new BMap.Marker(pp)); //添加标注
lng = pp.lng;
lat = pp.lat;
address = result.address;
}
var local = new BMap.LocalSearch(map, { //智能搜索
onSearchComplete: myFun
});
local.search(myValue);
}
map.addEventListener("click", function (e) {
//通过点击百度地图,可以获取到对应的point, 由point的lng、lat属性就可以获取对应的经度纬度
var pt = e.point;
addpoint(e.point);
});
/**
* 清除覆盖物
*/
function deletePoint() {
var allOverlay = map.getOverlays();
for (var i = 0; i < allOverlay.length; i++) {
map.removeOverlay(allOverlay[i]);
}
}
};
var close = function (data) {
var index = parent.Layer.getFrameIndex(window.name);
var callback = parent.$("#layui-layer" + index).data("callback");
//再执行关闭
parent.Layer.close(index);
//再调用回传函数
if (typeof callback === 'function') {
callback.call(undefined, data);
}
};
//点击确定后执行回调赋值
$(document).on('click', '.confirm', function () {
var zoom = map.getZoom();
var data = {lat: lat, lng: lng, zoom: zoom, address: address};
close(data);
});
init();
});
</script>
</body>
</html>
\ No newline at end of file
... ...
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<title>地图位置(经纬度)选择插件 - FastAdmin</title>
<!-- Bootstrap Core CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="https://cdn.demo.fastadmin.net/assets/css/frontend.css" rel="stylesheet">
<!-- Plugin CSS -->
<link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<div class="bs-docs-section clearfix">
<div class="row">
<div class="col-lg-12">
<div class="page-header">
<h2 id="navbar">地图位置(经纬度)选择示例</h2>
</div>
<div class="bs-component">
<form action="" method="post" role="form">
<div class="form-group">
<label for=""></label>
<input type="text" class="form-control" name="" id="address" placeholder="地址">
</div>
<div class="form-group">
<label for=""></label>
<input type="text" class="form-control" name="" id="lng" placeholder="经度">
</div>
<div class="form-group">
<label for=""></label>
<input type="text" class="form-control" name="" id="lat" placeholder="纬度">
</div>
<button type="button" class="btn btn-primary" data-toggle='addresspicker' data-input-id="address" data-lng-id="lng" data-lat-id="lat">点击选择地址获取经纬度</button>
</form>
</div>
<div class="page-header">
<h2 id="code">调用代码</h2>
</div>
<div class="bs-component">
<textarea class="form-control" rows="17">
<form action="" method="post" role="form">
<div class="form-group">
<label for=""></label>
<input type="text" class="form-control" name="" id="address" placeholder="地址">
</div>
<div class="form-group">
<label for=""></label>
<input type="text" class="form-control" name="" id="lng" placeholder="经度">
</div>
<div class="form-group">
<label for=""></label>
<input type="text" class="form-control" name="" id="lat" placeholder="纬度">
</div>
<button type="button" class="btn btn-primary" data-toggle='addresspicker' data-input-id="address" data-lng-id="lng" data-lat-id="lat">点击选择地址获取经纬度</button>
</form>
</textarea>
</div>
<div class="page-header">
<h2 id="navbar">参数说明</h2>
</div>
<div class="bs-component">
<table class="table table-condensed table-hover">
<thead>
<tr>
<th>参数</th>
<th>释义</th>
</tr>
</thead>
<tbody>
<tr>
<td>data-input-id</td>
<td>填充地址的文本框ID</td>
</tr>
<tr>
<td>data-lng-id</td>
<td>填充经度的文本框ID</td>
</tr>
<tr>
<td>data-lat-id</td>
<td>填充纬度的文本框ID</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var require = {
config: {$config | json_encode
}
}
;
</script>
<script>
require.callback = function () {
define('addons/address', ['jquery', 'bootstrap', 'frontend', 'template'], function ($, undefined, Frontend, Template) {
var Controller = {
index: function () {
;
}
};
return Controller;
});
define('lang', function () {
return [];
});
}
</script>
<script src="__CDN__/assets/js/require.min.js" data-main="__CDN__/assets/js/require-frontend.min.js?v={$site.version}"></script>
</body>
</html>
\ No newline at end of file
... ...
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>地址选择器</title>
<link rel="stylesheet" href="__CDN__/assets/css/bootstrap.min.css"/>
<link rel="stylesheet" href="__CDN__/assets/css/fastadmin.min.css"/>
<link rel="stylesheet" href="__CDN__/assets/libs/font-awesome/css/font-awesome.min.css"/>
<style type="text/css">
body {
margin: 0;
padding: 0;
}
#container {
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
}
.confirm {
position: absolute;
bottom: 30px;
right: 4%;
z-index: 99;
height: 50px;
width: 50px;
line-height: 50px;
font-size: 15px;
text-align: center;
background-color: white;
background: #1ABC9C;
color: white;
border: none;
cursor: pointer;
border-radius: 50%;
}
.search {
position: absolute;
width: 400px;
top: 0;
left: 50%;
padding: 5px;
margin-left: -200px;
}
</style>
</head>
<body>
<div class="search">
<div class="input-group">
<input type="text" id="place" name="q" class="form-control" placeholder="输入地点"/>
<span class="input-group-btn">
<button type="submit" name="search" id="search-btn" class="btn btn-success">
<i class="fa fa-search"></i>
</button>
</span>
</div>
</div>
<div class="confirm">确定</div>
<div id="container"></div>
<script charset="utf-8" src="//map.qq.com/api/js?v=2.exp&libraries=place&key={$config.tencentkey|default=''}"></script>
<script src="__CDN__/assets/libs/jquery/dist/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
var map, marker, geocoder, infoWin, searchService, address = null;
var init = function () {
var center = new qq.maps.LatLng({$lat}, {$lng});
map = new qq.maps.Map(document.getElementById('container'), {
center: center,
zoom: parseInt("{$config.zoom}")
});
//初始化marker
initmarker(center);
//实例化信息窗口
infoWin = new qq.maps.InfoWindow({
map: map
});
geocoder = new qq.maps.Geocoder({
complete: function (result) {
infoWin.open();
address = result.detail.addressComponents.province +
result.detail.addressComponents.city +
result.detail.addressComponents.district;
if (result.detail.addressComponents.streetNumber == '') {
address += result.detail.addressComponents.street;
} else {
address += result.detail.addressComponents.streetNumber;
}
infoWin.setContent(address);
infoWin.setPosition(result.detail.location);
}
});
//显示当前marker的位置信息窗口
geocoder.getAddress(center);
var latlngBounds = new qq.maps.LatLngBounds();
//查询poi类信息
searchService = new qq.maps.SearchService({
complete: function (results) {
var pois = results.detail.pois;
for (var i = 0, l = pois.length; i < l; i++) {
var poi = pois[i];
latlngBounds.extend(poi.latLng);
initmarker(poi.latLng);
//显示当前marker的位置信息窗口
geocoder.getAddress(poi.latLng);
}
map.fitBounds(latlngBounds);
}
});
//实例化自动完成
var ap = new qq.maps.place.Autocomplete(document.getElementById('place'));
//添加监听事件
qq.maps.event.addListener(ap, "confirm", function (res) {
searchKeyword();
});
qq.maps.event.addListener(
map,
'click',
function (event) {
try {
infoWin.setContent('<div style="text-align:center;white-space:nowrap;margin:10px;">加载中</div>');
var latLng = event.latLng,
lat = latLng.getLat().toFixed(5),
lng = latLng.getLng().toFixed(5);
var location = new qq.maps.LatLng(lat, lng);
//调用获取位置方法
geocoder.getAddress(location);
infoWin.setPosition(location);
marker.setPosition(location);
} catch (e) {
console.log(e);
}
}
);
};
//实例化marker和监听拖拽结束事件
var initmarker = function (latLng) {
marker = new qq.maps.Marker({
map: map,
position: latLng,
draggable: true,
title: '拖动图标选择位置'
});
//监听拖拽结束
qq.maps.event.addListener(marker, 'dragend', function (event) {
var latLng = event.latLng,
lat = latLng.getLat().toFixed(5),
lng = latLng.getLng().toFixed(5);
var location = new qq.maps.LatLng(lat, lng);
//调用获取位置方法
geocoder.getAddress(location);
});
};
var close = function (data) {
var index = parent.Layer.getFrameIndex(window.name);
var callback = parent.$("#layui-layer" + index).data("callback");
//再执行关闭
parent.Layer.close(index);
//再调用回传函数
if (typeof callback === 'function') {
callback.call(undefined, data);
}
};
//执行搜索方法
var searchKeyword = function () {
searchService.clear();//先清除
marker.setMap(null);
infoWin.close();
var keyword = $("#place").val();
searchService.setLocation("{$location}");//设置默认检索范围(默认为全国),类型可以是坐标或指定的城市名称。
searchService.setPageIndex(0);//设置检索的特定页数。
searchService.setPageCapacity(1);//设置每页返回的结果数量。
searchService.search(keyword);//开始查询
};
//点击确定后执行回调赋值
$(document).on('click', '.confirm', function () {
var as = marker.getPosition();
var x = as.getLat().toFixed(5);
var y = as.getLng().toFixed(5);
var zoom = map.getZoom();
var data = {lat: x, lng: y, zoom: zoom, address: address};
close(data);
});
//点击搜索按钮
$(document).on('click', '#search-btn', function () {
if ($("#place").val() == '')
return;
searchKeyword();
});
init();
});
</script>
</body>
</html>
\ No newline at end of file
... ...
... ... @@ -121,7 +121,6 @@ class Classification extends Api
/**
* @ApiTitle (商品规格)
* @ApiSummary (分类按钮页面右侧商品列表 初次点击分类页面可不传分类id值)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=goods_id, type=integer, required=true, description="商品id")
... ... @@ -130,6 +129,7 @@ class Classification extends Api
'msg':'返回成功'
'data':{
// 规格组合完毕的列表
// 如果sku是空数组 为单规格商品 只需要用list的值
"list": [
{
"goods_spec_id": 103,
... ... @@ -137,7 +137,7 @@ class Classification extends Api
"goods_no": "SNHW001",
"goods_price": "4499.00",
"line_price": "0.00",
"stock_num": 941,
"stock_num": 941, 库存
"goods_sales": 58,
"goods_weight": 500,
"spec_sku_id": "44_46", // 搜索字段 组合sku里面的id搜索 从小到大排序
... ...
... ... @@ -64,6 +64,86 @@ class Goods extends Api
$this->success('商品详情',$goods);
}
/**
* @ApiTitle (商品规格)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=goods_id, type=integer, required=true, description="商品id")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
'data':{
// 规格组合完毕的列表
"list": [
{
"goods_spec_id": 103,
"goods_id": 22,
"goods_no": "SNHW001",
"goods_price": "4499.00",
"line_price": "0.00",
"stock_num": 941,
"goods_sales": 58,
"goods_weight": 500,
"spec_sku_id": "44_46", // 搜索字段 组合sku里面的id搜索 从小到大排序
"spec_image": "",
"create_time": 1542784591,
"update_time": 1543242861
}
],
// 规格展示的列表
"sku": [
{
"name": "颜色",
"second": [
{
"id": 44,
"name": "亮黑色"
}
]
},
{
"name": "内存",
"second": [
{
"id": 46,
"name": "6GB+64GB"
}
]
}
]
}
})
*/
public function goodsSku()
{
$goods_id = $this->request->post('goods_id');
$goodsspecrelmodel = new GoodsSpecRel();
$list = $goodsspecrelmodel
->where('goods_id',$goods_id)
->select();
$array = [];
foreach ($list as $key => $value){
if (!isset($array[$value['spec_id']])){
$array[$value['spec_id']]['name'] = Db::name('litestore_spec')
->where('id',$value['spec_id'])
->value('spec_name');
}
$spec_value =Db::name('litestore_spec_value')
->where('id',$value['spec_value_id'])
->value('spec_value');
$array[$value['spec_id']]['second'][] = [
'id' => $value['spec_value_id'],
'name' => $spec_value
];
}
$array = array_values($array);
$goods_spec = GoodsSpec::all(['goods_id'=>$goods_id]);
$this->success('商品规格',['list'=>$goods_spec,'sku'=>$array]);
}
/**
* @ApiTitle (商品详情页评价)
* @ApiMethod (POST)
... ...
<?php
namespace app\api\controller;
use app\api\model\GoodsSpec;
use app\api\model\SpecValue;
use app\common\controller\Api;
class Order extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
/**
* @ApiTitle (下单页面)
* @ApiSummary ([{"goods_id":22,"goods_sku_id":106,"number":2},{"goods_id":23,"goods_sku_id":66,"number":2}])
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="data_json", type="string", required=true, description="下单的商品json数据")
* @ApiParams (name="goods_id", type="integer", required=false, description="商品id 此值不传 json数组注释用")
* @ApiParams (name="goods_sku_id", type="integer", required=false, description="规格id 此值不传 json数组注释用")
* @ApiParams (name="number", type="integer", required=false, description="购买数量 此值不传 json数组注释用")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
})
*/
public function orderCalculation()
{
$json = $this->request->post('data_json');
if (!$json) $this->error('data_json参数不能为空');
$json = '[{"goods_id":22,"goods_sku_id":106,"number":2},{"goods_id":23,"goods_sku_id":66,"number":2}]';
$data = json_decode($json,true);
$goodsmodel = new \app\api\model\Goods();
$skumodel = new GoodsSpec();
$specmodel = new SpecValue();
$goods_array = [];
$sum_price = 0;
foreach ($data as $key => $value){
if (!is_numeric($value['goods_id']) || !is_numeric($value['goods_sku_id']) || !is_numeric($value['number'])){
$this->error('参数不合法');
}
$goods = $goodsmodel->where('goods_id',$value['goods_id'])->field('goods_id,goods_name,image,spec_type')->find();
if (!$goods) $this->error('商品不存在');
$sku = $skumodel->where('goods_spec_id',$value['goods_sku_id'])
->field('goods_spec_id,spec_sku_id,goods_price')->find();
if (!$sku) $this->error('商品规格不存在');
$goods['sku_id'] = $sku['goods_spec_id'];
$goods['sku_price'] = $sku['goods_price'];
if ($goods['spec_type'] == 10){
$goods['sku_name'] ='';
}else{
$ids = explode('_',$sku['spec_sku_id']);
$sku_name = $specmodel->whereIn('id',$ids)->column('spec_value');
$goods['sku_name'] = implode(' ',$sku_name);
}
$goods['number'] = $value['number'];
$goods_array[] = $goods;
$sum_price = bcadd($sum_price,bcmul($sku['goods_price'],$value['number'],2),2);
}
$this->success('下单页详情',['list'=>$goods_array,'price'=>$sum_price]);
}
}
\ No newline at end of file
... ...
... ... @@ -8,6 +8,7 @@ use app\common\library\Sms;
use fast\Http;
use fast\Random;
use think\Config;
use think\Db;
use think\Validate;
/**
... ... @@ -15,7 +16,7 @@ use think\Validate;
*/
class User extends Api
{
protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'third'];
protected $noNeedLogin = ['third'];
protected $noNeedRight = '*';
public function _initialize()
... ... @@ -30,23 +31,28 @@ class User extends Api
/**
* 会员中心
* @ApiReturn (
* data:{
* nickname 昵称
* avatar 头像
* pay 待支付
* wait_send 待发货
* wait_collect 待收货
* wait_comment 待评价
* }
* )
*/
public function index()
{
$this->success('', ['welcome' => $this->auth->nickname]);
}
/**
* 退出登录
* @ApiMethod (POST)
*/
public function logout()
{
if (!$this->request->isPost()) {
$this->error(__('Invalid parameters'));
}
$this->auth->logout();
$this->success(__('Logout successful'));
$data = [];
$data['nickname'] = $this->auth->nickname;
$data['avatar'] = cdnurl($this->auth->avatar,true);
$data['mobile'] = $this->auth->mobile;
$data['pay'] = Db::name('litestore_order')->where('user_id',$this->auth->id)->where('pay_status','10')->count();
$data['wait_send'] = Db::name('litestore_order')->where('user_id',$this->auth->id)->where('freight_status','10')->count();
$data['wait_collect'] = Db::name('litestore_order')->where('user_id',$this->auth->id)->where('receipt_status','10')->count();
$data['wait_comment'] = Db::name('litestore_order')->where('user_id',$this->auth->id)->where('receipt_status','20')->count();
$this->success('会员中心', ['welcome' => $this->auth->nickname]);
}
/**
... ... @@ -54,106 +60,28 @@ class User extends Api
*
* @ApiMethod (POST)
* @param string $avatar 头像地址
* @param string $username 用户名
* @param string $mobile 联系方式
* @param string $nickname 昵称
* @param string $bio 个人简介
*/
public function profile()
{
$user = $this->auth->getUser();
$username = $this->request->post('username');
$mobile = $this->request->post('mobile');
$nickname = $this->request->post('nickname');
$bio = $this->request->post('bio');
$avatar = $this->request->post('avatar', '', 'trim,strip_tags,htmlspecialchars');
if ($username) {
$exists = \app\common\model\User::where('username', $username)->where('id', '<>', $this->auth->id)->find();
if ($exists) {
$this->error(__('Username already exists'));
}
$user->username = $username;
if ($mobile) {
$user->mobile = $mobile;
}
if ($nickname) {
$exists = \app\common\model\User::where('nickname', $nickname)->where('id', '<>', $this->auth->id)->find();
if ($exists) {
$this->error(__('Nickname already exists'));
}
$user->nickname = $nickname;
}
$user->bio = $bio;
$user->avatar = $avatar;
$user->save();
$this->success();
}
/**
* 修改邮箱
*
* @ApiMethod (POST)
* @param string $email 邮箱
* @param string $captcha 验证码
*/
public function changeemail()
{
$user = $this->auth->getUser();
$email = $this->request->post('email');
$captcha = $this->request->post('captcha');
if (!$email || !$captcha) {
$this->error(__('Invalid parameters'));
if ($avatar) {
$user->avatar = $avatar;
}
if (!Validate::is($email, "email")) {
$this->error(__('Email is incorrect'));
}
if (\app\common\model\User::where('email', $email)->where('id', '<>', $user->id)->find()) {
$this->error(__('Email already exists'));
}
$result = Ems::check($email, $captcha, 'changeemail');
if (!$result) {
$this->error(__('Captcha is incorrect'));
}
$verification = $user->verification;
$verification->email = 1;
$user->verification = $verification;
$user->email = $email;
$user->save();
Ems::flush($email, 'changeemail');
$this->success();
}
/**
* 修改手机号
*
* @ApiMethod (POST)
* @param string $mobile 手机号
* @param string $captcha 验证码
*/
public function changemobile()
{
$user = $this->auth->getUser();
$mobile = $this->request->post('mobile');
$captcha = $this->request->post('captcha');
if (!$mobile || !$captcha) {
$this->error(__('Invalid parameters'));
}
if (!Validate::regex($mobile, "^1\d{10}$")) {
$this->error(__('Mobile is incorrect'));
}
if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $user->id)->find()) {
$this->error(__('Mobile already exists'));
}
$result = Sms::check($mobile, $captcha, 'changemobile');
if (!$result) {
$this->error(__('Captcha is incorrect'));
}
$verification = $user->verification;
$verification->mobile = 1;
$user->verification = $verification;
$user->mobile = $mobile;
$user->save();
Sms::flush($mobile, 'changemobile');
$this->success();
}
/**
* 第三方登录
... ...
... ... @@ -481,3 +481,27 @@ if (!function_exists('check_ip_allowed')) {
}
}
}
if (!function_exists('getDistance')) {
function getDistance($lat1, $lng1, $lat2, $lng2)
{
$EARTH_RADIUS = 6378.137;
$radLat1 = rad($lat1);
$radLat2 = rad($lat2);
$a = $radLat1 - $radLat2;
$b = rad($lng1) - rad($lng2);
$s = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2)));
$s = $s * $EARTH_RADIUS;
$s = round($s * 10000) / 10000;
return $s;
}
}
if (!function_exists('rad')) {
function rad($d)
{
return $d * 3.1415926 / 180.0;
}
}
... ...
define([], function () {
require.config({
require([], function () {
//绑定data-toggle=addresspicker属性点击事件
$(document).on('click', "[data-toggle='addresspicker']", function () {
var that = this;
var callback = $(that).data('callback');
var input_id = $(that).data("input-id") ? $(that).data("input-id") : "";
var lat_id = $(that).data("lat-id") ? $(that).data("lat-id") : "";
var lng_id = $(that).data("lng-id") ? $(that).data("lng-id") : "";
var lat = lat_id ? $("#" + lat_id).val() : '';
var lng = lng_id ? $("#" + lng_id).val() : '';
var url = "/addons/address/index/select";
url += (lat && lng) ? '?lat=' + lat + '&lng=' + lng : '';
Fast.api.open(url, '位置选择', {
callback: function (res) {
input_id && $("#" + input_id).val(res.address).trigger("change");
lat_id && $("#" + lat_id).val(res.lat).trigger("change");
lng_id && $("#" + lng_id).val(res.lng).trigger("change");
try {
//执行回调函数
if (typeof callback === 'function') {
callback.call(that, res);
}
} catch (e) {
}
}
});
});
});
require.config({
paths: {
'litestorefreight_delivery': '../addons/litestore/js/litestorefreight_delivery',
'litestorefreight_regionalChoice': '../addons/litestore/js/litestorefreight_regionalChoice',
... ...