/**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $userIds = $input->getArgument('user');
     /** @var \Doctrine\ORM\EntityManager $em */
     $em = $this->getContainer()->get('doctrine.orm.default_entity_manager');
     $userRepo = $em->getRepository('VifeedUserBundle:User');
     $users = $userRepo->findBy(['id' => $userIds]);
     foreach ($users as $user) {
         $wallet = $em->getRepository('VifeedPaymentBundle:Wallet')->findOneBy(['user' => $user]);
         for ($i = 0; $i < 500; $i++) {
             $em->beginTransaction();
             $em->lock($user, LockMode::PESSIMISTIC_WRITE);
             try {
                 $withdrawal = new Withdrawal();
                 $withdrawal->setUser($user)->setAmount(20)->setWallet($wallet)->setStatus(Withdrawal::STATUS_CREATED);
                 $em->persist($withdrawal);
                 $userRepo->updateBalance($user, -$withdrawal->getAmount());
                 $em->flush();
                 $em->commit();
             } catch (\Exception $e) {
                 $em->rollback();
                 $em->close();
                 throw $e;
             }
             usleep(mt_rand(500, 2000));
         }
     }
 }
Exemple #2
0
 protected static function loadTestFixtures()
 {
     $userManager = self::getContainer()->get('fos_user.user_manager');
     $tokenManager = self::getContainer()->get('vifeed.user.wsse_token_manager');
     /** @var User $publisher */
     $publisher = $userManager->createUser();
     $publisher->setEmail('*****@*****.**')->setUsername('*****@*****.**')->setBalance(100)->setEnabled(true)->setType(User::TYPE_PUBLISHER)->setPlainPassword('12345');
     $userManager->updateUser($publisher);
     $publisher2 = $userManager->createUser();
     $publisher2->setEmail('*****@*****.**')->setUsername('*****@*****.**')->setBalance(100)->setEnabled(true)->setType(User::TYPE_PUBLISHER)->setPlainPassword('12345');
     $userManager->updateUser($publisher2);
     $wallet1 = new Wallet();
     $wallet1->setUser($publisher)->setNumber(12345)->setType('yandex');
     self::$em->persist($wallet1);
     $wallet2 = new Wallet();
     $wallet2->setUser($publisher)->setNumber(12345)->setType('wm');
     self::$em->persist($wallet2);
     $wallet3 = new Wallet();
     $wallet3->setUser($publisher2)->setNumber(12345)->setType('wm');
     self::$em->persist($wallet3);
     $withdrawal1 = new Withdrawal();
     $withdrawal1->setUser($publisher)->setAmount(40)->setWallet($wallet1)->setCreatedAt(new \DateTime('2014-02-09'))->setStatus(Withdrawal::STATUS_OK);
     self::$em->persist($withdrawal1);
     $withdrawal2 = new Withdrawal();
     $withdrawal2->setUser($publisher)->setAmount(60)->setWallet($wallet1)->setCreatedAt(new \DateTime('2014-02-10'))->setStatus(Withdrawal::STATUS_OK);
     self::$em->persist($withdrawal2);
     $withdrawal3 = new Withdrawal();
     $withdrawal3->setUser($publisher)->setAmount(60)->setWallet($wallet1)->setCreatedAt(new \DateTime('2014-02-10'))->setStatus(Withdrawal::STATUS_CREATED);
     self::$em->persist($withdrawal3);
     $withdrawal4 = new Withdrawal();
     $withdrawal4->setUser($publisher)->setAmount(60)->setWallet($wallet2)->setCreatedAt(new \DateTime('2014-02-10'))->setStatus(Withdrawal::STATUS_ERROR);
     self::$em->persist($withdrawal4);
     self::$em->flush();
     self::$em->getConnection()->executeQuery('update withdrawal set updated_at="2014-02-12 15:00" where id=' . $withdrawal1->getId());
     self::$em->getConnection()->executeQuery('update withdrawal set updated_at="2014-02-11 11:00" where id=' . $withdrawal2->getId());
     $tokenManager->createUserToken($publisher->getId());
     $tokenManager->createUserToken($publisher2->getId());
     return ['users' => [$publisher, $publisher2], 'wallets' => [$wallet1, $wallet2, $wallet3]];
 }
