app/Customize/Controller/ReferFriendController.php line 32

Open in your IDE?
  1. <?php
  2. namespace Customize\Controller;
  3. use Customize\Repository\CouponRepository;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use Eccube\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Customize\Service\CustomerService;
  8. use Customize\Service\ReferralLinkGenerator;
  9. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  10. class ReferFriendController extends AbstractController
  11. {
  12.     private $customerService;
  13.     private $referralCodeGenerator;
  14.     private $couponRepository;
  15.     public function __construct(CustomerService $customerServiceReferralLinkGenerator $referralCodeGeneratorCouponRepository $couponRepository)
  16.     {
  17.         $this->customerService $customerService;
  18.         $this->referralCodeGenerator $referralCodeGenerator;
  19.         $this->couponRepository $couponRepository;
  20.     }
  21.     /**
  22.      * 友達紹介キャンペーン LP
  23.      * @Route("/refer_friend_lp", name="refer_friend_lp", methods={"GET"})
  24.      * @Template("refer_friend_lp.twig")
  25.      */
  26.     public function lp(Request $request)
  27.     {
  28.         $customer $this->customerService->getCustomer();
  29.         // 発行済み友達紹介クーポンの件数を取得
  30.         if ($customer){
  31.             $issuedCoupon $this->couponRepository->getCountForIssuedReferralCoupon($customer);
  32.             $url $this->referralCodeGenerator->makeLink(
  33.                 $request->getSchemeAndHttpHost() . '/entry/before'$customer->getId());
  34.             $availableCount $this->eccubeConfig['max_issue_count_refer_friend'] - $issuedCoupon;
  35.         }
  36.         
  37.         // 必要ならユーザ情報を渡す
  38.         return [
  39.             'Customer' => $this->getUser() ?? null,
  40.             'referralLink' => $url ?? null,
  41.             'availableCount' => $availableCount ?? 0,
  42.         ];
  43.     }
  44. }