添加网站文件
This commit is contained in:
108
application/admin/controller/Mp.php
Normal file
108
application/admin/controller/Mp.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
// +---
|
||||
namespace app\admin\controller;
|
||||
use think\Db;
|
||||
|
||||
use app\admin\logic\MpLogic;
|
||||
use yx\admin\builderClass;
|
||||
|
||||
class Mp extends AdminBase
|
||||
{
|
||||
|
||||
public function index(){
|
||||
$where = [
|
||||
['lng','<>',''],
|
||||
['lat','<>',''],
|
||||
['onwork','=',1]
|
||||
];
|
||||
$u = Db::name('staff')->field('name,id,lng,lat,lnglat,mobile')->where($where)->select();
|
||||
// var_dump($u);
|
||||
$this->assign('u', json_encode($u));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
public function map_user(){
|
||||
$input = input();
|
||||
if(empty($input['lng'])){
|
||||
return json(['code'=>0,'msg'=>'lng empty']);
|
||||
}
|
||||
if(empty($input['lat'])){
|
||||
return json(['code'=>0,'msg'=>'lat empty']);
|
||||
}
|
||||
$where = [
|
||||
['lng','<>',''],
|
||||
['lat','<>',''],
|
||||
['onwork','=',1]
|
||||
];
|
||||
$list = Db::name('staff')->field('name,id,lng,lat,lnglat,mobile')->where($where)->select();
|
||||
|
||||
// 函数:将数组转换为 LatLng 对象数组
|
||||
function convertToLatLngArray($coordArray) {
|
||||
$latLngArray = [];
|
||||
for ($i = 0; $i < count($coordArray); $i += 2) {
|
||||
$lat = floatval($coordArray[$i]);
|
||||
$lng = floatval($coordArray[$i + 1]);
|
||||
$latLngArray[] = [$lng,$lat];
|
||||
}
|
||||
return $latLngArray;
|
||||
}
|
||||
|
||||
$u = [];
|
||||
foreach($list as $item=>$k){
|
||||
//获取用户的范围
|
||||
if( !$list[$item]['lnglat']){
|
||||
unset($list[$item]);
|
||||
continue;
|
||||
}
|
||||
$points = convertToLatLngArray(explode(',',$list[$item]['lnglat']));
|
||||
// // var_dump($points);
|
||||
|
||||
|
||||
if(!$this->is_ptin_poly($input['lng'],$input['lat'],$points)){
|
||||
unset($list[$item]);
|
||||
continue;
|
||||
}
|
||||
$u[] = $k;
|
||||
}
|
||||
|
||||
$this->_success('获取数据成功',$u);
|
||||
}
|
||||
|
||||
//是否再范围内
|
||||
public function is_ptin_poly($aLon, $aLat, $pointList = array())
|
||||
{
|
||||
$iSum = 0;
|
||||
$iCount = count($pointList);
|
||||
if ($iCount < 3) {
|
||||
return false;
|
||||
}
|
||||
foreach ($pointList as $key => $row) {
|
||||
$pLon1 = $row[0];
|
||||
$pLat1 = $row[1];
|
||||
if ($key === $iCount - 1) {
|
||||
$pLon2 = $pointList[0][0];
|
||||
$pLat2 = $pointList[0][1];
|
||||
} else {
|
||||
$pLon2 = $pointList[$key + 1][0];
|
||||
$pLat2 = $pointList[$key + 1][1];
|
||||
}
|
||||
if ((($aLat >= $pLat1) && ($aLat < $pLat2)) || (($aLat >= $pLat2) && ($aLat < $pLat1))) {
|
||||
if (abs($pLat1 - $pLat2) > 0) {
|
||||
$pLon = $pLon1 - (($pLon1 - $pLon2) * ($pLat1 - $aLat)) / ($pLat1 - $pLat2);
|
||||
if ($pLon < $aLon) {
|
||||
$iSum += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($iSum % 2 != 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user