app/Customize/Controller/Mypage/MypageController.php line 1047

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 Carbon\Carbon;
  14. use Customize\Controller\LM\LmAbstractController;
  15. use Customize\Event\LmEvents;
  16. use Customize\Service\CommonService;
  17. use Customize\Service\FavoriteService;
  18. use Customize\Service\ImageService;
  19. use Customize\Service\LmHelper;
  20. use Customize\Service\MobileDetector as LmMobileDetector;
  21. use Eccube\Entity\Customer;
  22. use Customize\Entity\CustomerFavoriteProductTrait;
  23. use Eccube\Entity\CustomerFavoriteProduct;
  24. use Eccube\Entity\Product;
  25. use Eccube\Event\EccubeEvents;
  26. use Eccube\Event\EventArgs;
  27. use Customize\Repository\CustomerFavoriteProductRepository;
  28. use Eccube\Form\Type\Front\CustomerLoginType;
  29. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  30. use Symfony\Component\HttpFoundation\Request;
  31. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  32. use Symfony\Component\Routing\Annotation\Route;
  33. use Customize\Service\CustomerService;
  34. use Customize\Service\OrderService;
  35. use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
  36. use Customize\Controller\ApiController;
  37. use Knp\Component\Pager\PaginatorInterface;
  38. use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
  39. use Lm\Service\Store\FileStoreService;
  40. use Symfony\Component\HttpFoundation\StreamedResponse;
  41. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  42. use Lm\Engine\Zaiko\Entity\SkuExtended;
  43. use Lm\Entity\GoodsColor;
  44. use Lm\Entity\GoodsPrice;
  45. use Lm\Service\Coupon\Coupon;
  46. class MypageController extends LmAbstractController
  47. {
  48.     protected $CommonService;
  49.     protected $CustomerService;
  50.     protected $OrderService;
  51.     /**
  52.      * @var CustomerFavoriteProductRepository
  53.      */
  54.     protected $customerFavoriteProductRepository;
  55.     protected $CFIMG_URL "https://img0.land-mark.biz/ut_img";
  56.     /**
  57.      * @var LmMobileDetector
  58.      */
  59.     private $mobileDetector;
  60.     /**
  61.      * @var FavoriteService
  62.      */
  63.     private $favoriteService;
  64.     public function __construct(
  65.         CustomerFavoriteProductRepository $customerFavoriteProductRepository,
  66.         CommonService   $commonService,
  67.         LmHelper        $lmHelper,
  68.         CustomerService $CustomerService,
  69.         OrderService    $OrderService,
  70.         LmMobileDetector       $mobileDetector,
  71.         FavoriteService $favoriteService
  72.     )
  73.     {
  74.         //
  75.         parent::__construct($commonService$lmHelper);
  76.         $this->customerFavoriteProductRepository $customerFavoriteProductRepository;
  77.         $this->CommonService $commonService;
  78.         $this->CustomerService $CustomerService;
  79.         $this->OrderService $OrderService;
  80.         $this->mPayment $lmHelper->getPaymentTypeList();
  81.         $this->DOW $lmHelper->getDayOfWeek();
  82.         $this->mobileDetector $mobileDetector;
  83.         $this->favoriteService $favoriteService;
  84.     }
  85.     /**
  86.      * マイページ
  87.      *
  88.      * @Route("/mypage/", name="mypage", methods={"GET"})
  89.      * @Template("Mypage/index.twig")
  90.      */
  91.     public function index(Request $request)
  92.     {
  93.         $Customer $this->getUser();
  94.         if(!$Customer) {
  95.             return $this->redirectToRoute('mypage_login');
  96.         }
  97.         $lmCustomerId $Customer->getLmCustomerId();
  98.         #LMカスタマーを取得
  99.         $lmCustomer $this->CustomerService->GetLandMarkCustomerId($lmCustomerId);
  100.         $mailDisp 0;
  101.         if (strlen($lmCustomer['customer_mail']) > 25 and isset($lmCustomer["customer_mail"]) and $lmCustomer["customer_mail"] != "" and preg_match("/@/"$lmCustomer["customer_mail"])) {
  102.             $mailDisp 1;
  103.         }
  104.         $data $this->OrderService->getDispCount ($lmCustomerId);
  105.         // Coupon logic using vendor/lm/engine-coupon functions
  106.         $coupons = [];
  107.         $customerBangou $lmCustomer['customer_bangou'] ?? null;
  108.         $customerId $lmCustomer['customer_id'] ?? null;
  109.         
  110.         if ($customerBangou) {
  111.             // Initialize coupon engine (no PDO needed - uses SqlService internally)
  112.             $couponEngine = new Coupon();
  113.             // Get all available coupons for the customer
  114.             $availableCoupons $couponEngine->getAvailableCouponList($customerBangou$customerId, new \DateTime());
  115.             // Process each coupon according to requirements
  116.             foreach ($availableCoupons as $campaign) {
  117.       
  118.                 $couponData = [
  119.                     'id' => $campaign->getCouponCampaignId(),
  120.                     'title' => $campaign->getCouponCampaignTitle() ?: 'クーポン',
  121.                     'coupon_campaign_display_name' => $campaign->getCouponCampaignDisplayName() ?: 'クーポン',
  122.                     'description' => $campaign->getCouponCampaignComment() ?: '',
  123.                     'code' => $campaign->getCouponCampaignCode() ?: '',
  124.                     'target' => $campaign->getCouponCampaignTarget(),
  125.                     'discount_amount' => $campaign->getCouponCampaignDiscount(),
  126.                     'price' => $campaign->getCouponCampaignPrice(),
  127.                     'expires_at' => $campaign->getCouponCampaignEndDate(),
  128.                     'start_date' => $campaign->getCouponCampaignStartDate(),
  129.                     'type' => $this->getCouponType($campaign->getCouponCampaignTarget(), $lmCustomer),
  130.                     'status' => $this->getCouponStatus($campaign->getCouponCampaignEndDate())
  131.                 ];
  132.                 
  133.                 $coupons[] = $couponData;
  134.             }
  135.             
  136.             // Sort by expiration date (ascending - closest to expiration first) - Requirement 0
  137.             usort($coupons, function($a$b) {
  138.                 $dateA = new \DateTime($a['expires_at']);
  139.                 $dateB = new \DateTime($b['expires_at']);
  140.                 return $dateA <=> $dateB;
  141.             });
  142.             // Filter coupons based on user's order status
  143.             $hasOrders false;
  144.             if ($History $this->OrderService->getHistory($lmCustomerId)) {
  145.                 $hasOrders count($History) > 0;
  146.             }
  147.             $coupons array_values(array_filter($coupons, function ($c) use ($hasOrders$lmCustomer) {
  148.                 if (isset($c['type']) && $c['type'] === 'newsletter' && $lmCustomer['customer_melmaga'] == 1) {
  149.                     return true;
  150.                 }
  151.             
  152.                 if (isset($c['type']) && $c['type'] === 'first_purchase' && !$hasOrders) {
  153.                     return true;
  154.                 }
  155.                 if (isset($c['type']) && $c['type'] === 'customer_feedback_without_photo') {
  156.                     return true;
  157.                 }
  158.                 if (isset($c['type']) && $c['type'] === 'customer_feedback_with_photo') {
  159.                     return true;
  160.                 }
  161.                 if (isset($c['type']) && $c['type'] === 'for_all_customer') {
  162.                     return true;
  163.                 }
  164.             
  165.                 return false;
  166.             }));
  167.         }
  168.         $main_h1 null;
  169.         $category_h1 null;
  170.         $h1_comment null;
  171.         $common_header_contents_all '';
  172.         $common_header_contents null;
  173.         $recentviews = [];
  174.         $custom_menu null;
  175.         $custom_frequently_searched_word null;
  176.         // ビュー(テンプレート)へデータを渡す
  177.         return [
  178.             'lmCustomer' => $lmCustomer,
  179.             'CFIMG_URL' => $this->CFIMG_URL,
  180.             'data' => $data,
  181.             'main_h1' => $main_h1,
  182.             'mailDisp' => $mailDisp,
  183.             'category_h1' => $category_h1,
  184.             'h1_comment' => $h1_comment,
  185.             'common_header_contents_all' => $common_header_contents_all,
  186.             'common_header_contents' => $common_header_contents,
  187.             'recentviews' => $recentviews,
  188.             'custom_menu' => $custom_menu,
  189.             'custom_frequently_searched_word' => $custom_frequently_searched_word,
  190.             'BreadCrumbs' => [],
  191.             'coupons' => $coupons,
  192.         ];
  193.     }
  194.     /**
  195.      * お気に入り商品を表示する.
  196.      *
  197.      * @Route("/mypage/favorite/", name="mypage_favorite", methods={"GET"})
  198.      * @Template("Mypage/favorite.twig")
  199.      */
  200.     public function favorite(Request $requestPaginatorInterface $paginator)
  201.     {
  202.         $sort $request->get('s'1);
  203.         $itemStart $request->get('no'0);
  204.         $pageLimit 10;
  205.         $Customer $this->getUser();
  206.         if(!$Customer) {
  207.             throw new AccessDeniedHttpException("Err1 このページは表示できません。");
  208.         }
  209.         $lmCustomerId $Customer->getLmCustomerId();
  210.         #LMカスタマーを取得
  211.         $lmCustomer $this->CustomerService->GetLandMarkCustomerId($lmCustomerId);
  212.         $mailDisp 0;
  213.         if (strlen($lmCustomer['customer_mail']) > 25 and isset($lmCustomer["customer_mail"]) and $lmCustomer["customer_mail"] != "" and preg_match("/@/"$lmCustomer["customer_mail"])) {
  214.             $mailDisp 1;
  215.         }
  216.         $main_h1 null;
  217.         $category_h1 null;
  218.         $h1_comment null;
  219.         $common_header_contents_all '';
  220.         $common_header_contents null;
  221.         $recentviews = [];
  222.         $custom_menu null;
  223.         $custom_frequently_searched_word null;
  224.         $data=[];
  225.         $BreadCrumbs = [
  226.             => $this->__getBreadCrumbs_MyPageTop(),
  227.         ];
  228.         $data $this->favoriteService->getFavoriteList ($sort$lmCustomerId$itemStart$pageLimit);
  229.         $totalItem $this->favoriteService->getTotalFavorites ($lmCustomerId);
  230.         return [
  231.             'lmCustomer' => $lmCustomer,
  232.             'CFIMG_URL' => $this->CFIMG_URL,
  233.             'sort' => $sort,
  234.             'mailDisp' => $mailDisp,
  235.             'data' => $data,
  236.             'main_h1' => $main_h1,
  237.             'category_h1' => $category_h1,
  238.             'h1_comment' => $h1_comment,
  239.             'common_header_contents_all' => $common_header_contents_all,
  240.             'common_header_contents' => $common_header_contents,
  241.             'recentviews' => $recentviews,
  242.             'custom_menu' => $custom_menu,
  243.             'custom_frequently_searched_word' => $custom_frequently_searched_word,
  244.             'BreadCrumbs' => $BreadCrumbs,
  245.             'totalItem' => $totalItem,
  246.             'itemStart' => $itemStart 1,
  247.             'itemEnd' => ($itemStart $pageLimit) > $totalItem $totalItem $itemStart $pageLimit,
  248.             'currentPage' => (int)$itemStart/10 1,
  249.             'totalPage' => ceil($totalItem/10),
  250.         ];
  251.     }
  252.     /**
  253.      * @Route("/mypage/add_favorite/{goods_id}/", name="mypage_add_favorite", methods={"GET"})
  254.      * @Template("Mypage/favorite.twig")
  255.      */
  256.     public function addFavorite(Request $request)
  257.     {
  258.         $customer $this->getUser();
  259.         if (!$customer) {
  260.             return $this->redirect($this->generateUrl('mypage_login'));
  261.         }
  262.         $goodsId $request->get('goods_id');
  263.         $goods $this->favoriteService->getGoodsById($goodsId);
  264.         if (empty($goods)) {
  265.             $this->favoriteService->setFavoriteFlashMessage("商品が見つかりません。もう一度はじめからやり直してください。");
  266.         } else {
  267.             $isFavoriteGoods $this->favoriteService->isFavoriteGoods($goodsId$customer->getLmCustomerId());
  268.             if ($isFavoriteGoods) {
  269.                 $this->favoriteService->setFavoriteFlashMessage("既にお気に入りリストに登録されています。");
  270.             } else {
  271.                 $this->favoriteService->addFavorite([
  272.                     'mylist_customer' => $customer->getLmCustomerId(),
  273.                     'mylist_goods' => $goodsId,
  274.                     'mylist_comment' => null,
  275.                     'mylist_rank' => null,
  276.                     'mylist_date' => Carbon::now(),
  277.                 ]);
  278.                 $this->favoriteService->setFavoriteFlashGoods($goods);
  279.                 //
  280.                 $event = new EventArgs([
  281.                     'goods_id' => $goodsId,
  282.                 ], $request);
  283.                 $this->eventDispatcher->dispatch($eventLmEvents::FRONT_PRODUCT_FAVORITE_ADD_COMPLETE);
  284.             }
  285.         }
  286.         return $this->redirect($this->generateUrl('mypage_favorite'));
  287.     }
  288.     /**
  289.      * お気に入り商品を削除する.
  290.      *
  291.      * @Route("/mypage/favorite/{id}/comment/", name="mypage_favorite_comment", methods={"POST"}, requirements={"id" = "\\d+"})
  292.      * @Template("Mypage/favorite_print.twig")
  293.      */
  294.     public function comment(Request $request$id)
  295.     {
  296.         if (!$request->isXmlHttpRequest()) {
  297.             throw new BadRequestHttpException();
  298.         }
  299.         $this->isTokenValid();
  300.         $Customer $this->getUser();
  301.         $lmCustomerId $Customer->getLmCustomerId();
  302.         log_info('お気に入りコメント開始', [$lmCustomerId$id]);
  303.         if ($id) {
  304.             $result $this->favoriteService->addComment($id$request->get('comment'), $request->get('rank'));
  305.             if ($result) {
  306.                 return $this->json(['success' => true]);
  307.             }
  308.         }
  309.         return $this->json(['success' => false]);
  310.     }
  311.     /**
  312.      * お気に入り商品を削除する.
  313.      *
  314.      * @Route("/mypage/favorite/print/", name="mypage_favorite_print", methods={"GET"})
  315.      * @Template("Mypage/favorite_print.twig")
  316.      */
  317.     public function favorite_print(Request $request)
  318.     {
  319.         $sort $request->get('s'1);
  320.         $Customer $this->getUser();
  321.         if(!$Customer) {
  322.             throw new AccessDeniedHttpException("Err1 このページは表示できません。");
  323.         }
  324.         $lmCustomerId $Customer->getLmCustomerId();
  325.         #LMカスタマーを取得
  326.         $lmCustomer $this->CustomerService->GetLandMarkCustomerId($lmCustomerId);
  327.         $FavoriteProducts $this->favoriteService->getFavoriteList ($sort$lmCustomerId00);
  328.         $BreadCrumbs = [
  329.             => $this->__getBreadCrumbs_MyPageTop(),
  330.         ];
  331.         return [
  332.             'lmCustomer' => $lmCustomer,
  333.             'CFIMG_URL' => $this->CFIMG_URL,
  334.             'FavoriteProducts' => $FavoriteProducts,
  335.             'BreadCrumbs' => $BreadCrumbs,
  336.         ];
  337.     }
  338.     /**
  339.      * お気に入り商品を削除する.
  340.      *
  341.      * @Route("/mypage/favorite/{id}/delete", name="mypage_favorite_delete", methods={"DELETE"}, requirements={"id" = "\d+"})
  342.      * @param Request $request
  343.      * @param $id
  344.      * @return \Symfony\Component\HttpFoundation\RedirectResponse
  345.      */
  346.     public function delete(Request $request$id)
  347.     {
  348.         $this->isTokenValid();
  349.         $Customer $this->getUser();
  350.         log_info('お気に入り商品削除開始', [$Customer->getLmCustomerId(), $id]);
  351.         $this->favoriteService->deleteFavorite ($id);
  352.         //
  353.         $event = new EventArgs([
  354.             'goods_id' => $id,
  355.         ], $request);
  356.         $this->eventDispatcher->dispatch($eventLmEvents::FRONT_PRODUCT_FAVORITE_DELETE_COMPLETE);
  357.         log_info('お気に入り商品削除完了', [$Customer->getLmCustomerId(), $id]);
  358.         return $this->redirect($this->generateUrl('mypage_favorite'));
  359.     }
  360.     /**
  361.      * マイページ / 購入履歴・再注文(名入れ無し)
  362.      *
  363.      * @Route("/mypage/history/", name="mypage/history", methods={"GET"})
  364.      * @Template("Mypage/history.twig")
  365.      */
  366.     public function history(Request $request)
  367.     {
  368.         $mSiteType $this->lmHelper->getSiteTypeList();
  369.         /**
  370.          * @var Customer $Customer
  371.          */
  372.         $Customer $this->getUser();
  373.         $lmCustomerId $Customer->getLmCustomerId();
  374.         #LMカスタマーを取得
  375.         $lmCustomer $this->CustomerService->GetLandMarkCustomerId($lmCustomerId);
  376.         // 会員のメール表示切替用
  377.         $mailDisp 0;
  378.         if (strlen($lmCustomer['customer_mail']) > 25 and isset($lmCustomer["customer_mail"]) and $lmCustomer["customer_mail"] != "" and preg_match("/@/"$lmCustomer["customer_mail"])) {
  379.             $mailDisp 1;
  380.         }
  381.         // メモ欄: LM成り代わりログイン時のみ表示 sessionについて確認必要
  382.         $memoDisp 0;
  383.         if (isset($_SESSION["landmark_fax_login"]) and $_SESSION["landmark_fax_login"] != "") {
  384.             $memoDisp 1;
  385.         }
  386.         // 購入履歴一覧の取得
  387.         $orderList=[];
  388.         $goodsList=[];
  389.         if( $History $this->OrderService->getHistory($lmCustomerId) ){
  390.             $no count($History);
  391.             foreach($History as $v){
  392.                 $shipping_infos = [];
  393.                 
  394.                 if ($v['has_sendsheet'] == 1) {
  395.                     $shipping_infos $this->OrderService->getShippingInfo($v['oh_id']);
  396.                 }
  397.                 
  398.                 $orderList[] = [
  399.                     'no'=> $no,
  400.                     'order'=>$v['oh_shubetsu'].'-'.$v['oh_id'],
  401.                     'date'=>$v['oh_date'],
  402.                     'payment'=>$this->mPayment[$v['oh_payment']],
  403.                     'new_kakunin_id'=>$v['new_kakunin_id'],
  404.                     'oh_id'=>$v['oh_id'],
  405.                     'oh_torikeshi'=>$v['oh_torikeshi'],
  406.                     'koguchi'=>$v['koguchi'],
  407.                     'oh_coupon_discount'=>$v['oh_coupon_discount'],
  408.                     'oh_discount'=>$v['oh_discount'],
  409.                     'oh_sendcharge'=>$v['oh_sendcharge'],
  410.                     'oh_sendcharge_service'=>$v['oh_sendcharge_service'],
  411.                     'oh_daibiki'=>$v['oh_daibiki'],
  412.                     'oh_daibiki_service'=>$v['oh_daibiki_service'],
  413.                     'oh_atobarai'=>$v['oh_atobarai'],
  414.                     'oh_atobarai_service'=>$v['oh_atobarai_service'],
  415.                     'oh_sumary'=>$v['oh_sumary'],
  416.                     'oh_zeus_linkpoint_flg'=>$v['oh_zeus_linkpoint_flg'],
  417.                     'has_sendsheet'=>$v['has_sendsheet'],
  418.                     'spr_pdate'=>$v['spr_pdate'],
  419.                     'shipping_infos'=> $shipping_infos,
  420.                 ];
  421.                 $goodsList[$no] = $this->OrderService->getHistoryGoods($v['oh_id']);
  422.                 $no $no-1;
  423.             }
  424.         }
  425.         $orderCnt count($History);
  426.         $page $request->query->get('page'1);     // ?pageの指定がない場合は1ページ目とする
  427.         $itemsPerPage=10;
  428.         $max_paging_links 10;
  429.         if ($this->mobileDetector->isMobile()) {
  430.             $max_paging_links 4;
  431.         }
  432.         $pager LmHelper::paging($page$orderList$itemsPerPage$max_paging_links);
  433.         $page_offset $pager['page_offset'];
  434.         $orderList array_slice($orderList$page_offset$itemsPerPage);
  435.         $pager['anKaishi'] = $pager['total_count']-$page_offset;
  436.         $anOwari $pager['anKaishi'] - $itemsPerPage +1;
  437.         if ($anOwari 1) {
  438.             $anOwari 1;
  439.         }
  440.         $pager['anOwari'] = $anOwari;
  441.         $main_h1 null;
  442.         $category_h1 null;
  443.         $h1_comment null;
  444.         $common_header_contents_all '';
  445.         $common_header_contents null;
  446.         $recentviews = [];
  447.         $custom_menu null;
  448.         $custom_frequently_searched_word null;
  449.         $data=[];
  450.         $review = [];
  451.         $BreadCrumbs = [
  452.             => $this->__getBreadCrumbs_MyPageTop(),
  453.         ];
  454.         $countAllOrder = [];
  455.         if ($this->mobileDetector->isMobile()) {
  456.             $countAllOrder $this->OrderService->getDispCount($lmCustomerId);
  457.         }
  458.         if(count($goodsList) > 0){
  459.             $this->checkOutOfStock($goodsList);
  460.         }
  461.         // ビュー(テンプレート)へデータを渡す
  462.         return [
  463.             'lmCustomerId' => $lmCustomerId,
  464.             'lmCustomer' => $lmCustomer,
  465.             'orderCnt' => $orderCnt,
  466.             'orderList' => $orderList,
  467.             'goodsList' => $goodsList,
  468.             'mPayment' => $this->mPayment,   // TODO: Don't do that.
  469.             'mSiteType' => $mSiteType// TODO: Don't do that.
  470.             'mailDisp' => $mailDisp,
  471.             'memoDisp' => $memoDisp,
  472.             'pager' => $pager,
  473.             'data' => $data,
  474.             'main_h1' => $main_h1,
  475.             'category_h1' => $category_h1,
  476.             'h1_comment' => $h1_comment,
  477.             'common_header_contents_all' => $common_header_contents_all,
  478.             'common_header_contents' => $common_header_contents,
  479.             'recentviews' => $recentviews,
  480.             'custom_menu' => $custom_menu,
  481.             'custom_frequently_searched_word' => $custom_frequently_searched_word,
  482.             'review' => $review,
  483.             'BreadCrumbs' => $BreadCrumbs,
  484.             'countAllOrder' => $countAllOrder
  485.         ];
  486.     }
  487.     private function checkOutOfStock(&$goodsList$isHistory true){
  488.         foreach($goodsList as &$goods){
  489.             foreach($goods as &$item){
  490.                 foreach($item as &$child){
  491.                     if(!$isHistory){
  492.                         $child = &$child['goods'];
  493.                     }
  494.                     foreach($child as &$childItem){
  495.                         $sku SkuExtended::getInstance(nullnull$childItem['gcl_id'], $childItem['gp_id']);
  496.                         if ($sku->isNoDisplay() || $sku->getGclDisplayStatus() === GoodsColor::DISPLAY_STATUS_UNAVAILABLE || $sku->getGpDisplay() === GoodsPrice::DISPLAY_HIDDEN) {
  497.                             $childItem['is_out_of_stock'] = true;
  498.                         }else{
  499.                             $childItem['is_out_of_stock'] = false;
  500.                         }
  501.                     }
  502.                 }
  503.             }
  504.         }
  505.     }
  506.     /**
  507.      * マイページ / 購入履歴・再注文(名入れ有り)
  508.      *
  509.      * @param Request $request
  510.      * @param ImageService $imageService
  511.      * @Route("/mypage/mhistory/", name="mypage/mhistory", methods={"GET"})
  512.      * @Template("Mypage/mhistory.twig")
  513.      * @return array
  514.      */
  515.     public function mhistory(Request $requestImageService $imageService)
  516.     {
  517.         $Customer $this->getUser();
  518.         $lmCustomerId $Customer->getLmCustomerId();
  519.         #LMカスタマーを取得
  520.         $lmCustomer $this->CustomerService->GetLandMarkCustomerId($lmCustomerId);
  521.         // 会員のメール表示切替用
  522.         $mailDisp 0;
  523.         if (strlen($lmCustomer['customer_mail']) > 25 and isset($lmCustomer["customer_mail"]) and $lmCustomer["customer_mail"] != "" and preg_match("/@/"$lmCustomer["customer_mail"])) {
  524.             $mailDisp 1;
  525.         }
  526.         // メモ欄: LM成り代わりログイン時のみ表示 sessionについて確認必要
  527.         $memoDisp 0;
  528.         if (isset($_SESSION["landmark_fax_login"]) and $_SESSION["landmark_fax_login"] != "") {
  529.             $memoDisp 1;
  530.         }
  531.         // 購入履歴一覧の取得
  532.         $orderList=[];
  533.         $goodsList=[];
  534.         if( $History $this->OrderService->getMhistory($lmCustomerId) ){
  535.             $no count($History);
  536.             foreach($History as $v){
  537.                 $img="/kanri_img/images/new_kakunin_img/" $v['oh_id'] . ".jpg";
  538.                 // $sslimageType = "kakunin";
  539.                 // $file_headers = @get_headers($img);
  540.                 // if($file_headers[0] != 'HTTP/1.1 403 Forbidden' or strpos( $file_headers[0],"OK" )){
  541.                 //     list($width, $height) = @getimagesize($img);
  542.                 // }
  543.                 // if (empty($width)) {
  544.                 //     $img="/kanri_img/images/kakunin_img/" . $v['oh_id'] . ".jpg";
  545.                 //     $sslimageType = "oldkakunin";
  546.                 //     $file_headers = @get_headers($img);
  547.                 //     if($file_headers[0] != 'HTTP/1.1 403 Forbidden' or strpos( $file_headers[0],"OK" )){
  548.                 //         list($width, $height) = @getimagesize($img);
  549.                 //     }
  550.                 // }
  551.                 $shipping_infos = [];
  552.                 
  553.                 if ($v['has_sendsheet'] == 1) {
  554.                     $shipping_infos $this->OrderService->getShippingInfo($v['oh_id']);
  555.                 }
  556.                 $orderList[] = [
  557.                     'no'=> $no,
  558.                     'order'=>$v['oh_shubetsu'].'-'.$v['oh_id'],
  559.                     'date'=>$v['oh_date'],
  560.                     'payment'=>$this->mPayment[$v['oh_payment']],
  561.                     'new_kakunin_id'=>$v['new_kakunin_id'],
  562.                     'oh_id'=>$v['oh_id'],
  563.                     'oh_torikeshi'=>$v['oh_torikeshi'],
  564.                     'koguchi'=>$v['koguchi'],
  565.                     'oh_coupon_discount'=>$v['oh_coupon_discount'],
  566.                     'oh_discount'=>$v['oh_discount'],
  567.                     'oh_sendcharge'=>$v['oh_sendcharge'],
  568.                     'oh_sendcharge_service'=>$v['oh_sendcharge_service'],
  569.                     'oh_daibiki'=>$v['oh_daibiki'],
  570.                     'oh_daibiki_service'=>$v['oh_daibiki_service'],
  571.                     'oh_atobarai'=>$v['oh_atobarai'],
  572.                     'oh_atobarai_service'=>$v['oh_atobarai_service'],
  573.                     'oh_sumary'=>$v['oh_sumary'],
  574.                     'oh_wrapping'=>$v['oh_wrapping'],
  575.                     'oh_zeus_linkpoint_flg'=>$v['oh_zeus_linkpoint_flg'],
  576.                     'has_sendsheet'=>$v['has_sendsheet'],
  577.                     'spr_pdate'=>$v['spr_pdate'],
  578.                     'shipping_infos'=> $shipping_infos,
  579.                 ];
  580.                 $goodsList[$no] = $this->OrderService->getMhistoryGoods($v['oh_id']);
  581.                 $no $no-1;
  582.             }
  583.         }
  584.         if(count($goodsList) > 0){
  585.             $this->checkOutOfStock($goodsListfalse);
  586.         }
  587.         // ページング
  588.         $orderCnt count($History);
  589.         $page $request->query->get('page'1);     // ?pageの指定がない場合は1ページ目とする
  590.         $itemsPerPage=5;
  591.         $max_paging_links 10;
  592.         if ($this->mobileDetector->isMobile()) {
  593.             $max_paging_links 4;
  594.         }
  595.         $pager LmHelper::paging($page$orderList$itemsPerPage$max_paging_links);
  596.         $page_offset $pager['page_offset'];
  597.         $orderList array_slice($orderList$page_offset$itemsPerPage);
  598.         // 画像の処理は重いため、ページング処理後のデータ分のみ処理
  599.         $orderList array_map(function ($order) use ($imageService) {
  600.             //
  601.             $sslimageType ImageService::IMAGE_TYPE_KAKUNIN;
  602.             if (!list($width$height) = $imageService->getImageSizeById($order['oh_id'], $sslimageType)) {
  603.                 //
  604.                 $sslimageType ImageService::IMAGE_TYPE_KAKUNIN_OLD;
  605.                 list($width$height) = $imageService->getImageSizeById($order['oh_id'], $sslimageType);
  606.             }
  607.             //
  608.             return array_merge($order, [
  609.                 'kakuninImgW'=>$width,
  610.                 'kakuninImgH'=>$height,
  611.                 'sslimageType'=>$sslimageType,
  612.             ]);
  613.         }, $orderList);
  614.         $pager['anKaishi'] = $pager['total_count']-$page_offset;
  615.         $anOwari $pager['anKaishi'] - $itemsPerPage +1;
  616.         if ($anOwari 1) {
  617.             $anOwari 1;
  618.         }
  619.         $pager['anOwari'] = $anOwari;
  620.         //var_dump($goodsList);
  621.         // ビュー(テンプレート)へデータを渡す
  622.         $main_h1 null;
  623.         $category_h1 null;
  624.         $h1_comment null;
  625.         $common_header_contents_all '';
  626.         $common_header_contents null;
  627.         $recentviews = [];
  628.         $custom_menu null;
  629.         $custom_frequently_searched_word null;
  630.         $data=[];
  631.         $BreadCrumbs = [
  632.             => $this->__getBreadCrumbs_MyPageTop(),
  633.         ];
  634.         $countAllOrder = [];
  635.         if ($this->mobileDetector->isMobile()) {
  636.             $countAllOrder $this->OrderService->getDispCount($lmCustomerId);
  637.         }
  638.         return [
  639.             'lmCustomerId' => $lmCustomerId,
  640.             'lmCustomer' => $lmCustomer,
  641.             'orderCnt' => $orderCnt,
  642.             'orderList' => $orderList,
  643.             'goodsList' => $goodsList,
  644.             'mPayment' => $this->mPayment,
  645.             'mailDisp' => $mailDisp,
  646.             'memoDisp' => $memoDisp,
  647.             'pager' => $pager,
  648.             'data' => $data,
  649.             'main_h1' => $main_h1,
  650.             'category_h1' => $category_h1,
  651.             'h1_comment' => $h1_comment,
  652.             'common_header_contents_all' => $common_header_contents_all,
  653.             'common_header_contents' => $common_header_contents,
  654.             'recentviews' => $recentviews,
  655.             'custom_menu' => $custom_menu,
  656.             'custom_frequently_searched_word' => $custom_frequently_searched_word,
  657.             'BreadCrumbs' => $BreadCrumbs,
  658.             'countAllOrder' => $countAllOrder,
  659.         ];
  660.     }
  661.     /**
  662.      * マイページ / サンプル貸出し履歴
  663.      *
  664.      * @Route("/mypage/chistory/", name="mypage/chistory", methods={"GET"})
  665.      * @Template("Mypage/chistory.twig")
  666.      */
  667.     public function chistory(Request $request)
  668.     {
  669.         $Customer $this->getUser();
  670.         $lmCustomerId $Customer->getLmCustomerId();
  671.         #LMカスタマーを取得
  672.         $lmCustomer $this->CustomerService->GetLandMarkCustomerId($lmCustomerId);
  673.         // 会員のメール表示切替用
  674.         $mailDisp 0;
  675.         if (strlen($lmCustomer['customer_mail']) > 25 and isset($lmCustomer["customer_mail"]) and $lmCustomer["customer_mail"] != "" and preg_match("/@/"$lmCustomer["customer_mail"])) {
  676.             $mailDisp 1;
  677.         }
  678.         // 購入履歴一覧の取得
  679.         $orderList=[];
  680.         $goodsList=[];
  681.         if( $History $this->OrderService->getChistory($lmCustomerId) ){
  682.             $no count($History);
  683.             foreach($History as $v){
  684.                 $sendsheet $this->OrderService->getOrderByOrderIdAndCustomerId($lmCustomerId$v['oh_id']);
  685.                 $shipping_infos = [];
  686.                 
  687.                 if ($sendsheet['has_sendsheet'] == 1) {
  688.                     $shipping_infos $this->OrderService->getShippingInfo($v['oh_id']);
  689.                 }
  690.                 $orderList[] = [
  691.                     'no'=> $no,
  692.                     'order'=>$v['oh_shubetsu'].'-'.$v['oh_id'],
  693.                     'date'=>$v['oh_date'],
  694.                     'oh_id'=>$v['oh_id'],
  695.                     'oh_catalog_id'=>$v['oh_catalog_id'],
  696.                     'order_catalog_list' => $v['order_catalog_list'],
  697.                     'oh_type'=>$v['oh_type'],
  698.                     'has_sendsheet'=>$sendsheet['has_sendsheet'],
  699.                     'spr_pdate'=>$sendsheet['spr_pdate'],
  700.                     'shipping_infos'=> $shipping_infos,
  701.                 ];
  702.                 $catalogList = [];
  703.                 $catalog null;
  704.                 if(!is_null($v['order_catalog_list']) and !empty($v['order_catalog_list'])){
  705.                     // 昔の希望カタログリスト
  706.                     $catalog $v['order_catalog_list'];
  707.                 }elseif(!is_null($v['oh_catalog_id']) and !empty($v['oh_catalog_id'])){
  708.                     // 現在の希望カタログリスト
  709.                     $tmp $this->OrderService->getChistoryCatalog($v['oh_catalog_id']);
  710.                     foreach($tmp as $data){
  711.                         $catalogList[] = $data['catalog_title'];
  712.                     }
  713.                     $catalogTitles implode("\n",$catalogList);
  714.                     $catalog $catalogTitles;
  715.                 }
  716.                 // サンプル希望商品
  717.                 $goods $this->OrderService->getChistoryGoods($v['oh_id']);
  718.                 if ($this->mobileDetector->isMobile()) {
  719.                     $goods $this->OrderService->formatGoodsForSP($v['oh_id'], $goods);
  720.                 }
  721.                 $goodsList[$no] =[
  722.                     'catalog_title' => $catalog,
  723.                     'goods' => $goods,
  724.                 ];
  725.                 $no $no-1;
  726.             }
  727.         }
  728.         $orderCnt count($orderList);
  729.         // ページング
  730.         $orderCnt count($History);
  731.         $page $request->query->get('page'1);     // ?pageの指定がない場合は1ページ目とする
  732.         $itemsPerPage=10;
  733.         $pager LmHelper::paging($page$orderList$itemsPerPage);
  734.         $page_offset $pager['page_offset'];
  735.         $orderList array_slice($orderList$page_offset$itemsPerPage);
  736.         $pager['anKaishi'] = $pager['total_count']-$page_offset;
  737.         $anOwari $pager['anKaishi'] - $itemsPerPage +1;
  738.         if ($anOwari 1) {
  739.             $anOwari 1;
  740.         }
  741.         $pager['anOwari'] = $anOwari;
  742.         $main_h1 null;
  743.         $category_h1 null;
  744.         $h1_comment null;
  745.         $common_header_contents_all '';
  746.         $common_header_contents null;
  747.         $recentviews = [];
  748.         $custom_menu null;
  749.         $custom_frequently_searched_word null;
  750.         $data=[];
  751.         $BreadCrumbs = [
  752.             => $this->__getBreadCrumbs_MyPageTop(),
  753.         ];
  754.         // ビュー(テンプレート)へデータを渡す
  755.         return [
  756.             'lmCustomerId' => $lmCustomerId,
  757.             'lmCustomer' => $lmCustomer,
  758.             'orderCnt' => $orderCnt,
  759.             'orderList' => $orderList,
  760.             'goodsList' => $goodsList,
  761.             'mailDisp' => $mailDisp,
  762.             'mailDisp' => $mailDisp,
  763.             'pager' => $pager,
  764.             'data' => $data,
  765.             'main_h1' => $main_h1,
  766.             'category_h1' => $category_h1,
  767.             'h1_comment' => $h1_comment,
  768.             'common_header_contents_all' => $common_header_contents_all,
  769.             'common_header_contents' => $common_header_contents,
  770.             'recentviews' => $recentviews,
  771.             'custom_menu' => $custom_menu,
  772.             'custom_frequently_searched_word' => $custom_frequently_searched_word,
  773.             'BreadCrumbs' => $BreadCrumbs,
  774.         ];
  775.     }
  776.     /**
  777.      * 納品書の表示
  778.      * @Route("/mypage/nouhinsho", name="nouhinsho", methods={"GET", "POST"})
  779.      * @Template("Mypage/nouhinsho.twig")
  780.      */
  781.     public function nouhinsho(Request $request)
  782.     {
  783.        //顧客情報取得
  784.         $Customer $this->getUser();
  785.         $lmCustomerId $Customer->getLmCustomerId();
  786.         $dirPath "backoffice-data/paper_data/nouhinsho_data/";
  787.         $s3 = new FileStoreService(env('S3_LM_DOC'), $dirPath);
  788.         $orderId $request->query->get('id');
  789.         $code md5(serialize($orderId));
  790.         $params = [
  791.             'dcl_type' => 'deliverynote',
  792.             'dcl_oh' => $orderId,
  793.             'dcl_customer' => $lmCustomerId,
  794.             'dcl_code' => $code,
  795.             'dcl_cdate' => date('Y-m-d H:i:s'),
  796.         ];
  797.         $message "ダウンロードエラー";
  798.         $order $this->OrderService->getOrderByOrderIdAndCustomerId($lmCustomerId$orderId);
  799.         if (!$order['oh_id']) {
  800.             return [
  801.                 'msg' => $message,
  802.             ];
  803.         }
  804.         if (!$order['has_sendsheet']) {
  805.             return [
  806.                 'msg' => 'この注文は納品書を発行していません。',
  807.             ];
  808.         }
  809.         //DB(document_create_list_table)へデータ追加 & insertデータID取得
  810.         $newId $this->OrderService->insertDocumentCreateList($params);
  811.         if($newId){
  812.             //backoffice側でデータ作成=>s3へアップ
  813.             $backURL=$this->eccubeConfig['S_BACK_URL'];
  814.             $certFilename=$this->eccubeConfig['S_BACK_CERT_FILENAME'];
  815.             $backURL=str_replace("backoffice","",$backURL);
  816.             $url="{$backURL}/getfrompc/document_download.php";
  817.             //POSTデータを作成
  818.             $params = array(
  819.                 "ID"        => $newId,
  820.                 "OH"        => $orderId,
  821.                 "CODE"        => $code,
  822.             );
  823.             $curl curl_init();
  824.             curl_setopt($curlCURLOPT_URL$url);
  825.             curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);
  826.             curl_setopt($curlCURLOPT_POSTtrue);
  827.             curl_setopt($curlCURLOPT_POSTFIELDS$params);
  828.             if (!empty($certFilename)) {
  829.                 curl_setopt($curlCURLOPT_SSLCERT$certFilename);
  830.                 curl_setopt($curlCURLOPT_USERAGENT'curl/7.52.1');
  831.             }
  832.             if($response curl_exec($curl)){
  833.                 $line explode(":",$response);
  834.                 if($line[0] = "OK"){
  835.                     //ファイル名
  836.                     $Filename $line[1];
  837.                     echo $Filename;
  838.                     if($s3->isObjectExists($Filename) !== false){
  839.                         $content=env('S3_LM_DOC_PATH') ."/".$dirPath.$Filename;
  840.                         header('Content-Type: application/pdf');
  841.                         readfile($content);
  842.                         exit;
  843.                     }
  844.                 }
  845.             }
  846.             curl_close($curl);
  847.         }
  848.         return [
  849.             'msg' => $message,
  850.         ];
  851.     }
  852.     /**
  853.      * マイページ / 確認書
  854.      *
  855.      * @Route("/mypage/kakuninsho", name="mypage/kakuninsho", methods={"GET"})
  856.      * @Template("Mypage/kakuninsho.twig")
  857.      */
  858.     public function kakuninsho(Request $request)
  859.     {
  860.         $orderId $request->query->get('id');
  861.         $Customer $this->getUser();
  862.         $lmCustomerId $Customer->getLmCustomerId();
  863.         $order $this->OrderService->getOrderByOrderIdAndCustomerId($lmCustomerId$orderId);
  864.         if (empty($order)) {
  865.             throw new NotFoundHttpException();
  866.         }
  867.         #LMカスタマーを取得
  868.         $lmCustomer $this->CustomerService->GetLandMarkCustomerId($lmCustomerId);
  869.         list($allData,$kakuninData) = $this->OrderService->getKakuninshoLibrary($orderId);
  870.         list($detailDisplay,$detailData,$goods_cnt) = $this->OrderService->getKakuninshoLibraryGoods($orderId);
  871.         // 名入れ加工の検索
  872.         list($insObj1,$insObj2,$insObj3,$dispArray) = $this->OrderService->getKakuninNaire($orderId);
  873.         // 裾上げ商品
  874.         $susoageGoods $this->OrderService->getSusoageGoods($orderId);
  875.         $today date('Y年m月d日');
  876.         $kakuninDate "";
  877.         $kakuninDate $kakuninData['new_kakunin_date']."(" $this->DOW[$kakuninData['new_kakunin_date_week']] . ")";
  878.         //asort( $detailData );
  879.         reset$detailData );
  880.         $kakuninImg "";
  881.         $img="/kanri_img/images/new_kakunin_img/" $orderId ".jpg";
  882.         $file_headers = @get_headers($img);
  883.         if(
  884.             isset($file_headers[0])
  885.             && ($file_headers[0] != 'HTTP/1.1 403 Forbidden' or strpos$file_headers[0],"OK" ))
  886.         ){
  887.             $kakuninImg "/sslimage?type=kakunin&id=" $orderId "&x=240";
  888.         } else if(!empty($susoageGoods)){
  889.             $kakuninImg "/kanri_img/images/hanger/susoage.jpg";
  890.         } else {
  891.             $kakuninImg "/images/mypage/blank.gif";
  892.         }
  893.         $BreadCrumbs = [
  894.             => $this->__getBreadCrumbs_MyPageTop(),
  895.         ];
  896.         // ビュー(テンプレート)へデータを渡す
  897.         return [
  898.             'lmCustomerId' => $lmCustomerId,
  899.             'lmCustomer' => $lmCustomer,
  900.             'data' => $kakuninData,
  901.             'kakuninAllData' => $allData,
  902.             'kakuninDetailDisplay' => $detailDisplay,
  903.             'kakuninDetailData' => $detailData,
  904.             'kakuninDate' => $kakuninDate,
  905.             'insObj1' => $insObj1,
  906.             'insObj2' => $insObj2,
  907.             'insObj3' => $insObj3,
  908.             'dispArray' => $dispArray,
  909.             'goods_cnt' => $goods_cnt,
  910.             'susoageGoods' => $susoageGoods,
  911.             'today' => $today,
  912.             'orderId' => $orderId,
  913.             'kakuninImg' => $kakuninImg,
  914.             'BreadCrumbs' => $BreadCrumbs,
  915.         ];
  916.     }
  917.     /**
  918.      * マイページトップのパンくず定義
  919.      * @return Array マイページトップのパンくず href, label
  920.      */
  921.     private function __getBreadCrumbs_MyPageTop()
  922.     {
  923.         return [
  924.             'href' => $this->generateUrl('mypage'),
  925.             'label' => $this->CommonService->GetPagename('mypage'),
  926.         ];
  927.     }
  928.     /**
  929.      * ログイン画面.
  930.      *
  931.      * @Route("/mypage/login", name="mypage_login", methods={"GET", "POST"})
  932.      * @Template("Mypage/login.twig")
  933.      */
  934.     public function login(Request $requestAuthenticationUtils $utils)
  935.     {
  936.         if ($this->isGranted('IS_AUTHENTICATED_FULLY')) {
  937.             log_info('認証済のためログイン処理をスキップ');
  938.             return $this->redirectToRoute('mypage');
  939.         }
  940.         /* @var $form \Symfony\Component\Form\FormInterface */
  941.         $builder $this->formFactory
  942.             ->createNamedBuilder(''CustomerLoginType::class);
  943.         $builder->get('login_memory')->setData((bool) $request->getSession()->get('_security.login_memory'));
  944.         if ($this->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
  945.             $Customer $this->getUser();
  946.             if ($Customer instanceof Customer) {
  947.                 $builder->get('login_email')
  948.                     ->setData($Customer->getEmail());
  949.             }
  950.         }
  951.         $event = new EventArgs(
  952.             [
  953.                 'builder' => $builder,
  954.             ],
  955.             $request
  956.         );
  957.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_MYPAGE_MYPAGE_LOGIN_INITIALIZE);
  958.         $form $builder->getForm();
  959.         $main_h1 null;
  960.         $category_h1 null;
  961.         $h1_comment null;
  962.         $common_header_contents_all '';
  963.         $common_header_contents null;
  964.         $recentviews = [];
  965.         $custom_menu null;
  966.         $custom_frequently_searched_word null;
  967.         $data=[];
  968.         return [
  969.             'error' => $utils->getLastAuthenticationError(),
  970.             'form' => $form->createView(),
  971.             'data' => $data,
  972.             'main_h1' => $main_h1,
  973.             'category_h1' => $category_h1,
  974.             'h1_comment' => $h1_comment,
  975.             'common_header_contents_all' => $common_header_contents_all,
  976.             'common_header_contents' => $common_header_contents,
  977.             'recentviews' => $recentviews,
  978.             'custom_menu' => $custom_menu,
  979.             'custom_frequently_searched_word' => $custom_frequently_searched_word,
  980.             'BreadCrumbs' => [],
  981.         ];
  982.     }
  983.     /**
  984.      * Get coupon type based on target
  985.      * 
  986.      * @param string $target
  987.      * @return string
  988.      */
  989.     private function getCouponType($target$lmCustomer)
  990.     {
  991.         switch ($target) {
  992.             case '未購入者':
  993.                 return 'first_purchase'// 1. 初回限定クーポン
  994.             case 'メルマガ購読者全員':
  995.                 return 'newsletter'// 2. メルマガ購読者用クーポン
  996.             case 'お客様の声に回答したお客様(写真無)':
  997.                 return 'customer_feedback_without_photo'// 3. お客様の声に回答したお客様(写真無)
  998.             case 'お客様の声に回答したお客様(写真有)':
  999.                 return 'customer_feedback_with_photo'// 4. お客様の声に回答したお客様(写真有)
  1000.             case '全員':
  1001.                 return 'for_all_customer'// 5. 全員
  1002.             default:
  1003.                 return 'general';
  1004.         }
  1005.     }
  1006.     /**
  1007.      * Get coupon status based on expiration date
  1008.      * 
  1009.      * @param string $expiresAt
  1010.      * @return string
  1011.      */
  1012.     private function getCouponStatus($expiresAt)
  1013.     {
  1014.         if (!$expiresAt) {
  1015.             return 'unknown';
  1016.         }
  1017.         
  1018.         $expiryDate = new \DateTime($expiresAt);
  1019.         $now = new \DateTime();
  1020.         $diff $now->diff($expiryDate);
  1021.         
  1022.         if ($expiryDate $now) {
  1023.             return 'expired';
  1024.         } elseif ($diff->days <= 3) {
  1025.             return 'expiring_soon';
  1026.         } else {
  1027.             return 'active';
  1028.         }
  1029.     }
  1030. }