app/Customize/Service/CatalogService.php line 198

Open in your IDE?
  1. <?php
  2. /**
  3.  * @version EC=CUBE4
  4.  * @copyright 株式会社 翔 kakeru.co.jp
  5.  * @author
  6.  * 2022年03月22日作成
  7.  *
  8.  * app/Customize/Service/CatalogService.php
  9.  *
  10.  *
  11.  * カタログサービス
  12.  * 2022/11/30
  13.  *
  14.  *                               C= C= C= ┌(;・_・)┘トコトコ
  15.  ******************************************************/
  16. namespace Customize\Service;
  17. use Lm\Service\Db\SqlService;
  18. use Customize\Service\CommonService;
  19. use Customize\Service\CustomerService;
  20. use Customize\Service\CartService;
  21. use Lm\Entity\OrderHeader;
  22. use Lm\Entity\Cart\CartHeader;
  23. use Lm\Engine\SampleLimit\Catalog;
  24. class CatalogService
  25. {
  26.     const Table_limit 'catalog_limit_table';
  27.     const Table_Catalog 'catalog_item_table';
  28.     const Table_Category 'category_table';
  29.     const Table_Goods 'goods_table';
  30.     const DEVICE_NAME_TO_DEVICE_TYPE = [
  31.         'PC' => 1,  // 1: パソコン
  32.         'SP' => 2,  // 2: スマホ
  33.         'TB' => 3,  // 3: タブレット
  34.     ];
  35.     protected $CommonService;
  36.     protected $CustomerService;
  37.     protected $CartService;
  38.     public function __construct(
  39.         CommonService     $CommonService
  40.         CustomerService $CustomerService
  41.         CartService     $CartService
  42.     )
  43.     {
  44.         $this->CommonService $CommonService;
  45.         $this->CustomerService $CustomerService;
  46.         $this->CartService $CartService;
  47.     }
  48.     /**
  49.      * カタログのリミットを取得する
  50.      *
  51.      * @return array $Limit
  52.      */
  53.     public function GetLimit()
  54.     {
  55.         $Sql = new SqlService();
  56.         return $Sql->Table(self::Table_limit)
  57.             ->Set('cl_device'$this->CommonService->GetDevice())
  58.             ->Find();
  59.     }
  60.     public function getOrderCountOfToday($customerId)
  61.     {
  62.         $order = (new SqlService())
  63.             ->Sql('
  64.                 SELECT COUNT(*) AS order_count
  65.                 FROM order_header_table
  66.                 WHERE oh_customer = :customer_id
  67.                 AND oh_catalog_id IS NOT NULL
  68.                 AND oh_payment NOT IN (
  69.                   :oh_payment_sample
  70.                 )
  71.                 AND oh_type NOT IN (
  72.                   :oh_type_cancel
  73.                 )
  74.                 AND DATE(oh_date) = CURDATE()
  75.             ')
  76.             ->Params([
  77.                 'customer_id' => $customerId,
  78.                 'oh_payment_sample' => OrderHeader::PAYMENT_TYPE_SAMPLE,
  79.                 'oh_type_cancel' => OrderHeader::TYPE_CANCEL,
  80.             ])
  81.             ->Fetch();
  82.         return !empty($order) ? $order['order_count'] : 0;
  83.     }
  84.     public function getOrderCountAfterPurchase($customerId)
  85.     {
  86.         $order = (new SqlService())
  87.             ->Sql("
  88.                 SELECT COUNT(oh_id) AS order_count
  89.                 FROM order_header_table
  90.                 WHERE oh_customer = :customer_id
  91.                     AND oh_catalog_id IS NOT NULL
  92.                     AND oh_payment IN (
  93.                       :oh_payment_catalog
  94.                     )
  95.                     AND oh_type NOT IN (
  96.                       :oh_type_cancel
  97.                     )
  98.                     AND DATE_FORMAT(oh_date, '%Y-%m-%d %H:%i:%s') > IFNULL(
  99.                         (
  100.                             SELECT DATE_FORMAT(oh_date, '%Y-%m-%d %H:%i:%s') AS latest_date
  101.                             FROM order_header_table
  102.                             WHERE oh_customer= :customer_id
  103.                             AND oh_payment NOT IN (
  104.                               :oh_payment_catalog
  105.                             , :oh_payment_sample
  106.                             )
  107.                             AND oh_type NOT IN (
  108.                               :oh_type_cancel
  109.                             )
  110.                             ORDER BY oh_date DESC LIMIT 1
  111.                         ),
  112.                         '1970-01-01'
  113.                     )
  114.             ")
  115.             ->Params([
  116.                 'customer_id' => $customerId,
  117.                 'oh_payment_catalog' => OrderHeader::PAYMENT_TYPE_CATALOG,
  118.                 'oh_payment_sample' => OrderHeader::PAYMENT_TYPE_SAMPLE,
  119.                 'oh_type_cancel' => OrderHeader::TYPE_CANCEL,
  120.             ])
  121.             ->Fetch();
  122.         return !empty($order) ? $order['order_count'] : 0;
  123.     }
  124.     /**
  125.      * カタログを取得する
  126.      *
  127.      * @param array param ['id',inids,'sihire']
  128.      * @return array $Limit
  129.      */
  130.     public function GetCatalog($Param null)
  131.     {
  132.         $Sql = new SqlService();
  133.         $LinkList $this->CommonService->GetYaml('catalog_link_list.yaml');
  134.         $Sql->Table(self::Table_Catalog)
  135.             ->Set('T.del_flg'0)
  136.             ->set('T.catalog_status'1)
  137.             ->Set('T.catalog_site_type''NULL')
  138.             ->set('T.catalog_category''NOT NULL')
  139.             ->Where('(T.iri * T.cases + T.hasu)>0');
  140.         if ($Id $Param['id'] ?? null) {
  141.             return $Sql->Set('T.catalog_id'$Id)->find();
  142.         }
  143.         if ($Ids $Param['InId'] ?? null) {
  144.             return $Sql->set('catalog_id'$Ids'IN')
  145.                 ->Order('catalog_category,catalog_display')
  146.                 ->FindAll();
  147.         }
  148.         if ($Shiire $Param['shiire'] ?? null) {
  149.             return $Sql->set('shiiresaki_cd'$Shiire'IN')
  150.                 ->Order('catalog_category,catalog_display')
  151.                 ->FindAll();
  152.         }
  153.         $Datas $Sql
  154.             ->Order('T.catalog_category,catalog_display')
  155.             ->FindAll();
  156.         $Re = [];
  157.         foreach ($Datas as $Data) {
  158.             $Data['link_list'][$Data['catalog_textlink_variation']] = $LinkList[$Data['catalog_textlink_variation']] ?? null;
  159.             $Data['link_list'][$Data['catalog_textlink_variation2']] = $LinkList[$Data['catalog_textlink_variation2']] ?? null;
  160.             $Data['link_list'][$Data['catalog_textlink_variation3']] = $LinkList[$Data['catalog_textlink_variation3']] ?? null;
  161.             $Re[$Data['catalog_category']][$Data['catalog_id']] = $Data;
  162.         }
  163.         return $Re;
  164.     }
  165.     public function CatalogValidation()
  166.     {
  167.         if (!in_array($this->CartService->getCartType(), [
  168.             CartService::CartTypeSample,
  169.             CartService::CartTypeCatalog,
  170.         ])) {
  171.             return false;
  172.         }
  173.         $cartHeader $this->createCardHeader();
  174.         $checkingResult Catalog::checkCart($cartHeader);
  175.         if ($checkingResult['result'] == 0) {
  176.             return $checkingResult['message'];
  177.         }
  178.         return false;
  179.     }
  180.     /**
  181.      * 2022/04/21
  182.      * 選択したカタログDATAを取得する
  183.      *
  184.      * @return array()
  185.      *
  186.      */
  187.     public function GetView()
  188.     {
  189.         if ($Ids $this->CommonService->GetLmOrderOption(CommonService::Lm_Option_Catalog)){
  190.             return $this->GetCatalog(['InId' => $Ids]);
  191.         };
  192.         return [];
  193.     }
  194.     /**
  195.      * SHOPPING サンプル 
  196.      *
  197.      *
  198.      */
  199.     public function GetSampleCatalogs()
  200.     {
  201.         $Cart $this->CartService->getCart();
  202.         $ProductIds = [];
  203.         foreach ($Cart->getItems() as $Item) {
  204.             if (!$Item->isProduct()) {
  205.                 continue;
  206.             }
  207.             $Product $Item->getProductClass()->getProduct();
  208.             $ProductIds[] = $Product->getId();
  209.         }
  210.         $Sql = new SqlService();
  211.         #商品の取得
  212.         $Goods $Sql->Table(self::Table_Goods)
  213.             ->Set('goods_id'$ProductIds'IN')
  214.             ->FindAll();
  215.         $ShiireCd = [];
  216.         foreach ($Goods as $Good) {
  217.             $ShiireCd[] = $Good['goods_shiiresaki'];
  218.         }
  219.         return $this->GetCatalog(['shiire' => $ShiireCd]);
  220.     }
  221.     public function createCardHeader() {
  222.         $cartHeader = new CartHeader();
  223.         if ($Customer $this->CommonService->getUser()) {
  224.             $customerId $Customer->getLmCustomerId();
  225.             $cartHeader->setCustomerId($customerId);
  226.         }
  227.         $deviceName $this->CommonService->GetDevice(true); // デバイス名(タブレットも判別するため
  228.         $device $this->GetDeviceTypeByDeviceName($deviceName);
  229.         $cartHeader->setDevice($device);
  230.         return $cartHeader;
  231.     }
  232.     /**
  233.      * デバイス名よりデバイス種別を判別する
  234.      *
  235.      * @param int $deviceName
  236.      * @return string
  237.      */
  238.     public function GetDeviceTypeByDeviceName($deviceName)
  239.     {
  240.         return self::DEVICE_NAME_TO_DEVICE_TYPE[$deviceName];
  241.     }
  242. }