/** * Execute the console command. * * @return mixed */ public function handle() { Error::$exitIfError = true; Request::$cookieFileName = __DIR__ . '/../../../storage/framework/cookies/cookie_'; $login = DB::table('config')->where('name', '=', 'login')->select('value')->get(); try { User::getInstance($login[0]->value)->getShortInfo(); } catch (\Exception $e) { $password = DB::table('config')->where('name', '=', 'password')->select('value')->get(); User::getInstance($login[0]->value)->Auth($login[0]->value, $password[0]->value); User::getInstance($login[0]->value)->getShortInfo(); } $jobs = DB::table('job')->get(); foreach ($jobs as $job) { $conditions = json_decode($job->conditions); if (User::getInstance($login[0]->value)->energy > $conditions->energy) { $vcJob = new VCJob($login[0]->value); $vcJob->companyId = $job->company_id; $vcJob->worker = true; try { $statistic = $vcJob->doWork($conditions->energy); DB::table('log')->insert(['section' => 'job', 'type' => 'success', 'message' => 'Work is done', 'data' => json_encode($statistic)]); } catch (\Exception $e) { DB::table('log')->insert(['section' => 'job', 'type' => 'error', 'message' => 'Work failed', 'data' => ['code' => $e->getCode(), 'message' => $e->getMessage()]]); } } } }
public function dashboard(Request $request) { $login = DB::table('config')->where('name', '=', 'login')->select('value')->get(); try { User::getInstance($login[0]->value)->getShortInfo(); } catch (\Exception $e) { $password = DB::table('config')->where('name', '=', 'password')->select('value')->get(); User::getInstance($login[0]->value)->Auth($login[0]->value, $password[0]->value); User::getInstance($login[0]->value)->getShortInfo(); } $job = new Job($login[0]->value); $job->getShortInfo(); if ($request->has('job')) { $form = $request->get('job'); DB::table('job')->insert(['user_id' => '', 'company_id' => $form['company_id'], 'conditions' => json_encode($form['condition'])]); return redirect()->action('MainController@dashboard'); } $logs = DB::table('log')->orderBy('created_at', 'desc')->get(); foreach ($logs as &$log) { $log->data = json_decode($log->data); } $plannedJobs = DB::table('job')->orderBy('created_at', 'desc')->get(); return view('main.dashboard', ['user' => User::getInstance($login[0]->value), 'job' => $job, 'logs' => $logs, 'plannedJobs' => $plannedJobs, 'companies' => User::getInstance($login[0]->value)->getCompanies()->toObject()]); }