Пример #1
0
 public function fetchLatestPaymentByAuction(Auction $auction)
 {
     $qb = $this->getEntityManager()->createQueryBuilder();
     $qb->select('payment')->from('WoojinStoreBundle:AuctionPayment', 'payment')->where($qb->expr()->andX($qb->expr()->eq('payment.isCancel', ':isCancel'), $qb->expr()->eq('payment.auction', ':auctionId')))->orderBy('payment.paidAt', 'DESC');
     $qb->setParameter('isCancel', false)->setParameter('auctionId', $auction->getId());
     return $qb->setFirstResult(0)->setMaxResults(1)->getQuery()->getOneOrNullResult();
 }
Пример #2
0
 protected function updateProductFeedBackOrderToComplete(Auction $auction)
 {
     $order = $auction->getProduct()->getFeedBackOrder();
     if (!$order instanceof Orders) {
         return;
     }
     $order->setRequired(0)->setOrgRequired(0)->setPaid(0)->setOrgPaid(0)->setStatus($this->em->getRepository('WoojinOrderBundle:OrdersStatus')->find(Avenue::OS_COMPLETE));
     $this->em->persist($order);
     $this->em->flush();
 }
Пример #3
0
 /**
  * @Route("/auction/{id}", name="auction_payment_create", options={"expose"=true})
  * @ParamConverter("auction", class="WoojinStoreBundle:Auction")
  * @Method("POST")
  */
 public function createAction(Auction $auction, Request $request)
 {
     /**
      * DoctrineManager
      *
      * @var \Doctrine\ORM\EntityManager;
      */
     $em = $this->getDoctrine()->getManager();
     /**
      * 目前登入的使用者實體
      *
      * @var \Woojin\UserBundle\Entity\User
      */
     $user = $this->get('security.token_storage')->getToken()->getUser();
     /**
      * @var \Woojin\OrderBundle\Entity\PayType
      */
     $payType = $em->getRepository('WoojinOrderBundle:PayType')->find($request->request->get('pay_type'));
     /**
      * Amount
      *
      * @var integer
      */
     $amount = (int) $request->request->get('amount');
     /**
      * @var \DateTime
      */
     $paidAt = new \DateTime($request->request->get('paid_at'));
     /**
      * Session
      *
      * @var \Symfony\Component\HttpFoundation\Session\Session
      */
     $session = $this->get('session');
     /**
      * @var \Woojin\Service\Store\AuctionPaymentService
      */
     $service = $this->get('auction.payment.service');
     if (!$auction->isAllowedEditPayment($user)) {
         throw $this->createAccessDeniedException('Not allowed to edit this auction!');
     }
     try {
         $payment = $service->create(array('auction' => $auction, 'payType' => $payType, 'amount' => $amount, 'creater' => $user, 'paidAt' => $paidAt));
         $em->persist($payment);
         $em->flush();
         $session->getFlashBag()->add('success', '競拍付款新增成功!');
     } catch (\Exception $e) {
         $session->getFlashBag()->add('error', $e->getMessage());
     }
     return $this->redirect($this->generateUrl('goods_edit_v2', array('id' => $auction->getProduct()->getId())) . '/#_soldop');
 }
Пример #4
0
 public function testInitVirtualProperty()
 {
     $this->auction->shouldReceive('getPrice')->andReturn(10000);
     $this->auction->shouldReceive('calCustomProfitAndGet')->andReturn(8000);
     $this->auction->shouldReceive('getRemainProfit')->andReturn(1300);
     $this->auction->shouldReceive('getStorePercentage')->twice()->andReturn(0.1);
     $this->auction->shouldReceive('getBsoPercentage')->once()->andReturn(0.1);
     $auction = Auction::initVirtualProperty($this->auction);
     $this->assertSame(8000, $this->auction->customProfit);
     $this->assertSame(650, $this->auction->storeProfit);
     $this->assertSame(650, $this->auction->bsoProfit);
     $this->assertTrue($this->auction->hasInitializedVirtualProperty);
 }
