app/Customize/Controller/CronJobController.php line 120

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;
  13. use Eccube\Controller\AbstractController;
  14. use Eccube\Repository\MemberRepository;
  15. use Eccube\Repository\CustomerRepository;
  16. use Eccube\Security\Core\Encoder\PasswordEncoder;
  17. use Symfony\Component\HttpFoundation\JsonResponse;
  18. use Symfony\Component\HttpFoundation\Request;
  19. use Symfony\Component\HttpFoundation\Response;
  20. use Symfony\Component\HttpKernel\Exception as HttpException;
  21. use Symfony\Component\Routing\Annotation\Route;
  22. use Customize\Service\MailService;
  23. use Customize\Service\CashbackService;
  24. use Customize\Service\UsageFeeService;
  25. use Customize\Repository\ChainStoreRepository;
  26. use Plugin\Coupon4\Repository\CouponRepository;
  27. use Doctrine\ORM\EntityManagerInterface;
  28. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  29. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  30. class CronJobController extends AbstractController
  31. {
  32.     private $key "e564c9a69921be4a9268be4df8bc3fa271437c28";
  33.     
  34.     /**
  35.      * @var ChainStoreRepository
  36.      */
  37.     protected $chainstoreRepository;
  38.     
  39.     /**
  40.      * @var MemberRepository
  41.      */
  42.     protected $memberRepository;
  43.     /**
  44.      * @var CustomerRepository
  45.      */
  46.     protected $customerRepository;
  47.     /**
  48.      * @var CouponRepository
  49.      */
  50.     protected $couponRepository;
  51.     /**
  52.      * @var MailService
  53.      */
  54.     protected $mailService;
  55.     /**
  56.      * @var CashbackService
  57.      */
  58.     protected $cashbackService;
  59.     /**
  60.      * @var UsageFeeService
  61.      */
  62.     protected $usageFeeService;
  63.     /**
  64.      * @var PasswordEncoder
  65.      */
  66.     protected $passwordEncoder;
  67.     
  68.     /**
  69.      * @var \Doctrine\ORM\EntityManagerInterface
  70.      */
  71.     protected $entityManager;
  72.     /**
  73.      * BankController constructor.
  74.      */
  75.     public function __construct(
  76.         ChainStoreRepository $chainstoreRepository,
  77.         MemberRepository $memberRepository,
  78.         CustomerRepository $customerRepository,
  79.         CouponRepository $couponRepository,
  80.         MailService $mailService,
  81.         CashbackService $cashbackService,
  82.         UsageFeeService $usageFeeService,
  83.         PasswordEncoder $passwordEncoder,
  84.         EntityManagerInterface $entityManager)
  85.     {
  86.         $this->chainstoreRepository $chainstoreRepository;
  87.         $this->memberRepository $memberRepository;
  88.         $this->customerRepository $customerRepository;
  89.         $this->couponRepository $couponRepository;
  90.         $this->mailService $mailService;
  91.         $this->cashbackService $cashbackService;
  92.         $this->usageFeeService $usageFeeService;
  93.         $this->passwordEncoder $passwordEncoder;
  94.         $this->entityManager $entityManager;
  95.     }
  96.     /**
  97.      * check chainstore mail.
  98.      *
  99.      * @Route("/cronjob/check_chainstore_mail/{key}", name="check_chainstore_mail", methods={"GET"})
  100.      * 
  101.      * @param Request $request
  102.      * 
  103.      * @return JsonResponse
  104.      */
  105.     public function checkChainStoreMail(Request $request$key)
  106.     {
  107.         $result = [];
  108.         
  109.         try {
  110.             if($this->key != $key){
  111.                 $result[] = "Incorrect registry key for Access!!";
  112.             }else{
  113.                 // タイムアウトを無効にする.
  114.                 set_time_limit(0);
  115.                 $CustomerList $this->customerRepository->findBy(["Status" => 2]);
  116.                 $MemberList $this->memberRepository->findBy(["Work" => 1]);
  117.                 //$MemberList = $this->memberRepository->findBy(["id" => 2]);
  118.                 $DealerCodeList = [];
  119.                 $StockNumberList = [];
  120.                 $CouponCodeList = [];
  121.                 foreach($CustomerList as $Customer){
  122.                     $ChainStore $Customer->getChainStore();
  123.                     if(is_object($ChainStore)){
  124.                         $ContractType $ChainStore->getContractType();
  125.                         
  126.                         $DealerCode $ChainStore->getDealerCode();
  127.                         if(!isset($DealerCode) || strlen($DealerCode) <= 1){
  128.                             $DealerCodeList[] = $Customer;
  129.                         }
  130.                         $StockNumber $ChainStore->getStockNumber();
  131.                         if(!isset($StockNumber) || strlen($StockNumber) <= 1){
  132.                             $StockNumberList[] = $Customer;
  133.                         }
  134.                         if($ContractType->getId() == || $ContractType->getId() == 2){
  135.                             $CouponList $this->couponRepository->findBy(["ChainStore" => $ChainStore]);
  136.                             if(!$CouponList){
  137.                                 $CouponCodeList[] = $Customer;
  138.                             }
  139.                         }
  140.                     }
  141.                 }
  142.                 if(count($DealerCodeList) > || count($CouponCodeList) > 0){
  143.                     foreach($MemberList as $Member){
  144.                         // チェック販売店会員メール送信
  145.                         $this->mailService->sendCheckChainStoreMail($Member$DealerCodeList$StockNumberList$CouponCodeList);
  146.                         $result[] = $Member->getId();
  147.                     }
  148.                 }
  149.             }
  150.         } catch (\Exception $e) {
  151.             log_error('予期しないエラーです', [$e->getMessage()]);
  152.             return $this->json(['status' => $e->getMessage()], 500);
  153.         }
  154.         return $this->json(array_merge(['status' => 'OK''data' => $result], []));
  155.     }
  156.     /**
  157.      * Cashback 計算画面.
  158.      *
  159.      * @Route("/cronjob/calc_cashback/{key}", name="calc_cashback", methods={"GET", "POST"})
  160.      * @Template("Cashback/calcCashback.twig")
  161.      */
  162.     public function calcCashback(Request $request$key)
  163.     {
  164.         $YM date('Y-m');
  165.         
  166.         return $this->calcCashbackYM($request$YM$key);
  167.     }
  168.     /**
  169.      * Cashback 計算画面(指定年月).
  170.      *
  171.      * @Route("/cronjob/calc_cashback/{YM}/{key}", name="calc_cashback_ym", methods={"GET", "POST"})
  172.      * @Template("Cashback/calcCashback.twig")
  173.      */
  174.     public function calcCashbackYM(Request $request$YM$key)
  175.     {
  176.         if($this->key != $key){
  177.             $error "Incorrect registry key for Access!!";
  178.             return [
  179.                 'Error' => $error
  180.             ];
  181.         }else{
  182.             $CashbackResult $this->cashbackService->calcCashback($YM);
  183.             return [
  184.                 'CashbackResult' => $CashbackResult,
  185.                 'Error' => null
  186.             ];
  187.         }
  188.     }
  189.     /**
  190.      * 購入数による掛け率変動の対応を実装する。 計算画面.
  191.      *
  192.      * @Route("/cronjob/calc_reback_amount/{key}", name="calc_reback_amount", methods={"GET", "POST"})
  193.      * @Template("Cashback/calcRebackAmount.twig")
  194.      */
  195.     public function calcRebackAmount(Request $request$key)
  196.     {
  197.         $YM date('Y-m');
  198.         
  199.         return $this->calcRebackAmountYM($request$YM$key);
  200.     }
  201.     /**
  202.      * 購入数による掛け率変動の対応を実装する。 計算画面(指定年月).
  203.      *
  204.      * @Route("/cronjob/calc_reback_amount/{YM}/{key}", name="calc_reback_amount_ym", methods={"GET", "POST"})
  205.      * @Template("Cashback/calcRebackAmount.twig")
  206.      */
  207.     public function calcRebackAmountYM(Request $request$YM$key)
  208.     {
  209.         if($this->key != $key){
  210.             $error "Incorrect registry key for Access!!";
  211.             return [
  212.                 'Error' => $error
  213.             ];
  214.         }else{
  215.             $CashbackResult $this->cashbackService->calcRebackAmount($YM);
  216.             return [
  217.                 'CashbackResult' => $CashbackResult,
  218.                 'Error' => null
  219.             ];
  220.         }
  221.     }
  222.     /**
  223.      * 小売販売契約に対するブランド使用料は毎月定額15,000円となっている。(指定年月).
  224.      *
  225.      * @Route("/cronjob/calc_retail_usage_fee/{YM}/{key}", name="calc_retail_usage_fee_month", methods={"GET", "POST"})
  226.      * @Template("UsageFee/calcUsageFee.twig")
  227.      */
  228.     public function calcRetailUsageFeeMonth(Request $request$YM$key)
  229.     {
  230.         if($this->key != $key){
  231.             $error "Incorrect registry key for Access!!";
  232.             return [
  233.                 'Error' => $error
  234.             ];
  235.         }else{
  236.             // タイムアウトを無効にする.
  237.             set_time_limit(0);
  238.             
  239.             $usageFeeResult $this->usageFeeService->calcUsageFee($request$this->formFactory$YM);
  240.             $MemberList $this->memberRepository->findBy(["Work" => 1]);
  241.             if($usageFeeResult["Error"] == null){
  242.                 $RetailUsageList $usageFeeResult["RetailUsageList"];
  243.                 $hasError $usageFeeResult["HasError"];
  244.                 $RetailUsageErrList = [];
  245.                 $RetailUsageGMOErrList = [];
  246.                 $BankTransferCount 0;
  247.                 $GMOPaymentCount 0;
  248.                 foreach($RetailUsageList as $RetailUsage){
  249.                     $Payment $RetailUsage->getChainStore()->getAutoUsageFeePayment();
  250.                     if($RetailUsage->getResult() != "OK"){
  251.                         $RetailUsageErrList[] = $RetailUsage;
  252.                     }else{
  253.                         if($RetailUsage->getAuthorResult() != "OK" && $RetailUsage->getAuthorResult() != "" && $RetailUsage->getAuthorResult() != null){
  254.                             $RetailUsageGMOErrList[] = $RetailUsage;
  255.                         }else{
  256.                             if($Payment->getId() == 3){
  257.                                 $BankTransferCount $BankTransferCount 1;
  258.                             }else{
  259.                                 $GMOPaymentCount $GMOPaymentCount 1;
  260.                             }
  261.                         }
  262.                     }
  263.                 }
  264.                 //if($hasError){
  265.                     //if(count($RetailUsageErrList) > 0){
  266.                         foreach($MemberList as $Member){
  267.                             $YM str_replace("-""年",$YM)."月";
  268.                             // ブランド使用料メール送信
  269.                             $this->mailService->sendChainStoreRetailUsageFeeMail($Member$YM$usageFeeResult$RetailUsageErrList$RetailUsageGMOErrList$BankTransferCount$GMOPaymentCount);
  270.                         }
  271.                     //}
  272.                 //}
  273.             }
  274.             return [
  275.                 'UsageFeeResult' => $usageFeeResult,
  276.                 'Error' => null
  277.             ];
  278.         }
  279.     }
  280.     /**
  281.      * 小売販売契約に対するブランド使用料は毎月定額15,000円となっている。(当月).
  282.      *
  283.      * @Route("/cronjob/calc_retail_usage_fee/{key}", name="calc_retail_usage_fee", methods={"GET", "POST"})
  284.      * @Template("UsageFee/calcUsageFee.twig")
  285.      */
  286.     public function calcRetailUsageFee(Request $request$key)
  287.     {
  288.         $YM date('Y-m');
  289.         
  290.         return $this->calcRetailUsageFeeMonth($request$YM$key);
  291.     }
  292.     /**
  293.      * change customer and member password.
  294.      *
  295.      * @Route("/cronjob/change_pwd/{key}", name="change_pwd", methods={"GET"})
  296.      * 
  297.      * @param Request $request
  298.      * 
  299.      * @return JsonResponse
  300.      */
  301.     public function change_pwd(Request $request$key)
  302.     {
  303.         $result = [];
  304.         
  305.         try {
  306.             // タイムアウトを無効にする.
  307.             set_time_limit(0);
  308.             $MemberList $this->memberRepository->findAll();   //->findOneBy(["id" => 2]);
  309.             foreach($MemberList as $Member){
  310.                 if(strlen($Member->getPassword()) <= 60){
  311.                     $newPassword $this->passwordEncoder->encodePassword($Member->getPassword(), $Member->getSalt());
  312.                     $Member->setPassword($newPassword);
  313.                     $this->memberRepository->save($Member);
  314.                     $this->entityManager->flush();
  315.                 }
  316.             }
  317.             $CustomerList $this->customerRepository->findAll();       //->findOneBy(["id" => 401]);
  318.             foreach($CustomerList as $Customer){
  319.                 if(strlen($Customer->getPassword()) <= 60){
  320.                     $newPassword $this->passwordEncoder->encodePassword($Customer->getPassword(), $Customer->getSalt());
  321.                     $Customer->setPassword($newPassword);
  322.                     $this->customerRepository->save($Customer);
  323.                     $this->entityManager->flush();
  324.                 }
  325.             }
  326.         } catch (\Exception $e) {
  327.             log_error('予期しないエラーです', [$e->getMessage()]);
  328.             return $this->json(['status' => $e->getMessage()], 500);
  329.         }
  330.         return $this->json(array_merge(['status' => 'OK''data' => $result], []));
  331.     }
  332.     /**
  333.      * test chainstore register to admin mail.
  334.      *
  335.      * @Route("/test_admin_mail", name="test_admin_mail", methods={"GET"})
  336.      * 
  337.      * @param Request $request
  338.      * 
  339.      * @return JsonResponse
  340.      */
  341.     public function test_admin_mail(Request $request)
  342.     {
  343.         $result = [];
  344.         
  345.         try {
  346.             // タイムアウトを無効にする.
  347.             set_time_limit(0);
  348.             $ChainStore $this->chainstoreRepository->findOneBy(["id" => 68]);
  349.             $Member $this->memberRepository->findOneBy(["id" => 2]);
  350.             $Customer $this->customerRepository->findOneBy(["id" => 108]);
  351.             // 販売店会員メール送信
  352.             $this->mailService->sendChainStoreConfirmAdminMail($Member$Customer$ChainStore$ChainStore->getContractType());
  353.         } catch (\Exception $e) {
  354.             log_error('予期しないエラーです', [$e->getMessage()]);
  355.             return $this->json(['status' => $e->getMessage()], 500);
  356.         }
  357.         return $this->json(array_merge(['status' => 'OK''data' => $result], []));
  358.     }
  359.     /**
  360.      * test chainstore register to admin mail.
  361.      *
  362.      * @Route("/test_kari_mail/{id}/{key}", name="test_kari_mail", methods={"GET"})
  363.      * 
  364.      * @param Request $request
  365.      * 
  366.      * @return JsonResponse
  367.      */
  368.     public function test_kari_mail(Request $request$id$key)
  369.     {
  370.         $result = [];
  371.         
  372.         try {
  373.             if($this->key != $key){
  374.                 $error "Incorrect registry key for Access!!";
  375.     
  376.                 return [
  377.                     'Error' => $error
  378.                 ];
  379.             }else{
  380.                 // タイムアウトを無効にする.
  381.                 set_time_limit(0);
  382.                 $ChainstoreType null;
  383.                 $Customer $this->customerRepository->findOneBy(["id" => $id]);
  384.                 $ChainStore $Customer->getChainStore();
  385.                 if(is_object($ChainStore)){
  386.                     $ChainstoreType $ChainStore->getContractType();
  387.                 }
  388.                 $activateUrl $this->generateUrl('entry_activate', ['secret_key' => $Customer->getSecretKey()], UrlGeneratorInterface::ABSOLUTE_URL);
  389.                 // 販売店会員メール送信
  390.                 $this->mailService->sendChainStoreConfirmMailFullReg($Customer$activateUrl$ChainstoreType);
  391.             }
  392.         } catch (\Exception $e) {
  393.             log_error('予期しないエラーです', [$e->getMessage()]);
  394.             return $this->json(['status' => $e->getMessage()], 500);
  395.         }
  396.         return $this->json(array_merge(['status' => 'OK''data' => $result], []));
  397.     }
  398. }