Exemplo n.º 1
0
 /**
  * Retreive Wallet Transaction Entries for a Character
  *
  * @param int  $character_id
  * @param bool $get
  * @param int  $chunk
  *
  * @return
  */
 public function getCharacterWalletTransactions(int $character_id, bool $get = true, int $chunk = 50)
 {
     $transactions = WalletTransaction::where('characterID', $character_id);
     if ($get) {
         return $transactions->orderBy('transactionDateTime', 'desc')->paginate($chunk);
     }
     return $transactions;
 }
Exemplo n.º 2
0
 /**
  * Run the Update
  *
  * @return mixed|void
  */
 public function call()
 {
     $pheal = $this->setScope('char')->getPheal();
     foreach ($this->api_info->characters as $character) {
         // 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(['characterID' => $character->characterID, '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($character->characterID, $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('characterID', $character->characterID)->where('hash', $transaction_hash)->first()) {
                     $transaction_overlap = true;
                     continue;
                 }
                 WalletTransaction::create(['characterID' => $character->characterID, 'hash' => $transaction_hash, 'transactionID' => $transaction->transactionID, 'transactionDateTime' => $transaction->transactionDateTime, 'quantity' => $transaction->quantity, 'typeName' => $transaction->typeName, 'typeID' => $transaction->typeID, 'price' => $transaction->price, 'clientID' => $transaction->clientID, 'clientName' => $transaction->clientName, '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)
     }
     return;
 }
Exemplo n.º 3
0
 /**
  * Retreive Wallet Transaction Entries for a Character
  *
  * @param                               $character_id
  * @param int                           $chunk
  * @param \Illuminate\Http\Request|null $request
  *
  * @return mixed
  */
 public function getCharacterWalletTransactions($character_id, $chunk = 50, Request $request = null)
 {
     $transactions = WalletTransaction::where('characterID', $character_id);
     // Apply any received filters
     if ($request && $request->filter) {
         $transactions = $this->where_filter($transactions, $request->filter, config('web.filter.rules.character_transactions'));
     }
     return $transactions->orderBy('transactionDateTime', 'desc')->paginate($chunk);
 }
Exemplo n.º 4
0
 /**
  * @param int $character_id
  *
  * @return \Illuminate\Support\Collection
  */
 public function characterTopWalletTransactionInteractions(int $character_id)
 {
     return WalletTransaction::leftJoin('character_affiliations', function ($join) {
         $join->on('character_affiliations.characterID', '=', 'character_wallet_transactions.clientID');
     })->where('character_wallet_transactions.characterID', $character_id)->where('character_wallet_transactions.clientID', '<>', $character_id)->select('character_affiliations.characterID', 'character_affiliations.characterName', 'character_affiliations.corporationID', 'character_affiliations.corporationName', 'character_affiliations.allianceID', 'character_affiliations.allianceName')->selectRaw('count(clientID) as total')->groupBy('clientID');
 }