Exemplo n.º 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()]]);
             }
         }
     }
 }
Exemplo n.º 2
0
Arquivo: Job.php Projeto: 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;
 }
Exemplo n.º 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;
 }
Exemplo n.º 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;
 }
Exemplo n.º 5
0
 public function loadVacancies()
 {
     $result = Request::get('/vacancies/index.json', $this->instanceIdentifier);
     $this->companies = $result->companies;
     if (empty($result->vacancies)) {
         $this->vacancies = array();
         $this->indexes = array();
     } else {
         $this->vacancies = $result->vacancies;
         $this->rebuildIndexes();
     }
 }
Exemplo n.º 6
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;
 }
Exemplo n.º 7
0
 public function __construct()
 {
     Error::$exitIfError = true;
     Request::$cookieFileName = __DIR__ . '/../../../storage/framework/cookies/cookie_';
 }
Exemplo n.º 8
0
 /**
  * @param string $currency (vdollars OR vgold)
  * @param $itemTypeId
  * @param string $sort (price or date)
  * @param string $direction (asc OR desc)
  * @return mixed
  */
 public function getLotsOffer($currency, $itemTypeId, $sort = 'price', $direction = 'asc')
 {
     $result = Request::get('/exchanges/lot_offers/' . $currency . '/' . $itemTypeId . '/' . $sort . '/' . $direction . '.json', $this->instanceIdentifier);
     return $this->validateResponse($result, 'offers');
 }
Exemplo n.º 9
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;
 }
Exemplo n.º 10
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;
 }
Exemplo n.º 11
0
Arquivo: User.php Projeto: pshon/vcapi
 public function unAuth()
 {
     Request::removeCookie($this->instanceIdentifier);
 }