<?php
namespace Customize\Controller;
use Customize\Repository\CouponRepository;
use Symfony\Component\Routing\Annotation\Route;
use Eccube\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Customize\Service\CustomerService;
use Customize\Service\ReferralLinkGenerator;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
class ReferFriendController extends AbstractController
{
private $customerService;
private $referralCodeGenerator;
private $couponRepository;
public function __construct(CustomerService $customerService, ReferralLinkGenerator $referralCodeGenerator, CouponRepository $couponRepository)
{
$this->customerService = $customerService;
$this->referralCodeGenerator = $referralCodeGenerator;
$this->couponRepository = $couponRepository;
}
/**
* 友達紹介キャンペーン LP
* @Route("/refer_friend_lp", name="refer_friend_lp", methods={"GET"})
* @Template("refer_friend_lp.twig")
*/
public function lp(Request $request)
{
$customer = $this->customerService->getCustomer();
// 発行済み友達紹介クーポンの件数を取得
if ($customer){
$issuedCoupon = $this->couponRepository->getCountForIssuedReferralCoupon($customer);
$url = $this->referralCodeGenerator->makeLink(
$request->getSchemeAndHttpHost() . '/entry/before', $customer->getId());
$availableCount = $this->eccubeConfig['max_issue_count_refer_friend'] - $issuedCoupon;
}
// 必要ならユーザ情報を渡す
return [
'Customer' => $this->getUser() ?? null,
'referralLink' => $url ?? null,
'availableCount' => $availableCount ?? 0,
];
}
}