Ejemplo n.º 1
0
 /**
  * Return Wallet Transactions for a Corporation
  *
  * @param int  $corporation_id
  * @param bool $get
  * @param int  $chunk
  *
  * @return
  */
 public function getCorporationWalletTransactions(int $corporation_id, bool $get = true, int $chunk = 50)
 {
     $transactions = WalletTransaction::where('corporationID', $corporation_id);
     if ($get) {
         return $transactions->orderBy('transactionDateTime', 'desc')->paginate($chunk);
     }
     return $transactions;
 }
Ejemplo n.º 2
0
 /**
  * Run the Update
  *
  * @return mixed|void
  */
 public function call()
 {
     $pheal = $this->setScope('corp')->setCorporationID()->getPheal();
     $account_ids = AccountBalanceModel::where('corporationID', $this->corporationID)->lists('accountKey');
     foreach ($account_ids as $account_id) {
         // Define the first MAX from_id to use when
         // retreiving transactions.
         $from_id = PHP_INT_MAX;
         // Set the transaction overlap marker. This will
         // be checked after processing an API response to
         // see if any of the transactions we got back was
         // already known.
         $transaction_overlap = false;
         // This infinite loop needs to be broken out of
         // once we have reached the end of the backwards
         // journal walking. Walking ends when we have
         // either received less rows than asked for, or
         // we have reached a known transaction hash.
         while (true) {
             $result = $pheal->WalletTransactions(['accountKey' => $account_id, 'rowCount' => $this->rows_per_call] + ($from_id == PHP_INT_MAX ? [] : ['fromID' => $from_id]));
             foreach ($result->transactions as $transaction) {
                 // Ensure that $from_id is at its lowest
                 $from_id = min($transaction->transactionID, $from_id);
                 // Transactions are uniquely identified by applying a
                 // quick hash function over a few identifying fields.
                 // This is because transactionID's may exhaust their
                 // lifetime and lapse.
                 $transaction_hash = $this->hash_transaction($this->corporationID, $account_id, $transaction->transactionDateTime . $transaction->clientID, $transaction->transactionID);
                 // Check if the transaction is known. If it is,
                 // then we can just continue to the next. We will
                 // also use this opportunity to mark that the results
                 // received overlapped an existing record, meaning
                 // that we can stop calling the API for more wallet
                 // transactions. We dont immediately break because
                 // the transactions are not always received in any
                 // order for the fromID that was specified.
                 if (WalletTransaction::where('corporationID', $this->corporationID)->where('hash', $transaction_hash)->first()) {
                     $transaction_overlap = true;
                     continue;
                 }
                 WalletTransaction::create(['hash' => $transaction_hash, 'corporationID' => $this->corporationID, 'accountKey' => $account_id, 'transactionDateTime' => $transaction->transactionDateTime, 'transactionID' => $transaction->transactionID, 'quantity' => $transaction->quantity, 'typeName' => $transaction->typeName, 'typeID' => $transaction->typeID, 'price' => $transaction->price, 'clientID' => $transaction->clientID, 'clientName' => $transaction->clientName, 'characterID' => $transaction->characterID, 'characterName' => $transaction->characterName, 'stationID' => $transaction->stationID, 'stationName' => $transaction->stationName, 'transactionType' => $transaction->transactionType, 'transactionFor' => $transaction->transactionFor, 'journalTransactionID' => $transaction->journalTransactionID, 'clientTypeID' => $transaction->clientTypeID]);
             }
             // Foreach transactions
             // As previously mentioned, there may be a few
             // conditions where we may decide its time to
             // break out of the infinite loop. This is where
             // we will be doing those checks. The most ob-
             // vious one being that we may have received less
             // than the total amount of rows asked for.
             if (count($result->transactions) < $this->rows_per_call) {
                 break;
             }
             // If the response contained known transactions,
             // stop processing for this character.
             if ($transaction_overlap) {
                 break;
             }
         }
         // while(true)
     }
     // Foreach account_id
     return;
 }
Ejemplo n.º 3
0
 /**
  * Return Wallet Transactions for a Corporation
  *
  * @param                               $corporation_id
  * @param int                           $chunk
  * @param \Illuminate\Http\Request|null $request
  *
  * @return mixed
  * @throws \Seat\Services\Exceptions\FilterException
  */
 public function getCorporationWalletTransactions($corporation_id, $chunk = 50, Request $request = null)
 {
     $transactions = WalletTransaction::where('corporationID', $corporation_id);
     // Apply any received filters
     if ($request && $request->filter) {
         $transactions = $this->where_filter($transactions, $request->filter, config('web.filter.rules.corporation_transactions'));
     }
     return $transactions->orderBy('transactionDateTime', 'desc')->paginate($chunk);
 }