Exemplo n.º 1
0
 /**
  * 對外開放的 api, 將根據 id 取得的發票(invoice)之狀態改為 hasPrint=true, <br/>
  * 若有傳入統編{sn}則將 sn 屬性 set 為 {sn},<br/>
  * 更新時間(updateAt)會在 entity 的 lifecyle 自動處理,回傳細項說明如下:<br/><br/>
  * 
  * 1. id : 發票id<br/>
  * 2. store: 店名<br/>
  * 3. createAt: 發票建立時間<br/>
  * 4. updateAt: 發票最後更新時間<br/>
  * 5. hasPrint: 是否已經列印<br/>
  * 6. sn: 統一編號<br/>
  * 
  * @Route(
  *     "/api/invoice/v1/{id}/{apiKey}.{_format}/{sn}", 
  *     requirements={"id" = "\d+"}, 
  *     defaults={"_format"="json", "sn"=""},
  *     name="invoice_api_update", 
  *     options={"expose"=true}
  * )
  * @ParamConverter("invoice", class="WoojinOrderBundle:Invoice")
  * @Method("PUT")
  * 
  * @ApiDoc(
  *  resource=true,
  *  description="更新指定(id)發票(invoice)的 hasPrint 屬性,同時修改更新時間(updateAt)屬性為現在時間,若有傳入統編(Sn)則更新 invoice 的sn屬性",
  *  requirements={
  *      {"name"="id", "dataType"="integer", "required"=true, "description"="發票的 id "},
  *      {"name"="apiKey", "dataType"="string", "required"=true, "description"="Used to validate permission"},
  *      {"name"="_format", "dataType"="string", "required"=true, "description"="Decide type of return MIME, default is json"}
  *  },
  *  statusCodes={
  *    200="Returned when successful",
  *    404={
  *     "Returned when something else is not found"
  *    },
  *    500={
  *     "Please contact author to fix it"
  *    }
  *  }
  * )
  */
 public function apiUpdateAction(Invoice $invoice, $apiKey, $sn)
 {
     // 設定發票屬性
     $invoice->setHasPrint(true)->setSn($sn);
     $em = $this->getDoctrine()->getManager();
     $em->persist($invoice);
     $em->flush();
     /**
      * orderService, use to set invoice in correct foramt
      * @var object
      */
     $orderService = $this->get('order_service');
     $orderService->setInvoiceMeta($tmp = new \stdClass(), $invoice);
     return new Response(json_encode($tmp));
 }
