app/Plugin/PiaPlazaMypage/Controller/MypageBuyController.php line 50

Open in your IDE?
  1. <?php
  2. namespace Plugin\PiaPlazaMypage\Controller;
  3. use Eccube\Controller\AbstractController;
  4. use Eccube\Repository\OrderRepository;
  5. use Plugin\PriceNegotiation\Repository\OfferHistoryRepository;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  8. use Symfony\Component\HttpFoundation\Request;
  9. /**
  10.  * マイページ購入履歴コントローラー
  11.  *
  12.  * @Route("/mypage")
  13.  */
  14. class MypageBuyController extends AbstractController
  15. {
  16.     /**
  17.      * @var OfferHistoryRepository
  18.      */
  19.     private $offerHistoryRepository;
  20.     /**
  21.      * @var OrderRepository
  22.      */
  23.     private $orderRepository;
  24.     /**
  25.      * コンストラクタ
  26.      *
  27.      * @param OfferHistoryRepository $offerHistoryRepository
  28.      * @param OrderRepository $orderRepository
  29.      */
  30.     public function __construct(
  31.         OfferHistoryRepository $offerHistoryRepository,
  32.         OrderRepository $orderRepository
  33.     )
  34.     {
  35.         $this->offerHistoryRepository $offerHistoryRepository;
  36.         $this->orderRepository $orderRepository;
  37.     }
  38.     /**
  39.      * 交渉中・成立
  40.      *
  41.      * @Route("/buy", name="mypage_buy")
  42.      * @IsGranted("ROLE_USER")
  43.      */
  44.     public function index(Request $request)
  45.     {
  46.         // ログイン会員取得
  47.         $Customer $this->getUser();
  48.         $customerId $Customer->getId();
  49.         // 成立した交渉履歴取得(過去4ヶ月分)
  50.         $offers $this->offerHistoryRepository->getSuccessfulOffers($customerId);
  51.         // 各カテゴリの件数取得
  52.         $exCoinNum1 count($offers); // 成立
  53.         $exCoinNum2 $this->offerHistoryRepository->getFailedOffersCount($customerId); // 不成立
  54.         $exCoinNum3 $this->orderRepository->getCustomerOrderCount($Customer); // 注文履歴
  55.         return $this->render('@PiaPlazaMypage/default/Mypage/buy.twig', [
  56.             'rows' => $offers,
  57.             'row' => [
  58.                 'ex_coin_num1' => $exCoinNum1,
  59.                 'ex_coin_num2' => $exCoinNum2,
  60.                 'ex_coin_num3' => $exCoinNum3,
  61.             ],
  62.         ]);
  63.     }
  64.     /**
  65.      * 交渉中・不成立
  66.      *
  67.      * @Route("/negotiation_failed", name="mypage_negotiation_failed")
  68.      * @IsGranted("ROLE_USER")
  69.      */
  70.     public function negotiationFailed(Request $request)
  71.     {
  72.         // ログイン会員取得
  73.         $Customer $this->getUser();
  74.         $customerId $Customer->getId();
  75.         // 不成立の交渉履歴取得(過去4ヶ月分)
  76.         $offers $this->offerHistoryRepository->getFailedOffers($customerId);
  77.         // 各カテゴリの件数取得
  78.         $exCoinNum1 $this->offerHistoryRepository->getSuccessfulOffersCount($customerId); // 成立
  79.         $exCoinNum2 count($offers); // 不成立
  80.         $exCoinNum3 $this->orderRepository->getCustomerOrderCount($Customer); // 注文履歴
  81.         return $this->render('@PiaPlazaMypage/default/Mypage/negotiation_failed.twig', [
  82.             'rows' => $offers,
  83.             'row' => [
  84.                 'ex_coin_num1' => $exCoinNum1,
  85.                 'ex_coin_num2' => $exCoinNum2,
  86.                 'ex_coin_num3' => $exCoinNum3,
  87.             ],
  88.         ]);
  89.     }
  90.     /**
  91.      * 注文履歴
  92.      *
  93.      * @Route("/buy_past", name="mypage_buy_past")
  94.      * @IsGranted("ROLE_USER")
  95.      */
  96.     public function buyPast(Request $request)
  97.     {
  98.         // ログイン会員取得
  99.         $Customer $this->getUser();
  100.         $customerId $Customer->getId();
  101.         // 注文履歴取得
  102.         $qb $this->orderRepository->createQueryBuilder('o')
  103.             ->leftJoin('o.OrderItems''oi')
  104.             ->leftJoin('oi.Product''p')
  105.             ->leftJoin('o.Shippings''s')
  106.             ->where('o.Customer = :customer')
  107.             ->andWhere('o.OrderStatus != :cancelStatus')
  108.             ->setParameter('customer'$Customer)
  109.             ->setParameter('cancelStatus'8// 8=キャンセル
  110.             ->orderBy('o.order_date''DESC');
  111.         $orders $qb->getQuery()->getResult();
  112.         // OrderItemを展開して配列に変換
  113.         $rows = [];
  114.         foreach ($orders as $Order) {
  115.             $OrderItems $Order->getOrderItems();
  116.             $Shippings $Order->getShippings();
  117.             $Shipping $Shippings->first();
  118.             foreach ($OrderItems as $OrderItem) {
  119.                 // 商品明細のみ(送料・手数料などは除外)
  120.                 if ($OrderItem->isProduct()) {
  121.                     // 価格交渉していない商品は除外(price_negoがnullの場合は表示しない)
  122.                     if ($OrderItem->getPriceNego() === null) {
  123.                         continue;
  124.                     }
  125.                     $Product $OrderItem->getProduct();
  126.                     $row = [
  127.                         'order_id' => $Order->getId(),
  128.                         'order_date' => $Order->getOrderDate(),
  129.                         'product_id' => $Product $Product->getId() : null,
  130.                         'name' => $OrderItem->getProductName(),
  131.                         'price' => $OrderItem->getPrice(),
  132.                         'price_nego' => $OrderItem->getPriceNego(),
  133.                         'payment_total' => $Order->getPaymentTotal(),
  134.                         'payment_method' => $Order->getPayment() ? $Order->getPayment()->getMethod() : '',
  135.                         'message' => $Order->getMessage(),
  136.                         'shipping_name01' => $Shipping $Shipping->getName01() : '',
  137.                         'shipping_name02' => $Shipping $Shipping->getName02() : '',
  138.                         'status_nm' => $Order->getOrderStatus() ? $Order->getOrderStatus()->getName() : '',
  139.                         'file_name' => $Product && $Product->getMainListImage() ? $Product->getMainListImage() : '',
  140.                     ];
  141.                     $rows[] = $row;
  142.                 }
  143.             }
  144.         }
  145.         // 各カテゴリの件数取得
  146.         $exCoinNum1 $this->offerHistoryRepository->getSuccessfulOffersCount($customerId); // 成立
  147.         $exCoinNum2 $this->offerHistoryRepository->getFailedOffersCount($customerId); // 不成立
  148.         $exCoinNum3 count($rows); // 注文履歴
  149.         return $this->render('@PiaPlazaMypage/default/Mypage/buy_past.twig', [
  150.             'rows' => $rows,
  151.             'row' => [
  152.                 'ex_coin_num1' => $exCoinNum1,
  153.                 'ex_coin_num2' => $exCoinNum2,
  154.                 'ex_coin_num3' => $exCoinNum3,
  155.             ],
  156.         ]);
  157.     }
  158. }