public static function getNearestOffices($gh_id, $lon, $lat) { $key = __METHOD__ . "{$gh_id}_{$lon}_{$lat}"; $value = Yii::$app->cache->get($key); if ($value !== false) { return $value; } $map = new MMapApi(); $rows = MOffice::find()->where(['gh_id' => $gh_id])->asArray()->all(); foreach ($rows as $key => &$row) { if ($row['lon'] < 1) { unset($rows[$key]); continue; } $row['distance'] = $map->getDistance($lon, $lat, $row['lon'], $row['lat']); } unset($row); \yii\helpers\ArrayHelper::multisort($rows, 'distance'); Yii::$app->cache->set($key, $rows, YII_DEBUG ? 10 : 5 * 60); return $rows; }