/** * @Route("/{round}/stats", name="stats", requirements={"round": "\d+"}) * @Template() */ public function statsAction($round = null) { $round = $round ? $this->roundRepo->find($round) : $this->roundRepo->findCurrent(); $payouts = $this->payoutRepo->findBy(['round' => $round], ['id' => 'desc']); return $this->common(['page' => 'stats', 'payouts' => $payouts, 'round' => $round]); }
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(); }