app/Plugin/PiaPlazaMypage/Controller/MypageListingStatusController.php line 56

Open in your IDE?
  1. <?php
  2. namespace Plugin\PiaPlazaMypage\Controller;
  3. use Eccube\Controller\AbstractController;
  4. use Plugin\ExhibitorCoin\Repository\ExhibitionRepository;
  5. use Plugin\ExhibitorCoin\Service\ExhibitPdfService;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. /**
  11.  * マイページ出品状況発送連絡コントローラー
  12.  *
  13.  * @Route("/mypage")
  14.  */
  15. class MypageListingStatusController extends AbstractController
  16. {
  17.     /**
  18.      * @var ExhibitionRepository
  19.      */
  20.     private $exhibitionRepository;
  21.     /**
  22.      * @var ExhibitPdfService
  23.      */
  24.     private $exhibitPdfService;
  25.     /**
  26.      * @var string
  27.      */
  28.     private $dirCoin;
  29.     /**
  30.      * コンストラクタ
  31.      *
  32.      * @param ExhibitionRepository $exhibitionRepository
  33.      * @param ExhibitPdfService $exhibitPdfService
  34.      */
  35.     public function __construct(
  36.         ExhibitionRepository $exhibitionRepository,
  37.         ExhibitPdfService $exhibitPdfService
  38.     )
  39.     {
  40.         $this->exhibitionRepository $exhibitionRepository;
  41.         $this->exhibitPdfService $exhibitPdfService;
  42.     }
  43.     /**
  44.      * 出品状況発送連絡
  45.      *
  46.      * @Route("/listing_status", name="mypage_listing_status")
  47.      * @IsGranted("ROLE_USER")
  48.      */
  49.     public function index(Request $request)
  50.     {
  51.         // ログイン会員取得
  52.         $Customer $this->getUser();
  53.         $customerId $Customer->getId();
  54.         // モード判定
  55.         $mode $request->query->get('mode''');
  56.         $msg '';
  57.         // 発送番号登録処理
  58.         if ($mode === 'regist') {
  59.             $exhibitionId $request->query->get('id');
  60.             $shippingComId $request->query->get('c_val');
  61.             $shippingNumber $request->query->get('n_val');
  62.             // バリデーション
  63.             if (empty($exhibitionId) || empty($shippingComId) || empty($shippingNumber)) {
  64.                 $this->addError('発送番号を登録出来ませんでした。再度ご登録お願いします。''admin');
  65.                 return $this->redirectToRoute('mypage_listing_status');
  66.             }
  67.             // 出品情報取得(本人確認)
  68.             $exhibition $this->exhibitionRepository->findOneBy([
  69.                 'id' => $exhibitionId,
  70.                 'customer_id' => $customerId,
  71.             ]);
  72.             if (empty($exhibition)) {
  73.                 $this->addError('発送情報を取得出来ませんでした。再度ご登録お願いします。''admin');
  74.                 return $this->redirectToRoute('mypage_listing_status');
  75.             }
  76.             // 発送番号更新
  77.             $exhibition->setShippingComId($shippingComId);
  78.             $exhibition->setShippingNumber($shippingNumber);
  79.             $exhibition->setUpdateDate(new \DateTime());
  80.             $this->entityManager->persist($exhibition);
  81.             $this->entityManager->flush();
  82.             $msg '配送No.を登録しました。';
  83.         }
  84.         // 出品一覧取得
  85.         $exhibitions $this->exhibitionRepository->findBy(
  86.             ['customer_id' => $customerId'del_flg' => 0],
  87.             ['id' => 'DESC']
  88.         );
  89.         // ステータス一覧・配送会社一覧取得
  90.         $htMyStatus $this->getHashMyPageStatus();
  91.         $htSend $this->exhibitionRepository->getHashDeliveryCompany();
  92.         return $this->render('@PiaPlazaMypage/default/Mypage/listing_status.twig', [
  93.             'rows' => $exhibitions,
  94.             'htMyStatus' => $htMyStatus,
  95.             'htSend' => $htSend,
  96.             'msg' => $msg,
  97.         ]);
  98.     }
  99.     /**
  100.      * 出品商品状況詳細
  101.      *
  102.      * @Route("/listing_detail", name="mypage_listing_detail")
  103.      * @IsGranted("ROLE_USER")
  104.      */
  105.     public function detail(Request $request)
  106.     {
  107.         // ログイン会員取得
  108.         $Customer $this->getUser();
  109.         $customerId $Customer->getId();
  110.         // 出品ID取得
  111.         $exhibitionId $request->query->get('id');
  112.         if (empty($exhibitionId)) {
  113.             $this->addError('出品情報が見つかりません。''admin');
  114.             return $this->redirectToRoute('mypage_listing_status');
  115.         }
  116.         // 出品情報取得(本人確認)
  117.         $exhibition $this->exhibitionRepository->findOneBy([
  118.             'id' => $exhibitionId,
  119.             'customer_id' => $customerId,
  120.             'del_flg' => 0,
  121.         ]);
  122.         if (empty($exhibition)) {
  123.             $this->addError('出品情報が見つかりません。''admin');
  124.             return $this->redirectToRoute('mypage_listing_status');
  125.         }
  126.         // ステータス一覧・配送会社一覧取得
  127.         $htMyStatus $this->getHashMyPageStatus();
  128.         $htSend $this->exhibitionRepository->getHashDeliveryCompany();
  129.         return $this->render('@PiaPlazaMypage/default/Mypage/listing_detail.twig', [
  130.             'row' => $exhibition,
  131.             'htMyStatus' => $htMyStatus,
  132.             'htSend' => $htSend,
  133.         ]);
  134.     }
  135.     /**
  136.      * コイン画像表示
  137.      *
  138.      * @Route("/listing_disp_photo", name="mypage_listing_disp_photo", methods={"GET"})
  139.      */
  140.     public function dispPhoto(Request $request)
  141.     {
  142.         // ログイン会員取得
  143.         if (!$this->isGranted('ROLE_USER')) {
  144.             return new Response(''404);
  145.         }
  146.         $Customer $this->getUser();
  147.         $customerId $Customer->getId();
  148.         $exhibitionId $request->query->get('id');
  149.         $photo $request->query->get('img');
  150.         if (empty($exhibitionId) || empty($photo)) {
  151.             return new Response(''404);
  152.         }
  153.         // 出品情報取得(本人確認)
  154.         $exhibition $this->exhibitionRepository->findOneBy([
  155.             'id' => $exhibitionId,
  156.             'customer_id' => $customerId,
  157.         ]);
  158.         if (empty($exhibition)) {
  159.             return new Response(''404);
  160.         }
  161.         // 画像ファイルパス
  162.         $this->dirCoin $this->getParameter('kernel.project_dir') . "/app/Coin";
  163.         $filePath $this->dirCoin "/" $exhibitionId "/" $photo;
  164.         // ディレクトリトラバーサル対策
  165.         $photo preg_replace("/\/\.\.\//"""$photo);
  166.         $filePath $this->dirCoin "/" $exhibitionId "/" $photo;
  167.         if (!is_file($filePath) || !file_exists($filePath) || filesize($filePath) <= 0) {
  168.             return new Response(''404);
  169.         }
  170.         // 画像データ取得
  171.         $data file_get_contents($filePath);
  172.         // MIMEタイプ判定
  173.         $extension strtolower(pathinfo($photoPATHINFO_EXTENSION));
  174.         $mimeType 'image/jpeg';
  175.         if ($extension === 'png') {
  176.             $mimeType 'image/png';
  177.         } elseif ($extension === 'gif') {
  178.             $mimeType 'image/gif';
  179.         }
  180.         // 画像レスポンス
  181.         $response = new Response($data);
  182.         $response->headers->set('Content-Type'$mimeType);
  183.         return $response;
  184.     }
  185.     /**
  186.      * 預り書PDF表示
  187.      *
  188.      * @Route("/custody_pdf", name="mypage_custody_pdf")
  189.      * @IsGranted("ROLE_USER")
  190.      */
  191.     public function custodyPdf(Request $request)
  192.     {
  193.         // ログイン会員取得
  194.         $Customer $this->getUser();
  195.         $customerId $Customer->getId();
  196.         // 出品ID取得
  197.         $exhibitionId $request->query->get('id');
  198.         if (empty($exhibitionId)) {
  199.             $this->addError('出品情報が見つかりません。''admin');
  200.             return $this->redirectToRoute('mypage_listing_status');
  201.         }
  202.         // 出品情報取得(本人確認)
  203.         $exhibition $this->exhibitionRepository->findOneBy([
  204.             'id' => $exhibitionId,
  205.             'customer_id' => $customerId,
  206.             'del_flg' => 0,
  207.         ]);
  208.         if (empty($exhibition)) {
  209.             $this->addError('出品情報が見つかりません。''admin');
  210.             return $this->redirectToRoute('mypage_listing_status');
  211.         }
  212.         // PDF生成
  213.         $formData = ['id' => $exhibitionId];
  214.         $result $this->exhibitPdfService->makePdf($formData);
  215.         if (!$result) {
  216.             $this->addError('PDFの生成に失敗しました。''admin');
  217.             return $this->redirectToRoute('mypage_listing_status');
  218.         }
  219.         // PDFファイル名
  220.         $fileName 'oazukari_' $exhibitionId '.pdf';
  221.         // PDF出力
  222.         return new Response(
  223.             $this->exhibitPdfService->Output($fileName'I'),
  224.             200,
  225.             [
  226.                 'Content-Type' => 'application/pdf',
  227.                 'Content-Disposition' => 'inline; filename="' $fileName '"',
  228.             ]
  229.         );
  230.     }
  231.     /**
  232.      * マイページ用ステータス一覧ハッシュ取得
  233.      *
  234.      * @return array
  235.      */
  236.     private function getHashMyPageStatus()
  237.     {
  238.         return [
  239.             => '受付完了',
  240.             => '出品依頼確認済み',
  241.             => '発送済み',
  242.             => '受取完了',
  243.             => '鑑定中',
  244.             => '鑑定完了',
  245.             => '商品準備完了',
  246.             => '出品中',
  247.             => '売却済み',
  248.             99 => 'キャンセル',
  249.         ];
  250.     }
  251. }