/** * Execute the console command. * * @return mixed */ public function fire(Almaty $almaty, Astana $astana) { $city = $this->option('city'); if ($city == 1) { $this->city = $almaty; } else { $this->city = $astana; } $wialon = new Wialon($this->city); $collection = Collection::make(); $cars = $wialon->get_units(); if (!empty($cars)) { DB::beginTransaction(); DB::connection($this->city->db)->table('wialon_cars')->truncate(); foreach ($cars as $v) { $gn = substr($v->nm, 0, 5); $insertion = ["wia_id" => $v->id, 'gn' => isset($gn) ? $gn : '', 'last_message' => isset($v->pos) ? $v->pos->t : 0, 'pos_x' => isset($v->pos) ? $v->pos->x : 0, 'pos_y' => isset($v->pos) ? $v->pos->y : 0, 'uptime' => time()]; $collection->push($insertion); } DB::connection($this->city->db)->table('wialon_cars')->insert($collection->toArray()); DB::commit(); } }