Example #1
0
 /**
  * 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;
     }
     $insertCollection = Collection::make();
     $updateCollection = Collection::make();
     $wialon = new Wialon($this->city);
     $start_day = strtotime('now 00:00:00');
     $end_day = strtotime('now 23:59:00');
     $drivers = $wialon->get_drivers();
     $get_exec = $wialon->select_exec();
     $violations = \App\Models\Violations::on($this->city->db)->whereBetween('vio_date', [$start_day, $end_day])->get(['id', 'vio_nomer', 'vio_date', 'updated']);
     if (!$violations->isEmpty()) {
         foreach ($violations as $db) {
             foreach ($get_exec as $key => $a) {
                 $number_car = $a->r[0]->c[1];
                 $number_car = substr($number_car, 0, 5);
                 $vio = $a->r[0]->c[3]->t;
                 $date_vio_timestamp = $a->r[0]->c[2]->v;
                 if ($db->vio_date == $date_vio_timestamp && $number_car == $db->vio_nomer) {
                     $db->updated = date('Y-m-d H:i:s', time());
                     $db->save();
                     unset($get_exec[$key]);
                 }
             }
         }
     }
     if (!isset($get_exec->error) && !empty($get_exec)) {
         foreach ($get_exec as $k => $a) {
             $number_car = substr($a->r[0]->c[1], 0, 5);
             $vio = $a->r[0]->c[3]->t;
             $date_vio = $a->r[0]->c[2]->v;
             $insertion = ['vio_nomer' => $number_car, 'vio_date' => $date_vio, 'vio_text' => $vio, 'status' => 0, 'city' => $this->city->city, 'updated' => date('Y-m-d H:i:s', time())];
             $insertCollection->push($insertion);
         }
     }
     \App\Models\Violations::on($this->city->db)->insert($insertCollection->toArray());
     $this->endUpdate($start_day);
     $this->call('drivers:violation', ['--city' => $city]);
 }