Example #1
0
 public function getPromotionDiffDays(Promotion $promotion)
 {
     $now = new \DateTime();
     $stopAt = $promotion->getStopAt();
     $interval = $now->diff($stopAt);
     return $interval->format('%a');
 }
Example #2
0
 /**
  * 取得官網顯示價格
  *
  * 2015-03-03
  * 1. 滿額贈模式
  *  -> 累計
  *  -> 不累計(單次)
  *  -> 商品獨自計算
  *  -> 滿額贈不可和折扣並用
  *
  * ======== flow =========
  *
  * 如果不允許網路顯示,直接返回 null
  *
  * 如果網路售價合法[大於等於 100,且小於原始售價]
  *     返回網路售價
  *
  * 若否
  *     存在活動且活動折扣 < 1
  *         返回原始售價 * 活動折扣金額
  *     若否
  *         返回 null
  *
  * ======= End Flow =======
  *
  * @return integer | boolean
  */
 public function getPromotionPrice($price = null)
 {
     if (!$this->isAllowWeb) {
         return null;
     }
     if ($this->productTl && $this->productTl->getPrice() >= 100 && $this->productTl->isValid()) {
         return $this->productTl->getPrice();
     }
     // 如果本商品屬於促銷活動,且該促銷活動有效
     if ($this->promotion && $this->promotion->isValid()) {
         $displayPrice = $this->webPrice && $this->webPrice >= 100 ? $this->webPrice : $this->price;
         // 根據贈送金額是否大於0判斷是否為滿額贈活動
         if ($this->promotion->getGift() > 0) {
             // 售價若大於滿額贈門檻
             if ($displayPrice >= $this->promotion->getThread()) {
                 return $this->promotion->getIsStack() ? $displayPrice - $this->promotion->getGift() * floor($displayPrice / $this->promotion->getThread()) : $displayPrice - $this->promotion->getGift();
             }
         }
         if ($this->promotion->getDiscount() < 1) {
             return $displayPrice * $this->promotion->getDiscount();
         }
     }
     if ($this->webPrice && $this->webPrice >= 100) {
         return $this->webPrice;
     }
     if ($price) {
         return $this->price;
     }
 }
Example #3
0
 /**
  * 將傳入的商品id作為條件選取出商品陣列,並將陣列內的商品從本促銷活動中移除
  * 
  * @Route("/api/{id}/product", name="promotion_api_product_delete", options={"expose"=true})
  * @ParamConverter("promotion", class="WoojinGoodsBundle:Promotion")
  * @Method("PUT")
  */
 public function removeAction(Request $request, Promotion $promotion)
 {
     $user = $this->get('security.token_storage')->getToken()->getUser();
     $em = $this->getDoctrine()->getManager();
     $qb = $em->createQueryBuilder();
     $qb->select('g')->from('WoojinGoodsBundle:GoodsPassport', 'g')->where($qb->expr()->in('g.id', json_decode($request->request->get('ids'))), $qb->expr()->eq('g.promotion', $promotion->getId()));
     $products = $qb->getQuery()->getResult();
     foreach ($products as $product) {
         $product->setPromotion(null);
         $em->persist($product);
     }
     $em->flush();
     return new Response('ok');
 }
Example #4
0
 /**
  * @Route(
  *   "/promotion/{id}", 
  *   requirements={"id"="\d+"},
  *   name="front_promotion_filter"
  * )
  * @ParamConverter("promotion", class="WoojinGoodsBundle:Promotion")
  * @Template("WoojinFrontBundle:Default:filter.html.twig")
  * @Method("GET")
  */
 public function promotionAction(Promotion $promotion)
 {
     if (!$promotion->isValid()) {
         throw $this->createNotFoundException('本活動已經結束或不存在!');
     }
     return $this->getParameters(array('promotion' => $promotion));
 }
Example #5
0
 /**
  * @Route("/promotion/{id}", name="mobile_front_promotion", options={"expose"=true})
  * @ParamConverter("promotion", class="WoojinGoodsBundle:Promotion")
  * @Method("GET")
  * @Template()
  */
 public function promotionAction(Request $request, Promotion $promotion)
 {
     $request->request->set('page', $request->query->get('page', 1));
     $request->request->set('promotion', array($promotion->getId()));
     $request->request->set('productStatus', array(Avenue::GS_ONSALE));
     $request->request->set('perpage', 10);
     $request->request->set('isAllowWeb', 1);
     $return = $this->get('product.finder')->find($request)->getMobileViewData();
     $return['promotion'] = $promotion;
     return $return;
 }