예제 #1
0
파일: Behalf.php 프로젝트: jocoonopa/avenue
 /**
  * 代購商品出貨 (訂單狀態: 已出貨)
  *
  * 1. 修改代購實體狀態
  * 2. 通知客戶已出貨
  *
  * @param  array  $options 
  * @return this
  */
 public function productOut(array $options = array())
 {
     $options = $this->resolver->resolve($options);
     $this->behalf = $options['behalf'];
     $this->behalf->setStatus($this->statusFacade->findPurOut())->setSendAt(new \DateTime())->setDeliverySn($options['deliverySn']);
     $this->em->getConnection()->beginTransaction();
     try {
         $custom = $this->behalf->getCustom();
         $got = $this->behalf->getGot();
         $required = $this->behalf->getWant()->getPromotionPrice(true);
         $invoice = new Invoice();
         $invoice->setCustom($custom)->setStore($this->behalf->getUser()->getStore())->setHasPrint(0)->setSn(uniqid());
         $this->em->persist($invoice);
         $order = new Orders();
         $order->setGoodsPassport($got)->setCustom($custom)->setPayType($this->em->find('WoojinOrderBundle:PayType', Avenue::PT_ATM))->setKind($this->em->find('WoojinOrderBundle:OrdersKind', Avenue::OK_OUT))->setStatus($this->em->find('WoojinOrderBundle:OrdersStatus', Avenue::OS_COMPLETE))->setRequired($required)->setOrgRequired($required)->setOrgPaid($required)->setPaid($required)->setInvoice($invoice);
         $this->em->persist($order);
         $got->setStatus($this->em->find('WoojinGoodsBundle:GoodsStatus', Avenue::GS_SOLDOUT));
         $this->em->persist($got);
         $this->em->flush();
         $this->container->get('logger.ope')->recordOpe($order, '成立銷貨訂單(代購)', $this->container->get('authority.judger')->getUser());
         $this->em->getConnection()->commit();
     } catch (\Exception $e) {
         $this->em->getConnection()->rollback();
         throw $e;
     }
     $this->notifier->behalfForCustom($this->behalf);
     return $this;
 }
예제 #2
0
 /**
  * @Route("/sell_goods", name="order_sell_goods" , options={"expose"=true})
  */
 public function orderSellGoodsAction(Request $request)
 {
     foreach ($request->request->keys() as $key) {
         ${$key} = $request->request->get($key);
     }
     $dc = $this->getDoctrine();
     $em = $dc->getManager();
     $em->getConnection()->beginTransaction();
     $sculper = $this->get('sculper.clue');
     $sculper->initSoldOut();
     $user = $this->get('security.token_storage')->getToken()->getUser();
     try {
         $paytype = $em->find('WoojinOrderBundle:PayType', $nPayTypeId);
         $orderKind = $em->find('WoojinOrderBundle:OrdersKind', $nOrdersKindId);
         $productStatus = $em->find('WoojinGoodsBundle:GoodsStatus', Avenue::GS_SOLDOUT);
         $oCustom = $dc->getRepository('WoojinOrderBundle:Custom')->findOneBy(array('mobil' => $nCustomMobil, 'store' => $user->getStore()->getId()));
         $product = $dc->getRepository('WoojinGoodsBundle:GoodsPassport')->findOneBy(array('sn' => $sGoodsSn));
         if (!in_array($product->getStatus()->getId(), array(Avenue::GS_ONSALE, Avenue::GS_ACTIVITY))) {
             throw $this->createNotFoundException('商品狀態非上架或活動中');
         }
         $product->setStatus($productStatus);
         $em->persist($product);
         $nDisRate = $paytype->getDiscount();
         $nOrdersRequired = $nOrdersRequired - ($nOrdersPaidReal - $nOrdersPaid);
         $nOrdersStatusId = $nOrdersRequired - $nOrdersPaid != 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)->setOrgRequired($request->request->get('nOrdersRequired'))->setOrgPaid($nOrdersPaidReal)->setPaid($nOrdersPaid)->setMemo($sOrdersMemo);
         // 找發票
         $Invoices = $dc->getRepository('WoojinOrderBundle:Invoice')->findBy(array('sn' => $request->request->get('invoice_key')));
         if (!$Invoices) {
             $Invoice = new Invoice();
             $Invoice->setCustom($oCustom)->setStore($this->getUser()->getStore())->setHasPrint(0)->setSn($request->request->get('invoice_key'));
             $em->persist($Invoice);
         } else {
             $Invoice = $Invoices[0];
         }
         $order->setInvoice($Invoice);
         $em->persist($order);
         $opeLogger = $this->get('logger.ope');
         $opeLogger->log($order, $user, $paytype, (int) $request->request->get('nOrdersRequired'), '成立售出訂單:[' . $request->request->get('nOrdersRequired') . '元][' . $paytype->getName() . '][' . $product->getSn() . ']');
         $em->persist($opeLogger->getOpe());
         $sculper->setAfter($opeLogger->getOpe());
         $clue = new AvenueClue();
         $clue->setUser($user)->setContent($sculper->getContent());
         $em->persist($clue);
         $em->flush();
         $em->getConnection()->commit();
     } catch (\Exception $e) {
         $em->getConnection()->rollback();
         throw $e;
     }
     // Yahoo同步刪除商品
     if ($product->getYahooId()) {
         $adapter = $this->get('yahoo.syncer');
         $adapter->delete($product);
     }
     return new Response($product->getId());
 }