app/Customize/Service/LmDeliveryFee.php line 40

Open in your IDE?
  1. <?php
  2. /**
  3.  * @version EC=CUBE4
  4.  * @copyright 株式会社 翔 kakeru.co.jp
  5.  * @author
  6.  * 2022年01月28日作成
  7.  *
  8.  * app/Customize/Service/LmDeliveryFee.php
  9.  *
  10.  *
  11.  * ランドマーク運賃・支払い方法の算出は、ここで計算する
  12.  * 
  13.  *
  14.  *
  15.  *                               C= C= C= ┌(;・_・)┘トコトコ
  16.  ******************************************************/
  17. namespace Customize\Service;
  18. use Symfony\Component\DependencyInjection\ContainerInterface;
  19. use Symfony\Component\HttpFoundation\RequestStack;
  20. use Eccube\Repository\DeliveryRepository;
  21. use Eccube\Repository\DeliveryFeeRepository;
  22. use Lm\Service\Db\SqlService;
  23. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  24. class LmDeliveryFee
  25. {
  26.     protected $Container;
  27.     protected $Request;
  28.     protected $DeliveryRepository;
  29.     protected $DeliveryFeeRepository;
  30.     protected $LmHelper;
  31.     protected $YamlService;
  32.     protected $Session;
  33.     const LM_Contact_Flg 'LM_Contact_Flg';
  34.     public function __construct(
  35.         ContainerInterface $Container,
  36.         RequestStack $Request,
  37.         DeliveryRepository $DeliveryRepository,
  38.         DeliveryFeeRepository $DeliveryFeeRepository,
  39.         YamlService $YamlService,
  40.         LmHelper $LmHelper,
  41.         SessionInterface $session
  42.     ) {
  43.         $this->Container $Container;
  44.         $this->DeliveryRepository $DeliveryRepository;
  45.         $this->DeliveryFeeRepository $DeliveryFeeRepository;
  46.         $this->YamlService $YamlService;
  47.         $this->LmHelper $LmHelper;
  48.         $this->Request $Request->getMasterRequest();
  49.         $this->Session $session;
  50.     }
  51.     /**
  52.      * 離島中軽量を返す
  53.      *
  54.      * @param string PostalCode
  55.      * @param int $fee
  56.      */
  57.     public function Island($PostalCode)
  58.     {
  59.         $Sql = new SqlService();
  60.         $PostalCode preg_replace('/[^0-9]+/','',$PostalCode);
  61.         $PostalCode substr_replace($PostalCode'-'30);
  62.         $Sql = new SqlService();
  63.         $Island $Sql->Table('island_table')
  64.             ->set('island_postcode'$PostalCode)
  65.             ->Find();
  66.         if(!$Island){
  67.             $PostalCode substr(str_replace("-"""$PostalCode), 03);
  68.             $PostalCode .= "-0000";
  69.             $Island $Sql->Table('island_table')
  70.             ->set('island_postcode'$PostalCode)
  71.             ->Find();
  72.         }
  73.         return    $Island['island_price'] ?? 0;
  74.     }
  75.     /**
  76.      * デリバリーフィーの取得
  77.      *
  78.      */
  79.     public function IsFee($Shipping)
  80.     {
  81.         $Pref $Shipping->getPref();
  82.         ##道府県が沖縄
  83.         if (47 == $Pref->getId()) {
  84.             return false;
  85.         }
  86.         $Delivery $Shipping->getDelivery();
  87.         #佐川意外
  88.         if (!= $Delivery->getId()) {
  89.             return true;
  90.         }
  91.         #離島
  92.         return  $this->Island($Shipping->getPostalCode()) ? false true;
  93.     }
  94.     /**
  95.      * 配送IDと県で 配送費を取得する
  96.      *
  97.      * @param int $Deliverryid
  98.      * @param int $Prefid
  99.      *
  100.      * @return int $frr
  101.      *
  102.      */
  103.     public function getFee($DeliveryId$PrefId)
  104.     {
  105.         $em $this->Container->get('doctrine.orm.entity_manager');
  106.         $Qb =  $em->createQueryBuilder();
  107.         $Delivery $Qb
  108.             ->select(['T1'])
  109.             ->from("Eccube\\Entity\\DeliveryFee"'T1')
  110.             ->innerJoin('Eccube\\Entity\\Delivery''T2')
  111.             ->innerJoin('Eccube\\Entity\\Master\\Pref''T3')
  112.             ->where('T2.id = :DeliveryId')
  113.             ->andWhere('T3.id = :PrefId')
  114.             ->setParameter('DeliveryId'$DeliveryId)
  115.             ->setParameter('PrefId'$PrefId)
  116.             ->getQuery()
  117.             ->getResult();
  118.         if (is_null($Delivery[0])) {
  119.             return null;
  120.         }
  121.         return $Delivery[0]->getFee();
  122.     }
  123.     /**
  124.      * #カートタイプに基づく配送業者を取得
  125.      *
  126.      * @return object $Deliverys
  127.      */
  128.     public function GetLmDelivery($Carts null)
  129.     {
  130.         $DeliverMap $this->YamlService->GetYaml('DeliveryMapping,yaml');
  131.         $CartType $this->LmHelper->getCartType();
  132.         if (!$this->LmHelper->hasNotEstimate($Carts) && ($this->LmHelper->hasSusoage($Carts) || $this->LmHelper->hasKyouei($Carts) || $this->LmHelper->hasShishu($Carts))) {
  133.             $CartType CartService::CartTypeNormal;
  134.         }
  135.         $DeliveryId $DeliverMap[$CartType] ?? 1;
  136.         return $this->DeliveryRepository->findBy(['id' => $DeliveryId]);
  137.     }
  138.     /**
  139.      * #カートタイプに基づく支払い方法の取得
  140.      * @param $Deliverys
  141.      * @param $Order
  142.      * @param $flg 0 OrderType 1 order helper
  143.      *
  144.      * @return array $Payment
  145.      *
  146.      */
  147.     public function GetLmPayment($Order$flg 0)
  148.     {
  149.         $CartType   $this->LmHelper->getCartType();
  150.         $Payments = [];
  151.         foreach ($this->GetLmDelivery() as $Delivery) {
  152.             $PaymentOptions $Delivery->getPaymentOptions();
  153.             foreach ($PaymentOptions as $PaymentOption) {
  154.                 /** @var Payment $Payment */
  155.                 $Payment $PaymentOption->getPayment();
  156.                 //アマゾンペイは アマゾン以外は 弾く
  157. //                if (12 == $Payment->getId() && !preg_match('/amazon_pay/', $this->Request->getUri())) {
  158. //                    continue;
  159. //                }
  160.                 if ($Payment->isVisible()) {
  161.                     $PaymentFlg true;
  162.                     switch (true) {
  163.                             #加工ありの場合代引きは無しに
  164.                         case $CartType == && $Payment->getId() == 4:
  165.                             $PaymentFlg false;
  166.                             break;
  167.                             #会社の場合後払いの表示
  168.                         case $Order->getCompanyName() && $Payment->getId() == 10:
  169.                             $PaymentFlg false;
  170.                             break;
  171.                             #個人の場合後払いの表示
  172.                         case !$Order->getCompanyName() && $Payment->getId() == 11:
  173.                             $PaymentFlg false;
  174.                             break;
  175.                     }
  176.                     if ($PaymentFlg) {
  177.                         if (== $flg) {
  178.                             $Payments[$Delivery->getId()][] = $Payment;
  179.                         } else {
  180.                             $Payments[] = $Payment;
  181.                         }
  182.                     }
  183.                 }
  184.             } //for
  185.         }
  186.         return $Payments;
  187.     }
  188.     /**
  189.      *  都道府県ID 郵便番号で 配送費を返す 
  190.      *  加工で仕様するため 佐川
  191.      *  @param int PrefId
  192.      *  @param string PostalCode
  193.      *
  194.      * @return int $fee;
  195.      *
  196.      */
  197.     public function GetDeliveryFee($PrefId,$PostalCode null){
  198.         $DeliveryMap$this->YamlService->GetYaml('DeliveryMapping,yaml');
  199.         switch($this->LmHelper->getCartType()){
  200.             case CartService::CartTypeCatalog:
  201.             case CartService::CartTypeSample:
  202.                 return 0;
  203.                 break;
  204.             case CartService::CartTypeNormal:
  205.                 return  $this->DeliveryFee($PrefId,$DeliveryMap[1]);
  206.                 break;
  207.             case CartService::CartTypeEstimate:
  208.                 default:
  209.                 return $this->DeliveryFee($PrefId,$DeliveryMap[2]) + $this->Island($PostalCode);
  210.                 break;
  211.         }//switch()
  212.     }
  213.     protected  function DeliveryFee($PrefId,$DereyId){
  214.         if ($Fee $this->DeliveryFeeRepository->findOneBy(['Pref'=>$PrefId,'Delivery'=>$DereyId])){
  215.             return $Fee->getFee();
  216.         }
  217.         return  0;
  218.     }
  219. }