Пример #1
0
 /**
  * @Route("/goods_passport/fetch/{_format}", defaults={"_format"="json"}, name="api_goodsPassport_fetchWithCondition", options={"expose"=true})
  * @Method("POST")
  *
  * @ApiDoc(
  *  resource=true,
  *  description="根據搜尋條件取得商品資訊,不需要作 cache"
  * )
  */
 public function fetchAction(Request $request, $_format)
 {
     /**
      * 字串流
      *
      * @var [string]
      */
     $content = $request->getContent();
     /**
      * stdClass, 有一個 jsonCondition屬性,該屬性內容為 json 字串
      *
      * @var [\stdClass]
      */
     $conditionClass = json_decode($content);
     /**
      * 條件物件, 格式如下
      *
      * @example
      * stdClass Object
      *(
      *    [gd] => stdClass Object
      *        (
      *            [brands] => Array
      *                (
      *                    [0] => stdClass Object
      *                        (
      *                            [id] => 59
      *                            [name] => 3.1
      *                            [isChecked] => 1
      *                        )
      *
      *                    [1] => stdClass Object
      *                        (
      *                            [id] => 23
      *                            [name] => ADMJ
      *                            [isChecked] => 1
      *                        )
      *
      *                    [2] => stdClass Object
      *                        (
      *                            [id] => 66
      *                            [name] => agnes b
      *                            [isChecked] => 1
      *                        )
      *
      *                )
      *
      *        )
      *
      *)
      *
      * @var [\stdClass]
      */
     $condition = json_decode($conditionClass->jsonCondition);
     $this->addOnBoardAndIsWebConstraint($condition);
     $serializer = \JMS\Serializer\SerializerBuilder::create()->build();
     /**
      * 自製的 條件轉換 query 服務
      */
     $gdConverter = $this->get('gd.converter');
     $gdConverter->gen($condition, false, false, true);
     // 除錯的時候拿掉這段註解可以看 condition 的詳情和實際執行的 Dql 語句
     //
     //$gdConverter->dump()->_print();
     $goodses = $gdConverter->getResult();
     // 對於權限不夠的,成本必須要隱藏起來,否則客人看到成本不就好笑了?
     if (!$this->get('authority.judger')->isCostValid()) {
         foreach ($goodses as $key => $goods) {
             $goods->setCost('0');
             $goods->setSn($goods->getSn(true));
         }
     }
     $count = $gdConverter->getCount();
     $res = array();
     $res['goodses'] = $goodses;
     $res['count'] = $count;
     $res['status'] = '1';
     $jsonResponse = $serializer->serialize($res, $_format);
     $responseHandler = new ResponseHandler();
     return $responseHandler->getNoncached($request, $jsonResponse, $_format);
 }
Пример #2
0
 /**
  * @Route("/mobile/order", name="mobile_order", options={"expose"=true})
  * @Method("POST")
  */
 public function orderAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $product = $em->find('WoojinGoodsBundle:GoodsPassport', $request->request->get('id'));
     $orders = $this->hasReadableAuth($product) ? $product->getOrders() : array();
     $serializer = \JMS\Serializer\SerializerBuilder::create()->build();
     $jsonResponse = $serializer->serialize($orders, 'json');
     $responseHandler = new ResponseHandler();
     return $responseHandler->getNoncached($request, $jsonResponse, 'json');
 }