Beispiel #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire(Almaty $almaty, Astana $astana)
 {
     $time = time() - 86400;
     $city = $this->option('city');
     if ($city == 1) {
         $this->city = $almaty;
     } else {
         $this->city = $astana;
     }
     if ($this->city->overmilleage == "0") {
         return false;
     }
     $wialon = new Wialon($this->city);
     $wialon->get_report();
     $milleages = Overmileage::on($this->city->db)->where('run', '=', '0')->where('time', '>', $time)->get();
     if (!$milleages->isEmpty()) {
         foreach ($milleages as $v) {
             $km = $v->mileage - 350;
             $pcm = $this->city->overmilleage_price;
             $summ = $km * $pcm;
             $driver = Driver::getDriverInfoByCar($this->city->db, $v->gn);
             if (isset($driver->driver_id)) {
                 $this->call('drivers:operations', ['driver' => $driver->driver_id, 'op' => 0, 'summ' => $summ, 'reason' => 'Суточный перепробег', 'time' => time(), '--city' => $city]);
                 $v->run = 1;
                 $v->save();
             }
         }
     }
 }
Beispiel #2
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;
     }
     if ($this->city->overshift == "0") {
         return false;
     }
     $start = microtime(true);
     $slise_size = 150;
     $crews = file_get_contents('http://api.komandir.kz/ovsh/main2.php');
     $crews = json_decode($crews, true);
     $wialon = new Wialon($this->city);
     $report_from_wialon = [];
     for ($i = 0; $i < count($crews); $i += $slise_size) {
         $tmp = array_slice($crews, $i, $i + $slise_size, true);
         $tmp = $wialon->get_test_report($tmp);
         $tmp = json_decode($tmp);
         $report_from_wialon = array_merge($tmp, $report_from_wialon);
     }
     $results = [];
     foreach ($report_from_wialon as $v) {
         if (isset($v->reportResult->stats)) {
             $cnt = str_replace(' km', '', $v->reportResult->stats[0][1]);
             if ($cnt > 2) {
                 $gn = substr($v->reportResult->stats[1][1], 0, 5);
                 array_push($results, ['gn' => $gn, 'cnt' => $cnt]);
             }
         }
     }
     $results = Helpers::merge_two_arrays($results, $crews, 'gn');
     foreach ($results as $v) {
         if (isset($v['cnt'])) {
             $driver = DB::connection($this->city->db)->table('crews_info')->where('crew_id', '=', $v['id'])->get(['driver_id']);
             $sum = $v['cnt'] * $this->city->overshift_price;
             if (!empty($driver)) {
                 foreach ($driver as $val) {
                     $this->call('drivers:operations', ['driver' => $val->driver_id, 'op' => 0, 'summ' => $sum, 'reason' => 'Перепробег вне смены', 'time' => time(), '--city' => $city]);
                     DB::connection($this->city->db)->table('overshift')->insert(['time' => time(), 'crews_id' => $v['id'], 'km' => $v['cnt'], 'begin' => $v['begin_time'], 'end' => $v['end_time']]);
                     DB::connection($this->city->db)->table('overshift_called')->insert(['crew_id' => $v['id'], 'time' => time()]);
                 }
             }
         }
     }
     $end_time = microtime(true);
     $this->info($end_time - $start);
 }
Beispiel #3
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]);
 }
Beispiel #4
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;
     }
     $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();
     }
 }