/** * 获取近几日附近签到过的经纪人坐标 * * @param $lng * @param $lat * @param $radius * @param $total * @param int $days * * @return array * * @throws Exception_General_InvalidParameters */ public static function getRoundBrokerLocationsInThePastFewDays($lng, $lat, $radius, $total, $days = 0) { if (!($days > 0 & $days <= 15)) { throw new Exception_General_InvalidParameters("Days must between 1 and 15, {$days} is given."); } $startTime = date('Y-m-d 00:00:00', strtotime(sprintf("-%d days", $days - 1))); $mile_info = Util_Map::round($lat, $lng, $radius); $locations = Model_Broker_Location::data_access()->filter_by_op_multi(array(array('updateTime', '>=', $startTime), array('lat', '>=', $mile_info['minLat']), array('lat', '<=', $mile_info['maxLat']), array('lng', '>=', $mile_info['minLng']), array('lng', '<=', $mile_info['maxLng'])))->limit($total)->find_all(); $keyedLocations = array(); foreach ($locations as $location) { $keyedLocations[$location['brokerId']] = $location; } return $keyedLocations; }
/** * 获取指定坐标点指定范围内指定个数的经纪人 (按rank分数从高到低排序) * @param $lat 纬度 * @param $lng 经度 * @param $radius 范围 单位米 * @param $limit 限制人数 * @return array * add by xiongjianxu */ public static function getBrokerInfoByXY($lat, $lng, $radius, $limit) { $result = array(); if (empty($lat) || empty($lng) || empty($radius)) { return $result; } $latLngRound = Util_Map::round($lat, $lng, $radius); echo 'lat,min:' . $latLngRound['minLat'] . 'max' . $latLngRound['maxLat'] . "\n"; echo 'lng,min:' . $latLngRound['minLng'] . 'max' . $latLngRound['maxLng'] . "\n"; $data = self::data_access()->filter_by_op_multi(array(array('centerX', '>=', $latLngRound['minLat']), array('centerX', '<=', $latLngRound['maxLat']), array('centerY', '>=', $latLngRound['minLng']), array('centerY', '<=', $latLngRound['maxLng'])))->sort('score', 'desc'); if ($limit) { $data->limit($limit); } $result = $data->find(); return $result; }
private function getCommList($brokerId, $lat, $lng) { // 从缓存中读取数据 $communities = Bll_Commsign::getCommList($brokerId); if (empty($communities)) { // 根据lat和lng获取1.5km内的小区列表 $latLngRound = Util_Map::round($lat, $lng, 1500); $communities = Model_Community_AjkCommunity::data_access()->load_field(array('commId', 'commName', 'sosolng', 'sosolat'))->filter('typeFlag', 0)->filter_by_op_multi(array(array('sosolat', '>=', $latLngRound['minLat']), array('sosolat', '<=', $latLngRound['maxLat']), array('sosolng', '>=', $latLngRound['minLng']), array('sosolng', '<=', $latLngRound['maxLng'])))->limit(1000)->get_all(); if (empty($communities)) { return array(); } // 实现按距离排序 • 升序 uasort($communities, function (&$a, &$b) use($lat, $lng) { // 计算坐标的距离 $a['distance'] = Util_Map::distance($lat, $lng, $a['sosolat'], $a['sosolng']); $b['distance'] = Util_Map::distance($lat, $lng, $b['sosolat'], $b['sosolng']); // 比较两小区坐标 if ($a['distance'] == $b['distance']) { return 0; } return $a['distance'] < $b['distance'] ? -1 : 1; }); $i = 0; $data = array(); foreach ($communities as $community) { if (++$i > 300) { break; } $row = array(); $row['commId'] = $community['commId']; $row['commName'] = $community['commName']; $row['lng'] = $community['sosolng']; $row['lat'] = $community['sosolat']; $row['distance'] = $community['distance']; $data[] = $row; } // 缓存数据 Bll_Commsign::setCommList($brokerId, $data); return $data; } else { if (is_array($communities)) { return $communities; } else { return array(); } } }