转载自 https://www.cnblogs.com/pxjbk/p/11808558.html

<?php
 
/**
 * @name 围栏算法,判断一个坐标,是否在围栏里面.如:['113.664673,34.810146','113.681667,34.796896','113.69231,34.794711','113.702009,34.809159']
 * @author macnie <mac@lenmy.com>
 * @param array $fences 围栏,是一组坐标数组 如:113.674458,34.804719
 * @param string $point 要判断的坐标
 * @return bool
 */
function in_fences($fences, $point) {
    $nvert = count($fences);
    $vertx = [];
    $verty = [];
    list($testy, $testx) = explode(',', $point);
    foreach ($fences as $r) {
        list($lng, $lat) = explode(',', $r);
        $vertx[] = $lat;
        $verty[] = $lng;
    }
    $i = $j = $c = 0;
    for ($i = 0, $j = $nvert - 1; $i < $nvert; $j = $i++) {
        if (( ($verty[$i] > $testy) != ($verty[$j] > $testy) ) &&
            ($testx < ($vertx[$j] - $vertx[$i]) * ($testy - $verty[$i]) / ($verty[$j] - $verty[$i]) + $vertx[$i]))
            $c = !$c;
    }
    return $c;
}
 
//围栏map数据
$fences=[
'113.626809,34.75027',
    '113.630975,34.752162',
    '113.626102,34.753941'
];
$p="113.633093,34.751396"; //当前的位置
$res = in_fences($fences,$p);
var_dump($res);

//php获取今日开始时间戳和结束时间戳 
$beginToday=mktime(0,0,0,date('m'),date('d'),date('Y')); 
$endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1; 
//php获取昨日起始时间戳和结束时间戳 
$beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y')); 
$endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1; 
//php获取上周起始时间戳和结束时间戳 
$beginLastweek=mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y')); 
$endLastweek=mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y')); 
//php获取本月起始时间戳和结束时间戳 
$beginThismonth=mktime(0,0,0,date('m'),1,date('Y')); 
$endThismonth=mktime(23,59,59,date('m'),date('t'),date('Y'));