/** * 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(); } } } }
/** * 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->violation == "0") { return false; } $start_day = strtotime('now 00:00:00'); $end_day = strtotime('now 23:59:00'); $violations = Violations::getUncheckedViolations($this->city->db, $start_day, $end_day); if (!$violations->isEmpty()) { foreach ($violations as $v) { $driver = Driver::getDriverInfoByCar($this->city->db, $v->vio_nomer); if (isset($driver->driver_id)) { $this->call('drivers:operations', ['driver' => $driver->driver_id, 'op' => 0, 'summ' => $this->city->violation_price, 'reason' => 'Штраф за превышение скорости', 'time' => time(), 'comment' => $v->vio_text, '--city' => $city]); $v->status = 1; $v->save(); } } } }
public function overmileage() { $time = time() - 86400; $this->wialon->get_report(); $res = DB::connection($this->city->db)->table('overmileage')->where('run', '=', '0')->where('time', '>', $time)->get(); foreach ($res as $v) { $km = $v->mileage - 350; $pcm = 20; $summ = $km * $pcm; $driver = Driver::getDriverInfoByCar($this->city->db, $v->gn); if (isset($driver->driver_id)) { // $v->driver_id = $driver->driver_id; $this->tm->driver_operation($driver->driver_id, 0, 1, 'TEST', 'TEST OVERMILEAGE' . $summ); } } $q = 'UPDATE `overmileage` SET `run`=1 WHERE `time`>' . (time() - 86400); DB::connection($this->city->db)->update($q); return $res; }
public function postCompensation(Request $request) { if ($request->has('id') && $request->has('end_repair')) { $id = $request->get('id'); $end_repair = str_replace('.', '-', $request->get('end_repair')); $end_repair = Carbon::parse($end_repair)->timestamp; $compensation = Compensation::find($id); if ($end_repair > $compensation->shift_end) { $end_repair = $compensation->shift_end; } if ($compensation->begin > $end_repair) { return 'Введенные данные не были правильны пожалуйста повторите'; } $price_for_one_second = $compensation->shift_sum / ($compensation->shift_end - $compensation->shift_start); $in_repair_second = $end_repair - $compensation->begin; $sum = round($price_for_one_second * $in_repair_second, 2); $driver = Driver::getDriverInfoByCar($this->city->db, $compensation->gn); if (empty($driver)) { return 'Извините водитель не найден на такой машине'; } //driver operations here $compensation->end = $end_repair; $compensation->save(); $user = $request->user(); $difference = Carbon::createFromTimestamp($end_repair)->diffInHours(Carbon::createFromTimestamp($compensation->begin)); if ($difference == 0) { $difference = Carbon::createFromTimestamp($end_repair)->diffInMinutes(Carbon::createFromTimestamp($compensation->begin)); $log_description = $user->name . " компенсировал водителю {$compensation->gn} за {$difference} мин"; } else { $log_description = $this->getRole($user) . " " . $user->name . " компенсировал водителю {$compensation->gn} за {$difference} " . Lang::choice('message.times', $difference, [], 'ru'); } $user->userLogs('compensation', $user->name, $log_description, $this->city->index); return "Компенсация в размере {$sum} за {$difference} часов"; } return 'Извините произошла ошибка повторите позже'; }