Exemple #3
0
 protected static function loadTestFixtures()
 {
     /** @var UserManager $userManager */
     $userManager = self::getContainer()->get('fos_user.user_manager');
     /** @var EntityManager $entityManager */
     $entityManager = self::$em;
     $campaignManager = self::getContainer()->get('vifeed.campaign.manager');
     $tokenManager = static::getContainer()->get('vifeed.user.wsse_token_manager');
     /** @var VideoViewPaymentManager $viewPaymentManager */
     $viewPaymentManager = self::getContainer()->get('vifeed.payment.video_view_payment_manager');
     $paymentPluginController = self::getContainer()->get('payment.plugin_controller');
     /** @var StatsManager $statsManager */
     $statsManager = self::getContainer()->get('vifeed.videoview.stats_manager');
     /** @var User $advertiser */
     $advertiser = $userManager->createUser();
     $advertiser->setEmail('*****@*****.**')->setUsername('*****@*****.**')->setBalance(26)->setEnabled(true)->setType(User::TYPE_ADVERTISER)->setPlainPassword('12345');
     $userManager->updateUser($advertiser, false);
     /** @var User $publisher */
     $publisher = $userManager->createUser();
     $publisher->setEmail('*****@*****.**')->setUsername('*****@*****.**')->setBalance(200)->setEnabled(true)->setType(User::TYPE_PUBLISHER)->setPlainPassword('12345');
     $userManager->updateUser($publisher, false);
     $campaign1 = new Campaign();
     $campaign1->setStatus(Campaign::STATUS_ON)->setBid(3)->setName('111')->setUser($advertiser)->setHash(substr(md5(mt_rand(1, 100)), 0, 11))->setDailyBudget(7)->setBalance(10)->setGeneralBudget(10);
     $campaignManager->save($campaign1);
     $campaign2 = new Campaign();
     $campaign2->setStatus(Campaign::STATUS_ON)->setBid(3)->setName('222')->setUser($advertiser)->setHash(substr(md5(mt_rand(1, 100)), 0, 11))->setDailyBudget(0)->setBalance(10)->setGeneralBudget(10)->setDeletedAt(new \DateTime('2014-02-10'));
     $campaignManager->save($campaign2);
     $platform1 = new Platform();
     $platform1->setName('111')->setUser($publisher)->setUrl('111')->setDescription('');
     $entityManager->persist($platform1);
     // плолщадка удалена (soft-delete)
     $platform2 = new Platform();
     $platform2->setName('222')->setUser($publisher)->setUrl('222')->setDescription('')->setDeletedAt(new \DateTime('2014-02-10'));
     $entityManager->persist($platform2);
     $view1 = new VideoView();
     $view1->setCampaign($campaign1)->setPlatform($platform1)->setCurrentTime(60)->setTimestamp((new \DateTime('2014-02-22 00:00:00'))->format('U'))->setTrackNumber(60)->setViewerId(md5(1));
     $entityManager->persist($view1);
     $entityManager->flush();
     $viewPaymentManager->reckon($view1);
     $view2 = new VideoView();
     $view2->setCampaign($campaign1)->setPlatform($platform2)->setCurrentTime(60)->setTimestamp((new \DateTime('2014-02-23 00:00:00'))->format('U'))->setTrackNumber(60)->setViewerId(md5(2));
     $entityManager->persist($view2);
     $entityManager->flush();
     $viewPaymentManager->reckon($view2);
     $view3 = new VideoView();
     $view3->setCampaign($campaign2)->setPlatform($platform1)->setCurrentTime(60)->setTimestamp((new \DateTime('2014-02-23 23:00:00'))->format('U'))->setTrackNumber(60)->setViewerId(md5(3));
     $entityManager->persist($view3);
     $entityManager->flush();
     $viewPaymentManager->reckon($view3);
     $view4 = new VideoView();
     $view4->setCampaign($campaign2)->setPlatform($platform1)->setCurrentTime(60)->setTimestamp((new \DateTime('2014-02-23 23:29:59'))->format('U'))->setTrackNumber(60)->setViewerId(md5(4));
     $entityManager->persist($view4);
     $entityManager->flush();
     $viewPaymentManager->reckon($view4);
     $view5 = new VideoView();
     $view5->setCampaign($campaign2)->setPlatform($platform1)->setCurrentTime(60)->setTimestamp((new \DateTime('2014-02-23 23:59:59'))->format('U'))->setTrackNumber(60)->setViewerId(md5(4));
     $entityManager->persist($view5);
     $entityManager->flush();
     $viewPaymentManager->reckon($view5);
     $instruction1 = new PaymentInstruction(100, 'RUR', 'robokassa');
     $paymentPluginController->createPaymentInstruction($instruction1);
     $instruction2 = new PaymentInstruction(50, 'RUR', 'robokassa');
     $paymentPluginController->createPaymentInstruction($instruction2);
     $instruction3 = new PaymentInstruction(50, 'RUR', 'robokassa');
     $paymentPluginController->createPaymentInstruction($instruction3);
     $order1 = new Order();
     $order1->setUser($advertiser)->setStatus(Order::STATUS_PAID)->setAmount(100)->setPaymentInstruction($instruction1);
     $entityManager->persist($order1);
     $order2 = new Order();
     $order2->setUser($advertiser)->setStatus(Order::STATUS_PAID)->setAmount(50)->setPaymentInstruction($instruction2);
     $entityManager->persist($order2);
     $order3 = new Order();
     $order3->setUser($advertiser)->setStatus(Order::STATUS_NEW)->setAmount(50)->setPaymentInstruction($instruction3);
     $entityManager->persist($order3);
     $wallet = new Wallet();
     $wallet->setUser($publisher)->setNumber(12345)->setType('yandex');
     $entityManager->persist($wallet);
     $withdrawal1 = new Withdrawal();
     $withdrawal1->setUser($publisher)->setAmount(50)->setWallet($wallet)->setCreatedAt(new \DateTime('2014-02-28 10:00:00'))->setStatus(Withdrawal::STATUS_OK);
     $entityManager->persist($withdrawal1);
     $withdrawal2 = new Withdrawal();
     $withdrawal2->setUser($publisher)->setAmount(100)->setWallet($wallet)->setCreatedAt(new \DateTime('2014-02-28 12:00:00'))->setStatus(Withdrawal::STATUS_OK);
     $entityManager->persist($withdrawal2);
     $withdrawal3 = new Withdrawal();
     $withdrawal3->setUser($publisher)->setAmount(20)->setWallet($wallet)->setCreatedAt(new \DateTime('2014-02-27 10:00:00'))->setStatus(Withdrawal::STATUS_CREATED);
     $entityManager->persist($withdrawal3);
     $withdrawal4 = new Withdrawal();
     $withdrawal4->setUser($publisher)->setAmount(30)->setWallet($wallet)->setCreatedAt(new \DateTime('2014-02-27 11:00:00'))->setStatus(Withdrawal::STATUS_ERROR);
     $entityManager->persist($withdrawal4);
     $entityManager->flush();
     $tokenManager->createUserToken($advertiser->getId());
     $tokenManager->createUserToken($publisher->getId());
     $statsManager->recollectAllStats();
     $statsManager->collectDailyStats((new \DateTime())->setTime(0, 0, 0));
     return array('advertiser' => $advertiser, 'publisher' => $publisher, 'platforms' => [$platform1, $platform2], 'campaigns' => array($campaign1, $campaign2));
 }