示例#1
0
文件: Job.php 项目: pshon/vcapi
 /**
  * @param $energy
  * @return array|bool
  * @throws \ErrorException
  */
 public function doWork($energy)
 {
     if (!$this->worker) {
         return Error::exception("User doesn't work now");
     }
     if (!User::getInstance($this->instanceIdentifier)->energy || User::getInstance($this->instanceIdentifier)->energy < $energy) {
         return Error::exception('No energy');
     }
     if ($energy === 0) {
         $energy = User::getInstance($this->instanceIdentifier)->energy;
     }
     if (!($energy = intval($energy))) {
         return Error::exception('Energy must be bigger than null');
     }
     $energy = $this->splitEnergy($energy);
     $statistic = array('energy' => 0, 'salary' => 0, 'experience' => 0, 'production_points' => 0);
     foreach ($energy as $value) {
         $query = array('data' => array('User' => array('energy' => $value), 'Company' => array('id' => $this->companyId)));
         $result = Request::post('/users/begin_work.json', $query, $this->instanceIdentifier);
         $statistic['energy'] += $result->work_report->user_energy_spent;
         $statistic['salary'] += $result->short_work_report->salary;
         $statistic['experience'] += $result->short_work_report->exp;
         $statistic['production_points'] += $result->short_work_report->today_production_points;
     }
     return $statistic;
 }
示例#2
0
 /**
  * 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()]]);
             }
         }
     }
 }
示例#3
0
文件: Vacancy.php 项目: pshon/vcapi
 public function getJob()
 {
     if (User::getInstance()->UserLevel->level < $this->level) {
         Error::exception('User professional level is low, be need ' . $this->level . ' level or higher');
         return false;
     }
     $result = Request::post('/vacancies/work_vacancy.json', array('data' => array('CompanyVacancy' => array('id' => $this->id))), $this->instanceIdentifier);
     return $result;
 }
示例#4
0
 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()]);
 }