app/Customize/Controller/Mypage/CustomMypageController.php line 250

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\Mypage;
  13. use Eccube\Controller\AbstractController;
  14. use Eccube\Controller\Mypage\MypageController as BaseMypageController;
  15. use Eccube\Entity\BaseInfo;
  16. use Eccube\Entity\Customer;
  17. use Eccube\Entity\Product;
  18. use Eccube\Entity\Order;
  19. use Eccube\Event\EccubeEvents;
  20. use Eccube\Event\EventArgs;
  21. use Eccube\Exception\CartException;
  22. use Eccube\Entity\ExportCsvRow;
  23. use Eccube\Entity\Master\OrderStatus;
  24. use Eccube\Entity\Master\CsvType;
  25. use Eccube\Form\Type\Front\CustomerLoginType;
  26. use Eccube\Repository\BaseInfoRepository;
  27. use Eccube\Repository\CustomerFavoriteProductRepository;
  28. use Eccube\Repository\OrderRepository;
  29. use Eccube\Repository\Master\OrderStatusRepository;
  30. use Customize\Repository\CashbackSummaryRepository;
  31. use Customize\Repository\OrderCashbackRepository;
  32. use Customize\Repository\NotificationRepository;
  33. use Customize\Repository\FCMHistoryRepository;
  34. use Eccube\Repository\ProductRepository;
  35. use Eccube\Service\CartService;
  36. use Customize\Service\CsvExportService;
  37. use Customize\Service\DzxPdfService;
  38. use Customize\Service\CashbackService;
  39. use Customize\Service\ProductService;
  40. use Customize\Service\OrderStateMachine;
  41. use Customize\Service\NotificationService;
  42. use Customize\Service\MailService;
  43. use Eccube\Service\PurchaseFlow\PurchaseContext;
  44. use Eccube\Service\PurchaseFlow\PurchaseFlow;
  45. use Knp\Component\Pager\PaginatorInterface;
  46. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  47. use Symfony\Component\HttpFoundation\RedirectResponse;
  48. use Symfony\Component\HttpFoundation\Request;
  49. use Symfony\Component\HttpFoundation\Response;
  50. use Symfony\Component\HttpFoundation\StreamedResponse;
  51. use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
  52. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  53. use Symfony\Component\Routing\Annotation\Route;
  54. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  55. // ▼ファイルアップロード
  56. use Customize\Entity\Myimage;
  57. use Customize\Repository\MyimageRepository;
  58. class CustomMypageController extends BaseMypageController
  59. {
  60.     /**
  61.      * @var CsvExportService
  62.      */
  63.     protected $csvExportService;
  64.     /**
  65.      * @var ProductRepository
  66.      */
  67.     protected $productRepository;
  68.     /**
  69.      * @var ProductService
  70.      */
  71.     protected $productService;
  72.     /**
  73.      * @var CashbackService
  74.      */
  75.     protected $cashbackService;
  76.     
  77.     /** @var DzxPdfService */
  78.     protected $dzxPdfService;
  79.     
  80.     /**
  81.      * @var CustomerFavoriteProductRepository
  82.      */
  83.     protected $customerFavoriteProductRepository;
  84.     /**
  85.      * @var BaseInfo
  86.      */
  87.     protected $BaseInfo;
  88.     /**
  89.      * @var CartService
  90.      */
  91.     protected $cartService;
  92.     /**
  93.      * @var OrderRepository
  94.      */
  95.     protected $orderRepository;
  96.     /**
  97.      * @var NotificationRepository
  98.      */
  99.     protected $notificationRepository;
  100.     /**
  101.      * @var NotificationService
  102.      */
  103.     protected $notificationService;
  104.     
  105.     /**
  106.      * @var FCMHistoryRepository
  107.      */
  108.     protected $fCMHistoryRepository;
  109.     /**
  110.      * @var OrderStatusRepository
  111.      */
  112.     protected $orderStatusRepository;
  113.     /**
  114.      * @var OrderStateMachine
  115.      */
  116.     protected $orderStateMachine;
  117.     /**
  118.      * @var OrderCashbackRepository
  119.      */
  120.     protected $orderCashbackRepository;
  121.     /**
  122.      * @var CashbackSummaryRepository
  123.      */
  124.     protected $cashbackSummaryRepository;
  125.     
  126.     /**
  127.      * @var PurchaseFlow
  128.      */
  129.     protected $purchaseFlow;
  130.     /** ▼ファイルアップロード
  131.      * @var MyimageRepository
  132.      */
  133.     protected $myimageRepository;
  134.     /**
  135.      * @var MailService
  136.      */
  137.     protected $mailService;
  138.     
  139.     /**
  140.      * MypageController constructor.
  141.      *
  142.      * @param CsvExportService $csvExportService
  143.      * @param MyimageRepository $myimageRepository ▼ファイルアップロード
  144.      * @param OrderRepository $orderRepository
  145.      * @param OrderStatusRepository $orderStatusRepository
  146.      * @param OrderCashbackRepository $orderCashbackRepository
  147.      * @param OrderStateMachine $orderStateMachine
  148.      * @param CustomerFavoriteProductRepository $customerFavoriteProductRepository
  149.      * @param CartService $cartService
  150.      * @param BaseInfoRepository $baseInfoRepository
  151.      * @param PurchaseFlow $purchaseFlow
  152.      */
  153.     public function __construct(
  154.         CsvExportService $csvExportService,
  155.         ProductService $productService,
  156.         CashbackService $cashbackService,
  157.         MyimageRepository $myimageRepository// ▼ファイルアップロード
  158.         OrderRepository $orderRepository,
  159.         OrderStatusRepository $orderStatusRepository,
  160.         OrderCashbackRepository $orderCashbackRepository,
  161.         NotificationRepository $notificationRepository,
  162.         NotificationService $notificationService,
  163.         FCMHistoryRepository $fCMHistoryRepository,
  164.         OrderStateMachine $orderStateMachine,
  165.         CashbackSummaryRepository $cashbackSummaryRepository,
  166.         DzxPdfService $dzxPdfService,
  167.         CustomerFavoriteProductRepository $customerFavoriteProductRepository,
  168.         CartService $cartService,
  169.         BaseInfoRepository $baseInfoRepository,
  170.         PurchaseFlow $purchaseFlow,
  171.         MailService $mailService
  172.     ) {
  173.         $this->csvExportService $csvExportService;
  174.         $this->productService $productService;
  175.         $this->cashbackService $cashbackService;
  176.         $this->myimageRepository $myimageRepository// ▼ファイルアップロード
  177.         $this->orderRepository $orderRepository;
  178.         $this->orderStatusRepository $orderStatusRepository;
  179.         $this->orderCashbackRepository $orderCashbackRepository;
  180.         $this->notificationRepository $notificationRepository;
  181.         $this->notificationService $notificationService;
  182.         $this->orderStateMachine $orderStateMachine;
  183.         $this->cashbackSummaryRepository $cashbackSummaryRepository;
  184.         $this->customerFavoriteProductRepository $customerFavoriteProductRepository;
  185.         $this->dzxPdfService $dzxPdfService;
  186.         $this->BaseInfo $baseInfoRepository->get();
  187.         $this->fCMHistoryRepository $fCMHistoryRepository;
  188.         $this->cartService $cartService;
  189.         $this->purchaseFlow $purchaseFlow;
  190.         $this->mailService $mailService;
  191.     }
  192.     /**
  193.      * ログイン画面.
  194.      *
  195.      * @Route("/mypage/login", name="mypage_login")
  196.      * @Template("Mypage/login.twig")
  197.      */
  198.     public function login(Request $requestAuthenticationUtils $utils)
  199.     {
  200.         return $this->loginapp($request$utilsfalse);
  201.     }
  202.     /**
  203.      * ログイン画面.
  204.      *
  205.      * @Route("/mypage/login/{isApp}", name="mypage_login_isapp")
  206.      * @Template("Mypage/login.twig")
  207.      */
  208.     public function loginapp(Request $requestAuthenticationUtils $utils$isApp)
  209.     {
  210.         if ($this->isGranted('IS_AUTHENTICATED_FULLY')) {
  211.             log_info('認証済のためログイン処理をスキップ');
  212.             return $this->redirectToRoute('mypage');
  213.             /*
  214.             if($request->get("isApp")=="1"){
  215.                 $appVer = $request->get("appVer");
  216.                 $os = $request->get("os");
  217.                 $params = array('isApp' => '1','os' => $os,'appVer' => $appVer);
  218.                 return $this->redirectToRoute('mypage', $params);
  219.             }else{
  220.                 return $this->redirectToRoute('mypage');
  221.             }
  222.             */
  223.         }
  224.         /* @var $form \Symfony\Component\Form\FormInterface */
  225.         $builder $this->formFactory
  226.             ->createNamedBuilder(''CustomerLoginType::class);
  227.         $builder->get('login_memory')->setData((bool) $request->getSession()->get('_security.login_memory'));
  228.         if ($this->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
  229.             $Customer $this->getUser();
  230.             if ($Customer instanceof Customer) {
  231.                 $builder->get('login_email')
  232.                     ->setData($Customer->getEmail());
  233.             }
  234.             $this->refreshNotificationCount();
  235.         }
  236.         $event = new EventArgs(
  237.             [
  238.                 'builder' => $builder,
  239.             ],
  240.             $request
  241.         );
  242.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_MYPAGE_MYPAGE_LOGIN_INITIALIZE);
  243.         $form $builder->getForm();
  244.         return [
  245.             'error' => $utils->getLastAuthenticationError(),
  246.             'form' => $form->createView(),
  247.             'isApp' => $isApp
  248.         ];
  249.     }
  250.     /**
  251.      * マイページ.
  252.      *
  253.      * @Route("/mypage/", name="mypage")
  254.      * @Template("Mypage/index.twig")
  255.      */
  256.     public function index(Request $requestPaginatorInterface $paginator)
  257.     {
  258.         $Customer $this->getUser();
  259.         $shareKey $this->productService->getEncodeByShareID($Customer->getId());
  260.         $showIntro $this->BaseInfo->getOptionOrderShowIntro();
  261.         // 購入処理中/決済処理中ステータスの受注を非表示にする.
  262.         $this->entityManager
  263.             ->getFilters()
  264.             ->enable('incomplete_order_status_hidden');
  265.         // paginator
  266.         $qb $this->orderRepository->getQueryBuilderByCustomer($Customer);
  267.         $event = new EventArgs(
  268.             [
  269.                 'qb' => $qb,
  270.                 'Customer' => $Customer,
  271.             ],
  272.             $request
  273.         );
  274.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_MYPAGE_MYPAGE_INDEX_SEARCH);
  275.         $pagination $paginator->paginate(
  276.             $qb,
  277.             $request->get('pageno'1),
  278.             $this->eccubeConfig['eccube_search_pmax']
  279.         );
  280.         $this->refreshNotificationCount();
  281.         return [
  282.             'showIntro' => $showIntro,
  283.             'shareKey' => $shareKey,
  284.             'pagination' => $pagination,
  285.         ];
  286.     }
  287.     /**
  288.      * ランキング情報.
  289.      *
  290.      * @Route("/mypage/ranking/", name="mypage_ranking")
  291.      * @Template("Mypage/ranking.twig")
  292.      */
  293.     public function ranking(Request $requestPaginatorInterface $paginator)
  294.     {
  295.         $Customer $this->getUser();
  296.         $shareKey $this->productService->getEncodeByShareID($Customer->getId());
  297.         //Summary
  298.         $rsProductList $this->cashbackService->getCustomerProductList($Customer);
  299.         $selCount count($rsProductList);
  300.         $this->refreshNotificationCount();
  301.         return [
  302.             'shareKey' => $shareKey,
  303.             'selCount' => $selCount,
  304.             'productList' => $rsProductList,
  305.         ];
  306.     }
  307.     /**
  308.      * ランキング明細情報. (ランキングトップ50位を表示する)
  309.      *
  310.      * @Route("/mypage/ranking_detail/{id}", name="mypage_ranking_detail")
  311.      * @Template("Mypage/ranking_detail.twig")
  312.      */
  313.     public function ranking_detail(Request $request$id)
  314.     {
  315.         $Customer $this->getUser();
  316.         $productList null;
  317.         $rsRankingList null;
  318.         $issucceeded false;
  319.         $totalCount 0;
  320.         $maxCashback $this->BaseInfo->getOptionDzxMaxCashback();  //キャッシュバック上限
  321.         $productId $this->productService->decodeId($id);
  322.         //ProductList
  323.         //$productList = $this->cashbackSummaryRepository->getRankProduct($productId);
  324.         $productList $this->cashbackService->getRankingList($Customer$productId);
  325.         //Cashback Count Total
  326.         $rsCountTotal $this->cashbackSummaryRepository->getCashbackFinishedTotal($productId$maxCashback);
  327.         //Ranking List
  328.         $rsRankingList $this->cashbackSummaryRepository->getRankListByDetail($productId$maxCashback);
  329.         
  330.         $this->refreshNotificationCount();
  331.         foreach($rsCountTotal as $item){
  332.             if($item["customerId"] == $Customer->getId()){
  333.                 $issucceeded true;
  334.                 break;
  335.             }
  336.         }
  337.         $hasRankingList sizeof($rsRankingList);
  338.         $hasProductList sizeof($productList);
  339.         $totalCount sizeof($rsCountTotal);
  340.         return [
  341.             'id' => $id,
  342.             'hasProductList' => $hasProductList,
  343.             'productList' => $productList,
  344.             'hasRankingList' => $hasRankingList,
  345.             'rankingList' => $rsRankingList,
  346.             'totalCount' => $totalCount,
  347.             'issucceeded' => $issucceeded,
  348.             'Customer' => $Customer,
  349.         ];
  350.     }
  351.     /**
  352.      * お知らせ確認.
  353.      *
  354.      * @Route("/mypage/notification/", name="mypage_notification")
  355.      * @Template("Mypage/notification.twig")
  356.      */
  357.     public function myNotification(Request $requestPaginatorInterface $paginator)
  358.     {
  359.         $Customer $this->getUser();
  360.         //Detail
  361.         $qb $this->notificationRepository->getQueryBuilderByDetail($Customer);
  362.         $pagination $paginator->paginate(
  363.             $qb,
  364.             $request->get('pageno'1),
  365.             $this->eccubeConfig['eccube_search_pmax']
  366.         );
  367.         $this->refreshNotificationCount();
  368.         
  369.         return [
  370.             'pagination' => $pagination
  371.         ];
  372.     }
  373.     /**
  374.      * お知らせ內容.
  375.      *
  376.      * @Route("/mypage/notification/{id}", name="mypage_notification_view")
  377.      * @Template("Mypage/notification_view.twig")
  378.      */
  379.     public function myNotificationView(Request $request$id)
  380.     {
  381.         $Customer $this->getUser();
  382.         //Detail
  383.         $PreviousId $this->notificationRepository->getPreviousRow($Customer$id);
  384.         $NextId $this->notificationRepository->getNextRow($Customer$id);
  385.         $detail $this->notificationRepository->findOneBy(['Customer' => $Customer'id'=>$id]);
  386.         $this->notificationService->plusNoticeViewCount($detail);
  387.         $this->refreshNotificationCount();
  388.         $newContents $this->linkify($detail->getContents());
  389.         $detail->setContents($newContents);
  390.         $fcmlist $this->fCMHistoryRepository->findBy(['Notification'=>$detail'Customer' => $Customer]);
  391.         return [
  392.             'PreviousId' => $PreviousId,
  393.             'NextId' => $NextId,
  394.             'detail' => $detail,
  395.             'fcmlist' => $fcmlist
  396.         ];
  397.     }
  398.     /**
  399.      * 売上情報.
  400.      *
  401.      * @Route("/mypage/mysales/", name="mypage_mysales")
  402.      * @Template("Mypage/mysales.twig")
  403.      */
  404.     public function mysales(Request $requestPaginatorInterface $paginator)
  405.     {
  406.         $Customer $this->getUser();
  407.         $rsSummary null;
  408.         $pageDetail null;
  409.         $selDate "";
  410.         $selDateName "";
  411.         $selCount 0;
  412.         $isShowCashbackAlert true;
  413.         $showIntro $this->BaseInfo->getOptionOrderShowIntro();
  414.         // 購入処理中/決済処理中ステータスの受注を非表示にする.
  415.         $this->entityManager
  416.             ->getFilters()
  417.             ->enable('incomplete_order_status_hidden');
  418.         // get date list
  419.         $lstDate $this->cashbackSummaryRepository->getListDate($Customer);
  420.         $selCount count($lstDate);
  421.         if(!empty($_SESSION["selDate"])){
  422.             $selDate $_SESSION["selDate"];
  423.             $selDateName str_replace("-""年"$selDate)."月";
  424.         }
  425.         if(!empty($_POST)){
  426.             if(!empty($_POST["selDate"])){
  427.                 $selDate $_POST["selDate"];
  428.                 $selDateName str_replace("-""年"$selDate)."月";
  429.                 $_SESSION["selDate"]=$selDate;
  430.             }
  431.         }
  432.         if($selCount 0){
  433.             if($selDate == ""){
  434.                 $selDate $lstDate[0]["dateVal"];
  435.                 $selDateName str_replace("-""年"$selDate)."月";
  436.             }
  437.             //Summary
  438.             $rsSummary $this->cashbackSummaryRepository->getQueryBuilderBySummary($Customer$selDate);
  439.             //Detail
  440.             $qDetail $this->orderCashbackRepository->getQueryBuilderByDetail($Customer$selDate);
  441.             $pageDetail $paginator->paginate(
  442.                 $qDetail,
  443.                 $request->get('pageno'1),
  444.                 $this->eccubeConfig['eccube_search_pmax']
  445.             );
  446.         }
  447.         $this->refreshNotificationCount();
  448.         //口座チェック
  449.         if($Customer != null){
  450.             if( $Customer->getBankName() != null && $Customer->getBankName() != "0" &&
  451.                     $Customer->getBankBranchCode() != null && $Customer->getBankBranchCode() !="0" &&
  452.                     $Customer->getBankAccount() != null && $Customer->getBankAccount() != "" ){
  453.                     $isShowCashbackAlert false;
  454.             }
  455.         }
  456.         return [
  457.             'showIntro' => $showIntro,
  458.             'selDate' => $selDate,
  459.             'selDateName' => $selDateName,
  460.             'selCount' => $selCount,
  461.             'listDate' => $lstDate,
  462.             'rsSummary' => $rsSummary,
  463.             'rsDetail' => $pageDetail,
  464.             'showCashbackAlert' => $isShowCashbackAlert
  465.         ];
  466.     }
  467.     /**
  468.      * 商品PDFの出力.
  469.      *
  470.      * @Route("/mypage/mysales/exportpdf/summary/{selDate}", name="mypage_mysales_exportpdf_summary")
  471.      *
  472.      * @param Request $request
  473.      *
  474.      * @return StreamedResponse
  475.      */
  476.     public function exportPdfSummary(Request $request$selDate){
  477.         $arrData = [];
  478.         $arrData["issue_date"] = new \DateTime();
  479.         $arrData["ids"] = "32";
  480.         $arrData["title"] = "test";
  481.         // 情報からPDFを作成する
  482.         $status $this->dzxPdfService->makePdf($arrData);
  483.         // 異常終了した場合の処理
  484.         if (!$status) {
  485.             $this->addError('admin.order.export.pdf.download.failure''admin');
  486.             log_info('Unable to create pdf files! Process have problems!');
  487.             return $this->render('@admin/Order/order_pdf.twig', [
  488.                 'form' => $form->createView(),
  489.             ]);
  490.         }
  491.         // ダウンロードする
  492.         $response = new Response(
  493.             $this->dzxPdfService->outputPdf(),
  494.             200,
  495.             ['content-type' => 'application/pdf']
  496.         );
  497.         $response->headers->set('Content-Disposition''attachment; filename="'.$this->dzxPdfService->getPdfFileName().'"');
  498.         return $response;
  499.     }
  500.     /**
  501.      * 商品CSVの出力.
  502.      *
  503.      * @Route("/mypage/mysales/export/summary/{selDate}", name="mypage_mysales_export_summary")
  504.      *
  505.      * @param Request $request
  506.      *
  507.      * @return StreamedResponse
  508.      */
  509.     public function exportSummary(Request $request$selDate)
  510.     {
  511.         // タイムアウトを無効にする.
  512.         set_time_limit(0);
  513.         // sql loggerを無効にする.
  514.         $em $this->entityManager;
  515.         $em->getConfiguration()->setSQLLogger(null);
  516.         $Customer $this->getUser();
  517.         $filename "summary_".$Customer->getId()."-".$selDate."-".date("Ymd").".csv";
  518.         $response = new StreamedResponse();
  519.         $response->setCallback(function () use ($request$selDate$Customer$filename) {
  520.             // 商品データ検索用のクエリビルダを取得.
  521.             $rsSummary $this->cashbackSummaryRepository->getQueryBuilderBySummary($Customer$selDate);
  522.             // データ行の出力.
  523.             $header = [];
  524.             $header[] = "商品名称";
  525.             $header[] = "キャシュバック予定金額";
  526.             $header[] = "キャシュバック金額";
  527.             $header[] = "キャシュバック日付";
  528.             $header[] = "単価";
  529.             $header[] = "全体販売数量";
  530.             $header[] = "全体販売売上";
  531.             $header[] = "シェアポイント";
  532.             $header[] = "販売売上";
  533.             if($request->get("isApp")=="1"){
  534.                 $this->csvExportService->fopen(__DIR__."/../../../../file/".$filename);
  535.             }else{
  536.                 $this->csvExportService->fopen();
  537.             }
  538.             $this->csvExportService->fputcsv($header);
  539.             // 
  540.             foreach($rsSummary as $row){
  541.                 $data = [];
  542.                 $data[] = $row["productName"];
  543.                 $data[] = "¥".number_format($row["preAmt"]);
  544.                 $data[] = "¥".number_format($row["finalAmt"]);
  545.                 $data[] = ($row["paymentDate"] == null "" date_format($row["paymentDate"], 'Y/m/d'));
  546.                 $product $row["Product"];
  547.                 if($product->hasProductClass()){
  548.                     if($product->getPrice02IncTaxMin() == $product->getPrice02IncTaxMax()){
  549.                         $data[] = "¥".number_format($product->getPrice02IncTaxMin());
  550.                     }else{
  551.                         $data[] = "¥".number_format($product->getPrice02IncTaxMin())."~".number_format($product->getPrice02IncTaxMax());
  552.                     }
  553.                 }else{
  554.                     $data[] = "¥".number_format($product->getPrice02IncTaxMin());
  555.                 }
  556.                 
  557.                 //$data[] = "¥".number_format($row["price"]);
  558.                 $data[] = number_format($row["quantity"]);
  559.                 $data[] = "¥".number_format($row["salesAmt"]);
  560.                 $data[] = number_format($row["sharePoint"]);
  561.                 $data[] = "¥".number_format($row["shareSalesAmt"]);
  562.                 $this->csvExportService->fputcsv($data);
  563.             }
  564.             $this->csvExportService->fclose();
  565.         });
  566.         if($request->get("isApp")=="1"){
  567.             $url "";
  568.             if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on'){
  569.                 $url "https://";
  570.             }else{
  571.                 $url "http://";
  572.             }
  573.             $url.= $_SERVER['HTTP_HOST'];
  574.             echo $url."/file/".$filename;
  575.         }else{
  576.             $now = new \DateTime();
  577.             $filename 'summary_'.$now->format('YmdHis').'.csv';
  578.             $response->headers->set('Content-Type''application/octet-stream');
  579.             $response->headers->set('Content-Disposition''attachment; filename='.$filename);
  580.             $response->send();
  581.             log_info('商品CSV出力ファイル名', [$filename]);
  582.         }
  583.         return $response;
  584.     }
  585.     /**
  586.      * 商品CSVの出力.
  587.      *
  588.      * @Route("/mypage/mysales/export/detail/{selDate}", name="mypage_mysales_export_detail")
  589.      *
  590.      * @param Request $request
  591.      *
  592.      * @return StreamedResponse
  593.      */
  594.     public function exportDetail(Request $request$selDate)
  595.     {
  596.         // タイムアウトを無効にする.
  597.         set_time_limit(0);
  598.         // sql loggerを無効にする.
  599.         $em $this->entityManager;
  600.         $em->getConfiguration()->setSQLLogger(null);
  601.         
  602.         $Customer $this->getUser();
  603.         $filename "detail_".$Customer->getId()."-".$selDate."-".date("Ymd").".csv";
  604.         $response = new StreamedResponse();
  605.         $response->setCallback(function () use ($request$selDate$Customer$filename) {
  606.             // 商品データ検索用のクエリビルダを取得.
  607.             $rsDetail $this->orderCashbackRepository->getQueryBuilderByDetailResult($Customer$selDate);
  608.             // データ行の出力.
  609.             $header = [];
  610.             $header[] = "購入日付";
  611.             $header[] = "注文番号";
  612.             $header[] = "売上区分";
  613.             $header[] = "商品名称";
  614.             $header[] = "単価";
  615.             $header[] = "販売数量";
  616.             $header[] = "販売売上";
  617.             $header[] = "シェアポイント";
  618.             $header[] = "シェア売上";
  619.             if($request->get("isApp")=="1"){
  620.                 $this->csvExportService->fopen(__DIR__."/../../../../file/".$filename);
  621.             }else{
  622.                 $this->csvExportService->fopen();
  623.             }
  624.             $this->csvExportService->fputcsv($header);
  625.             // 
  626.             foreach($rsDetail as $row){
  627.                 $data = [];
  628.                 $data[] = ($row["Order"]["order_date"] == null "" date_format($row["Order"]["order_date"], 'Y/m/d'));
  629.                 $data[] = $row["Order"]["id"];
  630.                 $data[] = $row["SalesStatus"]["name"];
  631.                 $data[] = $row["productName"];
  632.                 $data[] = "¥".number_format($row["price"]);
  633.                 $data[] = number_format($row["quantity"]);
  634.                 $data[] = "¥".number_format($row["salesAmt"]);
  635.                 $data[] = number_format($row["sharePoint"]);
  636.                 $data[] = "¥".number_format($row["shareSalesAmt"]);
  637.                 $this->csvExportService->fputcsv($data);
  638.             }
  639.             $this->csvExportService->fclose();
  640.         });
  641.         if($request->get("isApp")=="1"){
  642.             $url "";
  643.             if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on'){
  644.                 $url "https://";
  645.             }else{
  646.                 $url "http://";
  647.             }
  648.             $url.= $_SERVER['HTTP_HOST'];
  649.             echo $url."/file/".$filename;
  650.         }else{
  651.             $now = new \DateTime();
  652.             $filename 'detail_'.$now->format('YmdHis').'.csv';
  653.             $response->headers->set('Content-Type''application/octet-stream');
  654.             $response->headers->set('Content-Disposition''attachment; filename='.$filename);
  655.             $response->send();
  656.             log_info('商品CSV出力ファイル名', [$filename]);
  657.         }
  658.         return $response;
  659.     }
  660.     /**
  661.      * 取消訂單
  662.      *
  663.      * @Route("/mypage/cancel/{order_no}", name="mypage_cancel")
  664.      * @Template("Mypage/history.twig")
  665.      */
  666.     public function cancelOrder(Request $request$order_no)
  667.     {
  668.         $this->entityManager->getFilters()
  669.             ->enable('incomplete_order_status_hidden');
  670.         $Order $this->orderRepository->findOneBy(
  671.             [
  672.                 'order_no' => $order_no,
  673.                 'Customer' => $this->getUser(),
  674.             ]
  675.         );
  676.         if (!$Order) {
  677.             throw new NotFoundHttpException();
  678.         }
  679.         $OrderStatus $this->orderStatusRepository->findOneBy(['id' => OrderStatus::CANCEL]);
  680.         $orderStatus $Order->getOrderStatus();
  681.         //只有 新規受付、入金済み 可以取消訂單
  682.         if($orderStatus->getId()==|| $orderStatus->getId()==6){
  683.             //由 EC-Cube 判定是否能變更
  684.             if ($this->orderStateMachine->can($Order$OrderStatus)) {
  685.                 $this->orderStateMachine->apply($Order$OrderStatus);
  686.                 $this->entityManager->flush($Order);
  687.                 /*
  688.                 $Shippings = $Order->getShippings();
  689.                 foreach ($Shippings as $Ship) {
  690.                     $this->mailService->sendShippingNotifyMail($Ship);
  691.                     $Ship->setMailSendDate(new \DateTime());
  692.                 }
  693.                 */
  694.                 $this->cashbackService->updateOrderStatus($Order$OrderStatus);
  695.             }
  696.         }
  697.         $this->history($request$order_no);
  698.         return $this->redirect($this->generateUrl('mypage_history', ["order_no" => $order_no]));
  699.     }
  700.     /**
  701.      * 購入履歴詳細を表示する.
  702.      *
  703.      * @Route("/mypage/history/{order_no}", name="mypage_history", methods={"GET"})
  704.      * @Template("Mypage/history.twig")
  705.      */
  706.     public function history(Request $request$order_no)
  707.     {
  708.         $this->entityManager->getFilters()
  709.             ->enable('incomplete_order_status_hidden');
  710.         $Order $this->orderRepository->findOneBy(
  711.             [
  712.                 'order_no' => $order_no,
  713.                 'Customer' => $this->getUser(),
  714.             ]
  715.         );
  716.         $event = new EventArgs(
  717.             [
  718.                 'Order' => $Order,
  719.             ],
  720.             $request
  721.         );
  722.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_MYPAGE_MYPAGE_HISTORY_INITIALIZE);
  723.         /** @var Order $Order */
  724.         $Order $event->getArgument('Order');
  725.         if (!$Order) {
  726.             throw new NotFoundHttpException();
  727.         }
  728.         //是否能取消訂單
  729.         $cancelOrder false;
  730.         $orderStatus $Order->getOrderStatus();
  731.         if($orderStatus->getId()==|| $orderStatus->getId()==6){
  732.             $cancelOrder true;
  733.         }
  734.         $stockOrder true;
  735.         foreach ($Order->getOrderItems() as $orderItem) {
  736.             if ($orderItem->isProduct() && $orderItem->getQuantity() < 0) {
  737.                 $stockOrder false;
  738.                 break;
  739.             }
  740.         }
  741.         // ▼マイページアップロード
  742.         $Myimages $this->myimageRepository
  743.             ->findBy(
  744.                 ['visible' => true'order_no' => $order_no'fixed' => 3],
  745.                 ['sort_no' => 'ASC']
  746.             );
  747.         // ▼管理画面アップロード
  748.         $adminMyimages $this->myimageRepository
  749.             ->findBy(
  750.                 ['visible' => true'order_no' => $order_no'fixed' => 2],
  751.                 ['sort_no' => 'ASC']
  752.             );
  753.         return [
  754.             'Order' => $Order,
  755.             'cancelOrder' => $cancelOrder,
  756.             'stockOrder' => $stockOrder,
  757.             'Myimages' => $Myimages//▼マイページアップロード
  758.             'adminMyimages' => $adminMyimages//▼管理画面アップロード
  759.         ];
  760.     }
  761.     /**
  762.      * ▼領収書/購入明細書
  763.      *
  764.      * @Route("/mypage/receipt/{order_no}", name="mypage_receipt")
  765.      * @Template("Mypage/receipt.twig")
  766.      */
  767.     public function receipt(Request $request$order_no)
  768.     {
  769.         $this->entityManager->getFilters()
  770.             ->enable('incomplete_order_status_hidden');
  771.         $Order $this->orderRepository->findOneBy(
  772.             [
  773.                 'order_no' => $order_no,
  774.                 'Customer' => $this->getUser(),
  775.             ]
  776.         );
  777.         $event = new EventArgs(
  778.             [
  779.                 'Order' => $Order,
  780.             ],
  781.             $request
  782.         );
  783.         
  784.         /** @var Order $Order */
  785.         $Order $event->getArgument('Order');
  786.         if (!$Order) {
  787.             throw new NotFoundHttpException();
  788.         }
  789.         $stockOrder true;
  790.         foreach ($Order->getOrderItems() as $orderItem) {
  791.             if ($orderItem->isProduct() && $orderItem->getQuantity() < 0) {
  792.                 $stockOrder false;
  793.                 break;
  794.             }
  795.         }
  796.         return [
  797.             'Order' => $Order,
  798.             'stockOrder' => $stockOrder,
  799.         ];
  800.     }
  801.     private function refreshNotificationCount(){
  802.         $Customer $this->getUser();
  803.         $cnt $this->notificationService->getNoticeViewCount($Customer);
  804.         $session $this->get('session');
  805.         $session->set('notificationCount'$cnt);
  806.     }
  807.     private function linkify($text)
  808.     {
  809.       $re "@\b(https?://)?(([0-9a-zA-Z_!~*'().&=+$%-]+:)?[0-9a-zA-Z_!~*'().&=+$%-]+\@)?(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-zA-Z_!~*'()-]+\.)*([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\.[a-zA-Z]{2,6})(:[0-9]{1,4})?((/[0-9a-zA-Z_!~*'().;?:\@&=+$,%#-]+)*/?)@";
  810.       preg_match_all($re$text$matchesPREG_OFFSET_CAPTURE);
  811.     
  812.       $matches $matches[0];
  813.     
  814.       $i count($matches);
  815.       while ($i--)
  816.       {
  817.         $url $matches[$i][0];
  818.         if (!preg_match('@^https?://@'$url))
  819.           $url 'http://'.$url;
  820.     
  821.         $text substr_replace($text'<a href="'.$url.'" target="_blank">'.$matches[$i][0].'</a>'$matches[$i][1], strlen($matches[$i][0]));
  822.     
  823.       }
  824.     
  825.       return $text;
  826.     }
  827. }