app/Customize/Controller/Admin/AdminController.php line 342

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\Admin;
  13. use Carbon\Carbon;
  14. use Customize\Repository\CategoryRepository;
  15. use Customize\Repository\OrderItemRepository;
  16. use Customize\Repository\ProductRepository;
  17. use Doctrine\Common\Collections\Criteria;
  18. use Doctrine\ORM\NoResultException;
  19. use Doctrine\ORM\Query\ResultSetMapping;
  20. use Eccube\Controller\AbstractController;
  21. use Eccube\Entity\Master\CustomerStatus;
  22. use Eccube\Entity\Master\OrderStatus;
  23. use Eccube\Entity\Master\ProductStatus;
  24. use Eccube\Entity\ProductStock;
  25. use Eccube\Event\EccubeEvents;
  26. use Eccube\Event\EventArgs;
  27. use Eccube\Exception\PluginApiException;
  28. use Eccube\Form\Type\Admin\ChangePasswordType;
  29. use Eccube\Form\Type\Admin\LoginType;
  30. use Eccube\Repository\CustomerRepository;
  31. use Eccube\Repository\Master\OrderStatusRepository;
  32. use Eccube\Repository\MemberRepository;
  33. use Eccube\Repository\OrderRepository;
  34. use Eccube\Service\PluginApiService;
  35. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  36. use Symfony\Component\HttpFoundation\Request;
  37. use Symfony\Component\Routing\Annotation\Route;
  38. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  39. use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
  40. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  41. class AdminController extends AbstractController
  42. {
  43.     /**
  44.      * @var AuthorizationCheckerInterface
  45.      */
  46.     protected $authorizationChecker;
  47.     /**
  48.      * @var AuthenticationUtils
  49.      */
  50.     protected $helper;
  51.     /**
  52.      * @var MemberRepository
  53.      */
  54.     protected $memberRepository;
  55.     /**
  56.      * @var EncoderFactoryInterface
  57.      */
  58.     protected $encoderFactory;
  59.     /**
  60.      * @var OrderRepository
  61.      */
  62.     protected $orderRepository;
  63.     /**
  64.      * @var OrderStatusRepository
  65.      */
  66.     protected $orderStatusRepository;
  67.     /**
  68.      * @var CustomerRepository
  69.      */
  70.     protected $customerRepository;
  71.     /**
  72.      * @var ProductRepository
  73.      */
  74.     protected $productRepository;
  75.     /** @var PluginApiService */
  76.     protected $pluginApiService;
  77.     /**
  78.      * @var array 売り上げ状況用受注状況
  79.      */
  80.     private $excludes = [OrderStatus::CANCELOrderStatus::RETURNED];
  81.     protected $categoryRepository;
  82.     protected $orderItemRepository;
  83.     /**
  84.      * AdminController constructor.
  85.      *
  86.      * @param AuthorizationCheckerInterface $authorizationChecker
  87.      * @param AuthenticationUtils $helper
  88.      * @param MemberRepository $memberRepository
  89.      * @param EncoderFactoryInterface $encoderFactory
  90.      * @param OrderRepository $orderRepository
  91.      * @param OrderStatusRepository $orderStatusRepository
  92.      * @param CustomerRepository $custmerRepository
  93.      * @param ProductRepository $productRepository
  94.      * @param PluginApiService $pluginApiService
  95.      */
  96.     public function __construct(
  97.         AuthorizationCheckerInterface $authorizationChecker,
  98.         AuthenticationUtils $helper,
  99.         MemberRepository $memberRepository,
  100.         EncoderFactoryInterface $encoderFactory,
  101.         OrderRepository $orderRepository,
  102.         OrderStatusRepository $orderStatusRepository,
  103.         CustomerRepository $custmerRepository,
  104.         ProductRepository $productRepository,
  105.         CategoryRepository $categoryRepository,
  106.         PluginApiService $pluginApiService,
  107.         OrderItemRepository $orderItemRepository
  108.     ) {
  109.         $this->authorizationChecker $authorizationChecker;
  110.         $this->helper $helper;
  111.         $this->memberRepository $memberRepository;
  112.         $this->encoderFactory $encoderFactory;
  113.         $this->orderRepository $orderRepository;
  114.         $this->orderStatusRepository $orderStatusRepository;
  115.         $this->customerRepository $custmerRepository;
  116.         $this->productRepository $productRepository;
  117.         $this->pluginApiService $pluginApiService;
  118.         $this->categoryRepository $categoryRepository;
  119.         $this->orderItemRepository $orderItemRepository;
  120.     }
  121.     /**
  122.      * @Route("/%eccube_admin_route%/login", name="admin_login", methods={"GET", "POST"})
  123.      * @Template("@admin/login.twig")
  124.      */
  125.     public function login(Request $request)
  126.     {
  127.         if ($this->authorizationChecker->isGranted('ROLE_ADMIN')) {
  128.             return $this->redirectToRoute('admin_homepage');
  129.         }
  130.         /* @var $form \Symfony\Component\Form\FormInterface */
  131.         $builder $this->formFactory->createNamedBuilder(''LoginType::class);
  132.         $event = new EventArgs(
  133.             [
  134.                 'builder' => $builder,
  135.             ],
  136.             $request
  137.         );
  138.         $this->eventDispatcher->dispatch($eventEccubeEvents::ADMIN_ADMIM_LOGIN_INITIALIZE);
  139.         $form $builder->getForm();
  140.         return [
  141.             'error' => $this->helper->getLastAuthenticationError(),
  142.             'form' => $form->createView(),
  143.         ];
  144.     }
  145.     /**
  146.      * 管理画面ホーム
  147.      *
  148.      * @param Request $request
  149.      *
  150.      * @return array
  151.      *
  152.      * @throws NoResultException
  153.      * @throws \Doctrine\ORM\NonUniqueResultException
  154.      *
  155.      * @Route("/%eccube_admin_route%/", name="admin_homepage", methods={"GET"})
  156.      * @Template("@admin/index.twig")
  157.      */
  158.     public function index(Request $request)
  159.     {
  160.         $adminRoute $this->eccubeConfig['eccube_admin_route'];
  161.         $is_danger_admin_url false;
  162.         if ($adminRoute === 'admin') {
  163.             $is_danger_admin_url true;
  164.         }
  165.         /**
  166.          * 受注状況.
  167.          */
  168.         $excludes = [];
  169.         $excludes[] = OrderStatus::CANCEL;
  170.         $excludes[] = OrderStatus::DELIVERED;
  171.         $excludes[] = OrderStatus::PENDING;
  172.         $excludes[] = OrderStatus::PROCESSING;
  173.         $excludes[] = OrderStatus::RETURNED;
  174.         $event = new EventArgs(
  175.             [
  176.                 'excludes' => $excludes,
  177.             ],
  178.             $request
  179.         );
  180.         $this->eventDispatcher->dispatch($eventEccubeEvents::ADMIN_ADMIM_INDEX_ORDER);
  181.         $excludes $event->getArgument('excludes');
  182.         // 受注ステータスごとの受注件数.
  183.         $Orders $this->getOrderEachStatus($excludes);
  184.         // 受注ステータスの一覧.
  185.         $Criteria = new Criteria();
  186.         $Criteria
  187.             ->where($Criteria::expr()->notIn('id'$excludes))
  188.             ->orderBy(['sort_no' => 'ASC']);
  189.         $OrderStatuses $this->orderStatusRepository->matching($Criteria);
  190.         /**
  191.          * 売り上げ状況
  192.          */
  193.         $event = new EventArgs(
  194.             [
  195.                 'excludes' => $this->excludes,
  196.             ],
  197.             $request
  198.         );
  199.         $this->eventDispatcher->dispatch($eventEccubeEvents::ADMIN_ADMIM_INDEX_SALES);
  200.         $this->excludes $event->getArgument('excludes');
  201.         // 昨日の売上/件数
  202.         $salesYesterday $this->getSalesByDay(new \DateTime('-1 day'));
  203.         // 今日の売上/件数
  204.         $salesToday $this->getSalesByDay(new \DateTime());
  205.         // 今月の売上/件数
  206.         $salesThisMonth $this->getSalesByMonth(new \DateTime());
  207.         /**
  208.          * ショップ状況
  209.          */
  210.         // 在庫切れ商品数
  211.         $countNonStockProducts $this->countNonStockProducts();
  212.         // 取り扱い商品数
  213.         $countProducts $this->countProducts();
  214.         // 本会員数
  215.         $countCustomers $this->countCustomers();
  216.         $event = new EventArgs(
  217.             [
  218.                 'Orders' => $Orders,
  219.                 'OrderStatuses' => $OrderStatuses,
  220.                 'salesThisMonth' => $salesThisMonth,
  221.                 'salesToday' => $salesToday,
  222.                 'salesYesterday' => $salesYesterday,
  223.                 'countNonStockProducts' => $countNonStockProducts,
  224.                 'countProducts' => $countProducts,
  225.                 'countCustomers' => $countCustomers,
  226.             ],
  227.             $request
  228.         );
  229.         $this->eventDispatcher->dispatch($eventEccubeEvents::ADMIN_ADMIM_INDEX_COMPLETE);
  230.         // 推奨プラグイン
  231.         $recommendedPlugins = [];
  232.         try {
  233.             $recommendedPlugins $this->pluginApiService->getRecommended();
  234.         } catch (PluginApiException $ignore) {
  235.         }
  236.         $orderReport $this->orderItemRepository->getOrderReport();
  237.         $newOrderCount $this->orderItemRepository->queryNewOrderCategory();
  238.         $totalFee $this->orderItemRepository->getReportFee();
  239.         $currentDate = (new \DateTime())->setTime(0000);
  240.         $startWeek = (clone $currentDate)->format('w') != ? (clone $currentDate)->modify('last Sunday') : (clone $currentDate);
  241.         $startMonth = (clone $currentDate)->modify('first day of this month');
  242.         $startYear = (clone $currentDate)->setDate((int)$currentDate->format('Y'), 11);
  243.         $totalSaleWeek $this->orderItemRepository->getSalesCustom($startWeek, clone $currentDate);
  244.         $tatalSaleMonth $this->orderItemRepository->getSalesCustom($startMonth, clone $currentDate->setTime(0000)->modify('first day of 1 month'));
  245.         $totalSaleYear $this->orderItemRepository->getSalesCustom($startYear, clone $currentDate);
  246.         return [
  247.             'Orders' => $Orders,
  248.             'OrderStatuses' => $OrderStatuses,
  249.             'salesThisMonth' => $salesThisMonth,
  250.             'salesToday' => $salesToday,
  251.             'salesYesterday' => $salesYesterday,
  252.             'countNonStockProducts' => $countNonStockProducts,
  253.             'countProducts' => $countProducts,
  254.             'countCustomers' => $countCustomers,
  255.             'recommendedPlugins' => $recommendedPlugins,
  256.             'is_danger_admin_url' => $is_danger_admin_url,
  257.             'OrderReport' => $orderReport,
  258.             'NewOrderCount' => $newOrderCount,
  259.             'totalFee' => $totalFee,
  260.             'toalSaleWeek' => $totalSaleWeek,
  261.             'tatalSaleMonth' => $tatalSaleMonth,
  262.             'totalSaleYear' => $totalSaleYear,
  263.         ];
  264.     }
  265.     /**
  266.      *
  267.      * @Route("/%eccube_admin_route%/get-custom-report", methods={"GET"})
  268.      * @return JsonResponse
  269.      */
  270.     public function getCustomReport(Request $request)
  271.     {
  272.         $timezone = new \DateTimeZone('Asia/Tokyo');
  273.         $startDateStr $request->query->get('start_date');
  274.         $endDateStr $request->query->get('end_date');
  275.         $startTime null;
  276.         $endTime null;
  277.         if ($startDateStr) {
  278.             $startTime = new \DateTime($startDateStr$timezone);
  279.             if ($startTime) {
  280.                 $startTime->setTime(000); // Đầu ngày
  281.             }
  282.         }
  283.         if ($endDateStr) {
  284.             $endTime = new \DateTime($endDateStr$timezone);
  285.             if ($endTime) {
  286.                 $endTime->setTime(0000); // Cuối ngày
  287.                 $endTime->modify('+1 day');
  288.             }
  289.         }
  290.         $data $this->orderItemRepository->getCustomReport($startTime$endTime);
  291.         return $this->json(['data' => $data]);
  292.     }
  293.     /**
  294.      * 売上状況の取得
  295.      *
  296.      * @param Request $request
  297.      *
  298.      * @Route("/%eccube_admin_route%/sale_chart", name="admin_homepage_sale", methods={"GET"})
  299.      *
  300.      * @return \Symfony\Component\HttpFoundation\JsonResponse
  301.      */
  302.     public function sale(Request $request)
  303.     {
  304.         if (!($request->isXmlHttpRequest() && $this->isTokenValid())) {
  305.             return $this->json(['status' => 'NG'], 400);
  306.         }
  307.         $event = new EventArgs(
  308.             [
  309.                 'excludes' => $this->excludes,
  310.             ],
  311.             $request
  312.         );
  313.         $this->eventDispatcher->dispatch($eventEccubeEvents::ADMIN_ADMIM_INDEX_SALES);
  314.         $this->excludes $event->getArgument('excludes');
  315.         // 週間の売上金額
  316.         $toDate Carbon::now();
  317.         $fromDate Carbon::today()->subWeek();
  318.         $rawWeekly $this->getData($fromDate$toDate'Y/m/d');
  319.         // 月間の売上金額
  320.         $fromDate Carbon::now()->startOfMonth();
  321.         $rawMonthly $this->getData($fromDate$toDate'Y/m/d');
  322.         // 年間の売上金額
  323.         $fromDate Carbon::now()->subYear()->startOfMonth();
  324.         $rawYear $this->getData($fromDate$toDate'Y/m');
  325.         $datas = [$rawWeekly$rawMonthly$rawYear];
  326.         return $this->json($datas);
  327.     }
  328.     /**
  329.      * パスワード変更画面
  330.      *
  331.      * @Route("/%eccube_admin_route%/change_password", name="admin_change_password", methods={"GET", "POST"})
  332.      * @Template("@admin/change_password.twig")
  333.      *
  334.      * @param Request $request
  335.      *
  336.      * @return \Symfony\Component\HttpFoundation\RedirectResponse|array
  337.      */
  338.     public function changePassword(Request $request)
  339.     {
  340.         $builder $this->formFactory
  341.             ->createBuilder(ChangePasswordType::class);
  342.         $event = new EventArgs(
  343.             [
  344.                 'builder' => $builder,
  345.             ],
  346.             $request
  347.         );
  348.         $this->eventDispatcher->dispatch($eventEccubeEvents::ADMIN_ADMIM_CHANGE_PASSWORD_INITIALIZE);
  349.         $form $builder->getForm();
  350.         $form->handleRequest($request);
  351.         if ($form->isSubmitted() && $form->isValid()) {
  352.             $Member $this->getUser();
  353.             $salt $Member->getSalt();
  354.             $password $form->get('change_password')->getData();
  355.             $encoder $this->encoderFactory->getEncoder($Member);
  356.             // 2系からのデータ移行でsaltがセットされていない場合はsaltを生成.
  357.             if (empty($salt)) {
  358.                 $salt $encoder->createSalt();
  359.             }
  360.             $password $encoder->encodePassword($password$salt);
  361.             $Member
  362.                 ->setPassword($password)
  363.                 ->setSalt($salt);
  364.             $this->memberRepository->save($Member);
  365.             $event = new EventArgs(
  366.                 [
  367.                     'form' => $form,
  368.                     'Member' => $Member,
  369.                 ],
  370.                 $request
  371.             );
  372.             $this->eventDispatcher->dispatch($eventEccubeEvents::ADMIN_ADMIN_CHANGE_PASSWORD_COMPLETE);
  373.             $this->addSuccess('admin.change_password.password_changed''admin');
  374.             return $this->redirectToRoute('admin_change_password');
  375.         }
  376.         return [
  377.             'form' => $form->createView(),
  378.         ];
  379.     }
  380.     /**
  381.      * 在庫なし商品の検索結果を表示する.
  382.      *
  383.      * @Route("/%eccube_admin_route%/search_nonstock", name="admin_homepage_nonstock", methods={"GET"})
  384.      *
  385.      * @param Request $request
  386.      *
  387.      * @return \Symfony\Component\HttpFoundation\Response
  388.      */
  389.     public function searchNonStockProducts(Request $request)
  390.     {
  391.         // 在庫なし商品の検索条件をセッションに付与し, 商品マスタへリダイレクトする.
  392.         $searchData = [];
  393.         $searchData['stock'] = [ProductStock::OUT_OF_STOCK];
  394.         $session $request->getSession();
  395.         $session->set('eccube.admin.product.search'$searchData);
  396.         return $this->redirectToRoute('admin_product_page', [
  397.             'page_no' => 1,
  398.         ]);
  399.     }
  400.     /**
  401.      * 本会員の検索結果を表示する.
  402.      *
  403.      * @Route("/%eccube_admin_route%/search_customer", name="admin_homepage_customer", methods={"GET"})
  404.      *
  405.      * @param Request $request
  406.      *
  407.      * @return \Symfony\Component\HttpFoundation\Response
  408.      */
  409.     public function searchCustomer(Request $request)
  410.     {
  411.         $searchData = [];
  412.         $searchData['customer_status'] = [CustomerStatus::REGULAR];
  413.         $session $request->getSession();
  414.         $session->set('eccube.admin.customer.search'$searchData);
  415.         return $this->redirectToRoute('admin_customer_page', [
  416.             'page_no' => 1,
  417.         ]);
  418.     }
  419.     /**
  420.      * @param \Doctrine\ORM\EntityManagerInterface $em
  421.      * @param array $excludes
  422.      *
  423.      * @return Request|null
  424.      */
  425.     protected function getOrderEachStatus(array $excludes)
  426.     {
  427.         $sql 'SELECT
  428.                     t1.order_status_id as status,
  429.                     COUNT(t1.id) as count
  430.                 FROM
  431.                     dtb_order t1
  432.                 WHERE
  433.                     t1.order_status_id NOT IN (:excludes)
  434.                 GROUP BY
  435.                     t1.order_status_id
  436.                 ORDER BY
  437.                     t1.order_status_id';
  438.         $rsm = new ResultSetMapping();
  439.         $rsm->addScalarResult('status''status');
  440.         $rsm->addScalarResult('count''count');
  441.         $query $this->entityManager->createNativeQuery($sql$rsm);
  442.         $query->setParameters([':excludes' => $excludes]);
  443.         $result $query->getResult();
  444.         $orderArray = [];
  445.         foreach ($result as $row) {
  446.             $orderArray[$row['status']] = $row['count'];
  447.         }
  448.         return $orderArray;
  449.     }
  450.     /**
  451.      * @param \DateTime $dateTime
  452.      *
  453.      * @return array|mixed
  454.      *
  455.      * @throws \Doctrine\ORM\NonUniqueResultException
  456.      */
  457.     protected function getSalesByDay($dateTime)
  458.     {
  459.         $dateTimeStart = clone $dateTime;
  460.         $dateTimeStart->setTime(0000);
  461.         $dateTimeEnd = clone $dateTimeStart;
  462.         $dateTimeEnd->modify('+1 days');
  463.         $qb $this->orderRepository
  464.             ->createQueryBuilder('o')
  465.             ->select('
  466.             SUM(o.payment_total) AS order_amount,
  467.             COUNT(o) AS order_count')
  468.             ->setParameter(':excludes'$this->excludes)
  469.             ->setParameter(':targetDateStart'$dateTimeStart)
  470.             ->setParameter(':targetDateEnd'$dateTimeEnd)
  471.             ->andWhere(':targetDateStart <= o.order_date and o.order_date < :targetDateEnd')
  472.             ->andWhere('o.OrderStatus NOT IN (:excludes)');
  473.         $q $qb->getQuery();
  474.         $result = [];
  475.         try {
  476.             $result $q->getSingleResult();
  477.         } catch (NoResultException $e) {
  478.             // 結果がない場合は空の配列を返す.
  479.         }
  480.         return $result;
  481.     }
  482.     /**
  483.      * @param \DateTime $dateTime
  484.      *
  485.      * @return array|mixed
  486.      *
  487.      * @throws \Doctrine\ORM\NonUniqueResultException
  488.      */
  489.     protected function getSalesByMonth($dateTime)
  490.     {
  491.         $dateTimeStart = clone $dateTime;
  492.         $dateTimeStart->setTime(0000);
  493.         $dateTimeStart->modify('first day of this month');
  494.         $dateTimeEnd = clone $dateTime;
  495.         $dateTimeEnd->setTime(0000);
  496.         $dateTimeEnd->modify('first day of 1 month');
  497.         $qb $this->orderRepository
  498.             ->createQueryBuilder('o')
  499.             ->select('
  500.             SUM(o.payment_total) AS order_amount,
  501.             COUNT(o) AS order_count')
  502.             ->setParameter(':excludes'$this->excludes)
  503.             ->setParameter(':targetDateStart'$dateTimeStart)
  504.             ->setParameter(':targetDateEnd'$dateTimeEnd)
  505.             ->andWhere(':targetDateStart <= o.order_date and o.order_date < :targetDateEnd')
  506.             ->andWhere('o.OrderStatus NOT IN (:excludes)');
  507.         $q $qb->getQuery();
  508.         $result = [];
  509.         try {
  510.             $result $q->getSingleResult();
  511.         } catch (NoResultException $e) {
  512.             // 結果がない場合は空の配列を返す.
  513.         }
  514.         return $result;
  515.     }
  516.     /**
  517.      * 在庫切れ商品数を取得
  518.      *
  519.      * @return mixed
  520.      *
  521.      * @throws \Doctrine\ORM\NonUniqueResultException
  522.      */
  523.     protected function countNonStockProducts()
  524.     {
  525.         $qb $this->productRepository->createQueryBuilder('p')
  526.             ->select('count(DISTINCT p.id)')
  527.             ->innerJoin('p.ProductClasses''pc')
  528.             ->where('pc.stock_unlimited = :StockUnlimited AND pc.stock = 0')
  529.             ->andWhere('pc.visible = :visible')
  530.             ->setParameter('StockUnlimited'false)
  531.             ->setParameter('visible'true);
  532.         return $qb->getQuery()->getSingleScalarResult();
  533.     }
  534.     /**
  535.      * 商品数を取得
  536.      *
  537.      * @return mixed
  538.      *
  539.      * @throws \Doctrine\ORM\NonUniqueResultException
  540.      */
  541.     protected function countProducts()
  542.     {
  543.         $qb $this->productRepository->createQueryBuilder('p')
  544.             ->select('count(p.id)')
  545.             ->where('p.Status in (:Status)')
  546.             ->setParameter('Status', [ProductStatus::DISPLAY_SHOWProductStatus::DISPLAY_HIDE]);
  547.         return $qb->getQuery()->getSingleScalarResult();
  548.     }
  549.     /**
  550.      * 本会員数を取得
  551.      *
  552.      * @return mixed
  553.      *
  554.      * @throws \Doctrine\ORM\NonUniqueResultException
  555.      */
  556.     protected function countCustomers()
  557.     {
  558.         $qb $this->customerRepository->createQueryBuilder('c')
  559.             ->select('count(c.id)')
  560.             ->where('c.Status = :Status')
  561.             ->setParameter('Status'CustomerStatus::REGULAR);
  562.         return $qb->getQuery()->getSingleScalarResult();
  563.     }
  564.     /**
  565.      * 期間指定のデータを取得
  566.      *
  567.      * @param Carbon $fromDate
  568.      * @param Carbon $toDate
  569.      * @param $format
  570.      *
  571.      * @return array
  572.      */
  573.     protected function getData(Carbon $fromDateCarbon $toDate$format)
  574.     {
  575.         $qb $this->orderRepository->createQueryBuilder('o')
  576.             ->andWhere('o.order_date >= :fromDate')
  577.             ->andWhere('o.order_date <= :toDate')
  578.             ->andWhere('o.OrderStatus NOT IN (:excludes)')
  579.             ->setParameter(':excludes'$this->excludes)
  580.             ->setParameter(':fromDate'$fromDate->copy())
  581.             ->setParameter(':toDate'$toDate->copy())
  582.             ->orderBy('o.order_date');
  583.         $result $qb->getQuery()->getResult();
  584.         return $this->convert($result$fromDate$toDate$format);
  585.     }
  586.     /**
  587.      * 期間毎にデータをまとめる
  588.      *
  589.      * @param $result
  590.      * @param Carbon $fromDate
  591.      * @param Carbon $toDate
  592.      * @param $format
  593.      *
  594.      * @return array
  595.      */
  596.     protected function convert($resultCarbon $fromDateCarbon $toDate$format)
  597.     {
  598.         $raw = [];
  599.         for ($date $fromDate$date <= $toDate$date $date->addDay()) {
  600.             $raw[$date->format($format)]['price'] = 0;
  601.             $raw[$date->format($format)]['count'] = 0;
  602.         }
  603.         foreach ($result as $Order) {
  604.             $raw[$Order->getOrderDate()->format($format)]['price'] += $Order->getPaymentTotal();
  605.             ++$raw[$Order->getOrderDate()->format($format)]['count'];
  606.         }
  607.         return $raw;
  608.     }
  609. }