Beispiel #1
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()]]);
             }
         }
     }
 }
Beispiel #2
0
 /**
  * @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;
 }
Beispiel #3
0
 /**
  * @return mixed
  * @throws \ErrorException
  */
 public function getShortList()
 {
     $result = Request::get('/corporations/corporation_list.json', $this->instanceIdentifier);
     if (!empty($result->error)) {
         Error::exception($result->setFlash[0]->msg);
     }
     return $result->corporations;
 }
Beispiel #4
0
 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;
 }
Beispiel #5
0
 /**
  * @param $companyId
  * @param $level
  * @param $qty
  * @return bool
  * @throws \ErrorException
  */
 public function hire($companyId, $level, $qty)
 {
     $typeId = $this->getTypeIdByLevel($level);
     $qty = intval($qty);
     if ($typeId) {
         Error::exception('Bad worker level.');
         return false;
     }
     $result = Request::post('/company_foreign_workers/add/' . $companyId . '/' . $typeId . '/' . $qty . '.json', array(), $this->instanceIdentifier);
     if (!empty($result->error)) {
         Error::exception($result->setFlash[0]->msg);
         return false;
     }
     return true;
 }
Beispiel #6
0
 public function __construct()
 {
     Error::$exitIfError = true;
     Request::$cookieFileName = __DIR__ . '/../../../storage/framework/cookies/cookie_';
 }
Beispiel #7
0
 /**
  * @return bool
  * @throws \ErrorException
  */
 public function saveVacancy()
 {
     $query = array('data' => array('CompanyVacancy' => array('company_id' => $this->id, 'salary' => $this->vacancy->salary, 'level' => $this->vacancy->level, 'is_hiring' => $this->vacancy->is_hiring)));
     $result = Request::post('/vacancies/save_vacancy.json', $query);
     if (!empty($result->error)) {
         Error::exception($result->setFlash[0]->msg);
     }
     return true;
 }
Beispiel #8
0
 /**
  * @param $production
  * @param $count
  * @param $price
  * @param string $currency
  * @return bool
  * @throws \ErrorException
  */
 public function sellProduction($production, $count, $price, $currency = 'vdollars')
 {
     $result = Request::post('/exchanges/add_corporation_exchange.json', array('data' => array('Exchange' => array('price' => floatval($price), 'currency' => $currency, 'number' => $count, 'item_type_id' => $production instanceof Product ? $production->id : $production, 'corporation_id' => $this->id))), $this->instanceIdentifier);
     if (!empty($result->error)) {
         Error::exception($result->setFlash[0]->msg);
         return false;
     }
     return true;
 }
Beispiel #9
0
 /**
  * Get all companies that belong to user
  *
  * @return \VCAPI\Common\Collection
  * @throws \ErrorException
  */
 public function getCompanies()
 {
     $result = Request::get('/companies/user_companies.json', $this->instanceIdentifier);
     if (empty($result->userId)) {
         return Error::exception('Authorization error');
     }
     $companies = new Collection();
     foreach ($result->companies as $company) {
         $companies->add(new Company($company->Company, $this->instanceIdentifier));
     }
     return $companies;
 }