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