Пример #5
0
 /**
  * @Route("/auction/sold/{_format}", defaults={"_format"="json"}, name="api_sold_auction", options={"expose"=true})
  * @Method("PUT")
  *
  * @ApiDoc(
  *  resource=true,
  *  description="BSO auction sold action",
  *  requirements={
  *      {
  *          "name"="price",
  *          "requirement"="\d+",
  *          "dataType"="integer",
  *          "required"=true,
  *          "description"="The sold price"
  *      },
  *      {
  *          "name"="mobil",
  *          "dataType"="string",
  *          "required"=false,
  *          "description"="Custom mobil number"
  *      },
  *      {
  *          "name"="_format",
  *          "dataType"="string",
  *          "required"=false,
  *          "description"="回傳的格式,支援 json, xml, html"
  *      }
  *  }
  * )
  */
 public function soldAction(Request $request, $_format)
 {
     list($user, $em, $product) = $this->initBaseVar($request);
     /**
      * Price
      *
      * @var mixed
      */
     $price = $request->request->get('price');
     /**
      * The custom entity
      *
      * @var \Woojin\OrderBundle\Entity\Custom
      */
     $custom = $em->getRepository('WoojinOrderBundle:Custom')->findOneBy(array('mobil' => $request->request->get('mobil'), 'store' => $user->getStore()));
     /**
      * The auction entity
      *
      * @var \Woojin\StoreBundle\Entity\Auction
      */
     $auction = NULL === $product ? NULL : $em->getRepository('WoojinStoreBundle:Auction')->fetchAuctionByProduct($product);
     /**
      * Store the valide result
      *
      * @var array
      */
     $unValid = $this->execValidaters($this->getSoldActionValidaters(array($product, $auction, $user, $custom, $price)));
     if (!empty($unValid)) {
         return $this->_getResponse($unValid, $_format);
     }
     /**
      * The result of service operation
      *
      * @var mixed[\Woojin\StoreBundle\Entity\Auction|Exception]
      */
     $result = $this->get('auction.service')->setAuction($auction)->sold(['price' => $price, 'buyer' => $custom, 'bsser' => $user, 'soldAt' => new \DateTime()]);
     return $this->_genResponseWithServiceReturnAuction(\Woojin\StoreBundle\Entity\Auction::initVirtualProperty($result), $_format);
 }
Пример #6
0
 protected static function getCostByAuction(Auction $auction)
 {
     return static::getCostByPrice($auction->getPrice());
 }
Пример #7
0
 protected function fetchProductStatus($statusCode)
 {
     return $this->getEm()->getRepository('WoojinGoodsBundle:GoodsStatus')->find(Auction::fetchProductStatusId($statusCode));
 }
Пример #8
0
 /**
  * Is auction belong to the given user's store
  *
  * @param  \Woojin\UserBundle\Entity\User  User    $user
  * @param  \Woojin\StoreBundle\Entity\Auction  Auction $auction
  * @return boolean
  */
 protected function isAuctionBelongGivenUsersStore(User $user, Auction $auction)
 {
     return $auction->isAuctionBelongGivenUsersStore($user);
 }
Пример #9
0
 protected function getColMap(Auction $auction)
 {
     return array('A' => $auction->getProductSn(), 'B' => $auction->getProductName(), 'C' => $auction->getProductOrgSn(), 'D' => $auction->getProductBrandName(), 'E' => $auction->getProductColorName(), 'F' => $auction->getCreateStoreName(), 'G' => $auction->getSellerName(), 'H' => $auction->getSellerMobil(), 'I' => $auction->getBuyerName(), 'J' => $auction->getBuyerMobil(), 'K' => $auction->getPrice(), 'L' => $auction->getCustomPercentage(), 'M' => $auction->getStorePercentage(), 'N' => $auction->getBsoPercentage(), 'O' => $auction->getCustomProfit(), 'P' => $this->hasCostReadAuth() ? $auction->getStoreProfit() : '權限不足', 'Q' => $this->hasCostReadAuth() ? $auction->getBsoProfit() : '權限不足', 'R' => $auction->getCreateAt()->format('Y-m-d H:i:s'), 'S' => $auction->getCreaterName(), 'T' => $auction->getSoldAtString(), 'U' => $auction->getBsserName(), 'V' => $auction->getSoldAtUpdateCount(), 'W' => $auction->getSoldUpdateCount(), 'X' => $auction->getMemo(true));
 }
Пример #10
0
 /**
  * Setting auction profit assign percentage
  *
  * @param array $options
  */
 protected function setOptionPercentage(array &$options)
 {
     if (!array_key_exists('product', $options)) {
         throw new \Exception('Options doesnt include product');
     }
     $percentages = Auction::calculatePercentage($options['product']);
     $options['customPercentage'] = $percentages[0];
     $options['storePercentage'] = $percentages[1];
     $options['bsoPercentage'] = $percentages[2];
     return $this;
 }