距离排序,多少分钟前,今天开始到结束时间戳

//多少分钟前
if(!function_exists('get_time'))
{
    function get_time($time)
    {
        $now_time = time();//现在时间
        $dur = $now_time - $time;
        if ($dur < 0) {
            return date('Y-m-d',$time);
        } else {
            if ($dur < 60) {
                return $dur . '秒前';
            } else {
                if ($dur < 3600) {
                    return floor($dur / 60) . '分钟前';
                } else {
                    if ($dur < 86400) {
                        return floor($dur / 3600) . '小时前';
                    } else {
                        if ($dur < 259200) {//3天内
                            return floor($dur / 86400) . '天前';
                        } else {
                            if(is_numeric($time))
                            {
                                $time = date('Y-m-d',$time);
                            }
                            return $time;
                        }
                    }
                }
            }
        }
    }
}

  

//一天的开始和结束
if(!function_exists('get_today_mktime'))
{
    function get_today_mktime()
    {
        $m = date('m');
        $d = date('d');
        $y = date('y');
        $beginToday=mktime(0,0,0,$m,$d,$y);
        $endToday=mktime(0,0,0,$m,$d+1,$y)-1;
        return ['beginToday'=>$beginToday,'endToday'=>$endToday];
    }
}

  

//子查询距离排序
$subQuery = Db::table('dl_member')->alias('m')->field("ROUND(6378.138*2*ASIN(SQRT(POW(SIN(($lat*PI()/180-lat*PI()/180)/2),2)+COS($lat*PI()/180)*COS(lat*PI()/180)*POW(SIN(($lng*PI()/180-lng*PI()/180)/2),2)))*1000) AS 
distance,m.id,m.head,m.nickname,m.sign")->where($where)->order($order)->buildSql();
$result = Db::table($subQuery . 'd')->where('d.distance', '<=', 50000)->paginate(10);

  

posted @ 2018-12-10 16:14  无限REIZ  阅读(200)  评论(0编辑  收藏  举报