public function sendToFund(Request $request = null) { return $this->formbuilder->processForm(['object' => new SendFund(), 'caption' => 'Отправить', 'cancel_caption' => 'Отмена', 'action' => $this->action2], function (Form $form) { $user = $this->user->getUserObject(); //UserClient $fund = $form->getData()->fund; $c = $this->em->createQuery('UPDATE AppBundle:UserClientActivatedAction u ' . 'SET ' . 'u.fund=:fund,' . 'u.status=2 ' . 'WHERE ' . 'u.user=:user and ' . 'u.status=1')->execute(['user' => $user, 'fund' => $fund]); $c2 = $this->em->createQuery('UPDATE AppBundle:UserClientActionsClicks u ' . 'SET ' . 'u.fund=:fund,' . 'u.clickPriceActual=false ' . 'WHERE ' . 'u.user=:user and ' . 'u.clickPriceActual=true')->execute(['user' => $user, 'fund' => $fund]); if (!$c && !$c2) { throw new \Exception('Нечего отправлять, т.к. ваш баланс 0'); } }, $request); }
/** * * @throws \Exception */ public function deactivateAction(Request $request = null, $id = null) { $object = new DeactivateAction(); if (!is_null($id)) { $object->action_id = $id; } return $this->builder->processForm(['object' => $object, 'caption' => 'Деактивировать', 'action' => $this->action2], function ($form) { $user_object = $this->user->getUserObject(); $target = $this->em->getRepository('AppBundle:BizAction')->findOneBy(['biz' => $user_object, 'active' => true, 'id' => $form->getData()->action_id]); if (is_null($target)) { throw new \Exception('Акция уже деактивирована'); } $target->active = false; $this->em->persist($target); $this->em->flush(); }, $request); }
protected function processReport($biz_id = null, Request $request = null) { $object = new FundReport(); $object->biz_id = $biz_id; return $this->formbuilder->processForm(['object' => $object, 'caption' => 'Отправить', 'action' => $this->action], function ($form) { $data = $form->getData(); $this->user->checkImageAccess($data->photo, 'report_image'); $fund = $this->user->getUserObject(); $biz = $this->em->getRepository('AppBundle:UserBiz')->getExistsById($data->biz_id); $c = $this->em->createQuery('SELECT count(u) ' . 'FROM AppBundle:Cert u ' . 'WHERE u.brand=:biz and u.fund=:fund')->setHydrationMode(Query::HYDRATE_SINGLE_SCALAR)->execute(['biz' => $biz, 'fund' => $fund]); if (!$c) { throw new \Exception('Отправка отчета недоступна т.к. нет сертификатов для данного бизнеса'); } $data->setFund($fund); $data->setBiz($biz); $this->em->persist($data); $this->em->flush(); }, $request); }