public function updateSmens() { $res = $this->tm->get_shifts($this->start_day, $this->end_day); $time = time(); foreach ($res as $v) { $crew = DB::connection($this->city->db)->table('crews')->where('driver', $v->driver_id)->first(); $insert_data = ['id' => $v->shift_id, 'driver' => $v->driver_id, 'begin' => strtotime($v->plan_shift_start_time), 'end' => strtotime($v->plan_shift_finish_time), 'crew' => isset($crew->id) ? $crew->id : 0, 'type' => $v->shift_state, 'uptime' => $time]; $smen = DB::connection($this->city->db)->table('smens')->where('id', $v->shift_id)->first(); if (!empty($smen)) { unset($insert_data['id']); DB::connection($this->city->db)->table('smens')->where('id', $v->shift_id)->update($insert_data); } else { DB::connection($this->city->db)->table('smens')->insert($insert_data); $buy_driver = Driver::on($this->city->db)->find($v->driver_id); if (!empty($buy_driver) && $v->plan_shift_cost != 1) { $locked_alias = Driver::on($this->city->db)->where('name', $buy_driver->name)->where('type', 'dolg')->where('balans', '<', '0')->first(); if (!empty($locked_alias)) { $summ = $locked_alias->balans > -2000 ? abs($locked_alias->balans) : 2000; $this->dr->MoneyOperations($buy_driver->id, 0, 1, 'TEST', 'TEST TRANSFER TO DEB' . $summ); $this->dr->MoneyOperations($locked_alias->id, 1, 1, 'TEST', 'TEST TRANSFER TO DEB' . $summ); $locked_a2 = Driver::find($locked_alias->id); if (isset($locked_a2) && $locked_a2->balans >= 0) { $this->dr->deleteDriver($locked_a2->id); } } } } } return $res; }
/** * Execute the console command. * * @return mixed */ public function fire(Almaty $almaty, Astana $astana) { $city = $this->option('city'); $driverId = $this->argument('id'); if ($city == 1) { $this->city = $almaty; } else { $this->city = $astana; } Driver::on($this->city->db)->delete($driverId); }
/** * Execute the console command. * * @return mixed */ public function fire(Almaty $almaty, Astana $astana) { $city = $this->option('city'); $driverId = $this->argument('id'); if ($city == 1) { $this->city = $almaty; } else { $this->city = $astana; } $driver = Driver::on($this->city->db)->find($driverId); if ($driver != null && $driver->type == 'driver') { $this->call('drivers:operations', ['driver' => $driver->id, 'op' => 1, 'summ' => 15000, 'reason' => 'Бонусное пополнение счета', 'time' => time(), '--city' => $city]); $driver->is_new = 0; $driver->save(); } }
/** * Execute the console command. * * @return mixed */ public function fire(Almaty $almaty, Astana $astana) { $city = $this->option('city'); $start_day = strtotime('now 00:00:00'); $end_day = strtotime('now 23:59:59'); $insertCollection = Collection::make(); $updateCollection = Collection::make(); if ($city == 1) { $this->city = $almaty; } else { $this->city = $astana; } $tm = new TMBase($this->city); $shifts = $tm->get_shifts($start_day, $end_day); DB::beginTransaction(); foreach ($shifts as $v) { $crew = Crews::on($this->city->db)->where('driver', $v->driver_id)->first(); $insertion = ['id' => empty($v->shift_id) ? 'NULL' : $v->shift_id, 'driver' => empty($v->driver_id) ? 'NULL' : $v->driver_id, 'begin' => empty($v->plan_shift_start_time) ? 'NULL' : strtotime($v->plan_shift_start_time), 'end' => empty($v->plan_shift_finish_time) ? 'NULL' : strtotime($v->plan_shift_finish_time), 'crew' => isset($crew->id) ? $crew->id : 'NULL', 'type' => empty($v->shift_state) ? 'NULL' : $v->shift_state, 'uptime' => time()]; $shift = \App\Models\Smens::on($this->city->db)->find($v->shift_id); if (empty($shift)) { $insertCollection->push($insertion); $driver = Driver::on($this->city->db)->find($v->driver_id); if (!empty($driver) && $v->plan_shift_cost != 1 && $this->city->transfer_to_debtors == "1") { $locked_alias = Driver::getLockedDriver($this->city->db, $driver->name); if (!empty($locked_alias)) { $summ = $locked_alias->balans > -2000 ? abs($locked_alias->balans) : $this->city->transfer_to_debtor_price; $this->call('drivers:operations', ['driver' => $driver->id, 'op' => '0', 'summ' => $summ, 'reason' => 'Перевод в счет долга', 'time' => time(), '--city' => $city]); $this->call('drivers:operations', ['driver' => $locked_alias->id, 'op' => '1', 'summ' => $summ, 'reason' => 'Перевод в счет долга', 'time' => time(), '--city' => $city]); $locked_a2 = Driver::on($this->city->db)->find($locked_alias->id); if (isset($locked_a2) && $locked_a2->balans >= 0) { $this->call('drivers:delete', ['id' => $locked_a2->id, '--city' => $city]); } } } } } if (!$insertCollection->isEmpty()) { \App\Models\Smens::on($this->city->db)->insert($insertCollection->toArray()); } DB::commit(); }
public function deleteDriver($id) { $driver = Driver::on($this->city->db)->find($id); $driver->deleted = time(); $driver->save(); }
private function endUpdate($time) { Driver::on($this->city->db)->where('uptime', '<', $time)->delete(); }
public function shiftsToCredit(Request $request) { $drivers = Driver::on($this->city->db)->where('type', '=', 'driver')->orWhere('type', '=', 'base')->orderBy('name')->get(['id', 'name']); return view('personal.shiftsToCredit', ['drivers' => $drivers]); }