Beispiel #1
0
 /**
  * @return array|\Bml\CoinBundle\Entity\TransactionListResult[]
  */
 public function getNewIncomingTransactions()
 {
     $round = $this->round;
     $newTransactions = [];
     /* @var $newTransactions \Bml\CoinBundle\Entity\TransactionListResult[] */
     $from = 0;
     $step = 10;
     do {
         $transactions = $this->manager->listTransactions($round->getWalletAccount(), $step, $from);
         $transactions = array_reverse($transactions);
         /* @var $transactions TransactionListResult[] */
         foreach ($transactions as $transaction) {
             if ($transaction->getCategory() != TransactionListResult::CATEGORY_RECEIVE) {
                 continue;
             }
             if ($transaction->getTxId() == $round->getStats()->getLastCheckedTx() || !$transactions) {
                 break 2;
             }
             if (!$this->depositRepo->findOneBy(['txIn' => $transaction->getTxId(), 'round' => $this->round])) {
                 $newTransactions[] = $transaction;
             }
         }
         $from += $step;
     } while (count($transactions));
     $newTransactions = array_reverse($newTransactions);
     return !empty($newTransactions) ? $newTransactions : null;
 }
Beispiel #2
0
 public function realiseRoundEndPayouts()
 {
     // last deposit
     $balance = $this->round->getStats()->getBalance();
     if (!$balance) {
         return;
     }
     $lastPayoutPercent = $this->round->getLastPayoutPercent();
     $payoutsToRealise = [];
     if ($lastPayoutPercent > 0) {
         $lastDeposit = $this->depositRepo->findOneBy(['round' => $this->round->getId()], ['id' => 'desc']);
         $payout = $payoutsToRealise[] = $lastDeposit->getDefaultPayout();
         $amount = $lastDeposit->getAmount() * $lastPayoutPercent / 100;
         $payout->setExpectedAmount($amount);
         if ($amount > $balance) {
             $amount = $balance;
         }
         $payout->setAmount($amount);
         $payout->setFee($payout->getAmount() * $this->round->getPayoutFeePercent() / 100);
         $payout->setType(Payout::TYPE_LAST_PAYOUT);
         $payout->setReadyForPayout(true);
         $this->em->persist($payout);
         $this->em->flush();
         $balance -= $payout->getAmount() + $payout->getFee();
     }
     if ($balance > 0) {
         // admin last payout
         $adminLastPayoutPercent = $this->round->getAdminLastPayoutPercent();
         if ($adminLastPayoutPercent > 0) {
             $payout = new Payout();
             $amount = $balance * $adminLastPayoutPercent / 100;
             $payout->setExpectedAmount($amount);
             if ($amount > $balance) {
                 $amount = $balance;
             }
             $payout->setAmount($amount);
             $payout->setFee(0);
             $payout->setType(Payout::TYPE_LAST_ADMIN_PAYOUT);
             $payout->setReadyForPayout(true);
             $this->em->persist($payout);
             $this->em->flush();
             $payout->setPaid(true);
             // not sending it will simply stay on the wallet account for later manual withdrawal
             $this->em->flush();
             $balance -= $payout->getAmount() + $payout->getFee();
         }
     }
     // remaining payouts
     $payouts = $this->payoutRepo->findForPayout($this->round, 'desc');
     $payoutPercent = $this->round->getRoundEndRemainingReturnPercent();
     foreach ($payouts as $payout) {
         if ($payout->isLastPayout()) {
             // already in $payoutsToRealise array
             continue;
         }
         if ($balance > 0) {
             $amount = $payout->getDeposit()->getAmount() * $payoutPercent / 100;
             $payout->isReferrerPayout() && ($amount = $amount * $this->round->getReferrerPayoutPercent() / 100);
             $payout->setExpectedAmount($amount);
             if ($amount > $balance) {
                 $amount = $balance;
             }
             $payout->setAmount($amount);
             $payout->setFee($payout->getAmount() * $this->round->getPayoutFeePercent() / 100);
             $payoutsToRealise[] = $payout;
             $balance -= $payout->getAmount() + $payout->getFee();
         }
     }
     $this->_realisePayouts($payoutsToRealise);
     $this->em->flush();
 }