Example #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $points = DestinationPoint::with(['city', 'country'])->whereNull('destination_points.latitude')->orderBy('id')->get();
     $count = 0;
     foreach ($points as $point) {
         $count++;
         if (0 == $count % 1000) {
             $unprocessed_points = DestinationPoint::with(['city', 'country'])->whereNull('destination_points.latitude')->count();
             $collected_cycles_count = gc_collect_cycles();
             $this->comment($unprocessed_points . ' unprocessed destination points (' . $this->getMemoryUsage() . ' / ' . $collected_cycles_count . ' cycles)');
         }
         if (!($country = $point->country()->first())) {
             return $this->error("Skipped point #{$point->id}: country not found");
         }
         if (!($city = $point->city()->first())) {
             return $this->error("Skipped point #{$point->id}: city not found");
         }
         $address = $point->address;
         if (false === mb_strpos($address, $city->name)) {
             $address = $city->name . ', ' . $address;
         }
         if (false === mb_strpos($address, $country->name)) {
             $address = $country->name . ', ' . $address;
         }
         try {
             if ($point = $this->geocode($point, $address)) {
                 $point->save();
             }
         } catch (ChainNoResultException $e) {
             $this->error("Not founded {$address}");
         }
     }
     return;
 }
 protected function importInboundDestinationPoints()
 {
     $destination_points = [['city_id' => 398, 'point_id' => 1001], ['city_id' => 1338, 'point_id' => 10010001], ['city_id' => 1500, 'point_id' => 10010002], ['city_id' => 1781, 'point_id' => 10010003], ['city_id' => 1338, 'point_id' => 10010004]];
     foreach ($destination_points as $destination_points) {
         DestinationPoint::insert(['system_id' => 0, 'country_id' => 643, 'city_id' => $destination_points['city_id'], 'point_id' => $destination_points['point_id'], 'currencies' => 'RUR,USD,EUR', 'is_published' => 1, 'direction' => 'inout']);
     }
     return count($destination_points);
 }
 /**
  * Возвращает список точек в городе в прямоугольнике с заданными координатами
  * левой верхней и правой нижней точек.
  *
  * @param  Illuminate\Http\Request $request
  * @param  string $format Формат, в котором необходимо вернуть ответ
  * @param  int $city_id (optional) Идентификатор искомого города
  * @return Illuminate\Http\Response
  */
 public function getPointsInRectangle(Request $request, $format, $city_id = null)
 {
     $input = $request->all();
     $latlong1 = static::validateLatLongParam($input['latlong1']);
     $latlong2 = static::validateLatLongParam($input['latlong2']);
     if ($latlong1 !== false && $latlong2 !== false) {
         list($lat1, $long1) = $latlong1;
         list($lat2, $long2) = $latlong2;
         $points_query = DestinationPoint::where('is_published', 1)->where('latitude', '>', $lat1)->where('latitude', '<', $lat2)->where('longitude', '>', $long1)->where('longitude', '<', $long2);
         $system_id = $request->get('system_id', false);
         if ($system_id !== false) {
             $points_query = $points_query->where('system_id', $system_id);
         }
         if (is_null($city_id)) {
             $city_id = $request->get('city_id', null);
         }
         if (!is_null($city_id)) {
             $points_query = $points_query->where('city_id', $city_id);
         }
         $points = $points_query->get();
         return static::response($points->toArray(), 200, $format);
     }
     return static::response(['code' => 400, 'message' => "Bad request"], 404, $format);
 }