<?php
namespace Plugin\PiaPlazaMypage\Controller;
use Eccube\Controller\AbstractController;
use Plugin\ExhibitorCoin\Repository\ExhibitionRepository;
use Plugin\ExhibitorCoin\Service\ExhibitPdfService;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* マイページ出品状況発送連絡コントローラー
*
* @Route("/mypage")
*/
class MypageListingStatusController extends AbstractController
{
/**
* @var ExhibitionRepository
*/
private $exhibitionRepository;
/**
* @var ExhibitPdfService
*/
private $exhibitPdfService;
/**
* @var string
*/
private $dirCoin;
/**
* コンストラクタ
*
* @param ExhibitionRepository $exhibitionRepository
* @param ExhibitPdfService $exhibitPdfService
*/
public function __construct(
ExhibitionRepository $exhibitionRepository,
ExhibitPdfService $exhibitPdfService
)
{
$this->exhibitionRepository = $exhibitionRepository;
$this->exhibitPdfService = $exhibitPdfService;
}
/**
* 出品状況発送連絡
*
* @Route("/listing_status", name="mypage_listing_status")
* @IsGranted("ROLE_USER")
*/
public function index(Request $request)
{
// ログイン会員取得
$Customer = $this->getUser();
$customerId = $Customer->getId();
// モード判定
$mode = $request->query->get('mode', '');
$msg = '';
// 発送番号登録処理
if ($mode === 'regist') {
$exhibitionId = $request->query->get('id');
$shippingComId = $request->query->get('c_val');
$shippingNumber = $request->query->get('n_val');
// バリデーション
if (empty($exhibitionId) || empty($shippingComId) || empty($shippingNumber)) {
$this->addError('発送番号を登録出来ませんでした。再度ご登録お願いします。', 'admin');
return $this->redirectToRoute('mypage_listing_status');
}
// 出品情報取得(本人確認)
$exhibition = $this->exhibitionRepository->findOneBy([
'id' => $exhibitionId,
'customer_id' => $customerId,
]);
if (empty($exhibition)) {
$this->addError('発送情報を取得出来ませんでした。再度ご登録お願いします。', 'admin');
return $this->redirectToRoute('mypage_listing_status');
}
// 発送番号更新
$exhibition->setShippingComId($shippingComId);
$exhibition->setShippingNumber($shippingNumber);
$exhibition->setUpdateDate(new \DateTime());
$this->entityManager->persist($exhibition);
$this->entityManager->flush();
$msg = '配送No.を登録しました。';
}
// 出品一覧取得
$exhibitions = $this->exhibitionRepository->findBy(
['customer_id' => $customerId, 'del_flg' => 0],
['id' => 'DESC']
);
// ステータス一覧・配送会社一覧取得
$htMyStatus = $this->getHashMyPageStatus();
$htSend = $this->exhibitionRepository->getHashDeliveryCompany();
return $this->render('@PiaPlazaMypage/default/Mypage/listing_status.twig', [
'rows' => $exhibitions,
'htMyStatus' => $htMyStatus,
'htSend' => $htSend,
'msg' => $msg,
]);
}
/**
* 出品商品状況詳細
*
* @Route("/listing_detail", name="mypage_listing_detail")
* @IsGranted("ROLE_USER")
*/
public function detail(Request $request)
{
// ログイン会員取得
$Customer = $this->getUser();
$customerId = $Customer->getId();
// 出品ID取得
$exhibitionId = $request->query->get('id');
if (empty($exhibitionId)) {
$this->addError('出品情報が見つかりません。', 'admin');
return $this->redirectToRoute('mypage_listing_status');
}
// 出品情報取得(本人確認)
$exhibition = $this->exhibitionRepository->findOneBy([
'id' => $exhibitionId,
'customer_id' => $customerId,
'del_flg' => 0,
]);
if (empty($exhibition)) {
$this->addError('出品情報が見つかりません。', 'admin');
return $this->redirectToRoute('mypage_listing_status');
}
// ステータス一覧・配送会社一覧取得
$htMyStatus = $this->getHashMyPageStatus();
$htSend = $this->exhibitionRepository->getHashDeliveryCompany();
return $this->render('@PiaPlazaMypage/default/Mypage/listing_detail.twig', [
'row' => $exhibition,
'htMyStatus' => $htMyStatus,
'htSend' => $htSend,
]);
}
/**
* コイン画像表示
*
* @Route("/listing_disp_photo", name="mypage_listing_disp_photo", methods={"GET"})
*/
public function dispPhoto(Request $request)
{
// ログイン会員取得
if (!$this->isGranted('ROLE_USER')) {
return new Response('', 404);
}
$Customer = $this->getUser();
$customerId = $Customer->getId();
$exhibitionId = $request->query->get('id');
$photo = $request->query->get('img');
if (empty($exhibitionId) || empty($photo)) {
return new Response('', 404);
}
// 出品情報取得(本人確認)
$exhibition = $this->exhibitionRepository->findOneBy([
'id' => $exhibitionId,
'customer_id' => $customerId,
]);
if (empty($exhibition)) {
return new Response('', 404);
}
// 画像ファイルパス
$this->dirCoin = $this->getParameter('kernel.project_dir') . "/app/Coin";
$filePath = $this->dirCoin . "/" . $exhibitionId . "/" . $photo;
// ディレクトリトラバーサル対策
$photo = preg_replace("/\/\.\.\//", "", $photo);
$filePath = $this->dirCoin . "/" . $exhibitionId . "/" . $photo;
if (!is_file($filePath) || !file_exists($filePath) || filesize($filePath) <= 0) {
return new Response('', 404);
}
// 画像データ取得
$data = file_get_contents($filePath);
// MIMEタイプ判定
$extension = strtolower(pathinfo($photo, PATHINFO_EXTENSION));
$mimeType = 'image/jpeg';
if ($extension === 'png') {
$mimeType = 'image/png';
} elseif ($extension === 'gif') {
$mimeType = 'image/gif';
}
// 画像レスポンス
$response = new Response($data);
$response->headers->set('Content-Type', $mimeType);
return $response;
}
/**
* 預り書PDF表示
*
* @Route("/custody_pdf", name="mypage_custody_pdf")
* @IsGranted("ROLE_USER")
*/
public function custodyPdf(Request $request)
{
// ログイン会員取得
$Customer = $this->getUser();
$customerId = $Customer->getId();
// 出品ID取得
$exhibitionId = $request->query->get('id');
if (empty($exhibitionId)) {
$this->addError('出品情報が見つかりません。', 'admin');
return $this->redirectToRoute('mypage_listing_status');
}
// 出品情報取得(本人確認)
$exhibition = $this->exhibitionRepository->findOneBy([
'id' => $exhibitionId,
'customer_id' => $customerId,
'del_flg' => 0,
]);
if (empty($exhibition)) {
$this->addError('出品情報が見つかりません。', 'admin');
return $this->redirectToRoute('mypage_listing_status');
}
// PDF生成
$formData = ['id' => $exhibitionId];
$result = $this->exhibitPdfService->makePdf($formData);
if (!$result) {
$this->addError('PDFの生成に失敗しました。', 'admin');
return $this->redirectToRoute('mypage_listing_status');
}
// PDFファイル名
$fileName = 'oazukari_' . $exhibitionId . '.pdf';
// PDF出力
return new Response(
$this->exhibitPdfService->Output($fileName, 'I'),
200,
[
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'inline; filename="' . $fileName . '"',
]
);
}
/**
* マイページ用ステータス一覧ハッシュ取得
*
* @return array
*/
private function getHashMyPageStatus()
{
return [
1 => '受付完了',
2 => '出品依頼確認済み',
3 => '発送済み',
4 => '受取完了',
5 => '鑑定中',
6 => '鑑定完了',
7 => '商品準備完了',
8 => '出品中',
9 => '売却済み',
99 => 'キャンセル',
];
}
}