Exemplo n.º 2
0
 /**
  * @Route("/multisale/sell", name="order_multisale_sell", options={"expose"=true})
  */
 public function orderMultieSell(Request $request)
 {
     foreach ($request->request->keys() as $key) {
         ${$key} = $request->request->get($key);
     }
     $successProducts = array();
     $user = $this->get('security.token_storage')->getToken()->getUser();
     $opeLogger = $this->get('logger.ope');
     $dc = $this->getDoctrine();
     $em = $dc->getManager();
     $em->getConnection()->beginTransaction();
     try {
         // 訂單id陣列
         $rRollback = array();
         // 金額總計
         $nTotal = 0;
         // 回傳產編字串
         $returnSn = '';
         // 取得付款方式
         $paytype = $em->find('WoojinOrderBundle:PayType', $nPayTypeId);
         // 根據付款方式取得折扣
         $nDisRate = $paytype->getDiscount();
         // 取得訂單狀態
         $orderKind = $em->find('WoojinOrderBundle:OrdersKind', $nOrdersKindId);
         // 取得商品狀態
         $productStatus = $em->find('WoojinGoodsBundle:GoodsStatus', Avenue::GS_SOLDOUT);
         // 取得客戶
         $oCustom = $dc->getRepository('WoojinOrderBundle:Custom')->findOneBy(array('mobil' => $mobil == '' ? '00000' : $mobil, 'store' => $user->getStore()->getId()));
         // 若找尋的客戶不存在, 回覆錯誤訊息
         if (!is_object($oCustom)) {
             return new Response('<div class="alert alert-block alert-danger fade in">
         <button type="button" class="close" data-dismiss="alert">×</button>
         <h4 class="alert-heading">手機號碼不存在</h4>
       </div>');
         }
         // 檢查有無傳入資料
         if (!isset($rId)) {
             return new Response('<div class="alert alert-block alert-danger fade in">
         <button type="button" class="close" data-dismiss="alert">×</button>
         <h4 class="alert-heading">無傳入資料</h4>
       </div>');
         }
         if (!is_array($rId)) {
             return new Response('<div class="alert alert-block alert-danger fade in">
         <button type="button" class="close" data-dismiss="alert">×</button>
         <h4 class="alert-heading">無傳入資料</h4>
       </div>');
         }
         // 移除重複的id
         $rId = array_unique($rId);
         /**
          * 新增一張發票
          * 
          * @var Invoice
          */
         $invoice = new Invoice();
         $invoice->setHasPrint(false)->setSn(md5(time()));
         $em->persist($invoice);
         // 根據傳入的 rId 迭代
         foreach ($rId as $key => $id) {
             // 取得商品
             $product = $dc->getRepository('WoojinGoodsBundle:GoodsPassport')->find($id);
             if ($product->getStatus()->getId() != Avenue::GS_ONSALE) {
                 continue;
             }
             // 更新商品狀態
             $product->setStatus($productStatus);
             $em->persist($product);
             // 計算折扣後的應付金額
             $nOrdersRequired = $rOrdersRequired[$key] * $nDisRate;
             // 根據應付金額與實付金額決定訂單狀態
             $nOrdersStatusId = $nOrdersRequired - $rOrdersRequired[$key] != 0 ? Avenue::OS_HANDLING : Avenue::OS_COMPLETE;
             $orderStatus = $em->find('WoojinOrderBundle:OrdersStatus', $nOrdersStatusId);
             // 成立新的訂單
             $order = new Orders();
             // 設定新的訂單資料
             $order->setGoodsPassport($product)->setCustom($oCustom)->setPayType($paytype)->setKind($orderKind)->setStatus($orderStatus)->setRequired($nOrdersRequired)->setPaid($nOrdersRequired)->setOrgRequired($nOrdersRequired)->setOrgPaid($nOrdersRequired)->setInvoice($invoice);
             $em->persist($order);
             $nTotal += $nOrdersRequired;
             $opeLogger->log($order, $user, $paytype, $nOrdersRequired, '成立' . $orderKind->getName() . '訂單[' . $rOrdersRequired[$key] . '元][' . $paytype->getName() . ']');
             $em->persist($opeLogger->getOpe());
             $sculper->setAfter($opeLogger->getOpe());
             $clue = new AvenueClue();
             $clue->setUser($user)->setContent($sculper->getContent());
             $em->persist($clue);
             $em->flush();
             // 存入rollback陣列
             array_push($rRollback, $order->getId());
             if ($product->getYahooId()) {
                 $successProducts[] = $product;
             }
             $returnSn .= "<a href=\"" . $this->get('router')->generate('goods_edit_v2', array('id' => $product->getId())) . "?iframe=true&width=100%&height=100%\" rel=\"prettyPhoto[iframes]\">" . $rGoodsSn[$key] . ($product->getColor() ? $product->getColor()->getName() : '') . '</a>,';
         }
         // Yahoo同步刪除
         if (!empty($successProducts)) {
             $adapter = $this->get('yahoo.syncer');
             $adapter->delete($successProducts);
         }
         $em->getConnection()->commit();
     } catch (Exception $e) {
         $em->getConnection()->rollback();
         throw $e;
     }
     if (empty($returnSn)) {
         return new Response('<div class="alert alert-block alert-warning fade in">
         <button type="button" class="close" data-dismiss="alert">×</button>
         <h4 class="alert-heading">此次操作無任何商品結帳完成</h4></div>');
     } else {
         return new Response('<div class="alert alert-block alert-success fade in">
         <button type="button" class="close" data-dismiss="alert">×</button>
         <h4 class="alert-heading">' . substr($returnSn, 0, -1) . '結帳完成, 合計' . $nTotal . '元</h4>
       <a class="btn btn-primary" href="' . $this->get('router')->generate('invoice_print', array('id' => $invoice->getId(), 'page' => 1)) . '" target="_blank">銷貨單列印</a><button type="button" class="rollback btn btn-inverse" data-roll="' . json_encode($rRollback) . '">取消販售</button></div>');
     }
 }