app/Customize/Controller/SalesController.php line 83

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Customize\Controller;
  13. use Customize\Event\EccubeEvents;
  14. use Eccube\Entity\Customer;
  15. use Customize\Entity\AuctionResult;
  16. use Customize\Form\Type\SearchSalesType;
  17. use Customize\Repository\AuctionResultRepository;
  18. use Customize\Repository\BitHistoryRepository;
  19. use Eccube\Repository\CustomerRepository;
  20. use Customize\Repository\ProductRepository;
  21. use Eccube\Controller\AbstractController;
  22. use Eccube\Entity\Product;
  23. use Eccube\Event\EventArgs;
  24. use Eccube\Repository\CustomerFavoriteProductRepository;
  25. use Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination;
  26. use Knp\Component\Pager\PaginatorInterface;
  27. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  28. use Symfony\Component\HttpFoundation\Request;
  29. use Symfony\Component\Routing\Annotation\Route;
  30. class SalesController extends AbstractController
  31. {
  32.     /**
  33.      * @var AuctionResultRepository
  34.      */
  35.     protected $auctionResultRepository;
  36.     /**
  37.      * @var BitHistoryRepository
  38.      */
  39.     protected $bitHistoryRepository;
  40.     /**
  41.      * @var CustomerFavoriteProductRepository
  42.      */
  43.     protected $customerFavoriteProductRepository;
  44.     /**
  45.      * @var ProductRepository
  46.      */
  47.     protected $productRepository;
  48.     /**
  49.      * @var CustomerRepository
  50.      */
  51.     protected $customerRepository;
  52.     /**
  53.      * ListingController constructor.
  54.      */
  55.     public function __construct(
  56.         ProductRepository $productRepository,
  57.         AuctionResultRepository $auctionResultRepository,
  58.         BitHistoryRepository $bitHistoryRepository,
  59.         CustomerRepository $customerRepository
  60.     ) {
  61.         $this->productRepository $productRepository;
  62.         $this->auctionResultRepository $auctionResultRepository;
  63.         $this->bitHistoryRepository $bitHistoryRepository;
  64.         $this->customerRepository $customerRepository;
  65.     }
  66.     /**
  67.      * 売上一覧画面.
  68.      *
  69.      * @Route("/sales/list", name="sales_list", methods={"GET"})
  70.      *
  71.      * @Template("Product/sales.twig")
  72.      */
  73.     public function index(Request $requestPaginatorInterface $paginator)
  74.     {
  75.         if ($this->isGranted('ROLE_USER')) {
  76.             // handleRequestは空のqueryの場合は無視するため
  77.             if ($request->getMethod() === 'GET') {
  78.                 $request->query->set('pageno'$request->query->get('pageno'''));
  79.                 $request->query->set('orderby'$request->query->get('orderby'3));
  80.             }
  81.             // searchForm
  82.             /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
  83.             $builder $this->formFactory->createNamedBuilder(''SearchSalesType::class);
  84.             $Customer $this->getUser();
  85.             if ($request->getMethod() === 'GET') {
  86.                 $builder->setMethod('GET');
  87.             }
  88.             $event = new EventArgs(
  89.                 [
  90.                     'builder' => $builder,
  91.                 ],
  92.                 $request
  93.             );
  94.             $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_INDEX_INITIALIZE);
  95.             /* @var $searchForm \Symfony\Component\Form\FormInterface */
  96.             $searchForm $builder->getForm();
  97.             $searchForm->handleRequest($request);
  98.             // paginator
  99.             $searchData $searchForm->getData();
  100.             $searchData['Customer'] = $Customer;
  101.             $qb $this->productRepository->getQueryBuilderBySalesSearchData($searchData);
  102.             $event = new EventArgs(
  103.                 [
  104.                     'searchData' => $searchData,
  105.                     'qb' => $qb,
  106.                 ],
  107.                 $request
  108.             );
  109.             $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_INDEX_SEARCH);
  110.             $searchData $event->getArgument('searchData');
  111.             $query $qb->getQuery()
  112.                 ->useResultCache(true$this->eccubeConfig['eccube_result_cache_lifetime_short']);
  113.             /** @var SlidingPagination $pagination */
  114.             $pagination $paginator->paginate(
  115.                 $query,
  116.                 ! empty($searchData['pageno']) ? $searchData['pageno'] : 1,
  117.                 ! empty($searchData['disp_number']) ? $searchData['disp_number'] : 20
  118.             );
  119.             $Products $qb->getQuery()->getResult();
  120.             $biddingCompaniesCounts = [];
  121.             $productIds array_map(function ($Product) {
  122.                 return $Product->getId();
  123.             }, $Products);
  124.             $biddingCompaniesResults $this->bitHistoryRepository->countBiddingCompaniesForProducts($productIds);
  125.             foreach ($biddingCompaniesResults as $result) {
  126.                 $biddingCompaniesCounts[$result['productId']] = $result['count'];
  127.             }
  128.             foreach ($pagination as $Product) {
  129.                 // もし結果が存在しない場合は 0 をセット
  130.                 $biddingCompaniesCounts[$Product->getId()] = $biddingCompaniesCounts[$Product->getId()] ?? 0;
  131.             }
  132.             $totalPrice $this->productRepository->getTotalSalesPrice($Customer$searchData["auction"]);
  133.             $totalCount count($pagination);
  134.             return [
  135.                 'subtitle' => '売上一覧',
  136.                 'pagination' => $pagination,
  137.                 'search_form' => $searchForm->createView(),
  138.                 'Customer' => $Customer,
  139.                 'biddingCompaniesCounts' => $biddingCompaniesCounts,
  140.                 'totalPrice' => $totalPrice,
  141.                 'totalCount' => $totalCount
  142.             ];
  143.         } else {
  144.             // 非会員の場合、ログイン画面を表示
  145.             return $this->redirectToRoute('mypage_login');
  146.         }
  147.     }
  148.     protected function getPageTitle($searchData)
  149.     {
  150.         if (isset($searchData['name']) && ! empty($searchData['name'])) {
  151.             return trans('front.auction.search_result');
  152.         } elseif (isset($searchData['category_id']) && $searchData['category_id']) {
  153.             return $searchData['category_id']->getName();
  154.         } else {
  155.             return trans('front.auction.all_auctions');
  156.         }
  157.     }
  158. }