예제 #1
0
 /**
  * @Route("", name="admin_custom_create", options={"expose"=true})
  * @Template("WoojinOrderBundle:Custom:res.html.twig")
  * @Method("POST")
  */
 public function createAction(Request $request)
 {
     $user = $this->get('security.token_storage')->getToken()->getUser();
     if (null === $user) {
         return $this->redirect($this->generateUrl('login'), 302);
     }
     $em = $this->getDoctrine()->getManager();
     $em->getConnection()->beginTransaction();
     $qb = $em->createQueryBuilder();
     $custom = $qb->select('c')->from('WoojinOrderBundle:Custom', 'c')->where($qb->expr()->andX($qb->expr()->eq('c.mobil', $request->request->get('custom_mobil')), $qb->expr()->eq('c.store', $user->getStore()->getId())))->getQuery()->getOneOrNullResult();
     if ($custom) {
         throw new \Exception('客戶已經存在!');
     }
     try {
         $custom = new Custom();
         $custom->setStore($user->getStore())->setName($request->request->get('custom_name'))->setSex($request->request->get('custom_sex', '保密'))->setMobil($request->request->get('custom_mobil'))->setEmail($request->request->get('custom_email', '*****@*****.**'))->setAddress($request->request->get('custom_address', 'avenue2003預設地址'))->setMemo($request->request->get('custom_memo'))->setCreatetime(new \DateTime());
         if ($birthday = $request->request->get('custom_birthday')) {
             $custom->setBirthday(new \DateTime($birthday));
         }
         $em->persist($custom);
         $em->flush();
         $em->getConnection()->commit();
     } catch (Exception $e) {
         $em->getConnection()->rollback();
         throw $e;
     }
     return array('rCustom' => array($custom), 'nCount' => 1, 'nNowPage' => 1);
 }
예제 #2
0
 /**
  * 開通帳號
  * 
  * @param \Woojin\OrderBundle\Entity\Custom $custom
  */
 public function active(Custom $custom)
 {
     $message = $this->genMessage(array($custom->getEmail()), '香榭國際精品帳號開通', $this->templating->render('::Email/active.html.twig', array('custom' => $custom)));
     $this->mailer->send($message);
     return $this;
 }
예제 #3
0
 /**
  * 是否為該客戶的訂單
  * 
  * @param integer $id
  * @return boolean
  */
 public function isOwnInvoice($id)
 {
     return $this->custom->getId() === (int) $id;
 }
예제 #4
0
 /**
  * @Route(
  *      "/auction_custom/{id}/{_format}",
  *      name="api_auction_customer_update",
  *      requirements={"id"="\d+"},
  *      options={"expose"=true},
  *      defaults={"_format": "json"}
  *  )
  * @ParamConverter("custom", class="WoojinOrderBundle:Custom")
  * @ApiDoc(
  *  description="Update custom information",
  *  parameters={
  *      {"name"="name", "dataType"="string", "required"=true, "description"="name"},
  *      {"name"="mobil", "dataType"="string", "required"=true, "description"="mobil"},
  *      {"name"="sex", "dataType"="string", "required"=false, "description"="sex"},
  *      {"name"="address", "dataType"="string", "required"=false, "description"="address"},
  *      {"name"="birthday", "dataType"="string", "required"=false, "description"="birthday"},
  *      {"name"="email", "dataType"="string", "required"=false, "description"="email"}
  *  }
  * )
  * @Method("PUT")
  */
 public function updateAction(Request $request, $custom = NULL, $_format)
 {
     /**
      * DoctrineManager
      *
      * @var \Doctrine\ORM\EntityManager;
      */
     $em = $this->getDoctrine()->getManager();
     /**
      * The Current User
      *
      * @var \Woojin\UserBundle\Entity\User
      */
     $user = $this->get('security.token_storage')->getToken()->getUser();
     /**
      * Store the valide result
      *
      * @var array
      */
     $unValid = $this->execValidaters($this->getUpdateActionValidaters(array($custom, $user)));
     if (!empty($unValid)) {
         return $this->_getResponse($unValid, $_format);
     }
     try {
         $custom = new Custom();
         $birthday = NULL === $request->get('birthday') ? NULL : new \DateTime($request->get('birthday'));
         $custom->setName($request->get('name'))->setMobil($request->get('mobil'))->setSex($request->get('sex'))->setAddress($request->get('address'))->setBirthday($birthday)->setEmail($request->get('email'))->setStore($user->getStore());
         $em->persist($custom);
         $em->flush();
         return $this->_genResponseWithCustom($custom, $_format);
     } catch (\Exception $e) {
         return $this->_genResponseWithCustom($e, $_format);
     }
 }
예제 #5
0
 /**
  * Check if this custom has no orders
  *
  * @return boolean
  */
 protected function hasNoOrders(Custom $custom)
 {
     return $custom->hasNoOrders();
 }
예제 #6
0
 /**
  * 登入成功後的回呼動作
  * 
  * @param  Session $session 
  * @param  Custom  $custom 
  * @param  Entity Manager $em
  * @return $this           
  */
 private function loginSuccessCallback(Session $session, Custom $custom, $em)
 {
     $custom->setCsrf('avenue2003');
     $custom->setPreCsrf($custom->getCsrf());
     $em->persist($custom);
     $em->flush();
     $serializer = \JMS\Serializer\SerializerBuilder::create()->build();
     $session->set('custom', $serializer->serialize($custom, 'json'));
     $session->set('avenue_token', $custom->getCsrf());
     return $this;
 }
예제 #7
0
 public function findOwn(Custom $custom)
 {
     $qb = $this->getEntityManager()->createQueryBuilder();
     return $qb->select('p')->from('WoojinOrderBundle:Benefit', 'p')->where($qb->expr()->andX($qb->expr()->lte('p.expireAt', $qb->expr()->literal($date->format('Y-m-d H:i:s'))), $qb->expr()->gt('p.remain', 0), $qb->expr()->eq('p.custom', $custom->getId())))->orderBy('p.expireAt', 'DESC')->getQuery()->getResult();
 }