public function defineWalletAccount(Round $round) { $round->setWalletAccount($this->walletAccountPrefix . $round->getId()); $this->em->flush($round); }
/** * @Route("/round/{round}", name="admin_round", defaults={"round" = null}) * @Template() */ public function roundAction(Request $request, Round $round = null) { $this->checkIp($request); // new round defining if (!$round) { $round = new Round(); if (!($currentRound = $this->roundRepo->findOneBy(['started' => true, 'finished' => false]))) { // first round auto start $roundId = 1; } else { $lastRound = $this->roundRepo->findOneBy([], ['id' => 'desc']); $roundId = $lastRound->getId() + 1; } } else { $roundId = $round->getId(); } $form = $this->createForm(new RoundType(), $round); if ($request->isMethod('post')) { $form->submit($request); if ($form->isValid()) { if ($roundId == 1) { $round->setStarted(true); } $this->em->persist($round); $this->em->flush(); $this->roundManager->defineWalletAccount($round); return $this->redirect($this->generateUrl('admin')); } } return $this->render('AppBundle:Admin:round.html.twig', ['round' => $round, 'roundId' => $roundId, 'form' => $form->createView()]); }
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(); }