app/Customize/Converter/DynamicConverter.php line 1989

Open in your IDE?
  1. <?php
  2. /**
  3.  * @version EC=CUBE4
  4.  * @copyright 株式会社 翔 kakeru.co.jp
  5.  * @author
  6.  * 2021年12月17日作成
  7.  *
  8.  * app\Customize\Converter\CustomerConverter.php
  9.  *
  10.  *
  11.  *  コンバーター
  12.  * 会員郡のコンバーを行う
  13.  *
  14.  *
  15.  *                              C= C= C= ┌(;・_・)┘トコトコ
  16.  ******************************************************/
  17. namespace Customize\Converter;
  18. use Customize\Service\DynamicConverterService;
  19. use Customize\Service\ItemSashikomiImageService;
  20. use Customize\Service\LmAbstractService;
  21. use Lm\Engine\EC\Entity\CategoryWithRelated;
  22. use Lm\Entity\Goods;
  23. use Lm\Service\Cache\CacheService;
  24. use Lm\Service\Db\DbManager;
  25. use Lm\Service\Db\SqlService;
  26. use Customize\Service\LmHelper;
  27. use Eccube\Common\EccubeConfig;
  28. use Eccube\Service\TaxRuleService;
  29. class DynamicConverter extends LmAbstractService
  30. {
  31.     const TYPE_BASE_01 'base_01';            // 基本01-イメージ部分
  32.     const TYPE_WEARING_IMAGE_01 'wearing_image_01';    // 着用イメージ01
  33.     const TYPE_WEARING_IMAGE_02 'wearing_image_02';    // 着用イメージ02
  34.     const TYPE_WEARING_IMAGE_03 'wearing_image_03';    // 着用イメージ03
  35.     const TYPE_WEARING_IMAGE_04 'wearing_image_04';    // 着用イメージ04
  36.     const TYPE_MODEL_MENS 'model_mens';            // 10-モデル雰囲気・モデル前後(メンズ)
  37.     const TYPE_MODEL_LADIES 'model_ladies';        // 10-モデル雰囲気・モデル前後(レディース)
  38.     const TYPE_HANGER_ILLUST 'hanger_illust';        // 11-ハンガーイラスト前後
  39.     const TYPE_FABRIC 'fabric';                // 素材・機能について(複数)
  40.     const TYPE_UPPER 'upper';                // アッパー
  41.     const TYPE_MID_SOLE 'mid_sole';            // ミッドソール
  42.     const TYPE_OUT_SOLE 'out_sole';            // アウトソール
  43.     const TYPE_DETAIL_FRONT_BACK 'detail_front_back';    // こだわりPOINT(商品の平置き写真-前後)
  44.     const TYPE_DETAIL_COLUMN 'detail_column';        // こだわりPOINT(詳細写真2カラム・3カラム)(複数)
  45.     const TYPE_BASE_03 'base_03';            // 15-基本03-色展開
  46.     const TYPE_COLOR_VARIATION 'color_variation';    // 色展開(個別)
  47.     const TYPE_COLORUP 'colorup';            // カラーアップ
  48.     const TYPE_SIZE_SILHOUETTE 'size_silhouette';    // サイズシルエット
  49.     const TYPE_POCKET_SIZE_AREA 'pocket_size_area';    // ポケットサイズエリア
  50.     const TYPE_PRINT_AREA 'print_area';            // プリントエリア
  51.     const TYPE_SIZE_GUIDE 'size_guide';            // サイズガイド
  52.     const WEARING_IMAGE_MAX_COUNT 4;                        // 着用イメージの最大画像数
  53.     const DB_STATUS_TRUE 1;
  54.     const DB_STATUS_FALSE 0;
  55.     const CAMPAIGN_CATEGORY_LIST = [
  56.         'kucho-fuku',
  57.     ];
  58.     // Follow Up Model
  59.     const REPLY_OPTION_NO_REPLIED '0'// 未返信
  60.     const REPLY_OPTION_WAIT_ENTIRE '1'// A)全て待ちます
  61.     const REPLY_OPTION_WAIT_SEQUENTIAL '2'// B)揃ったものから順次発送してください
  62.     const REPLY_OPTION_CANCEL_DELAYED '3'// C)遅れた分だけキャンセルします
  63.     const REPLY_OPTION_CANCEL_ALL '4'// C)遅れた分だけキャンセルします
  64.     const REPLY_OPTION_ALTERNATIVE_DESIRED '5';
  65.     const REPLY_OPTION_LIST = [
  66.         self::REPLY_OPTION_NO_REPLIED => [
  67.             'id' => self::REPLY_OPTION_NO_REPLIED,
  68.             'text' => '未回答',
  69.             'value' => 'count_reply_no_replied',
  70.             'enabled' => false,
  71.             'linked' => false,
  72.         ],
  73.         self::REPLY_OPTION_WAIT_ENTIRE => [
  74.             'id' => self::REPLY_OPTION_WAIT_ENTIRE,
  75.             'text' => 'A)全て待ちます',
  76.             'value' => 'count_reply_wait_entire',
  77.             'enabled' => false,
  78.             'linked' => true,
  79.         ],
  80.         self::REPLY_OPTION_WAIT_SEQUENTIAL => [
  81.             'id' => self::REPLY_OPTION_WAIT_SEQUENTIAL,
  82.             'text' => 'A)在庫有り分のみ発送してください',
  83.             'value' => 'count_reply_wait_sequential',
  84.             'enabled' => true,
  85.             'linked' => true,
  86.         ],
  87.         self::REPLY_OPTION_CANCEL_DELAYED => [
  88.             'id' => self::REPLY_OPTION_CANCEL_DELAYED,
  89.             'text' => 'C)遅れた分だけキャンセルします',
  90.             'value' => 'count_reply_cancel_delayed',
  91.             'enabled' => false,
  92.             'linked' => true,
  93.         ],
  94.         self::REPLY_OPTION_CANCEL_ALL => [
  95.             'id' => self::REPLY_OPTION_CANCEL_ALL,
  96.             'text' => 'B)全てキャンセル',
  97.             'value' => 'count_reply_cancel_all',
  98.             'enabled' => true,
  99.             'linked' => true,
  100.         ],
  101.         self::REPLY_OPTION_ALTERNATIVE_DESIRED => [
  102.             'id' => self::REPLY_OPTION_ALTERNATIVE_DESIRED,
  103.             'text' => 'C)代替え商品(※色・サイズ希望をご返信下さい)',
  104.             'value' => 'count_reply_alternative_desired',
  105.             'enabled' => true,
  106.             'linked' => false,
  107.         ],
  108.     ];
  109.     const MEMO_FORMAT '%s【納期遅れ対応】%s';
  110.     private static $GROUP_CONCAT_SEPARATOR "%%__\t__%%";        // 画像説明やaltのテキストとして使用されてなさそうであればなんでもよい
  111.     public static $IMAGE_INFO_MAP = array(
  112.         // 基本01-イメージ部分
  113.         self::TYPE_BASE_01 => array(
  114.             'server_dir_name' => 'images',
  115.             'image_name' => '%s-images',
  116.         ),
  117.         // 着用イメージ部分1
  118.         self::TYPE_WEARING_IMAGE_01 => array(
  119.             'server_dir_name' => 'first-images',
  120.             'image_name' => '%s-first-images',
  121.         ),
  122.         // 着用イメージ部分2
  123.         self::TYPE_WEARING_IMAGE_02 => array(
  124.             'server_dir_name' => 'second-images',
  125.             'image_name' => '%s-second-images',
  126.         ),
  127.         // 着用イメージ部分3
  128.         self::TYPE_WEARING_IMAGE_03 => array(
  129.             'server_dir_name' => 'third-images',
  130.             'image_name' => '%s-third-images',
  131.         ),
  132.         // 着用イメージ部分4
  133.         self::TYPE_WEARING_IMAGE_04 => array(
  134.             'server_dir_name' => 'fourth-images',
  135.             'image_name' => '%s-fourth-images',
  136.         ),
  137.         // 10-モデル雰囲気・モデル前後(メンズ)
  138.         self::TYPE_MODEL_MENS => array(
  139.             'server_dir_name' => 'front-back',
  140.             'image_name' => '%s-mens-front-back',
  141.         ),
  142.         // 10-モデル雰囲気・モデル前後(レディース)
  143.         self::TYPE_MODEL_LADIES => array(
  144.             'server_dir_name' => 'front-back',
  145.             'image_name' => '%s-ladies-front-back',
  146.         ),
  147.         // 11-ハンガーイラスト前後
  148.         self::TYPE_HANGER_ILLUST => array(
  149.             'server_dir_name' => 'hanger-illust',
  150.             'image_name' => '%s-hanger-illust',
  151.         ),
  152.         // 素材・機能(複数枚)
  153.         self::TYPE_FABRIC => array(
  154.             'server_dir_name' => 'fabric',
  155.             'image_name' => '%s-fabric-%s',
  156.         ),
  157.         // アッパー
  158.         self::TYPE_UPPER => array(
  159.             'server_dir_name' => 'shoes-upper',
  160.             'image_name' => '%s-upper',
  161.         ),
  162.         // ミッドソール
  163.         self::TYPE_MID_SOLE => array(
  164.             'server_dir_name' => 'shoes-mid-sole',
  165.             'image_name' => '%s-mid-sole',
  166.         ),
  167.         // アウトソール
  168.         self::TYPE_OUT_SOLE => array(
  169.             'server_dir_name' => 'shoes-out-sole',
  170.             'image_name' => '%s-sole',
  171.         ),
  172.         // こだわりPOINT(商品の平置き写真-前後)
  173.         self::TYPE_DETAIL_FRONT_BACK => array(
  174.             'server_dir_name' => 'detail-front-back',
  175.             'image_name' => '%s-detail-front-back',
  176.         ),
  177.         // こだわりPOINT(詳細写真2カラム・3カラム) (複数枚)
  178.         self::TYPE_DETAIL_COLUMN => array(
  179.             'server_dir_name' => 'detail-column',
  180.             'image_name' => '%s-detail-column-%s',
  181.             'default_column_num' => 3
  182.         ),
  183.         // 15-基本03-色展開
  184.         self::TYPE_BASE_03 => array(
  185.             'server_dir_name' => 'color',
  186.             'image_name' => '%s-color',
  187.         ),
  188.         // 色展開(個別)
  189.         self::TYPE_COLOR_VARIATION => array(
  190.             'server_dir_name' => 'color-kobetsu',
  191.             'image_name' => '%s-color-%s',
  192.             'default_column_num' => 3
  193.         ),
  194.         // カラーUP
  195.         self::TYPE_COLORUP => array(
  196.             'server_dir_name' => 'colorup',
  197.             'image_name' => '%s-colorup',
  198.         ),
  199.         // サイズシルエット
  200.         self::TYPE_SIZE_SILHOUETTE => array(
  201.             'server_dir_name' => 'size-silhouette',
  202.             'image_name' => '%s-ladies-silhouette',
  203.         ),
  204.         // ポケットサイズエリア
  205.         self::TYPE_POCKET_SIZE_AREA => array(
  206.             'server_dir_name' => 'pocket-size',
  207.             'image_name' => '%s-pocket-size',
  208.         ),
  209.         // プリントエリア
  210.         self::TYPE_PRINT_AREA => array(
  211.             'server_dir_name' => 'printarea',
  212.             'image_name' => '%s-printarea',
  213.         ),
  214.         // サイズガイド
  215.         self::TYPE_SIZE_GUIDE => array(
  216.             'server_dir_name' => 'size-guide',
  217.             'image_name' => '%s-size-guide',
  218.         ),
  219.     );
  220.     /**
  221.      * @var SqlService $Sql
  222.      */
  223.     protected $Sql;
  224.     /**
  225.      * @var LmHelper
  226.      */
  227.     protected $lmHelper;
  228.     /**
  229.      * @var EccubeConfig
  230.      */
  231.     protected $eccubeConfig;
  232.     /**
  233.      * @var ProductConverter
  234.      */
  235.     private $ProductConverter;
  236.     /**
  237.      * @var DynamicConverterService
  238.      */
  239.     private $dynamicConverterService;
  240.     public function __construct(LmHelper                $lmHelper,
  241.                                 EccubeConfig            $eccubeConfig,
  242.                                 ProductConverter        $productConverter,
  243.                                 DynamicConverterService $dynamicConverterService)
  244.     {
  245.         //
  246.         parent::__construct(new CacheService());
  247.         //
  248.         $this->lmHelper $lmHelper;
  249.         $this->eccubeConfig $eccubeConfig;
  250.         $this->ProductConverter $productConverter;
  251.         $this->dynamicConverterService $dynamicConverterService;
  252.     }
  253.     /**
  254.      * FIXME: DELETE ME.
  255.      * @param int $goodsId
  256.      * @return array|null
  257.      */
  258.     public function getGoodsById($goodsId)
  259.     {
  260.         //
  261.         $result = (new SqlService())
  262.             ->Table('goods_table')
  263.             ->Set('goods_id'$goodsId)
  264.             ->Find();
  265.         //
  266.         return $result;
  267.     }
  268.     public function getRankingList()
  269.     {
  270.         $result = (new SqlService())
  271.             ->Table('daily_ranking_table')
  272.             ->Join('goods_table''T.goods_id = T1.goods_id''inner')
  273.             ->Select('T1.goods_id, T1.goods_name, ROUND(goods_price/ 1.08, 0) AS goods_price, ranking_no, T.goods_genre_text, create_date, update_date, COALESCE(T1.goods_canonical_hinban, T1.goods_id) AS item_id')
  274.             ->FindAll();
  275.         return $result;
  276.     }
  277.     public function getFbnrs($params = [])
  278.     {
  279.         //
  280.         if (!isset($params['type'])) {
  281.             $params $this->lmHelper->getPageType();
  282.         }
  283.         //
  284.         $siteType $this->eccubeConfig['LM_SITE_ID'];
  285.         $webName $params['value'];
  286.         //
  287.         return $this->dynamicConverterService->getFbnrs($params$siteType$webName);
  288.     }
  289.     public function getMessageCountByCategory()
  290.     {
  291.         $result = (new SqlService())
  292.             ->Table('customer_message_category_table')
  293.             ->Set('cmc_id'28'!=')
  294.             ->Set('delete'0)
  295.             ->Order('cmc_count''DESC')
  296.             ->Limit(5)
  297.             ->FindAll();
  298.         return $result;
  299.     }
  300.     public function getCommonContentsMap($site_type$device_type$is_not_super_category_id)
  301.     {
  302.         $result = (new SqlService())
  303.             ->Table('common_contents_table')
  304.             ->Join('main_category_table''T.super_category_id = T1.main_category_id''LEFT')
  305.             ->Set('site_type'$site_type)
  306.             ->Set('device_type'$device_type)
  307.             ->Select('T.*, T1.main_category_webname')
  308.             ->Limit(5)
  309.             ->FindAll();
  310.         $map = array();
  311.         if (isset($result)) {
  312.             foreach ($result as $row) {
  313.                 if ((int)$row['super_category_id'] === $is_not_super_category_id) {
  314.                     $map[$row['page_type']][$row['position']] = $row['contents'];
  315.                 } else {
  316.                     $map[$row['page_type']][$row['position']][$row['main_category_webname']] = $row['contents'];
  317.                 }
  318.             }
  319.         }
  320.         return $map;
  321.     }
  322.     public function getVisitSubCategoryList()
  323.     {
  324.         $result = (new SqlService())
  325.             ->Table('category_table')
  326.             ->Join('main_category_table''T.category_main_category = T1.main_category_id')
  327.             ->Set('T1.main_category_webname''visit')
  328.             ->Set('T.category_status'1)
  329.             ->Order('T.category_webname''DESC')
  330.             ->Limit(5)
  331.             ->FindAll();
  332.         return $result;
  333.     }
  334.     public function getGoodsVendingStatusList()
  335.     {
  336.         $result = (new SqlService())
  337.             ->Table('goods_table')
  338.             ->Set('goods_ddate'null)
  339.             ->Select('goods_id, goods_vending_status')
  340.             ->FindAll();
  341.         return $result;
  342.     }
  343.     public function getMessageList($select '*'$limit null$file null)
  344.     {
  345.         $query = (new SqlService())
  346.             ->Table('customer_message_table')
  347.             ->Select($select)
  348.             ->Set('cm_id'0'>')
  349.             ->Set('display'1)
  350.             ->Set('approval'1)
  351.             ->Order('cm_id''desc');
  352.         if (isset($file)) $query->Set('file''NOT NULL');
  353.         if (isset($limit)) $query->Limit($limit);
  354.         return $query->FindAll();
  355.     }
  356.     public function getTopicData()
  357.     {
  358.         $result = (new SqlService())
  359.             ->Table('topix_table')
  360.             ->Select("*, date_format( topix_cdate, '%Y/%m/%d' ) as cdate")
  361.             ->Order('topix_cdate''DESC')
  362.             ->Order('topix_display')
  363.             ->Limit(6)
  364.             ->FindAll();
  365.         return $result;
  366.     }
  367.     public function LM_get_koe_count()
  368.     {
  369.         $result = (new SqlService())
  370.             ->Table('customer_message_table')
  371.             ->Set('cm_id'0'>')
  372.             ->Set('display'1)
  373.             ->Set('approval'1)
  374.             ->Select('COUNT(*) as CNT')
  375.             ->FindAll();
  376.         if (sizeof($result) > 0) return $result[0]['CNT'];
  377.         return null;
  378.     }
  379.     public function getHolidayInfo($year$month$day$week$count)
  380.     {
  381.         $result = (new SqlService())
  382.             ->Table('holiday_calendar_table')
  383.             ->Where("holiday_year = 0 or holiday_year = {$year}")
  384.             ->Where("holiday_month = 0 or holiday_month = {$month}")
  385.             ->Where("holiday_day = 0 or holiday_day = {$day}")
  386.             ->Where("holiday_week = 0 or holiday_week = {$week}")
  387.             ->Where("holiday_count = 0 or holiday_count = {$count}")
  388.             ->Where("not ( holiday_year = 0 and holiday_month = 0 and holiday_day = 0 and holiday_count = 0 and holiday_week = 0 )")
  389.             ->Find();
  390.         return $result;
  391.     }
  392.     public function getMenuGroup($menu_group$bool_true 1)
  393.     {
  394.         $result = (new SqlService())
  395.             ->Table('sp_customized_menu_table')
  396.             ->Set('menu_group_name'$menu_group)
  397.             ->Set('is_active'$bool_true)
  398.             ->Where('main_category_id IS NULL')
  399.             ->Order('menu_id')
  400.             ->Limit(5)
  401.             ->FindAll();
  402.         if (empty($result)) return [];
  403.         return $this->buildMenu($result);
  404.     }
  405.     public function getMainCategoryMenu($main_category_webname)
  406.     {
  407.         $items = (new SqlService())
  408.             ->Sql('
  409.                 SELECT sp_customized_menu_table.*
  410.                 FROM sp_customized_menu_table
  411.                 JOIN main_category_table ON main_category_table.main_category_id = sp_customized_menu_table.main_category_id
  412.                 WHERE is_active = 1 AND menu_group_name = :menu_group_name AND main_category_webname = :main_category_webname
  413.                 ORDER BY menu_id
  414.             ')
  415.             ->Params([
  416.                 'menu_group_name' => $this->eccubeConfig['EditSpMenu']['MENU_NAME_CATEGORY'],
  417.                 'main_category_webname' => $main_category_webname
  418.             ])
  419.             ->FetchAll();
  420.         if (empty($items)) {
  421.             return [];
  422.         }
  423.         return $this->buildMenu($items);
  424.     }
  425.     public function getSearchWordGroup($word_group$bool_true 1)
  426.     {
  427.         $result = (new SqlService())
  428.             ->Table('sp_customized_frequently_searched_word_table')
  429.             ->Set('word_group_name'$word_group)
  430.             ->Where('main_category_id IS NULL')
  431.             ->Set('is_active'$bool_true)
  432.             ->Order('word_id')
  433.             ->Limit(5)
  434.             ->FindAll();
  435.         if (empty($result)) return [];
  436.         return $result;
  437.     }
  438.     private static function buildMenu($rows)
  439.     {
  440.         $menu = (object)[
  441.             'id' => 0,
  442.             'children' => []
  443.         ];
  444.         $parent_ref = &$menu;
  445.         $menu_map = [=> $menu];
  446.         $parent_id 0;
  447.         $current_indent 0;
  448.         foreach ($rows as &$row) {
  449.             $id = (int)$row['menu_id'];
  450.             $indent = (int)$row['indent'];
  451.             $menu_data = (object)[
  452.                 'id' => $id,
  453.                 'label' => $row['label'],
  454.                 'url' => $row['url'],
  455.                 'children' => [],
  456.                 'parent_id' => $parent_id
  457.             ];
  458.             $menu_map[$id] = $menu_data;
  459.             // 階層落ちる
  460.             if ($indent $current_indent) {
  461.                 $parent_ref = &$menu_map[$parent_id];
  462.                 $parent_ref->children[] = &$menu_map[$id];
  463.                 $parent_id $id;
  464.             } // 階層上がる
  465.             else if ($indent $current_indent) {
  466.                 // 3階層から1階層に上がることもあるので、ループで処理
  467.                 for ($i 0$i <= $current_indent $indent$i++) {
  468.                     $parent_id $menu_map[$parent_id]->parent_id;
  469.                 }
  470.                 $parent_ref = &$menu_map[$parent_id];
  471.                 $menu_map[$id]->parent_id $parent_ref->id;
  472.                 $parent_ref->children[] = &$menu_map[$id];
  473.                 $parent_id $id;
  474.             } // 階層変わらず
  475.             else {
  476.                 // 階層落ちの段階でparent_idが同階層のメニューになっているので1つ戻す
  477.                 // &$menu_map[$id]->parent_id = $menu_map[$parent_id]->parent_id;
  478.                 $menu_map[$id]->parent_id $menu_map[$parent_id]->parent_id;
  479.                 $parent_ref = &$menu_map[$menu_map[$parent_id]->parent_id];
  480.                 $parent_ref->children[] = &$menu_map[$id];
  481.                 $parent_id $id;
  482.             }
  483.             $current_indent $indent;
  484.         }
  485.         return $menu->children;
  486.     }
  487.     public function getPageContent($deviceName$pageName$contentName)
  488.     {
  489.         $result = (new SqlService())
  490.             ->Table('page_content_table')
  491.             ->Set('pc_site_type'1)
  492.             ->Set('pc_device_name'$deviceName)
  493.             ->Set('pc_page_name'$pageName)
  494.             ->Set('pc_content_name'$contentName)
  495.             ->Find();
  496.         return $result;
  497.     }
  498.     public function getUpperColumnByCategory($siteType null$webName null)
  499.     {
  500.         //
  501.         if ($siteType === null) {
  502.             $siteType $this->eccubeConfig['LM_SITE_ID'];
  503.         }
  504.         //
  505.         $query = (new SqlService())
  506.             ->Table('upper_column_table')
  507.             ->Set('site_type'$siteType);
  508.         if ($webName) {
  509.             $query->Join('main_category_table''T.target_category_id = T1.main_category_id''Left')
  510.                 ->Set('T1.main_category_has_main_categories'1)
  511.                 ->Set('T1.main_category_webname'$webName)
  512.                 ->Set('T1.main_category_status'1);
  513.         } else {
  514.             $query
  515.                 ->Set('target_category_id'null);
  516.         }
  517.         return $query->Select('upper_one_column_content')->Find();
  518.     }
  519.     public function getReview($id$isSecret true$main_category_id null$category_id null$limit ''$offset 0)
  520.     {
  521.         $SELECT = !empty($limit) ? "SELECT SQL_CALC_FOUND_ROWS" "SELECT";
  522.         $sql "$SELECT
  523.                 DISTINCT
  524.                 cr_oh_id
  525.                 ,cr_goods_id
  526.                 ,cr_customer_id
  527.                 ,cr_name
  528.                 ,cr_points
  529.                 ,cr_title
  530.                 ,cr_comment
  531.                 ,cr_staff_comment
  532.                 ,CASE cr_age
  533.                     WHEN '1' THEN '10代'
  534.                     WHEN '2' THEN '20代'
  535.                     WHEN '3' THEN '30代'
  536.                     WHEN '4' THEN '40代'
  537.                     WHEN '5' THEN '50代'
  538.                     WHEN '6' THEN '60代'
  539.                     ELSE '秘密'
  540.                  END cr_age
  541.                 ,CASE cr_sex
  542.                     WHEN '0' THEN '男性'
  543.                     WHEN '1' THEN '女性'
  544.                     ELSE '秘密'
  545.                  END cr_sex
  546.                 ,cr_approval
  547.                 ,app_datetime
  548.                 ,upd_datetime
  549.                 ,add_datetime
  550.                 ,goods_name
  551.                 ,(SELECT min(gp_kataban) FROM goods_price_table where cr_goods_id = gp_goods GROUP BY gp_goods) as gp_kataban
  552.                 FROM customer_review_table
  553.                 LEFT JOIN goods_table ON goods_id = cr_goods_id
  554.                 WHERE cr_approval = '1' AND cr_site_id = 0";
  555.         if (!empty($id) && empty($main_category_id)) {
  556.             // 商品ページのみに表示
  557.             $sql .= " AND cr_goods_id = {$id}
  558.                       AND cr_main_category_id = 0
  559.                       AND EXISTS (
  560.                         SELECT * FROM goods_table WHERE goods_id = {$id} AND goods_ddate IS NULL";
  561.             if (!$isSecret) {
  562.                 $sql .= " AND goods_status = 1 ";
  563.             }
  564.             $sql .= " )";
  565.         } else if (!empty($main_category_id) && empty($category_id)) {
  566.             // 親カテページのみに表示
  567.             $sql .= " AND cr_main_category_id = {$main_category_id}
  568.                       AND cr_category_id = 0";
  569.         } else if (!empty($main_category_id) && !empty($category_id)) {
  570.             // 子カテページのみに表示
  571.             $sql .= " AND cr_main_category_id = {$main_category_id}
  572.                       AND cr_category_id = '{$category_id}'";
  573.         }
  574.         $sql .= " ORDER BY `customer_review_table`.`app_datetime` desc";
  575.         if (!empty($limit)) {
  576.             // 商品ページのみに表示
  577.             $sql .= " LIMIT {$offset}{$limit}";
  578.         }
  579.         return (new SqlService())->Sql($sql)->FetchAll();
  580.     }
  581.     public function LM_displayteika_new($id$getOnlyTeika false)
  582.     {
  583.         $rs $this->getGoodsPriceSelect($id) ?? [];
  584.         $tmp_row 0;
  585.         $ma 0;
  586.         $mi 100;
  587.         $ma_kakaku 0;
  588.         $mi_kakaku 0;
  589.         $max_teika 0;
  590.         $min_teika 0;
  591.         $max_teika2 0;
  592.         $min_teika2 0;
  593.         $viewStr = array('teika' => null'off' => null);
  594.         foreach ($rs as $row) {
  595.             $tmp_row++;
  596.             if ($tmp_row == 1) {
  597.                 $ma_kakaku $row['gp_price'];
  598.                 $mi_kakaku $row['gp_price'];
  599.             } else {
  600.                 if ($ma_kakaku $row['gp_price'])
  601.                     $ma_kakaku $row['gp_price'];
  602.                 if ($mi_kakaku $row['gp_price'])
  603.                     $mi_kakaku $row['gp_price'];
  604.             }
  605.             $gp_teika round(intval($row['gp_teika']) / 1.10);
  606.             if ($max_teika2 $gp_teika) {
  607.                 $max_teika2 $gp_teika;
  608.                 $max_teika intval($row['gp_teika']);
  609.             }
  610.             if ($min_teika2 == or $min_teika2 $gp_teika) {
  611.                 $min_teika2 $gp_teika;
  612.                 $min_teika intval($row['gp_teika']);
  613.             }
  614.             if (intval($row['gp_teika']) > and intval($row['gp_price']) > 0) {
  615.                 $hikaku round(($row['gp_price'] / $row['gp_teika']) * 100);
  616.                 if ($ma $hikaku$ma $hikaku;
  617.                 if ($mi == or $mi $hikaku$mi $hikaku;
  618.             }
  619.             $sagaku[] = intval($row['gp_teika']) - $row['gp_price'];
  620.         }
  621.         if ($tmp_row 0) {
  622.             $teika "";
  623.             if ($min_teika != $max_teika and $max_teika and $min_teika 0) {
  624.                 $teika2 number_format($min_teika2) . "~" number_format($max_teika2);
  625.                 $teika number_format($min_teika) . "~" number_format($max_teika);
  626.                 $sagakuMsg "" number_format(max($sagaku));
  627.             } elseif ($min_teika == $max_teika) {
  628.                 $teika2 number_format($min_teika2);
  629.                 $teika number_format($min_teika);
  630.                 $sagakuMsg number_format(max($sagaku));
  631.             }
  632.             $per "";
  633.             if ($ma == $mi and $ma != 0) {
  634.                 $per $ma "%";
  635.             } elseif ($mi != and $ma != 0) {
  636.                 // $per = $mi . "~" . $ma . "%";
  637.                 $per "" $ma "%";
  638.             }
  639.             if (!empty($teika)) {
  640.                 if ($getOnlyTeika) {
  641.                     return $teika;
  642.                 }
  643.                 $viewStr['teika'] = '<span style="text-decoration: line-through;">' $teika '円&nbsp;(税抜価格' $teika2 '円)</span>&nbsp;&#8595;&nbsp;';
  644.             }
  645.             if ($teika != "" and $per != "") {
  646.                 $viewStr['off'] = $per "OFF";
  647.             }
  648.         }
  649.         return $viewStr;
  650.     }
  651.     public function getGoodsPriceJoinedByGoodsIdList($goodsIdList)
  652.     {
  653.         // just accept integer for id in $goodsIdList
  654.         $goodsIdList = (array)$goodsIdList;
  655.         foreach ($goodsIdList as $key => &$id) {
  656.             if ($id) {
  657.                 $id intval($id);
  658.             } else {
  659.                 // remove $id not avaiable like null and empty ''
  660.                 unset($goodsIdList[$key]);
  661.             }
  662.         }
  663.         // re - index array
  664.         $goodsIdList array_values($goodsIdList);
  665.         //
  666.         $goodsIdIn implode(',', (array)$goodsIdList);
  667.         //
  668.         $sql "SELECT
  669.                     goods_id
  670.                 ,    gp_kataban
  671.                 ,    gp_id
  672.                 ,    SUM(ROUND(`gp_teika` / 1.10)) AS `sum_teika_ex_tax`
  673.                 ,    SUM(`gp_teika`) AS `sum_teika_in_tax`
  674.                 ,    SUM(CASE WHEN cp_price IS NOT NULL AND cp_price > 0 THEN (truncate((cp_price/1.10) + .5,0)) ELSE (gp_price2) END) AS `sum_price_ex_tax`
  675.                 ,    SUM(CASE WHEN cp_price IS NOT NULL AND cp_price > 0 THEN (cp_price) ELSE (ROUND(gp_price2 * (1+ 10/100))) END) AS `sum_price_in_tax`
  676.                 ,    (NOW() BETWEEN MIN(`cp_start_datetime`) AND MAX(`cp_end_datetime`)) AS is_campaign
  677.                 ,    MIN(`cp_start_date`) AS `cp_start_date`
  678.                 ,    MAX(`cp_end_date`) AS `cp_end_date`
  679.                 ,    MIN(`cp_start_datetime`) AS `cp_start_datetime`
  680.                 ,    MAX(`cp_end_datetime`) AS `cp_end_datetime`
  681.                 FROM (
  682.                     SELECT
  683.                         IfNull(`parent_goods_id`, goods_id) AS `goods_id`
  684.                     ,    IfNull(`parent_goods_main_kataban`, gp_kataban) AS `gp_kataban`
  685.                     ,    gp_id
  686.                     ,    COALESCE(`gsp_gp_teika`, gp_teika) AS `gp_teika`
  687.                     ,    COALESCE(`gsp_gp_price2`, gp_price2) AS `gp_price2`
  688.                     ,    COALESCE(`gsp_cp_price`, cp_price) AS `cp_price`
  689.                     ,    COALESCE(`gsp_cp_start_date`, cp_start_date) AS `cp_start_date`
  690.                     ,    COALESCE(`gsp_cp_end_date`, cp_end_date) AS `cp_end_date`
  691.                     ,    COALESCE(`gsp_cp_start_datetime`, cp_start_datetime) AS `cp_start_datetime`
  692.                     ,    COALESCE(`gsp_cp_end_datetime`, cp_end_datetime) AS `cp_end_datetime`
  693.                     FROM (
  694.                         SELECT
  695.                             gp_goods AS `goods_id`
  696.                         ,    gp_kataban
  697.                         ,    gp_id
  698.                         ,    gp_teika
  699.                         ,    gp_price2
  700.                         ,    cp_price
  701.                         ,    cp_start_date
  702.                         ,    cp_end_date
  703.                         ,    cp_start_datetime
  704.                         ,    cp_end_datetime
  705.                         FROM goods_price_table
  706.                         LEFT JOIN campaign_price_table ON cp_gp = gp_id AND `cp_end_datetime` >= NOW() and `cp_start_datetime` <= NOW() and cp_del_flg = 0
  707.                         WHERE (gp_display != 99 OR gp_display IS NULL) AND gp_goods IN ({$goodsIdIn})
  708.                     ) AS `main_gp`
  709.                     LEFT JOIN (
  710.                         SELECT
  711.                             `parent`.goods_id AS `parent_goods_id`
  712.                         ,    `parent`.goods_main_kataban AS `parent_goods_main_kataban`
  713.                         ,    `parent_gp`.gp_id
  714.                         ,    `child_gp`.gp_teika AS `gsp_gp_teika`
  715.                         ,    `child_gp`.gp_price2 AS `gsp_gp_price2`
  716.                         ,    `child_cp`.cp_price AS `gsp_cp_price`
  717.                         ,    `child_cp`.cp_start_date AS `gsp_cp_start_date`
  718.                         ,    `child_cp`.cp_end_date AS `gsp_cp_end_date`
  719.                         ,    `child_cp`.cp_start_datetime AS `gsp_cp_start_datetime`
  720.                         ,    `child_cp`.cp_end_datetime AS `gsp_cp_end_datetime`
  721.                         FROM goods_table AS `parent`
  722.                         INNER JOIN goods_price_table AS `parent_gp` ON `parent`.goods_id = `parent_gp`.gp_goods
  723.                         INNER JOIN goods_set_purchase_table ON `parent`.goods_id = gsp_goods_parent
  724.                         INNER JOIN gsp_gp_table ON `parent_gp`.gp_id = gsp_gp_parent
  725.                         INNER JOIN goods_table AS `child` ON `child`.goods_id = gsp_goods_child
  726.                         INNER JOIN goods_price_table AS `child_gp` ON `child`.goods_id = `child_gp`.gp_goods AND `child_gp`.gp_id IN ( gsp_gp_main, gsp_gp_sub, gsp_gp_other )
  727.                         LEFT JOIN campaign_price_table AS `child_cp` ON `child_gp`.gp_id = `child_cp`.cp_gp AND `child_cp`.`cp_end_datetime` >= NOW() and `child_cp`.`cp_start_datetime` <= NOW() and `child_cp`.`cp_del_flg` =0
  728.                         WHERE `parent`.goods_id IN ({$goodsIdIn})
  729.                     ) AS `gsp_gp` USING (
  730.                         gp_id
  731.                     )
  732.                 ) AS `gp`
  733.                 GROUP BY
  734.                     `goods_id`
  735.                 ,    gp_id";
  736.         //
  737.         return $sql;
  738.     }
  739.     public function LM_displayPriceList3($data)
  740.     {
  741.         // コーディネート用デザインで使用
  742.         $viewStr '';
  743.         // 通常の場合のみ表示
  744.         if (!isset($data['tt_type']) or $data['tt_type'] == "1") {
  745.             $gp $this->getGoodsPriceJoinedByGoodsIdList($data);
  746.             $strSql "SELECT
  747.                 goods_id
  748.             ,    CONCAT('https://www.l-m.co.jp/item/', `goods_id`, '.html') AS `URL`
  749.             ,    MIN(`sum_price_ex_tax`) AS `gp_price`
  750.             ,    MIN(`sum_price_in_tax`) AS `mi`
  751.             ,    MAX(`sum_price_in_tax`) AS `ma`
  752.             ,    MAX(`is_campaign`) AS `is_campaign`
  753.             ,    MIN(`cp_start_datetime`) AS `cp_start_datetime`
  754.             ,    MAX(`cp_end_datetime`) AS `cp_end_datetime`
  755.             FROM (
  756.                 {$gp}
  757.             ) AS `g`
  758.             GROUP BY
  759.                 `goods_id`";
  760.             $row2 = (new SqlService())->Sql($strSql)->FetchAll();
  761.             if ($row2) {
  762.                 if ($row2[0]['mi'] == $row2[0]['ma']) {
  763.                     $viewStr .= number_format($row2[0]['mi']);
  764.                 } else {
  765.                     $viewStr .= number_format($row2[0]['mi']) . "~" number_format($row2[0]['ma']);
  766.                 }
  767.             }
  768.         }
  769.         //return $viewStr;
  770.         return $row2[0];
  771.     }
  772.     public function getGoodsPriceSelect($id)
  773.     {
  774.         $strSql "SELECT gp_teika,
  775.                     (CASE WHEN cp_price IS NOT NULL AND cp_price > 0 THEN truncate(cp_price + .5,0) ELSE ROUND(gp_price2 * (1+ 10/100)) END) as gp_price
  776.                     FROM jancode_table
  777.                     INNER JOIN  goods_price_table ON jan_price = gp_id
  778.                     INNER JOIN  size_table ON gp_size_id = size_id
  779.                     INNER JOIN  goods_color_table ON jan_color = gcl_id
  780.                     INNER JOIN  color_table ON gcl_color_id = color_id
  781.                     LEFT JOIN campaign_price_table ON cp_gp = gp_id AND `cp_end_datetime` >= NOW() and `cp_start_datetime` <= NOW() and cp_del_flg = 0
  782.                     WHERE jan_goods = :goods_id
  783.                     AND jan_ddate IS NULL
  784.                     AND gp_price IS NOT NULL
  785.                     AND gp_teika IS NOT NULL
  786.                     AND (gp_display != 99 OR gp_display IS NULL)
  787.                     GROUP BY cp_id,gp_id";
  788.         return (new SqlService())
  789.             ->Sql($strSql)
  790.             ->Params([
  791.                 'goods_id' => $id,
  792.             ])
  793.             ->FetchAll();
  794.     }
  795.     public function getSearchCoordinate($id)
  796.     {
  797.         $result = (new SqlService())
  798.             ->Table('goods_table')
  799.             ->Set('goods_id'$id)
  800.             ->Set('goods_design_coo''NOT NULL')
  801.             ->Select('goods_design_coo')
  802.             ->FindAll();
  803.         return $result;
  804.     }
  805.     public function getCoosData($goods_design_coo)
  806.     {
  807.         $result = (new SqlService())
  808.             ->Table('goods_table')
  809.             ->Set('goods_id'$goods_design_coo'IN')
  810.             ->Set('goods_status'Goods::GOODS_STATUS_AVAIABLE)
  811.             ->Set('goods_ddate''NULL')
  812.             ->Select("goods_id, goods_canonical_hinban, goods_name")
  813.             ->FindAll();
  814.         return $result;
  815.     }
  816.     public function getMainCategoryNameSelect($mcName)
  817.     {
  818.         $result = (new SqlService())
  819.             ->Table('main_category_table')
  820.             ->Join('category_group_table''T1.category_group_id = T.main_category_group''INNER')
  821.             ->Join('category_table''T.main_category_id = T2.category_main_category''LEFT')
  822.             ->Set('main_category_webname'$mcName)
  823.             ->Select("main_category_webname AS mc, T2.category_webname AS ct, main_category_id, T2.category_id, T1.category_group_noshowdb, T1.category_group_only_main, main_category_name, T2.category_name")
  824.             ->FindAll();
  825.         return $result;
  826.     }
  827.     public function getSubCategoryNameSelect($mcId$ctName)
  828.     {
  829.         $result = (new SqlService())
  830.             ->Table('main_category_table')
  831.             ->Join('category_table''T.main_category_id = T1.category_main_category''INNER')
  832.             ->Set('main_category_id'$mcId)
  833.             ->Set('T1.category_webname'$ctName)
  834.             ->Select("main_category_webname AS mc, T1.category_webname AS ct, main_category_id, T1.category_id")
  835.             ->FindAll();
  836.         return $result;
  837.     }
  838.     public function getPopularityItemLIstByMainCategoryId2($mcId$isSecret false$limit 30$offset 0)
  839.     {
  840.         // DBからデータ取得
  841.         $sql "select goods_id, goods_canonical_hinban, goods_recommend, goods_name, goods_sub_name, goods_caption, goods_display, goods_cdate, goods_udate, min( gp_price2 ) as price, min( gp_kataban ) as kataban, NULL AS category_id, COALESCE(cra_average_points,0) as average, cra_target_count as review_count
  842.                 from goods_table
  843.                 inner join goods_main_category_table on gmc_goods = goods_id
  844.                 inner join main_category_table on main_category_id = gmc_main_category
  845.                 inner join category_group_table on category_group_id = main_category_group AND category_group_only_main = 1
  846.                 left join goods_price_table on goods_id = gp_goods
  847.                 left join rank_table on goods_id = rank_goods
  848.                 left join customer_review_average_table on cra_goods_id = goods_id
  849.                 where goods_ddate is null AND main_category_id = {$mcId}";
  850.         if (!$isSecret) {
  851.             $sql .= " AND goods_status = 1 ";
  852.         }
  853.         $sql .= "
  854.                 group by rank_money, goods_id, goods_recommend, goods_name, goods_caption, goods_display, goods_cdate, goods_udate
  855.                 order by isnull( rank_money ), rank_money DESC, goods_recommend desc, price, isnull( goods_display ), goods_display, goods_udate desc, goods_cdate desc limit {$limit} offset {$offset}";
  856.         $tempRow = (new SqlService())->Sql($sql)->FetchAll();
  857.         $item = array();
  858.         if (isset($tempRow)) {
  859.             foreach ($tempRow as $row) {
  860.                 $item[] = $row;
  861.             }
  862.         }
  863.         return $item;
  864.     }
  865.     public function getSearchAllCategory($mc)
  866.     {
  867.         return (new SqlService())->Sql("SELECT *, '全商品' AS category_name, 'allitem' AS category_id FROM front_main_category_table WHERE main_category_id = '{$mc}'")->FetchAll();
  868.     }
  869.     public function getSearchGoodsImage($mc$ct)
  870.     {
  871.         $result = (new SqlService())
  872.             ->Table('front_main_category_table')
  873.             ->Join('front_category_table''T1.category_main_category = T.main_category_id')
  874.             ->Set('main_category_id'$mc)
  875.             ->Set('T1.category_id'$ct)
  876.             ->FindAll();
  877.         return $result;
  878.     }
  879.     public function getSearchCategory($mc)
  880.     {
  881.         return (new SqlService())
  882.             ->Table('front_main_category_table')
  883.             ->Set('main_category_id'$mc)
  884.             ->FindAll();
  885.     }
  886.     public function getGoodsKatabanSelect($id)
  887.     {
  888.         $query "SELECT DISTINCT gp_kataban FROM goods_price_table WHERE gp_goods = :goods_id AND NOT(gp_display <=> 99) LIMIT 0,3";
  889.         $rows = (new SqlService())->Sql($query)
  890.             ->Param('goods_id'$id)
  891.             ->FetchAll();
  892.         return $rows;
  893.     }
  894.     public function getGoodsColorSelect($id)
  895.     {
  896.         $strSql "SELECT
  897.                         *
  898.                     FROM (
  899.                         SELECT
  900.                             COALESCE(`gcl_parent`.gcl_id, `gcl_child`.gcl_id) AS `gcl_id`
  901.                         ,   COALESCE(`gcl_parent`.gcl_display, `gcl_child`.gcl_display) AS `gcl_display`
  902.                         ,   COALESCE(`color_parent`.color_id, `color_child`.color_id) AS `color_id`
  903.                         ,   COALESCE(`color_parent`.color_display, `color_child`.color_display) AS `color_display`
  904.                         ,   COALESCE(`color_parent`.color_name, `color_child`.color_name) AS `color_name`
  905.                         ,   COALESCE(`color_parent`.color_rgb, `color_child`.color_rgb) AS `color_rgb`
  906.                         FROM goods_table AS `parent`
  907.                         LEFT JOIN goods_color_table AS `gcl_parent` ON `parent`.goods_id = `gcl_parent`.gcl_goods AND `gcl_parent`.gcl_display_status = 1
  908.                         LEFT JOIN color_table AS `color_parent` ON `color_parent`.color_id = `gcl_parent`.gcl_color_id
  909.                         LEFT JOIN goods_set_purchase_table ON `parent`.goods_id = gsp_goods_parent AND gsp_type = 0
  910.                         LEFT JOIN goods_table AS `child` ON `child`.goods_id = gsp_goods_child
  911.                         LEFT JOIN goods_color_table AS `gcl_child` ON `child`.goods_id = `gcl_child`.gcl_goods AND `gcl_child`.gcl_display_status = 1 and `gcl_child`.gcl_color_id = `gcl_parent`.gcl_color_id
  912.                         LEFT JOIN color_table AS `color_child` ON `color_child`.color_id = `gcl_child`.gcl_color_id
  913.                         WHERE `parent`.goods_id = {$id}
  914.                     ) AS `goods`
  915.                     ORDER BY
  916.                         gcl_display
  917.                     ,   color_display
  918.                     ,   CAST( color_name AS binary )";
  919.         return (new SqlService())->Sql($strSql)->FetchAll();
  920.     }
  921.     public function getStockList($id)
  922.     {
  923.         $sql "SELECT gcl_id, gp_id, stock.stock, stock.jan_stock3, stock.jan_stock3_nyuka_date, stock.jan_stock4, stock.jan_stock5, stock.jan_stock6, stock.jan_stock7, stock.jan_stock8, stock.jan_stock9, stock.nodisp, stock.jan_color, stock.jan_price, ki_id IS NOT NULL AS keppin
  924.                     FROM goods_color_table
  925.                     INNER JOIN color_table ON gcl_color_id = color_id
  926.                     INNER JOIN (
  927.                         SELECT gp_goods, gp_id,
  928.                         (CASE WHEN cp_price IS NOT NULL AND cp_price > 0 THEN truncate((cp_price/1.10) + .5,0) ELSE gp_price2 END) as gp_price
  929.                         FROM goods_price_table
  930.                         INNER JOIN size_table ON gp_size_id = size_id
  931.                         LEFT JOIN campaign_price_table ON cp_gp = gp_id AND `cp_end_datetime` >= NOW() and `cp_start_datetime` <= NOW() and cp_del_flg =0
  932.                         WHERE gp_goods = {$id}
  933.                         AND ( gp_display IS NULL OR ( gp_display IS NOT NULL AND gp_display != 99 ) )
  934.                     ) AS size ON gcl_goods = gp_goods
  935.                     INNER JOIN (
  936.                         SELECT jan_goods, jan_color, jan_price, coalesce( jan_stock, '*' ) AS stock, jan_stock3, jan_stock3_nyuka_date, jan_stock4, jan_stock5, jan_stock6, jan_stock7, jan_stock8, jan_stock9, jan_nodisplay AS nodisp
  937.                         FROM jancode_table
  938.                         WHERE jan_goods = {$id}
  939.                     ) AS stock ON jan_goods = gcl_goods AND jan_color = gcl_id AND jan_price = gp_id
  940.                     LEFT JOIN (
  941.                         SELECT ki_id, ki_goods, ki_gcl, ki_gp, MAX(ki_id) AS max_ki_id
  942.                         FROM keppin_item_table AS ki
  943.                         INNER JOIN (
  944.                             SELECT MAX(ki_id) AS max_ki_id
  945.                             FROM keppin_item_table
  946.                             WHERE ki_goods = {$id} AND ki_date >= '" date('Y-m-d 00:00:00') . "'
  947.                             GROUP BY ki_goods, ki_gcl, ki_gp
  948.                         ) AS max_ki ON ki_id = max_ki_id
  949.                     ) AS max_ki ON ki_goods = gcl_goods AND (ki_gcl IS NULL OR ki_gcl = gcl_id) AND (ki_gp IS NULL AND ki_gp = gp_id)
  950.                     WHERE gcl_goods = {$id}
  951.                     AND gcl_display_status = 1
  952.                     ORDER BY gcl_display, color_display, CAST( color_name AS binary )";
  953.         return (new SqlService())->Sql($sql)->FetchAll();
  954.     }
  955.     public function LM_chokusouCheck($goodsId$gcl ""$gp "")
  956.     {
  957.         #2022/09/08 chkPass初期化
  958.         $chkPass 0;
  959.         $data $this->getShiiresakiGoodsData2($goodsId$gcl$gp);
  960.         $goods $data[0] ?? null;
  961.         if (isset($goods) && ($goods['goods_shiiresaki'] == "" or $goods['gp_kataban'] == "" or $goods['jan_shiire_no'] == "")) {
  962.             //セット品番か確認
  963.             $data $this->getShiiresakiGoodsData3($goodsId);
  964.             $goods $data[0] ?? null;
  965.             if (isset($goods) && $goods['goods_shiiresaki'] != "") {
  966.                 // 直送確認
  967.                 $directData $this->getShiiresakiDirectDeliveryData($goods['goods_shiiresaki']);
  968.                 if ($directData[0]['dd_shiiresaki'] == $goods['goods_shiiresaki'] && $directData[0]['dd_hinban_chokusou'] == "" && $directData[0]['dd_hinban_exclude'] == "" && $directData[0]['dd_hinban_bichiku'] == "") {
  969.                     return 1;
  970.                 }
  971.             }
  972.             return 2;
  973.         }
  974.         // 直送確認
  975.         $directData $this->getShiiresakiDirectDeliveryData($goods['goods_shiiresaki']);
  976.         if (empty($directData)) {
  977.             return 2;
  978.         }
  979.         // 仕入先品番
  980.         $shiireno mb_ereg_replace('[^a-zA-Z]'''$goods['jan_shiire_no']);
  981.         //直送除外品番(LM品番)
  982.         if ($directData[0]['dd_hinban_exclude'] != "") {
  983.             $chkKey1 explode(","$directData[0]['dd_hinban_exclude']);
  984.             for ($i 0$i count($chkKey1); $i++) {
  985.                 if ($goods['gp_kataban'] == $chkKey1[$i]) {
  986.                     return 2;
  987.                 }
  988.             }
  989.         }
  990.         $chkPass "";
  991.         //備蓄対象品番(LM品番)
  992.         if ($directData[0]['dd_hinban_bichiku'] != "") {
  993.             $chkKey1 explode(","$directData[0]['dd_hinban_bichiku']);
  994.             $chkPass 2;
  995.             for ($i 0$i count($chkKey1); $i++) {
  996.                 if ($goods['gp_kataban'] == $chkKey1[$i]) {
  997.                     $chkPass 1;
  998.                     break;
  999.                 }
  1000.             }
  1001.         }
  1002.         //直送対象品番(該当アルファベット)
  1003.         $soukoData $this->getShiiresakiSoukoData($goods['goods_shiiresaki']);
  1004.         if (isset($soukoData)) {
  1005.             if ($chkPass != && $soukoData[0]['shiiresaki_souko_hantei'] != "") {
  1006.                 $chkPass 2;
  1007.                 $chkKey2 explode(","$soukoData[0]['shiiresaki_souko_hantei']);
  1008.                 for ($i 0$i count($chkKey2); $i++) {
  1009.                     if ($shiireno == $chkKey2[$i]) {
  1010.                         $chkPass 1;
  1011.                         break;
  1012.                     }
  1013.                 }
  1014.             }
  1015.         }
  1016.         //直送対象品番(LM品番)
  1017.         if ($chkPass != && $directData[0]['dd_hinban_chokusou'] != "") {
  1018.             $chkPass 2;
  1019.             $chkKey1 explode(","$directData[0]['dd_hinban_chokusou']);
  1020.             for ($i 0$i count($chkKey1); $i++) {
  1021.                 if ($goods['gp_kataban'] == $chkKey1[$i]) {
  1022.                     $chkPass 1;
  1023.                     break;
  1024.                 }
  1025.             }
  1026.         }
  1027.         //備蓄在庫数登録
  1028.         if ($goods['jan_stock8_max'] > 0) {
  1029.             $chkPass 1;
  1030.         } else if ($goods['jan_stock8_max'] !== null && !empty($goods['same_day_available'])) {
  1031.             // 2020-04-06 worker_g: チトセより一部SKUの買取り在庫の対応。
  1032.             // ・84-MZ0018
  1033.             // ・84-MZ0019
  1034.             // ・84-MZ0092
  1035.             // ・84-MZ0093
  1036.             $chkPass 1;
  1037.         }
  1038.         //外部在庫数
  1039.         if ($goods['jan_stock9_max'] > 0) {
  1040.             $chkPass 1;
  1041.         }
  1042.         if ($chkPass == "") {
  1043.             $chkPass 1;
  1044.         }
  1045.         // chkPass=1なら直送対象
  1046.         return $chkPass;
  1047.     }
  1048.     public function getShiiresakiGoodsData2($goods$gcl$gp)
  1049.     {
  1050.         $strSql "SELECT goods_shiiresaki, gp_kataban, jan_shiire_no
  1051.             , MAX(jan_stock8) AS jan_stock8_max
  1052.             , MAX(jan_stock9) AS jan_stock9_max
  1053.             , MAX(jan_stock3 > 1 && IfNull(jan_stock3_nyuka_date, '0000-00-00') < NOW()) AS same_day_available
  1054.             FROM jancode_table
  1055.             INNER JOIN goods_table ON goods_id = jan_goods
  1056.             INNER JOIN goods_price_table ON goods_id = gp_goods AND gp_id = jan_price
  1057.             WHERE goods_id = {$goods} AND jan_ddate IS NULL";
  1058.         if ($gcl != "" and $gp != "") {
  1059.             $strSql .= " AND jan_color = " $gcl " AND jan_price = " $gp " ";
  1060.             $strSql .= " GROUP BY gp_id";
  1061.         } else {
  1062.             $strSql .= " GROUP BY goods_id";
  1063.         }
  1064.         return (new SqlService())->Sql($strSql)->FetchAll();
  1065.     }
  1066.     public function getShiiresakiGoodsData3($id)
  1067.     {
  1068.         return (new SqlService())
  1069.             ->Table('goods_table')
  1070.             ->Set('goods_id'$id)
  1071.             ->Set('goods_set_purchase_flg'1)
  1072.             ->Select('goods_shiiresaki')
  1073.             ->FindAll();
  1074.     }
  1075.     public function getShiiresakiDirectDeliveryData($shiiresaki)
  1076.     {
  1077.         return (new SqlService())
  1078.             ->Table('direct_delivery_table')
  1079.             ->Set('dd_shiiresaki'$shiiresaki)
  1080.             ->Where('dd_ddate IS NULL')
  1081.             ->FindAll();
  1082.     }
  1083.     public function getShiiresakiSoukoData($shiiresaki)
  1084.     {
  1085.         $strSql "SELECT shiiresaki_souko_hantei,shiiresaki_souko_hinban,shiiresaki_souko2_hantei,shiiresaki_souko2_hinban,DATE_FORMAT( shiiresaki_shimekiri_time, '%H%i' ) AS stime FROM shiiresaki_table WHERE (shiiresaki_souko_hantei is not null OR shiiresaki_souko_hinban is not null OR shiiresaki_souko2_hantei is not null OR shiiresaki_souko2_hinban is not null ) AND shiiresaki_id = " $shiiresaki;
  1086.         return (new SqlService())->Sql($strSql)->FetchAll();
  1087.     }
  1088.     // 商品メイン画像
  1089.     public function getGoodsImage($id$title null)
  1090.     {
  1091.         $dir substr($id, -1);
  1092.         $goodsDir "/goods.img/{$dir}/{$id}/";
  1093.         $image = [];
  1094.         $tmpBigUrl $goodsDir "main.jpg";
  1095.         $tmpMinUrl $goodsDir "main_45x45.jpg";
  1096.         $tmpCom "";
  1097.         if (!empty($title)) {
  1098.             $tmpCom str_replace(array("\r\n""\n""\r"), ''strip_tags($title));
  1099.             $tmpCom mb_substr($tmpCom020"UTF-8");
  1100.         }
  1101.         $image = [$tmpBigUrl$tmpMinUrl$tmpCom];
  1102.         return $image;
  1103.     }
  1104.     // 非営業日判定(Y-m-d形式)
  1105.     public function getIsHoliday($date null)
  1106.     {
  1107.         if (is_null($date)) $date date('Y-m-d');
  1108.         // DBには日曜が1、土曜が7として登録されているので1足す
  1109.         $wday = (int)date('w'strtotime($date)) + 1;
  1110.         list($year$month$day) = explode('-'$date);
  1111.         $sql "select
  1112.                     *
  1113.                 from
  1114.                     holiday_calendar_table
  1115.                 where
  1116.                     holiday_week = {$wday} or
  1117.                     (holiday_year = {$year} and holiday_month = {$month} and holiday_day = {$day})
  1118.         ";
  1119.         return (new SqlService())->Sql($sql)->FetchAll();
  1120.     }
  1121.     public function sqlGspMain($parent_id)
  1122.     {
  1123.         $sql "SELECT
  1124.                     gsp_goods_parent, gsp_type, gsp_name, gsp_show_flg, `child`.goods_id, `child`.goods_name, gp_child.gp_id, gp_child.gp_display,gp_child.gp_kataban, gp_child.gp_price, ROUND(MIN(cp_price)) AS cp_price, COALESCE(ROUND(MIN(cp_price)), gp_child.gp_price) AS price, size_id, size_name, size_display, gcl_id, gcl_display, color_id, color_display, color_name, color_rgb, jan_id, jan_shiire_no, jan_stock, jan_stock2, jan_stock3, jan_stock3_nyuka_date, jan_stock4, jan_stock5, IfNull(jan_stock, 0) + IfNull(jan_stock2, 0) + IfNull(jan_stock3, 0) + IfNull(jan_stock4, 0) + IfNull(jan_stock5, 0) as stock, jan_nodisplay, ki_comment, ki_date, zero_period, DATE_FORMAT(COALESCE(DATE_ADD(zero_period, INTERVAL 1 DAY), ki_date), '%c月%e日') AS zdate, COALESCE(ki_date, zero_period) AS nyuuka_yoteibi
  1125.                 ,    (
  1126.                         IfNull(MAX(jan_stock3), 0) > 0
  1127.                     AND IfNull(MAX(jan_stock3_nyuka_date), '0000-00-00') < NOW()
  1128.                     ) AS `chokusou_flg`
  1129.                 FROM goods_table AS `parent`
  1130.                 INNER JOIN goods_set_purchase_table ON `parent`.goods_id = gsp_goods_parent
  1131.                 INNER JOIN goods_table AS `child` ON `child`.goods_id = gsp_goods_child
  1132.                 INNER JOIN goods_price_table AS gp_child ON `child`.goods_id = gp_child.gp_goods AND gp_child.gp_display != 99
  1133.                 INNER JOIN size_table ON size_id = gp_child.gp_size_id
  1134.                 INNER JOIN goods_color_table ON `child`.goods_id = gcl_goods AND gcl_display_status = 1
  1135.                 INNER JOIN color_table ON color_id = gcl_color_id
  1136.                 INNER JOIN jancode_table ON `child`.goods_id = jan_goods AND gcl_id = jan_color AND gp_child.gp_id = jan_price
  1137.                 LEFT JOIN campaign_price_table ON gp_child.gp_id = cp_gp AND cp_end_datetime >= NOW() and cp_start_datetime <= NOW() AND cp_price > 0
  1138.                 LEFT JOIN keppin_item_table ON `child`.goods_id = ki_goods AND gcl_id = ki_gcl AND gp_id = ki_gp AND ki_date > NOW()
  1139.                 LEFT JOIN zero_stock_table ON gcl_id = zero_gcl AND gp_id = zero_gp AND zero_period > NOW()
  1140.                 WHERE `parent`.goods_id = {$parent_id}
  1141.                 AND gsp_type = 0
  1142.                 GROUP BY gsp_goods_parent, gsp_type, `child`.goods_id, size_id, color_id
  1143.                 ORDER BY gsp_goods_parent, gsp_type, `child`.goods_id, size_id, color_id";
  1144.         return $sql;
  1145.     }
  1146.     public function sqlGspSub($parent_id)
  1147.     {
  1148.         $sql "SELECT
  1149.                     gsp_goods_parent, gsp_type, gsp_name, gsp_show_flg, `child`.goods_id, `child`.goods_name, gp_child.gp_id, gp_child.gp_display,gp_child.gp_kataban, gp_child.gp_price, ROUND(MIN(cp_price)) AS cp_price, COALESCE(ROUND(MIN(cp_price)), gp_child.gp_price) AS price, size_id, size_name, size_display, gcl_id, gcl_display, color_id, color_display, color_name, color_rgb, jan_id, jan_shiire_no, jan_stock, jan_stock2, jan_stock3, jan_stock3_nyuka_date, jan_stock4, jan_stock5, IfNull(jan_stock, 0) + IfNull(jan_stock2, 0) + IfNull(jan_stock3, 0) + IfNull(jan_stock4, 0) + IfNull(jan_stock5, 0) as stock, jan_nodisplay, ki_comment, ki_date, zero_period, DATE_FORMAT(COALESCE(DATE_ADD(zero_period, INTERVAL 1 DAY), ki_date), '%c月%e日') AS zdate, COALESCE(ki_date, zero_period) AS nyuuka_yoteibi
  1150.                 ,    (
  1151.                         IfNull(MAX(jan_stock3), 0) > 0
  1152.                     AND IfNull(MAX(jan_stock3_nyuka_date), '0000-00-00') < NOW()
  1153.                     ) AS `chokusou_flg`
  1154.                 FROM goods_table AS `parent`
  1155.                 INNER JOIN goods_set_purchase_table ON `parent`.goods_id = gsp_goods_parent
  1156.                 INNER JOIN goods_table AS `child` ON `child`.goods_id = gsp_goods_child
  1157.                 INNER JOIN goods_price_table AS gp_child ON `child`.goods_id = gp_child.gp_goods AND gp_child.gp_display != 99
  1158.                 INNER JOIN size_table ON size_id = gp_child.gp_size_id
  1159.                 INNER JOIN goods_color_table ON `child`.goods_id = gcl_goods AND gcl_display_status = 1
  1160.                 INNER JOIN color_table ON color_id = gcl_color_id
  1161.                 INNER JOIN jancode_table ON `child`.goods_id = jan_goods AND gcl_id = jan_color AND gp_child.gp_id = jan_price
  1162.                 LEFT JOIN campaign_price_table ON gp_child.gp_id = cp_gp AND cp_end_datetime >= NOW() and cp_start_datetime <= NOW() AND cp_price > 0
  1163.                 LEFT JOIN keppin_item_table ON `child`.goods_id = ki_goods AND gcl_id = ki_gcl AND gp_id = ki_gp AND ki_date > NOW()
  1164.                 LEFT JOIN zero_stock_table ON gcl_id = zero_gcl AND gp_id = zero_gp AND zero_period > NOW()
  1165.                 WHERE `parent`.goods_id = {$parent_id}
  1166.                 AND gsp_type = 10
  1167.                 GROUP BY gsp_goods_parent, gsp_type, `child`.goods_id, size_id, color_id
  1168.                 ORDER BY gsp_goods_parent, gsp_type, `child`.goods_id, size_id, color_id";
  1169.         return $sql;
  1170.     }
  1171.     public function sqlGspOther($parent_id)
  1172.     {
  1173.         $sql "SELECT
  1174.                     gsp_goods_parent, gsp_type, gsp_name, gsp_show_flg, `child`.goods_id, `child`.goods_name, gp_child.gp_id, gp_child.gp_display,gp_child.gp_kataban, gp_child.gp_price, ROUND(MIN(cp_price)) AS cp_price, COALESCE(ROUND(MIN(cp_price)), gp_child.gp_price) AS price, size_id, size_name, size_display, gcl_id, gcl_display, color_id, color_display, color_name, color_rgb, jan_id, jan_shiire_no, jan_stock, jan_stock2, jan_stock3, jan_stock3_nyuka_date, jan_stock4, jan_stock5, IfNull(jan_stock, 0) + IfNull(jan_stock2, 0) + IfNull(jan_stock3, 0) + IfNull(jan_stock4, 0) + IfNull(jan_stock5, 0) as stock, jan_nodisplay, ki_comment, ki_date, zero_period, DATE_FORMAT(COALESCE(DATE_ADD(zero_period, INTERVAL 1 DAY), ki_date), '%c月%e日') AS zdate, COALESCE(ki_date, zero_period) AS nyuuka_yoteibi
  1175.                 ,    (
  1176.                         IfNull(MAX(jan_stock3), 0) > 0
  1177.                     AND IfNull(MAX(jan_stock3_nyuka_date), '0000-00-00') < NOW()
  1178.                     ) AS `chokusou_flg`
  1179.                 FROM goods_table AS `parent`
  1180.                 INNER JOIN goods_set_purchase_table ON `parent`.goods_id = gsp_goods_parent
  1181.                 INNER JOIN goods_table AS `child` ON `child`.goods_id = gsp_goods_child
  1182.                 INNER JOIN goods_price_table AS gp_child ON `child`.goods_id = gp_child.gp_goods AND gp_child.gp_display != 99
  1183.                 INNER JOIN size_table ON size_id = gp_child.gp_size_id
  1184.                 INNER JOIN goods_color_table ON `child`.goods_id = gcl_goods AND gcl_display_status = 1
  1185.                 INNER JOIN color_table ON color_id = gcl_color_id
  1186.                 INNER JOIN jancode_table ON `child`.goods_id = jan_goods AND gcl_id = jan_color AND gp_child.gp_id = jan_price
  1187.                 LEFT JOIN campaign_price_table ON gp_child.gp_id = cp_gp AND cp_end_datetime >= NOW() and cp_start_datetime <= NOW() AND cp_price > 0
  1188.                 LEFT JOIN keppin_item_table ON `child`.goods_id = ki_goods AND gcl_id = ki_gcl AND gp_id = ki_gp AND ki_date > NOW()
  1189.                 LEFT JOIN zero_stock_table ON gcl_id = zero_gcl AND gp_id = zero_gp AND zero_period > NOW()
  1190.                 WHERE `parent`.goods_id = {$parent_id}
  1191.                 AND gsp_type NOT IN ( 0, 10 )
  1192.                 GROUP BY gsp_goods_parent, gsp_type, `child`.goods_id, size_id, color_id
  1193.                 ORDER BY gsp_goods_parent, gsp_type, `child`.goods_id, size_id, color_id";
  1194.         return $sql;
  1195.     }
  1196.     public function sqlGsp($parent_id)
  1197.     {
  1198.         $sqlGspMain $this->sqlGspMain($parent_id);
  1199.         $sqlGspSub $this->sqlGspSub($parent_id);
  1200.         $sqlGspOther $this->sqlGspOther($parent_id);
  1201.         $sql "SELECT
  1202.                     goods_parent.goods_id AS parent_goods_id
  1203.                 ,    goods_parent.goods_name AS parent_goods_name
  1204.                 ,    gp.gp_kataban AS parent_kataban
  1205.                 ,    gsp_main.gsp_type AS main_gsp_type
  1206.                 ,    gsp_main.gsp_name AS main_gsp_name
  1207.                 ,    gsp_main.gsp_show_flg AS main_gsp_show_flg
  1208.                 ,    gsp_main.goods_id AS main_goods_id
  1209.                 ,    gsp_main.goods_name AS main_goods_name
  1210.                 ,    gsp_main.gp_kataban AS main_kataban
  1211.                 ,    gsp_main.gp_price AS main_gp_price
  1212.                 ,    gsp_main.cp_price AS main_cp_price
  1213.                 ,    gsp_main.price AS main_price
  1214.                 ,    gsp_main.jan_id AS main_jan_id
  1215.                 ,    gsp_main.gcl_id AS main_gcl_id
  1216.                 ,    gsp_main.gcl_display AS main_gcl_display
  1217.                 ,    gsp_main.gp_id AS main_gp_id
  1218.                 ,    gsp_main.gp_display AS main_gp_display
  1219.                 ,    gsp_main.color_id AS main_color_id
  1220.                 ,    gsp_main.color_display AS main_color_display
  1221.                 ,    gsp_main.color_name AS main_color_name
  1222.                 ,    gsp_main.color_rgb AS main_color_rgb
  1223.                 ,    gsp_main.size_id AS main_size_id
  1224.                 ,    gsp_main.size_name AS main_size_name
  1225.                 ,    gsp_main.size_display AS main_size_display
  1226.                 ,    gsp_main.stock AS main_stock
  1227.                 ,    gsp_main.jan_stock3 AS main_stock3
  1228.                 ,    gsp_main.jan_stock3_nyuka_date AS main_stock3_nyuka_date
  1229.                 ,    gsp_main.`chokusou_flg` AS main_chokusou_flg
  1230.                 ,    gsp_main.jan_nodisplay AS main_nodisp
  1231.                 ,    gsp_main.ki_comment AS main_ki_comment
  1232.                 ,    gsp_main.ki_date AS main_ki_date
  1233.                 ,    gsp_main.zero_period AS main_zero_period
  1234.                 ,    gsp_main.zdate AS main_zdate
  1235.                 ,    gsp_main.nyuuka_yoteibi AS main_nyuuka_yoteibi
  1236.                 ,    gsp_sub.gsp_type AS sub_gsp_type
  1237.                 ,    gsp_sub.gsp_name AS sub_gsp_name
  1238.                 ,    gsp_sub.gsp_show_flg AS sub_gsp_show_flg
  1239.                 ,    gsp_sub.goods_id AS sub_goods_id
  1240.                 ,    gsp_sub.goods_name AS sub_goods_name
  1241.                 ,    gsp_sub.gp_kataban AS sub_kataban
  1242.                 ,    gsp_sub.gp_price AS sub_gp_price
  1243.                 ,    gsp_sub.cp_price AS sub_cp_price
  1244.                 ,    gsp_sub.price AS sub_price
  1245.                 ,    gsp_sub.jan_id AS sub_jan_id
  1246.                 ,    gsp_sub.gcl_id AS sub_gcl_id
  1247.                 ,    gsp_sub.gcl_display AS sub_gcl_display
  1248.                 ,    gsp_sub.gp_id AS sub_gp_id
  1249.                 ,    gsp_sub.gp_display AS sub_gp_display
  1250.                 ,    gsp_sub.color_id AS sub_color_id
  1251.                 ,    gsp_sub.color_display AS sub_color_display
  1252.                 ,    gsp_sub.color_name AS sub_color_name
  1253.                 ,    gsp_sub.color_rgb AS sub_color_rgb
  1254.                 ,    gsp_sub.size_id AS sub_size_id
  1255.                 ,    gsp_sub.size_name AS sub_size_name
  1256.                 ,    gsp_sub.size_display AS sub_size_display
  1257.                 ,    gsp_sub.stock AS sub_stock
  1258.                 ,    gsp_sub.jan_stock3 AS sub_stock3
  1259.                 ,    gsp_sub.jan_stock3_nyuka_date AS sub_stock3_nyuka_date
  1260.                 ,    gsp_sub.`chokusou_flg` AS sub_chokusou_flg
  1261.                 ,    gsp_sub.jan_nodisplay AS sub_nodisp
  1262.                 ,    gsp_sub.ki_comment AS sub_ki_comment
  1263.                 ,    gsp_sub.ki_date AS sub_ki_date
  1264.                 ,    gsp_sub.zero_period AS sub_zero_period
  1265.                 ,    gsp_sub.zdate AS sub_zdate
  1266.                 ,    gsp_sub.nyuuka_yoteibi AS sub_nyuuka_yoteibi
  1267.                 ,    gsp_other.gsp_type AS other_gsp_type
  1268.                 ,    gsp_other.gsp_name AS other_gsp_name
  1269.                 ,    gsp_other.gsp_show_flg AS other_gsp_show_flg
  1270.                 ,    gsp_other.goods_id AS other_goods_id
  1271.                 ,    gsp_other.goods_name AS other_goods_name
  1272.                 ,    gsp_other.gp_kataban AS other_kataban
  1273.                 ,    gsp_other.gp_price AS other_gp_price
  1274.                 ,    gsp_other.cp_price AS other_cp_price
  1275.                 ,    gsp_other.price AS other_price
  1276.                 ,    gsp_other.jan_id AS other_jan_id
  1277.                 ,    gsp_other.gcl_id AS other_gcl_id
  1278.                 ,    gsp_other.gcl_display AS other_gcl_display
  1279.                 ,    gsp_other.gp_id AS other_gp_id
  1280.                 ,    gsp_other.gp_display AS other_gp_display
  1281.                 ,    gsp_other.color_id AS other_color_id
  1282.                 ,    gsp_other.color_display AS other_color_display
  1283.                 ,    gsp_other.color_name AS other_color_name
  1284.                 ,    gsp_other.color_rgb AS other_color_rgb
  1285.                 ,    gsp_other.size_id AS other_size_id
  1286.                 ,    gsp_other.size_name AS other_size_name
  1287.                 ,    gsp_other.size_display AS other_size_display
  1288.                 ,    gsp_other.stock AS other_stock
  1289.                 ,    gsp_other.jan_stock3 AS other_stock3
  1290.                 ,    gsp_other.jan_stock3_nyuka_date AS other_stock3_nyuka_date
  1291.                 ,    gsp_other.`chokusou_flg` AS other_chokusou_flg
  1292.                 ,    gsp_other.jan_nodisplay AS other_nodisp
  1293.                 ,    gsp_other.ki_comment AS other_ki_comment
  1294.                 ,    gsp_other.ki_date AS other_ki_date
  1295.                 ,    gsp_other.zero_period AS other_zero_period
  1296.                 ,    gsp_other.zdate AS other_zdate
  1297.                 ,    gsp_other.nyuuka_yoteibi AS other_nyuuka_yoteibi
  1298.                 ,    CONCAT(gsp_main.jan_id, '-', gsp_sub.jan_id, '-', gsp_other.jan_id) AS jan_id_list
  1299.                 ,    COALESCE(ROUND(MIN(cp.cp_price)), gp.gp_price) AS price
  1300.                 ,    (
  1301.                         ( ( `gsp_main`.goods_id IS NULL ) OR `gsp_main`.`chokusou_flg`)
  1302.                     AND ( ( `gsp_sub`.goods_id IS NULL ) OR `gsp_sub`.`chokusou_flg`)
  1303.                     AND ( ( `gsp_other`.goods_id IS NULL ) OR `gsp_other`.`chokusou_flg`)
  1304.                     ) AS `chokusou_flg`
  1305.                 ,    gp.gp_id
  1306.                 ,    gp.gp_teika
  1307.                 ,    gp.gp_price
  1308.                 ,    gp.gp_price2
  1309.                 ,    gp.gp_genka
  1310.                 ,    size.size_id
  1311.                 ,    size.size_name
  1312.                 FROM ({$sqlGspMain}) AS `gsp_main`
  1313.                 INNER JOIN ({$sqlGspSub}) AS `gsp_sub` USING ( gsp_goods_parent )
  1314.                 LEFT JOIN ({$sqlGspOther}) AS `gsp_other` USING ( gsp_goods_parent )
  1315.                 INNER JOIN goods_table AS goods_parent ON goods_parent.goods_id = gsp_main.gsp_goods_parent
  1316.                 INNER JOIN gsp_gp_table AS gsp_sp ON gsp_gp_main = gsp_main.gp_id AND gsp_gp_sub = gsp_sub.gp_id AND IfNull(gsp_gp_other, 0) = IfNull(gsp_other.gp_id, 0)
  1317.                 INNER JOIN goods_price_table AS gp ON gp.gp_id = gsp_gp_parent
  1318.                 LEFT JOIN campaign_price_table AS cp ON gp.gp_id = cp.cp_gp AND cp.cp_end_datetime >= NOW() and cp.cp_start_datetime <= NOW() AND cp.cp_price > 0
  1319.                 LEFT JOIN size_table AS size ON size.size_id = gp.gp_size_id
  1320.                 GROUP BY
  1321.                     goods_parent.goods_id
  1322.                 ,    gsp_main.jan_id
  1323.                 ,    gsp_sub.jan_id
  1324.                 ,    gsp_other.jan_id
  1325.                 ORDER BY
  1326.                     parent_goods_id
  1327.                 ,    main_goods_id
  1328.                 ,    main_gcl_display
  1329.                 ,    main_color_display
  1330.                 ,    CAST( main_color_name AS binary )
  1331.                 ,    sub_goods_id
  1332.                 ,    sub_gcl_display
  1333.                 ,    sub_color_display
  1334.                 ,    CAST( sub_color_name AS binary )
  1335.                 ,    other_goods_id
  1336.                 ,    other_gcl_display
  1337.                 ,    other_color_display
  1338.                 ,    CAST( other_color_name AS binary )";
  1339.         return $sql;
  1340.     }
  1341.     public function getGoodsSetPurchaseList($parent_id)
  1342.     {
  1343.         $sqlGsp $this->sqlGsp($parent_id);
  1344.         //
  1345.         $strSql "SELECT
  1346.                     parent_goods_id
  1347.                 ,    parent_goods_name
  1348.                 ,    parent_kataban
  1349.                 ,    main_goods_id
  1350.                 ,    main_goods_name
  1351.                 ,    main_kataban
  1352.                 ,    main_gsp_name
  1353.                 ,    main_gsp_show_flg
  1354.                 ,    main_jan_id
  1355.                 ,    main_gp_id
  1356.                 ,    main_gp_display
  1357.                 ,    main_size_name
  1358.                 ,    main_gcl_id
  1359.                 ,    main_gcl_display
  1360.                 ,    main_color_id
  1361.                 ,    main_color_name
  1362.                 ,    main_color_rgb
  1363.                 ,    main_stock
  1364.                 ,    main_stock3
  1365.                 ,    main_stock3_nyuka_date
  1366.                 ,    main_ki_comment
  1367.                 ,    main_ki_date
  1368.                 ,    main_zero_period
  1369.                 ,    main_zdate
  1370.                 ,    main_nyuuka_yoteibi
  1371.                 ,    sub_goods_id
  1372.                 ,    sub_goods_name
  1373.                 ,    sub_kataban
  1374.                 ,    sub_gsp_name
  1375.                 ,    sub_gsp_show_flg
  1376.                 ,    sub_jan_id
  1377.                 ,    sub_gp_id
  1378.                 ,    sub_gp_display
  1379.                 ,    sub_size_name
  1380.                 ,    sub_gcl_id
  1381.                 ,    sub_gcl_display
  1382.                 ,    sub_color_id
  1383.                 ,    sub_color_name
  1384.                 ,    sub_color_rgb
  1385.                 ,    sub_stock
  1386.                 ,    sub_stock3
  1387.                 ,    sub_stock3_nyuka_date
  1388.                 ,    sub_ki_comment
  1389.                 ,    sub_ki_date
  1390.                 ,    sub_zero_period
  1391.                 ,    sub_zdate
  1392.                 ,    sub_nyuuka_yoteibi
  1393.                 ,    other_goods_id
  1394.                 ,    other_goods_name
  1395.                 ,    other_kataban
  1396.                 ,    other_gsp_type
  1397.                 ,    other_gsp_name
  1398.                 ,    other_gsp_show_flg
  1399.                 ,    other_jan_id
  1400.                 ,    other_gp_id
  1401.                 ,    other_gp_display
  1402.                 ,    other_size_name
  1403.                 ,    other_gcl_id
  1404.                 ,    other_gcl_display
  1405.                 ,    other_color_id
  1406.                 ,    other_color_name
  1407.                 ,    other_color_rgb
  1408.                 ,    other_stock
  1409.                 ,    other_stock3
  1410.                 ,    other_stock3_nyuka_date
  1411.                 ,    other_ki_comment
  1412.                 ,    other_ki_date
  1413.                 ,    other_zero_period
  1414.                 ,    other_zdate
  1415.                 ,    other_nyuuka_yoteibi
  1416.                 ,    LEAST(IfNull(main_stock, 99999), IfNull(sub_stock, 99999), IfNull(other_stock, 99999)) AS stock
  1417.                 ,    LEAST(
  1418.                         CASE main_goods_id
  1419.                             WHEN NULL THEN 99999
  1420.                             ELSE IfNull(main_stock3, 0)
  1421.                         END
  1422.                     ,    CASE sub_goods_id
  1423.                             WHEN NULL THEN 99999
  1424.                             ELSE IfNull(sub_stock3, 0)
  1425.                         END
  1426.                     ,    CASE other_goods_id
  1427.                             WHEN NULL THEN 99999
  1428.                             ELSE IfNull(other_stock3, 0)
  1429.                         END
  1430.                     ) AS stock3
  1431.                 ,    COALESCE(main_ki_comment, sub_ki_comment, other_ki_comment) AS comment
  1432.                 ,    COALESCE(main_zdate, sub_zdate, other_zdate) AS zdate
  1433.                 ,    COALESCE(main_nyuuka_yoteibi, sub_nyuuka_yoteibi, other_nyuuka_yoteibi) AS nyuuka_yoteibi
  1434.                 -- ,    GREATEST(IfNull(main_stock, -1), IfNull(sub_stock, -1), IfNull(other_stock, -1)) AS stock
  1435.                 ,    `chokusou_flg`
  1436.                 ,    price
  1437.                 ,    gp_id
  1438.                 ,    gp_teika
  1439.                 ,    gp_price
  1440.                 ,    gp_price2
  1441.                 ,    gp_genka
  1442.                 ,    size_id
  1443.                 ,    size_name
  1444.                 FROM
  1445.                     ({$sqlGsp}) AS `gsp`
  1446.                 ORDER BY
  1447.                     other_gsp_type
  1448.                 ,    main_gcl_display
  1449.                 ,    sub_gcl_display
  1450.                 ,    other_gcl_display
  1451.                 ,    main_gp_display
  1452.                 ,    sub_gp_display
  1453.                 ,    other_gp_display";
  1454.         return (new SqlService())->Sql($strSql)->FetchAll();
  1455.     }
  1456.     public function getJanShireColorData($dataId)
  1457.     {
  1458.         $sql "SELECT DISTINCT `jan_goods`,`jan_color`,IFNULL(`jan_shiire_color`,`jan_uniform1_color_number`) AS jan_shiire_color
  1459.                 FROM jancode_table
  1460.                 INNER JOIN goods_table ON jan_goods = goods_id
  1461.                 WHERE jan_goods = :goods_id
  1462.                 AND jan_ddate IS NULL";
  1463.         return (new SqlService())->Sql($sql)
  1464.             ->Param('goods_id'$dataId)
  1465.             ->FetchAll();
  1466.     }
  1467.     public function convertGoodsSetPurchaseListToMap($set_purchase_list)
  1468.     {
  1469.         $map = ['main' => [], 'sub' => [], 'other' => []];
  1470.         $filter = ['color' => [], 'size' => []];
  1471.         if (isset($set_purchase_list)) {
  1472.             foreach ($set_purchase_list as $sku) {
  1473.                 foreach (array_keys($map) as $prefix) {
  1474.                     $data = &$map[$prefix];
  1475.                     if (empty($sku["{$prefix}_goods_id"])) continue;
  1476.                     $data['goods_id'] = $sku["{$prefix}_goods_id"];
  1477.                     $data['label'] = $sku["{$prefix}_gsp_name"];
  1478.                     $data['nodisp'] = (int)$sku["{$prefix}_gsp_show_flg"] === 0;
  1479.                     $data['color_list'] = isset($data['color_list']) ? $data['color_list'] : [];
  1480.                     $color_id $sku["{$prefix}_gcl_id"];
  1481.                     if (!isset($filter['color'][$color_id])) {
  1482.                         $data['color_list'][] = [
  1483.                             'color_id' => $color_id,
  1484.                             'color_name' => $sku["{$prefix}_color_name"],
  1485.                             'color_rgb' => $sku["{$prefix}_color_rgb"]
  1486.                         ];
  1487.                         $filter['color'][$color_id] = true;
  1488.                     }
  1489.                     $data['size_list'] = isset($data['size_list']) ? $data['size_list'] : [];
  1490.                     $gp_id $sku["{$prefix}_gp_id"];
  1491.                     if (!isset($filter['size'][$gp_id])) {
  1492.                         $data['size_list'][] = [
  1493.                             'gp_id' => $gp_id,
  1494.                             'size_name' => $sku["{$prefix}_size_name"]
  1495.                         ];
  1496.                         $filter['size'][$gp_id] = true;
  1497.                     }
  1498.                     $data['jan_id_map'][$color_id][$gp_id] = $sku["{$prefix}_jan_id"];
  1499.                 }
  1500.             }
  1501.             // 仕入先色番号セット
  1502.             foreach ($map as $key => &$goods) {
  1503.                 if (empty($goods)) {
  1504.                     unset($map[$key]);
  1505.                     continue;
  1506.                 }
  1507.                 $color_num_map $this->getShiireColorNumberMap($goods['goods_id']);
  1508.                 foreach ($goods['color_list'] as &$color) {
  1509.                     if (isset($color_num_map[$color['color_id']])) $color['color_num'] = $color_num_map[$color['color_id']];
  1510.                 }
  1511.             }
  1512.         }
  1513.         return $map;
  1514.     }
  1515.     public function getShiireColorNumberMap($goods_id)
  1516.     {
  1517.         $rows $this->getJanShireColorData($goods_id);
  1518.         $map = [];
  1519.         if (isset($rows)) {
  1520.             foreach ($rows as $row) {
  1521.                 $map[$row['jan_color']] = is_null($row['jan_shiire_color']) ? '' $row['jan_shiire_color'];
  1522.             }
  1523.         }
  1524.         return $map;
  1525.     }
  1526.     public function getGoodsLinkSelect($data$is_secret true$count false)
  1527.     {
  1528.         if (is_array($data)) {
  1529.             $whereGoods "target_goods_id IN (" implode(","$data) . ")";
  1530.         } else {
  1531.             $whereGoods "target_goods_id = " $data;
  1532.         }
  1533.         $strSql "
  1534.             SELECT DISTINCT gl.goods_id, g.goods_canonical_hinban, gl.goods_name, gl.goods_count, min_gp_price, count_gp_price
  1535.             FROM goods_link_table AS gl
  1536.             INNER JOIN goods_table AS g ON g.goods_id = gl.goods_id AND g.goods_ddate IS NULL";
  1537.         if (!$is_secret) {
  1538.             $strSql .= " AND g.goods_status = 1 ";
  1539.         }
  1540.         $strSql .= "
  1541.             WHERE {$whereGoods}
  1542.             ORDER BY goods_count DESC
  1543.         ";
  1544.         if ($count 0) {
  1545.             $strSql .= " LIMIT 0, " $count;
  1546.         } else {
  1547.             $strSql .= " LIMIT 0, 16";
  1548.         }
  1549.         return (new SqlService())->Sql($strSql)->FetchAll();
  1550.     }
  1551.     // 口コミ平均評価取得
  1552.     public function getReviewAverageData($goods_id null)
  1553.     {
  1554.         $query = (new SqlService())
  1555.             ->Table('customer_review_average_table')
  1556.             ->Set('cra_target_count'1'>=')
  1557.             ->Select('cra_goods_id, cra_average_points, cra_target_count');
  1558.         if ($goods_id) {
  1559.             $query->Set('cra_goods_id'$goods_id);
  1560.         }
  1561.         return $query->FindAll();
  1562.     }
  1563.     public function getReviewAverage($goods_id)
  1564.     {
  1565.         $temp $this->getReviewAverageData($goods_id);
  1566.         $average = array();
  1567.         if (isset($temp)) {
  1568.             foreach ((array)$temp as $data) {
  1569.                 $average[$data['cra_goods_id']] = $data['cra_average_points'];
  1570.             }
  1571.         }
  1572.         return $average;
  1573.     }
  1574.     public function getSashikomiImageInfoMap($goods_id)
  1575.     {
  1576.         /**
  1577.          * 差し込みタイプ情報マップ
  1578.          * 差し込みタイプは差し込みの表示・非表示や、表示するさいのカラム数などを持っている。
  1579.          * 「作成しない」になっている画像はここではじかれる。
  1580.          */
  1581.         $sashikomi_info_map = [];
  1582.         $rows = (new SqlService())
  1583.             ->Table('sashikomi_image_table')
  1584.             ->Set('goods_id'$goods_id)
  1585.             ->FindAll();
  1586.         if (isset($rows)) {
  1587.             foreach ($rows as $row) {
  1588.                 $sashikomi_info_map[$row['sashikomi_type']] = $row;
  1589.             }
  1590.         }
  1591.         // sashikomi_image_tableにデータが登録されていない差し込みはデフォルト値で生成する。
  1592.         // 「そのまま表示」「作成しない」のリリース前から一度も保存されていない商品など。
  1593.         foreach (array_keys(self::$IMAGE_INFO_MAP) as $sashikomi_type) {
  1594.             if (isset($sashikomi_info_map[$sashikomi_type])) {
  1595.                 // 「作成しない」はここで削除
  1596.                 if ((int)$sashikomi_info_map[$sashikomi_type]['has_image'] === self::DB_STATUS_FALSE) {
  1597.                     unset($sashikomi_info_map[$sashikomi_type]);
  1598.                 }
  1599.                 continue;
  1600.             }
  1601.             $column_num = isset(self::$IMAGE_INFO_MAP[$sashikomi_type]['default_column_num'])
  1602.                 ? self::$IMAGE_INFO_MAP[$sashikomi_type]['default_column_num']
  1603.                 : 1;
  1604.             //$sashikomi_info_map[$sashikomi_type] = (Object)[
  1605.             $sashikomi_info_map[$sashikomi_type] = [
  1606.                 'goods_id' => $goods_id,
  1607.                 'sashikomi_type' => $sashikomi_type,
  1608.                 'has_image' => self::DB_STATUS_TRUE,
  1609.                 'column_num' => $column_num
  1610.             ];
  1611.         }
  1612.         $rows = (new SqlService())
  1613.             ->Sql("
  1614.             SELECT
  1615.                 goods_main_kataban,
  1616.                 shiiresaki_url,
  1617.                 s.*
  1618.             FROM
  1619.                 goods_table g
  1620.             JOIN
  1621.                 shiiresaki_table
  1622.             ON
  1623.                 goods_shiiresaki = shiiresaki_id
  1624.             JOIN(
  1625.                 SELECT
  1626.                     goods_id,
  1627.                     sashikomi_type,
  1628.                     GROUP_CONCAT(option_key order by option_key SEPARATOR :seperator) AS option_keys,
  1629.                     GROUP_CONCAT( IFNULL(option_value, '') order by option_key SEPARATOR :seperator) AS option_values
  1630.                 FROM
  1631.                     sashikomi_image_option_table
  1632.                 WHERE
  1633.                     goods_id = :goods_id
  1634.                 GROUP BY
  1635.                     goods_id, sashikomi_type
  1636.             )s
  1637.             USING(goods_id)")
  1638.             ->Param('goods_id'$goods_id)
  1639.             ->Param('seperator'self::$GROUP_CONCAT_SEPARATOR)
  1640.             ->FetchAll();
  1641.         if (isset($rows)) {
  1642.             foreach ($rows as $row) {
  1643.                 unset($sashikomi_info_ref);
  1644.                 foreach (array_keys($sashikomi_info_map) as $sashikomi_type) {
  1645.                     if (preg_match('/^' preg_quote($sashikomi_type) . '(?:_(.+))?$/'$row['sashikomi_type'], $m)) {
  1646.                         $sashikomi_info_ref = &$sashikomi_info_map[$sashikomi_type];
  1647.                         break;
  1648.                     }
  1649.                 }
  1650.                 if (!isset($sashikomi_info_ref)) continue;
  1651.                 $sashikomi_image array_combine(
  1652.                     explode(self::$GROUP_CONCAT_SEPARATOR$row['option_keys']),
  1653.                     explode(self::$GROUP_CONCAT_SEPARATOR$row['option_values'])
  1654.                 );
  1655.                 // 「非表示」に設定されている画像はとばす
  1656.                 if ((int)$sashikomi_image['status'] === self::DB_STATUS_FALSE) continue;
  1657.                 if (!isset($sashikomi_info_ref['image_list'])) $sashikomi_info_ref['image_list'] = [];
  1658.                 // 画像番号(複数枚画像の場合に$mに入っている)
  1659.                 $image_num = isset($m[1]) ? $m[1] : null;
  1660.                 $sashikomi_image['image_num'] = $image_num;
  1661.                 $sashikomi_image['path'] = ItemSashikomiImageService::getImagePath(
  1662.                     $sashikomi_type,
  1663.                     $row['goods_main_kataban'],
  1664.                     $row['shiiresaki_url'],
  1665.                     $image_num,
  1666.                     $sashikomi_image['ext']
  1667.                 );
  1668.                 $sashikomi_info_ref['image_list'][] = (object)$sashikomi_image;
  1669.             }
  1670.         }
  1671.         $sashikomi $this->adjustInfoMap($sashikomi_info_map$goods_id);
  1672.         if (!empty($sashikomi['color_variation']['image_list'])) {
  1673.             $goodsDirectDeliveries $this->getGoodsDirectDeliveries($goods_id);
  1674.             $sashikomi['color_variation']['image_list'] = array_map(function ($colorVariation) use ($goodsDirectDeliveries) {
  1675.                 $colorVariation->is_direct_delivery = !empty($goodsDirectDeliveries[$colorVariation->image_num]);
  1676.                 return $colorVariation;
  1677.             }, $sashikomi['color_variation']['image_list']);
  1678.         }
  1679.         return $sashikomi;
  1680.     }
  1681.     private function getGoodsDirectDeliveries($goodsId)
  1682.     {
  1683.         $goods = (new SqlService())
  1684.             ->Sql('
  1685.                 SELECT
  1686.                     goods_id,
  1687.                     goods_main_kataban AS kataban,
  1688.                     goods_shiiresaki AS shiiresaki_id,
  1689.                     goods_set_purchase_flg AS is_set_item
  1690.                 FROM goods_table
  1691.                 WHERE goods_id = :goods_id AND goods_ddate IS NULL
  1692.             ')
  1693.             ->Param('goods_id'$goodsId)
  1694.             ->Fetch();
  1695.         if (empty($goods)) {
  1696.             return [];
  1697.         }
  1698.         // セット品番
  1699.         if ($goods['is_set_item'] == 1) {
  1700.             return $this->getSetDirectDeliveries($goodsId);
  1701.         }
  1702.         $directDeliveryProvider $this->getDirectDeliveryProviderByShiiresakiId($goods['shiiresaki_id']);
  1703.         // 直送対象メーカーでなければ在庫状況(LM備蓄=stock3)からマップを生成
  1704.         if (empty($directDeliveryProvider)) {
  1705.             return $this->getGoodsDirectDeliveriesByInventory($goods);
  1706.         } else { // メーカー直送設定と在庫状況からマップを生成
  1707.             return $this->getGoodsDirectDeliveriesByProvider($directDeliveryProvider$goods);
  1708.         }
  1709.     }
  1710.     private function getSetDirectDeliveries($goodsId)
  1711.     {
  1712.         $goodsList = (new SqlService())
  1713.             ->Sql('
  1714.                 SELECT
  1715.                     gsp_goods_child AS goods_id,
  1716.                     CASE WHEN gsp_type = 0 THEN 1 ELSE 0 END AS is_main
  1717.                 FROM goods_set_purchase_table
  1718.                 WHERE gsp_goods_parent = :goods_id
  1719.             ')
  1720.             ->Param('goods_id'$goodsId)
  1721.             ->FetchAll();
  1722.         $mainId null;
  1723.         $subIds = [];
  1724.         foreach ($goodsList as $goods) {
  1725.             if ((int)$goods['is_main'] === 1) {
  1726.                 $mainId = (int)$goods['goods_id'];
  1727.             } else {
  1728.                 $subIds[] = (int)$goods['goods_id'];
  1729.             }
  1730.         }
  1731.         $mainGoodsDirectDeliveries $this->getGoodsDirectDeliveries($mainId);
  1732.         $subGoodsHasNotDirectDelivery false;
  1733.         foreach ($subIds as $subId) {
  1734.             $subGoodsDirectDeliveries $this->getGoodsDirectDeliveries($subId);
  1735.             // サブ品番の全カラーが在庫0だったら在庫なし
  1736.             if (!in_array(truearray_values($subGoodsDirectDeliveries))) {
  1737.                 $subGoodsHasNotDirectDelivery true;
  1738.                 break;
  1739.             }
  1740.         }
  1741.         // サブ品番の在庫がなければ全カラー即日発送不可にする。
  1742.         if ($subGoodsHasNotDirectDelivery) {
  1743.             $mainGoodsDirectDeliveries array_combine(
  1744.                 array_keys($mainGoodsDirectDeliveries),
  1745.                 array_pad([], count($mainGoodsDirectDeliveries), false)
  1746.             );
  1747.         }
  1748.         return $mainGoodsDirectDeliveries;
  1749.     }
  1750.     private function getDirectDeliveryProviderByShiiresakiId($shiiresakiId)
  1751.     {
  1752.         $directDeliveryProviders $this->getDirectDeliveryProviders();
  1753.         return $directDeliveryProviders[$shiiresakiId] ?? null;
  1754.     }
  1755.     private function getDirectDeliveryProviders()
  1756.     {
  1757.         $directDeliveries = (new SqlService())
  1758.             ->Sql("
  1759.                 SELECT
  1760.                     shiiresaki_id,
  1761.                     IFNULL(shiiresaki_souko_hantei, '') AS chokusou_hinban_alphabet,
  1762.                     IFNULL(dd_hinban_chokusou, '') AS chokusou_hinban,
  1763.                     IFNULL(dd_hinban_exclude, '') AS exclude_hinban,
  1764.                     IFNULL(dd_hinban_bichiku, '') AS bichiku_hinban
  1765.                 FROM shiiresaki_table
  1766.                 JOIN direct_delivery_table ON shiiresaki_id = dd_shiiresaki
  1767.                 WHERE dd_ddate IS NULL
  1768.             ")
  1769.             ->FetchAll();
  1770.         if (empty($directDeliveries)) {
  1771.             return [];
  1772.         }
  1773.         $directDeliveryProviders = [];
  1774.         foreach ($directDeliveries as $directDelivery) {
  1775.             $directDeliveryProviders[(int)$directDelivery['shiiresaki_id']] = [
  1776.                 'shiiresaki_id' => $directDelivery['shiiresaki_id'],
  1777.                 'chokusou_alphabet_list' => $directDelivery['chokusou_hinban_alphabet'] === ''
  1778.                     ? [] : explode(','$directDelivery['chokusou_hinban_alphabet']),
  1779.                 'chokusou_hinban_list' => $directDelivery['chokusou_hinban'] === ''
  1780.                     ? [] : explode(','$directDelivery['chokusou_hinban']),
  1781.                 'exclude_hinban_list' => $directDelivery['exclude_hinban'] === ''
  1782.                     ? [] : explode(','$directDelivery['exclude_hinban']),
  1783.                 'bichiku_hinban_list' => $directDelivery['bichiku_hinban'] === ''
  1784.                     ? [] : explode(','$directDelivery['bichiku_hinban'])
  1785.             ];
  1786.         }
  1787.         return $directDeliveryProviders;
  1788.     }
  1789.     private function getGoodsDirectDeliveriesByInventory($goods_data)
  1790.     {
  1791.         $colorStockList $this->getColorStockList($goods_data['goods_id']);
  1792.         /**
  1793.          * 在庫から判断するのはメーカー直送設定が行われていない仕入先なので、
  1794.          * stock3以外は見る必要がない。
  1795.          */
  1796.         $goodsDirectDeliveries = [];
  1797.         foreach ($colorStockList as $colorStock) {
  1798.             $goodsDirectDeliveries[$colorStock['color_num']] = $colorStock['has_lm_stock'];
  1799.         }
  1800.         return $goodsDirectDeliveries;
  1801.     }
  1802.     private function getGoodsDirectDeliveriesByProvider($directDeliveryProvider$goods)
  1803.     {
  1804.         /**
  1805.          * 直送対象であっても、在庫があることが前提となる。
  1806.          */
  1807.         $colorStockList $this->getColorStockList($goods['goods_id']);
  1808.         $makerAlphabetList $directDeliveryProvider['chokusou_alphabet_list'];
  1809.         $chokusouHinbanList $directDeliveryProvider['chokusou_hinban_list'];
  1810.         $excludeHinbanList $directDeliveryProvider['exclude_hinban_list'];
  1811.         $bichikuHinbanList $directDeliveryProvider['bichiku_hinban_list'];
  1812.         /**
  1813.          * メーカー直送品番(該当アルファベット)、メーカー直送品番(対象商品をLM品番で入力)、LM備蓄在庫(アシスト物流で在庫している)、除外品番が未設定であれば、
  1814.          * 全カラー、サイズが直送対象。
  1815.          */
  1816.         $allItemCanDelivery =
  1817.             empty($makerAlphabetList) &&
  1818.             empty($chokusouHinbanList) &&
  1819.             empty($excludeHinbanList) &&
  1820.             empty($bichikuHinbanList);
  1821.         $goodsDirectDeliveries = [];
  1822.         foreach ($colorStockList as $colorStock) {
  1823.             // LM備蓄在庫があればどんな条件であっても(excludeに設定されていても)直送可能
  1824.             if ($colorStock['has_lm_stock']) {
  1825.                 $goodsDirectDeliveries[$colorStock['color_num']] = true;
  1826.                 continue;
  1827.             }
  1828.             // デフォルトで通常在庫が直送在庫になる(LM備蓄がある場合は既に上の処理で直送可能判定済み)。
  1829.             $hasStock $colorStock['has_stock'];
  1830.             // 直送可能在庫数の有無判定(メーカーごとに異なる)
  1831.             switch ($directDeliveryProvider['shiiresaki_id']) {
  1832.                 // チトセ
  1833.                 case 84:
  1834.                     $hasStock $hasStock || $colorStock['has_chitose_lm_bichiku_stock'] || $colorStock['has_chitose_gaibu_bichiku_stock'];
  1835.                     // 商品ID 8172(特殊)
  1836.                     if ((int)$goods['goods_id'] === 8172) {
  1837.                         $hasStock $hasStock || $colorStock['has_chitose_lm_stock'] || $colorStock['has_chitose_kaitori_stock'];
  1838.                     }
  1839.                     break;
  1840.                 default:
  1841.                     break;
  1842.             }
  1843.             // 除外品番になっている、もしくは在庫がない場合は直送不可
  1844.             if (in_array($goods['kataban'], $excludeHinbanList) || !$hasStock) {
  1845.                 $goodsDirectDeliveries[$colorStock['color_num']] = false;
  1846.                 continue;
  1847.             }
  1848.             if (
  1849.                 // 全て直送可能
  1850.                 $allItemCanDelivery ||
  1851.                 // メーカー直送品番(該当アルファベット)が指定されていてそれに含まれている
  1852.                 (
  1853.                     !empty($makerAlphabetList) &&
  1854.                     in_array($colorStock['hinban_alpabet'], $makerAlphabetList)
  1855.                 ) ||
  1856.                 // メーカー直送品番(対象商品をLM品番で入力)が指定されていてそれに含まれている
  1857.                 (
  1858.                     !empty($chokusouHinbanList) &&
  1859.                     in_array($goods['kataban'], $chokusouHinbanList)
  1860.                 ) ||
  1861.                 // LM備蓄在庫(アシスト物流で在庫している)している品番が指定されていてそれに含まれている
  1862.                 (
  1863.                     !empty($bichikuHinbanList) &&
  1864.                     in_array($goods['kataban'], $bichikuHinbanList) &&
  1865.                     $colorStock['has_lm_stock']
  1866.                 )
  1867.             ) {
  1868.                 $goodsDirectDeliveries[$colorStock['color_num']] = true;
  1869.                 continue;
  1870.             }
  1871.             $goodsDirectDeliveries[$colorStock['color_num']] = false;
  1872.         }
  1873.         return $goodsDirectDeliveries;
  1874.     }
  1875.     private function getColorStockList($goodsId)
  1876.     {
  1877.         /**
  1878.          * 真偽値をMAXすることで在庫あり=1をひっぱる
  1879.          * 仕入先色番号がNULLのレコードがあるので(特にセットのサブ品番)、その場合はCOLOR_ID_をprefixにしたキーを使う。
  1880.          */
  1881.         $colorStockList = (new SqlService())
  1882.             ->Sql("
  1883.                 SELECT
  1884.                     IFNULL(jan_shiire_color, CONCAT('COLOR_ID_', jan_color)) AS color_num,
  1885.                     jan_shiire_no AS shiire_no,
  1886.                     MAX( IFNULL(jan_stock,  0) > 1 ) AS has_stock,
  1887.                     MAX( IFNULL(jan_stock6, 0) > 1 ) AS has_chitose_lm_stock,
  1888.                     MAX( IFNULL(jan_stock7, 0) > 1 ) AS has_chitose_kaitori_stock,
  1889.                     MAX( IFNULL(jan_stock8, 0) > 1 ) AS has_chitose_lm_bichiku_stock,
  1890.                     MAX( IFNULL(jan_stock9, 0) > 1 ) AS has_chitose_gaibu_bichiku_stock,
  1891.                     MAX(
  1892.                         IFNULL(jan_stock3, 0) > 0 AND
  1893.                         IFNULL(jan_stock3_nyuka_date, '0000-00-00') < NOW()
  1894.                     ) AS has_lm_stock
  1895.                 FROM (
  1896.                     SELECT jancode_table.*, keppin_id, zero_stock_id
  1897.                     FROM jancode_table
  1898.                     LEFT JOIN(
  1899.                         SELECT
  1900.                             ki_id AS keppin_id,
  1901.                             ki_goods AS goods_id,
  1902.                             ki_gcl AS gcl_id,
  1903.                             ki_gp AS gp_id
  1904.                         FROM keppin_item_table
  1905.                         WHERE ki_date IS NULL OR ki_date > NOW() AND ki_goods = :goods_id
  1906.                     ) t1 ON jan_goods = t1.goods_id AND jan_color = t1.gcl_id AND jan_price = t1.gp_id
  1907.                     LEFT JOIN(
  1908.                         SELECT zero_id AS zero_stock_id, zero_goods AS goods_id, zero_gcl AS gcl_id, zero_gp AS gp_id
  1909.                         FROM zero_stock_table
  1910.                         WHERE zero_period > NOW() AND zero_goods = :goods_id
  1911.                     ) t2 ON jan_goods = t2.goods_id AND jan_color = t2.gcl_id AND jan_price = t2.gp_id
  1912.                     WHERE jan_goods = :goods_id
  1913.                 ) t
  1914.                 WHERE jan_ddate IS NULL AND jan_nodisplay IS NULL
  1915.                 GROUP BY jan_shiire_color, jan_shiire_no
  1916.             ")
  1917.             ->Param('goods_id'$goodsId)
  1918.             ->FetchAll();
  1919.         return array_map(function ($colorStock) {
  1920.             $colorStock['hinban_alpabet'] = preg_replace('/[^a-z]/i'''$colorStock['shiire_no']);
  1921.             $colorStock['has_stock'] = (int)$colorStock['has_stock'] === 1;
  1922.             $colorStock['has_lm_stock'] = (int)$colorStock['has_lm_stock'] === 1;
  1923.             $colorStock['has_chitose_lm_stock'] = (int)$colorStock['has_chitose_lm_stock'] === 1;
  1924.             $colorStock['has_chitose_kaitori_stock'] = (int)$colorStock['has_chitose_kaitori_stock'] === 1;
  1925.             $colorStock['has_chitose_lm_bichiku_stock'] = (int)$colorStock['has_chitose_lm_bichiku_stock'] === 1;
  1926.             $colorStock['has_chitose_gaibu_bichiku_stock'] = (int)$colorStock['has_chitose_gaibu_bichiku_stock'] === 1;
  1927.             return $colorStock;
  1928.         }, $colorStockList);
  1929.     }
  1930.     private function adjustInfoMap($map$goods_id)
  1931.     {
  1932.         $color_number_map $this->getColorNumberMap($goods_id);
  1933.         foreach ($map as $sashikomi_type => $data) {
  1934.             if (empty($data['image_list'])) continue;
  1935.             switch ($sashikomi_type) {
  1936.                 // 画像番号順にソート
  1937.                 case self::TYPE_FABRIC:
  1938.                 case self::TYPE_DETAIL_COLUMN:
  1939.                     $seek array_map(function ($image) {
  1940.                         return $image->image_num;
  1941.                     }, $data['image_list']);
  1942.                     array_multisort(
  1943.                         $seek,
  1944.                         SORT_ASC,
  1945.                         SORT_STRING,
  1946.                         $map[$sashikomi_type]['image_list']
  1947.                     );
  1948.                     break;
  1949.                 // 色番号順にソートし、画像情報に色名を追加する
  1950.                 case self::TYPE_COLOR_VARIATION:
  1951.                     $order_map $seek = [];
  1952.                     foreach (array_keys($color_number_map) as $idx => $color_num) {
  1953.                         $order_map[$color_num] = $idx;
  1954.                     }
  1955.                     foreach ($map[$sashikomi_type]['image_list'] as $idx => &$image) {
  1956.                         // 色名がない色は表示しない
  1957.                         if (!isset($color_number_map[$image->image_num])) {
  1958.                             unset($map[$sashikomi_type]['image_list'][$idx]);
  1959.                             continue;
  1960.                         }
  1961.                         $image->color_name $color_number_map[$image->image_num];
  1962.                         $seek[] = isset($order_map[$image->image_num]) ? $order_map[$image->image_num] : 999;    // 登録されていない色番号は最後に表示するよう999をセット
  1963.                     }
  1964.                     array_multisort(
  1965.                         $seek,
  1966.                         SORT_ASC,
  1967.                         SORT_NUMERIC,
  1968.                         $map[$sashikomi_type]['image_list']
  1969.                     );
  1970.                     break;
  1971.                 default:
  1972.                     break;
  1973.             }
  1974.         }
  1975.         return $map;
  1976.     }
  1977.     private function getColorNumberMap($goods_id)
  1978.     {
  1979.         /**
  1980.          * セット品番の場合はメインidに差し替える。
  1981.          */
  1982.         $rows = (new SqlService())
  1983.             ->Table('goods_set_purchase_table')
  1984.             ->Set('gsp_goods_parent'$goods_id)
  1985.             ->Set('gsp_type'0)
  1986.             ->FindAll();
  1987.         $row = isset($rows) ? array_shift($rows) : null;
  1988.         if (!is_null($row)) $goods_id $row['gsp_goods_child'];
  1989.         $map = [];
  1990.         $query '
  1991.             SELECT
  1992.                 t3.*,
  1993.                 color_name,
  1994.                 gcl_display
  1995.             FROM(
  1996.                 SELECT DISTINCT
  1997.                     *
  1998.                 FROM(
  1999.                     SELECT
  2000.                         goods_id
  2001.                     FROM
  2002.                         goods_table
  2003.                     WHERE
  2004.                         goods_ddate IS NULL AND
  2005.                         goods_id = :goods_id
  2006.                 )t1
  2007.                 JOIN(
  2008.                     SELECT
  2009.                         jan_goods AS goods_id,
  2010.                         jan_shiire_color,
  2011.                         jan_color
  2012.                     FROM
  2013.                         jancode_table
  2014.                     WHERE
  2015.                         jan_shiire_color IS NOT NULL
  2016.                 )t2
  2017.                 USING(goods_id)
  2018.             )t3
  2019.             JOIN
  2020.                 goods_color_table
  2021.             ON
  2022.                 jan_color = gcl_id AND
  2023.                 gcl_display_status = 1
  2024.             JOIN color_table ON color_id = gcl_color_id
  2025.             ORDER BY
  2026.                 goods_id, gcl_display
  2027.         ';
  2028.         $rows = (new SqlService())->Sql($query)
  2029.             ->Param('goods_id'$goods_id)
  2030.             ->FetchAll();
  2031.         if (isset($rows)) {
  2032.             foreach ($rows as $row) {
  2033.                 $map[$row['jan_shiire_color']] = $row['color_name'];
  2034.             }
  2035.         }
  2036.         return $map;
  2037.     }
  2038.     public function getListByGoodsId($siteType$goodsId)
  2039.     {
  2040.         $sql "SELECT
  2041.             nt.nt_id
  2042.         ,    nt.nt_title
  2043.         ,    nt.nt_url
  2044.         FROM
  2045.             new_tag_table AS nt, goods_new_tag_table AS gnt, goods_table AS goods
  2046.         WHERE
  2047.             goods_id = {$goodsId}
  2048.         AND
  2049.             nt_site_type = {$siteType}
  2050.         AND
  2051.             gnt_site_type = nt_site_type
  2052.         AND
  2053.             gnt_goods = goods_id
  2054.         AND
  2055.             gnt_new_tag = nt_id
  2056.         ORDER BY
  2057.             gnt_display
  2058.         ,    nt_tag_number
  2059.         ,    nt_display
  2060.         ,    nt_title";
  2061.         return (new SqlService())->Sql($sql)->FetchAll();
  2062.     }
  2063.     public function getLargeFooterListByGoodsId($siteType$goodsId)
  2064.     {
  2065.         $SQL = new SqlService();
  2066.         $result $SQL->Select('T.footer_id, T.footer_title, T.footer_content_html')
  2067.             ->Table('footer_table')
  2068.             ->Join('goods_footer_table''T.footer_id = T1.gf_footer''INNER')
  2069.             ->Join('goods_table''T2.goods_id = T1.gf_goods''INNER')
  2070.             ->Set('footer_type'2)
  2071.             ->Set('footer_site_type'$siteType)
  2072.             ->Set('T2.goods_id'$goodsId)
  2073.             ->OrderBy('T1.gf_display, T.footer_number, T.footer_display, T.footer_title')
  2074.             ->FindAll();
  2075.         return $result;
  2076.     }
  2077.     public function LM_displaySizeMatrix_cross2($goodsId)
  2078.     {
  2079.         $viewStr = array();
  2080.         $viewData = [];
  2081.         // サイズを検索
  2082.         $sql "SELECT * FROM size_detail_table ORDER BY size_detail_display";
  2083.         $sizeDetailList = (new SqlService())->Sql($sql)->FetchAll();
  2084.         $gp_detail_list = array();
  2085.         foreach ($sizeDetailList as $sizeDetail) {
  2086.             $gp_detail_list[] = "MAX(CASE sd.size_detail_id WHEN {$sizeDetail['size_detail_id']} THEN gsd.gsd_value END) AS gp_detail{$sizeDetail['size_detail_id']}";
  2087.         }
  2088.         $gp_detail_select implode(', '$gp_detail_list);
  2089.         $sql "SELECT gp_id, gp_goods, gp_kataban, gp_size, gp_price, gp_comment, gp_display, gp_genka, gp_size_id, gp_teika, gp_price2,goods_set_purchase_flg, size.*, gsd.*
  2090.                 FROM goods_price_table AS gp
  2091.                 INNER JOIN goods_table AS goods ON goods_id = gp_goods
  2092.                 LEFT JOIN size_table AS size ON size_id = gp_size_id
  2093.                 LEFT JOIN (
  2094.                     SELECT gsd_goods_price AS gp_id, {$gp_detail_select}
  2095.                     FROM goods_size_detail_table AS gsd
  2096.                     INNER JOIN size_detail_table AS sd ON size_detail_id = gsd_size_detail
  2097.                     WHERE gsd_goods = {$goodsId}
  2098.                     GROUP BY gsd_goods_price
  2099.                 ) AS gsd USING ( gp_id )
  2100.                 WHERE gp_goods = :goodsId AND IfNull(gp_display, 0) != 99
  2101.                 ORDER BY ISNULL( gp_display ), gp_display, gp_kataban, gp_price";
  2102.         $rs = (new SqlService())->Sql($sql)
  2103.             ->Param('goodsId'$goodsId)
  2104.             ->FetchAll();
  2105.         if (!empty($rs)) {
  2106.             $result = array();
  2107.             foreach ($rs as $rowNum => $row) {
  2108.                 $buf = array();
  2109.                 foreach ($row as $colName => $col) {
  2110.                     if (preg_match('/^gp_detail/'$colName)) {
  2111.                         $buf['gp_detail_list'][$colName] = $col;
  2112.                     } else {
  2113.                         $buf[$colName] = $col;
  2114.                     }
  2115.                 }
  2116.                 $result[] = $buf;
  2117.             }
  2118.         } else {
  2119.             $result $rs;
  2120.         }
  2121.         $goodsSizeDetaiList $result;
  2122.         $gp_size = array();
  2123.         $gp_detail = array();
  2124.         $gp_comment = array();
  2125.         $gp_size_buf "";
  2126.         $tmp_row count($goodsSizeDetaiList);
  2127.         foreach ($goodsSizeDetaiList as $i => $goodsSizeDetail) {
  2128.             $gp_size_list[$i] = $goodsSizeDetail['size_name'];
  2129.             $gp_comment_list[$i] = $goodsSizeDetail['gp_comment'];
  2130.             $gp_detail_list[$i] = $goodsSizeDetail["gp_detail_list"];
  2131.             $purchase_flg $goodsSizeDetail["goods_set_purchase_flg"];
  2132.         }
  2133.         // 見出しの書き込み
  2134.         $gp_size_count_list = array();
  2135.         foreach ($gp_size_list as $i => $gp_size) {
  2136.             if ($gp_size_buf != $gp_size) {
  2137.                 $gp_size_buf $gp_size;
  2138.                 $gp_size_count_list[$gp_size] = 1;
  2139.             } else {
  2140.                 $gp_size_count_list[$gp_size]++;
  2141.             }
  2142.         }
  2143.         foreach ($gp_size_count_list as $gp_size => $colspan) {
  2144.             $viewStr['size'][] = $gp_size;
  2145.             $viewStr['colspan'][] = $colspan;
  2146.         }
  2147.         $loop 0;
  2148.         foreach ($sizeDetailList as $i => $sizeDetail) {
  2149.             $chk false;
  2150.             foreach ($gp_detail_list as $j => $gp_detail) {
  2151.                 if (!empty($gp_detail["gp_detail{$sizeDetail['size_detail_id']}"])) {
  2152.                     $chk true;
  2153.                     break;
  2154.                 }
  2155.             }
  2156.             if ($chk) {
  2157.                 $tablet_ids = array(
  2158.                     22,        // タブレットが入るポケットの深さ
  2159.                     23,        // タブレットが入るポケット口
  2160.                     24,        // タブレットが入るポケット口実寸
  2161.                     26        // タブレットが入るポケット
  2162.                 );
  2163.                 if (//isSizeHelpExists($sizeDetail['size_detail_id']) &&
  2164.                 !in_array((int)$sizeDetail['size_detail_id'], $tablet_ids)        // タブレット系のサイズはリンクを表示しない
  2165.                 ) {
  2166.                     $viewData[$loop]['link'] = $sizeDetail['size_detail_id'];
  2167.                 } else {
  2168.                     $viewData[$loop]['link'] = "";
  2169.                 }
  2170.                 $viewData[$loop]['position'] = $sizeDetail['size_detail_name'];
  2171.                 $count_td = array();
  2172.                 $last_value null;
  2173.                 $gp_detail = array();
  2174.                 foreach ($gp_detail_list as $j => $gp_detail) {
  2175.                     //$td_value = "";
  2176.                     if (!empty($gp_detail["gp_detail{$sizeDetail['size_detail_id']}"])) {
  2177.                         $td_value $gp_detail["gp_detail{$sizeDetail['size_detail_id']}"];
  2178.                     } else {
  2179.                         continue;
  2180.                     }
  2181.                     if ($last_value != $td_value) {
  2182.                         array_push($count_td, array('count' => 1'val' => $td_value));
  2183.                     } else {
  2184.                         $count_td[count($count_td) - 1]['count'] += 1;
  2185.                     }
  2186.                     $last_value $td_value;
  2187.                 }
  2188.                 // 3つ以上同じサイズが続く場合、セルを結合,2つまでは独自セル
  2189.                 // ただし、全てが同じサイズであれば2つ以下でも結合
  2190.                 // 同じ値が2つの場合でも、文字列の長さが4文字以上(ないし5文字以上)の場合には結合
  2191.                 $uniqueCont count($count_td);
  2192.                 $loop2 0;
  2193.                 foreach ($count_td as $count_val) {
  2194.                     $viewData[$loop]['count'][$loop2] = $count_val['count'];
  2195.                     $viewData[$loop]['val'][$loop2] = $count_val['val'];
  2196.                     /*
  2197.                     if (empty($data['goods_set_purchase_flg']) && $count_val['count'] == 2 && mb_strlen($count_val['val']) >= 4) {
  2198.                         $viewData[$loop]['count'][$loop2] = $count_val['count'];
  2199.                         $viewData[$loop]['val'][$loop2] = $count_val['val'];
  2200.                     }elseif((empty($purchase_flg) && $count_val['count'] <= 2 && $uniqueCont != 1) || $count_val['val'] == '') {
  2201.                         //セル数が2以下の場合且つ、サイズ種類が2つ以上ある場合独立セル
  2202.                         for($j=1; $j<=$count_val['count']; $j++) {
  2203.                             $viewData[$loop]['count'][$loop2] = "";
  2204.                             $viewData[$loop]['val'][$loop2] = $count_val['val'];
  2205.                         }
  2206.                     } else {
  2207.                         //結合セル
  2208.                         $viewData[$loop]['count'][$loop2] = $count_val['count'];
  2209.                         $viewData[$loop]['val'][$loop2] = $count_val['val'];
  2210.                     }
  2211.                     */
  2212.                     $loop2++;
  2213.                 }
  2214.             }
  2215.             $loop++;
  2216.         }
  2217.         $chk false;
  2218.         for ($j 0$j $tmp_row$j++) {
  2219.             if ($gp_comment_list[$j] != "") {
  2220.                 $chk true;
  2221.                 break;
  2222.             }
  2223.         }
  2224.         if ($chk) {
  2225.             for ($j 0$j $tmp_row$j++) {
  2226.                 $viewStr['comment'][] = $gp_comment_list[$j];
  2227.             }
  2228.         }
  2229.         return [$viewStr$viewData];
  2230.     }
  2231.     public function getGoodsSeriesListByGoodsId($goodsId$formatted true)
  2232.     {
  2233.         $query "SELECT
  2234.                     gs_id
  2235.                 ,   gs_column_number
  2236.                 ,   gs_title
  2237.                 ,   gs_sub_title
  2238.                 ,   goods_id
  2239.                 ,   goods_canonical_hinban
  2240.                 ,   COALESCE(goods_canonical_hinban, goods_id) AS item_id
  2241.                 ,   goods_name
  2242.                 ,   goods_new_name
  2243.                 ,   goods_caption
  2244.                 ,   goods_series_2column_caption
  2245.                 ,   MIN(gp_kataban) AS kataban
  2246.                 ,   COALESCE(color.color_id, color2.color_id) AS color_id
  2247.                 ,   COALESCE(color.color_name, color2.color_name) AS color_name
  2248.                 ,   COALESCE(color.color_rgb, color2.color_rgb) AS color_rgb
  2249.                 FROM goods_series_table AS gs
  2250.                 INNER JOIN goods_series_goods_table AS gsg ON gs_id = gsg_gs
  2251.                 INNER JOIN goods_table AS goods ON goods_id = gsg_goods
  2252.                 LEFT JOIN goods_price_table AS gp ON goods_id = gp_goods
  2253.                 LEFT JOIN goods_set_purchase_table ON goods_id = gsp_goods_parent AND gsp_type = 0
  2254.                 LEFT JOIN goods_color_table AS gcl ON goods_id = gcl.gcl_goods AND gcl.gcl_display_status = 1
  2255.                 LEFT JOIN color_table AS color ON color.color_id = gcl.gcl_color_id
  2256.                 -- gcl2, color2 --> セット品番対応。メイン品番のカラーを使用する。
  2257.                 LEFT JOIN goods_color_table AS gcl2 ON gsp_goods_child = gcl2.gcl_goods AND gcl2.gcl_display_status = 1
  2258.                 LEFT JOIN color_table AS color2 ON color2.color_id = gcl2.gcl_color_id
  2259.                 WHERE gs_goods = :gs_goods AND goods_status = 1 AND goods_ddate IS NULL AND gs_del_flg = 0
  2260.                 GROUP BY
  2261.                     gs_id
  2262.                 ,   gsg_id
  2263.                 ,   goods_id
  2264.                 ,   COALESCE(color.color_id, color2.color_id)
  2265.                 ORDER BY
  2266.                     gs_column_number
  2267.                 ,   gsg_id
  2268.                 ,   COALESCE(gcl.gcl_display, gcl2.gcl_display, 999)
  2269.                 ,   COALESCE(color.color_display, color2.color_display, 999)
  2270.                 ,   COALESCE(color.color_name, color2.color_name)";
  2271.         $tmp = (new SqlService())->Sql($query)
  2272.             ->Param('gs_goods'$goodsId)
  2273.             ->FetchAll();
  2274.         if ($formatted) {
  2275.             // データ構造を階層型に整形
  2276.             $result = array();
  2277.             foreach ((array)$tmp as $row) {
  2278.                 //
  2279.                 $gsId $row['gs_id'];
  2280.                 $columnNumber $row['gs_column_number'];
  2281.                 $goodsId $row['goods_id'];
  2282.                 $colorId $row['color_id'];
  2283.                 //
  2284.                 $result[$columnNumber][$gsId]['gs_column_number'] = $row['gs_column_number'];
  2285.                 $result[$columnNumber][$gsId]['gs_title'] = $row['gs_title'];
  2286.                 $result[$columnNumber][$gsId]['gs_sub_title'] = $row['gs_sub_title'];
  2287.                 //
  2288.                 $result[$columnNumber][$gsId]['goods_list'][$goodsId]['goods_id'] = $row['goods_id'];
  2289.                 $result[$columnNumber][$gsId]['goods_list'][$goodsId]['goods_canonical_hinban'] = $row['goods_canonical_hinban'];
  2290.                 $result[$columnNumber][$gsId]['goods_list'][$goodsId]['item_id'] = $row['item_id'];
  2291.                 $result[$columnNumber][$gsId]['goods_list'][$goodsId]['goods_name'] = $row['goods_name'];
  2292.                 $result[$columnNumber][$gsId]['goods_list'][$goodsId]['goods_new_name'] = $row['goods_new_name'];
  2293.                 $result[$columnNumber][$gsId]['goods_list'][$goodsId]['goods_caption'] = $row['goods_caption'];
  2294.                 $result[$columnNumber][$gsId]['goods_list'][$goodsId]['goods_series_2column_caption'] = $row['goods_series_2column_caption'];
  2295.                 $dir substr($row['goods_id'], -1);
  2296.                 $result[$columnNumber][$gsId]['goods_list'][$goodsId]['goods_image'] = "/goods.img/{$dir}/{$row['goods_id']}/main.jpg";
  2297.                 //
  2298.                 $result[$columnNumber][$gsId]['goods_list'][$goodsId]['kataban'] = $row['kataban'];
  2299.                 //
  2300.                 $result[$columnNumber][$gsId]['goods_list'][$goodsId]['color_list'][$colorId]['color_id'] = $row['color_id'];
  2301.                 $result[$columnNumber][$gsId]['goods_list'][$goodsId]['color_list'][$colorId]['color_name'] = $row['color_name'];
  2302.                 $result[$columnNumber][$gsId]['goods_list'][$goodsId]['color_list'][$colorId]['color_rgb'] = $row['color_rgb'];
  2303.             }
  2304.             // 階層のために連想配列で組立てたデータを配列に変換
  2305.             foreach ($result as &$gs2) {
  2306.                 foreach ($gs2 as &$gs) {
  2307.                     foreach ($gs['goods_list'] as &$goods) {
  2308.                         foreach ($goods['color_list'] as &$color) {
  2309.                             // no operation.
  2310.                         }
  2311.                         $goods['color_list'] = array_values($goods['color_list']);
  2312.                     }
  2313.                     $gs['goods_list'] = array_values($gs['goods_list']);
  2314.                 }
  2315.             }
  2316.             // 一番外側だけは連想配列(シリーズのカラム数をキーとする)のままとする
  2317.             // // $result = array_values($result);
  2318.         } else {
  2319.             $result $tmp;
  2320.         }
  2321.         return $result;
  2322.     }
  2323.     public function detectMainCategory($goodsId)
  2324.     {
  2325.         $campaignCategoryList self::CAMPAIGN_CATEGORY_LIST;
  2326.         $campaignCategoryListIn implode(","array_map(function ($item) {
  2327.             return "'{$item}'";
  2328.         }, $campaignCategoryList));
  2329.         $query "SELECT
  2330.                     `mc`.*
  2331.                 ,    main_category_webname IN (
  2332.                         {$campaignCategoryListIn}
  2333.                     ) AS `is_campaign_category`
  2334.                 FROM (
  2335.                     SELECT
  2336.                         main_category_id
  2337.                     ,    main_category_webname
  2338.                     ,    COUNT(*) AS `CNT`
  2339.                     FROM
  2340.                         category_group_table
  2341.                     INNER JOIN
  2342.                         main_category_table
  2343.                     ON
  2344.                         category_group_id = main_category_group
  2345.                     INNER JOIN
  2346.                         category_table
  2347.                     ON
  2348.                         main_category_id = category_main_category
  2349.                     INNER JOIN
  2350.                         goods_category_table
  2351.                     ON
  2352.                         category_id = gc_category
  2353.                     AND
  2354.                         category_group_only_main = 0
  2355.                     INNER JOIN
  2356.                         goods_table
  2357.                     ON
  2358.                         goods_id = gc_goods
  2359.                     WHERE
  2360.                         goods_id = :goods_id
  2361.                     GROUP BY
  2362.                         main_category_webname
  2363.                     UNION ALL
  2364.                     SELECT
  2365.                         main_category_id
  2366.                     ,    main_category_webname
  2367.                     ,    COUNT(*) AS `CNT`
  2368.                     FROM
  2369.                         category_group_table
  2370.                     INNER JOIN
  2371.                         main_category_table
  2372.                     ON
  2373.                         category_group_id = main_category_group
  2374.                     INNER JOIN
  2375.                         goods_main_category_table
  2376.                     ON
  2377.                         main_category_id = gmc_main_category
  2378.                     AND
  2379.                         category_group_only_main = 1
  2380.                     INNER JOIN
  2381.                         goods_table
  2382.                     ON
  2383.                         goods_id = gmc_goods
  2384.                     WHERE
  2385.                         goods_id = :goods_id
  2386.                     GROUP BY
  2387.                         main_category_webname
  2388.                 ) AS `mc`
  2389.                 ORDER BY
  2390.                     `is_campaign_category` DESC
  2391.                 ,    main_category_id ASC
  2392.                 ,    `CNT` DESC
  2393.                 LIMIT 1";
  2394.         $rs = (new SqlService())->Sql($query)
  2395.             ->Param('goods_id'$goodsId)
  2396.             ->FetchAll();
  2397.         if (!empty($rs)) {
  2398.             $mct $rs[0]['main_category_webname'];
  2399.         } else {
  2400.             $mct null;
  2401.         }
  2402.         return $mct;
  2403.     }
  2404.     public function getDisplayCategorySql4($goodsId$mct$is_except_supersale false)
  2405.     {
  2406.         $addWhereStr '';
  2407.         if ($is_except_supersale) {
  2408.             $addWhereStr " AND main_category_webname != 'super-sale'";
  2409.         }
  2410.         $query "SELECT DISTINCT main_main_id, main_main_name, main_main_web_name, main_id, main_name, main_web_name, main_has_main_categories, cate_id, cate_name, cate_web_name, priority, cate_display
  2411.                 FROM (
  2412.                   -- 1
  2413.                   SELECT
  2414.                     main_category_main_category AS main_main_id,
  2415.                     main_category_main_category_name AS main_main_name,
  2416.                     main_category_main_category_webname AS main_main_web_name,
  2417.                     main_category_id AS main_id,
  2418.                     main_category_name AS main_name,
  2419.                     main_category_webname AS main_web_name,
  2420.                     main_category_has_main_categories AS main_has_main_categories,
  2421.                     NULL AS cate_id,
  2422.                     NULL AS cate_name,
  2423.                     NULL AS cate_web_name,
  2424.                     0 AS priority,
  2425.                     NULL AS cate_display
  2426.                   FROM
  2427.                     main_category_table
  2428.                   INNER JOIN
  2429.                     goods_main_category_table
  2430.                   ON
  2431.                     main_category_id = gmc_main_category
  2432.                   INNER JOIN
  2433.                     category_group_table
  2434.                   ON
  2435.                     category_group_id = main_category_group
  2436.                   WHERE
  2437.                     main_category_status = 1
  2438.                   AND
  2439.                     gmc_goods = :goodsId
  2440.                   AND
  2441.                     NOT EXISTS (
  2442.                       SELECT *
  2443.                       FROM category_table
  2444.                       INNER JOIN goods_category_table ON category_id = gc_category
  2445.                       INNER JOIN goods_table ON goods_id = gc_goods
  2446.                       WHERE goods_id = :goodsId AND category_main_category = main_category_id
  2447.                     )
  2448.                 {$addWhereStr}
  2449.                   -- LIMIT 0, 2
  2450.                   UNION ALL
  2451.                   -- 2
  2452.                   SELECT
  2453.                     main_category_main_category,
  2454.                     main_category_main_category_name,
  2455.                     main_category_main_category_webname,
  2456.                     main_category_id,
  2457.                     main_category_name,
  2458.                     main_category_webname,
  2459.                     main_category_has_main_categories,
  2460.                     NULL,
  2461.                     NULL,
  2462.                     NULL,
  2463.                     4 AS priority,
  2464.                     NULL
  2465.                   FROM
  2466.                     main_category_table
  2467.                   INNER JOIN
  2468.                     goods_main_category_table
  2469.                   ON
  2470.                     main_category_id = gmc_main_category
  2471.                   INNER JOIN
  2472.                     category_group_table
  2473.                   ON
  2474.                     category_group_id = main_category_group
  2475.                   WHERE
  2476.                     main_category_status = 1
  2477.                   AND
  2478.                     gmc_goods = :goodsId
  2479.                   AND
  2480.                     NOT EXISTS (
  2481.                       SELECT *
  2482.                       FROM category_table
  2483.                       INNER JOIN goods_category_table ON category_id = gc_category
  2484.                       INNER JOIN goods_table ON goods_id = gc_goods
  2485.                       WHERE goods_id = :goodsId AND category_main_category = main_category_id
  2486.                     )
  2487.                 {$addWhereStr}
  2488.                   -- LIMIT 2, 6
  2489.                   -- 3
  2490.                   UNION ALL
  2491.                   SELECT
  2492.                     main_category_main_category,
  2493.                     main_category_main_category_name,
  2494.                     main_category_main_category_webname,
  2495.                     main_category_id,
  2496.                     main_category_name,
  2497.                     main_category_webname,
  2498.                     main_category_has_main_categories,
  2499.                     category_id,
  2500.                     category_name,
  2501.                     category_webname,
  2502.                     1 AS priority,
  2503.                     category_display
  2504.                   FROM
  2505.                     main_category_table
  2506.                   INNER JOIN
  2507.                     category_table
  2508.                   ON
  2509.                     main_category_id = category_main_category
  2510.                   INNER JOIN
  2511.                     goods_category_table
  2512.                   ON
  2513.                     category_id = gc_category
  2514.                   INNER JOIN
  2515.                     category_group_table
  2516.                   ON
  2517.                     category_group_id = main_category_group
  2518.                   WHERE
  2519.                     main_category_status = 1
  2520.                   AND
  2521.                     main_category_webname = :mct
  2522.                   AND
  2523.                     category_status = 1
  2524.                   AND
  2525.                     gc_goods = :goodsId
  2526.                   AND
  2527.                     category_group_only_main = 0
  2528.                 {$addWhereStr}
  2529.                   -- LIMIT 0, 4
  2530.                   -- 4
  2531.                   UNION ALL
  2532.                   SELECT
  2533.                     main_category_main_category,
  2534.                     main_category_main_category_name,
  2535.                     main_category_main_category_webname,
  2536.                     main_category_id,
  2537.                     main_category_name,
  2538.                     main_category_webname,
  2539.                     main_category_has_main_categories,
  2540.                     category_id,
  2541.                     category_name,
  2542.                     category_webname,
  2543.                     2 AS priority,
  2544.                     category_display
  2545.                   FROM
  2546.                     main_category_table
  2547.                   INNER JOIN
  2548.                     category_table
  2549.                   ON
  2550.                     main_category_id = category_main_category
  2551.                   INNER JOIN
  2552.                     goods_category_table
  2553.                   ON
  2554.                     category_id = gc_category
  2555.                   INNER JOIN
  2556.                     category_group_table
  2557.                   ON
  2558.                     category_group_id = main_category_group
  2559.                   WHERE
  2560.                     main_category_status = 1
  2561.                   AND
  2562.                     main_category_webname <> :mct
  2563.                   AND
  2564.                     category_status = 1
  2565.                   AND
  2566.                     gc_goods = :goodsId
  2567.                   AND
  2568.                     category_group_only_main = 0
  2569.                 {$addWhereStr}
  2570.                   -- LIMIT 0, 6
  2571.                   -- 5
  2572.                   UNION ALL
  2573.                   SELECT
  2574.                     main_category_main_category,
  2575.                     main_category_main_category_name,
  2576.                     main_category_main_category_webname,
  2577.                     main_category_id,
  2578.                     main_category_name,
  2579.                     main_category_webname,
  2580.                     main_category_has_main_categories,
  2581.                     category_id,
  2582.                     category_name,
  2583.                     category_webname,
  2584.                     3 AS priority,
  2585.                     category_display
  2586.                   FROM
  2587.                     main_category_table
  2588.                   INNER JOIN
  2589.                     category_table
  2590.                   ON
  2591.                     main_category_id = category_main_category
  2592.                   INNER JOIN
  2593.                     goods_category_table
  2594.                   ON
  2595.                     category_id = gc_category
  2596.                   INNER JOIN
  2597.                     category_group_table
  2598.                   ON
  2599.                     category_group_id = main_category_group
  2600.                   WHERE
  2601.                     main_category_status = 1
  2602.                   AND
  2603.                     main_category_webname = :mct
  2604.                   AND
  2605.                     category_status = 1
  2606.                   AND
  2607.                     gc_goods = :goodsId
  2608.                   AND
  2609.                     category_group_only_main = 0
  2610.                 {$addWhereStr}
  2611.                   -- LIMIT 4, 2
  2612.                 -- dummy
  2613.                   UNION ALL
  2614.                   SELECT NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL FROM main_category_table WHERE 1 != 1
  2615.                 ) AS CATE
  2616.                 ORDER BY priority, ISNULL( cate_display ), cate_display, cate_id LIMIT 0, 6";
  2617.         $rows = (new SqlService())->Sql($query)
  2618.             ->Param('goodsId'$goodsId)
  2619.             ->Param('mct'$mct)
  2620.             ->FetchAll();
  2621.         return $rows;
  2622.     }
  2623.     public function getMainCategoryWebnameByMcId($mcId)
  2624.     {
  2625.         $query "SELECT
  2626.                     main_category_webname
  2627.                 FROM
  2628.                     main_category_table
  2629.                 WHERE
  2630.                     main_category_id = :mc_id";
  2631.         $rows = (new SqlService())->Sql($query)
  2632.             ->Param('mc_id'$mcId)
  2633.             ->FetchAll();
  2634.         $row array_shift($rows);
  2635.         $result $row['main_category_webname'];
  2636.         return $result;
  2637.     }
  2638.     public function getGoodsCategories($goodsId)
  2639.     {
  2640.         $goodsCategories = (new SqlService())
  2641.             ->Sql('
  2642.                 SELECT
  2643.                     main_category_main_category AS main_main_id,
  2644.                     main_category_main_category_name AS main_main_name,
  2645.                     main_category_main_category_webname AS main_main_web_name,
  2646.                     main_category_id AS main_id,
  2647.                     main_category_name AS main_name,
  2648.                     main_category_webname AS main_web_name,
  2649.                     main_category_has_main_categories AS main_has_main_categories,
  2650.                     category_id AS cate_id,
  2651.                     category_name AS cate_name,
  2652.                     category_webname AS cate_web_name,
  2653.                     category_display AS cate_display
  2654.                 FROM goods_category_table
  2655.                 INNER JOIN category_table ON gc_category = category_id
  2656.                 INNER JOIN main_category_table ON category_main_category = main_category_id
  2657.                 INNER JOIN category_group_table ON category_group_id = main_category_group
  2658.                 WHERE category_table.category_status = 1 AND category_group_only_main = 0 AND gc_goods = :goods_id
  2659.                 UNION ALL
  2660.                 SELECT
  2661.                     main_category_main_category AS main_main_id,
  2662.                     main_category_main_category_name AS main_main_name,
  2663.                     main_category_main_category_webname AS main_main_web_name,
  2664.                     main_category_id AS main_id,
  2665.                     main_category_name AS main_name,
  2666.                     main_category_webname AS main_web_name,
  2667.                     main_category_has_main_categories AS main_has_main_categories,
  2668.                     NULL AS cate_id,
  2669.                     NULL AS cate_name,
  2670.                     NULL AS cate_web_name,
  2671.                     NULL AS cate_display
  2672.                 FROM main_category_table
  2673.                 INNER JOIN goods_main_category_table ON main_category_id = gmc_main_category
  2674.                 WHERE gmc_goods = :goods_id
  2675.             ')
  2676.             ->Param('goods_id'$goodsId)
  2677.             ->FetchAll();
  2678.         if (empty($goodsCategories)) {
  2679.             return [];
  2680.         }
  2681.         return $goodsCategories;
  2682.     }
  2683.     public function LM_displayCategory($id$isExceptSupersale false)
  2684.     {
  2685.         $goodsCategories $this->getGoodsCategories($id);
  2686.         $viewStr '';
  2687.         $viewStrReview '';
  2688.         $viewStrReviewList = array();
  2689.         foreach ($goodsCategories as $goodsCategoryIndex => $goodsCategory) {
  2690.             // 配下カテゴリ
  2691.             $mcName $goodsCategory['main_web_name'];
  2692.             $mcMcName $goodsCategory['main_main_web_name'];
  2693.             $canonicalMcName $mcName;
  2694.             if (!empty($mcMcName)) {
  2695.                 $canonicalMcName "{$mcMcName}/{$mcName}";
  2696.             }
  2697.             /**
  2698.              * 800-491-7……アユダンテ提案……サーバーサイド側……フロントエンド側を一通り対応した結果、システム開発が必要となった4項目の対応
  2699.              * ●項番2:”スーパーセール”カテゴリは除外する
  2700.              */
  2701.             if ($isExceptSupersale && ($goodsCategory['main_main_web_name'] == 'super-sale')) {
  2702.                 continue;
  2703.             }
  2704.             if ($goodsCategoryIndex <= 5) {
  2705.                 $viewStr .= "<p class=\"category\">";
  2706.                 if (!empty($goodsCategory['main_main_web_name']) && !empty($goodsCategory['main_main_name'])) {
  2707.                     $viewStr .= "<a href=\"/" $goodsCategory['main_main_web_name'] . "/\">" $goodsCategory['main_main_name'] . "</a> &gt; ";
  2708.                 }
  2709.                 $viewStr .= "<a href=\"/" $canonicalMcName "/\">" $goodsCategory['main_name'] . "</a>";
  2710.                 // 掲載カテゴリーURLが二重スラッシュ「//」となってしまうバグ修正
  2711.                 if (!empty($goodsCategory['cate_web_name']) && !empty($goodsCategory['cate_name'])) {
  2712.                     $viewStr .= " &gt; <a href=\"/" $canonicalMcName "/" $goodsCategory['cate_web_name'] . "/\">" $goodsCategory['cate_name'] . "</a>";
  2713.                 }
  2714.                 $viewStr .= "</p>\n";
  2715.                 $viewStrReview .= "<a href=\"/" $canonicalMcName "/\">" $goodsCategory['main_name'] . "</a> &gt;&gt; <a href=\"/" $canonicalMcName "/" $goodsCategory['cate_web_name'] . "/\">" $goodsCategory['cate_name'] . "</a>\n";
  2716.                 $viewStrReviewList[] = "<a href=\"/" $canonicalMcName "/\">" $goodsCategory['main_name'] . "</a>";
  2717.                 $viewStrReviewList[] = "<a href=\"/" $canonicalMcName "/" $goodsCategory['cate_web_name'] . "/\">" $goodsCategory['cate_name'] . "</a>";
  2718.             }
  2719.             $mainCategoryList[$goodsCategory['main_id']] = $goodsCategory;
  2720.             $mainCategoryIdList[] = $goodsCategory['main_id'];
  2721.         }
  2722.         $categories array_count_values($mainCategoryIdList);
  2723.         $categoriesWithMostProducts array_keys($categoriesmax($categories));
  2724.         $canonicalPankuzuMainCategory = [$mainCategoryList[$categoriesWithMostProducts[0]]];
  2725.         return array(
  2726.             "viewStr" => $viewStr,
  2727.             "viewStrReview" => $viewStrReview,
  2728.             "viewStrReviewList" => $viewStrReviewList,
  2729.             "canonicalPankuzuMainCategory" => $canonicalPankuzuMainCategory
  2730.         );
  2731.     }
  2732.     public function LM_displayCategory4($goodsId$mct null$additionalList = array(), $is_except_supersale false)
  2733.     {
  2734.         return $this->getCached(function () use ($goodsId$mct$additionalList$is_except_supersale) {
  2735.             $viewStr "";
  2736.             $viewStrReview "";
  2737.             // パン屑用カテゴリの指定が無い場合、当該商品の掲載数の最も多い親カテを採用する。
  2738.             if (empty($mct)) {
  2739.                 $mct $this->detectMainCategory($goodsId);
  2740.             }
  2741.             $rs self::getDisplayCategorySql4($goodsId$mct$is_except_supersale);
  2742.             // 800-172-2……UTの商品ページの「当商品の掲載カテゴリー」……「作業服」のKW対策
  2743.             if (!empty($additionalList)) {
  2744.                 $rs array_merge($rs$additionalList);
  2745.             }
  2746.             foreach ((array)$rs as $row) {
  2747.                 // 配下カテゴリ
  2748.                 $mcName $row['main_web_name'];
  2749.                 $mcMcName $row['main_main_web_name'];
  2750.                 $canonicalMcName $mcName;
  2751.                 if (!empty($mcMcName)) {
  2752.                     $canonicalMcName "{$mcMcName}/{$mcName}";
  2753.                 }
  2754.                 //
  2755.                 $viewStr .= "<p class=\"category\">";
  2756.                 if (!empty($row['main_main_web_name']) && !empty($row['main_main_name'])) {
  2757.                     $viewStr .= "<a href=\"/" $row['main_main_web_name'] . "/\">" $row['main_main_name'] . "</a> &gt; ";
  2758.                     //$viewStr[$loop][] = array($row['main_main_web_name'],$row['main_main_name']);
  2759.                 }
  2760.                 if (!empty($row['main_web_name']) && !empty($row['main_name'])) {
  2761.                     $viewStr .= "<a href=\"/" $canonicalMcName "/\">" $row['main_name'] . "</a>";
  2762.                     //$viewStr[$loop][] = array($canonicalMcName,$row['main_name']);
  2763.                 }
  2764.                 if (!empty($row['cate_web_name']) && !empty($row['cate_name'])) {
  2765.                     $viewStr .= " &gt; <a href=\"/" $canonicalMcName "/" $row['cate_web_name'] . "/\">" $row['cate_name'] . "</a>";
  2766.                     //$viewStr[$loop][] = array($canonicalMcName. "/" . $row['cate_web_name'],$row['cate_name']);
  2767.                 }
  2768.                 $viewStr .= "</p>";
  2769.                 //$viewStrReview[$loop][] = array($canonicalMcName,$row['main_name'],$canonicalMcName . "/" . $row['cate_web_name'],$row['cate_name']);
  2770.                 $viewStrReview .= "<a href=\"/" $canonicalMcName "/\">" $row['main_name'] . "</a> &gt;&gt; <a href=\"/" $canonicalMcName "/" $row['cate_web_name'] . "/\">" $row['cate_name'] . "</a>\n";
  2771.             }
  2772.             $query "SELECT main_category_main_category AS main_main_id, main_category_main_category_name AS main_main_name, main_category_main_category_webname AS main_main_web_name, main_category_id AS main_id, main_category_name AS main_name, main_category_webname AS main_web_name, main_category_has_main_categories AS main_has_main_categories
  2773.                     ,    main_leftmenuup1
  2774.                     ,    main_leftmenuup2
  2775.                     ,    main_leftmenuup3
  2776.                     ,    main_leftmenudown1
  2777.                     ,    main_leftmenudown2
  2778.                     ,    main_leftmenudown3
  2779.                     ,    main_leftmenudown4
  2780.                     ,    main_leftmenudown5
  2781.                     ,    main_leftmenudown6
  2782.                     ,    main_leftmenudown7
  2783.                     FROM main_category_table
  2784.                     WHERE main_category_webname = :mc_id";
  2785.             $rs = (new SqlService())->Sql($query)
  2786.                 ->Param('mc_id'$mct)
  2787.                 ->FetchAll();
  2788.             $canonicalPankuzuMainCategory $rs;
  2789.             return array("viewStr" => $viewStr"viewStrReview" => $viewStrReview"canonicalPankuzuMainCategory" => $canonicalPankuzuMainCategory);
  2790.         });
  2791.     }
  2792.     public function getMainCategorySqlFromGoodsId2($goodsId)
  2793.     {
  2794.         $query "SELECT
  2795.                     main_category_main_category AS main_main_id
  2796.                 ,    main_category_main_category_name AS main_main_name
  2797.                 ,    main_category_main_category_webname AS main_main_web_name
  2798.                 ,    main_category_id AS main_id
  2799.                 ,    main_category_name AS main_name
  2800.                 ,    main_category_webname AS main_web_name
  2801.                 ,    main_category_has_main_categories AS main_has_main_categories
  2802.                 ,    category_id AS cate_id
  2803.                 ,    category_name AS cate_name
  2804.                 ,    category_webname AS cate_web_name
  2805.                 ,    Null AS priority
  2806.                 ,    Null AS cate_display
  2807.                 ,    main_leftmenuup1
  2808.                 ,    main_leftmenuup2
  2809.                 ,    main_leftmenuup3
  2810.                 ,    main_leftmenudown1
  2811.                 ,    main_leftmenudown2
  2812.                 ,    main_leftmenudown3
  2813.                 ,    main_leftmenudown4
  2814.                 ,    main_leftmenudown5
  2815.                 ,    main_leftmenudown6
  2816.                 ,    main_leftmenudown7
  2817.                 FROM
  2818.                     main_category_table
  2819.                 INNER JOIN
  2820.                     category_table
  2821.                 ON
  2822.                     main_category_id = category_main_category
  2823.                 INNER JOIN
  2824.                     goods_category_table
  2825.                 ON
  2826.                     category_id = gc_category
  2827.                 WHERE
  2828.                     gc_goods = :goods_id
  2829.                 AND
  2830.                     (
  2831.                         (main_category_webname, category_webname) IN (
  2832.                             ('work', 'warm')
  2833.                         )
  2834.                     OR    main_category_webname IN ('work-cool', 'work-bigsize', 'work-coolbiz')
  2835.                     )
  2836.                 ORDER BY
  2837.                     main_category_id";
  2838.         $tmp = (new SqlService())->Sql($query)
  2839.             ->Param('goods_id'$goodsId)
  2840.             ->FetchAll();
  2841.         return $tmp;
  2842.     }
  2843.     public function getGoodsDataForRecentviews2($goodsIdList)
  2844.     {
  2845.         // SQLインジェクション対策
  2846.         $goodsIdList $this->lmHelper->getIntegerArray($goodsIdList);
  2847.         if (empty($goodsIdList)) {
  2848.             return [];
  2849.         }
  2850.         $goodsId implode(', '$goodsIdList);
  2851.         $query "
  2852.             SELECT
  2853.                 goods_id, goods_canonical_hinban, goods_name, MIN(ROUND(gp_price2 * (1+ 10/100))) AS min_gp_price, COUNT(DISTINCT(ROUND(gp_price2 * (1+ 10/100)))) AS count_gp_price,
  2854.                 (CASE WHEN cp_price IS NOT NULL AND cp_price > 0 THEN MIN(cp_price) ELSE MIN(ROUND(gp_price2 * (1+ 10/100))) END) as min_gp_price,
  2855.                 (CASE WHEN cp_price IS NOT NULL AND cp_price > 0 THEN COUNT(DISTINCT(cp_price)) ELSE COUNT(DISTINCT(ROUND(gp_price2 * (1+ 10/100)))) END) as count_gp_price,
  2856.                 IfNull(cra_average_points, 0) AS review_average, IfNull(cra_target_count, 0) AS review_count
  2857.             FROM goods_table
  2858.             LEFT JOIN jancode_table ON goods_id = jan_goods
  2859.             LEFT JOIN goods_price_table ON goods_id = gp_goods
  2860.             LEFT JOIN campaign_price_table ON cp_gp = gp_id AND `cp_end_datetime` >= NOW() and `cp_start_datetime` <= NOW()
  2861.             LEFT JOIN customer_review_average_table ON goods_id = cra_goods_id AND cra_target_count >= 1
  2862.             WHERE goods_id IN (" $goodsId ")
  2863.                 AND jan_ddate IS NULL AND gp_price IS NOT NULL
  2864.             GROUP BY
  2865.                 goods_id
  2866.             ORDER BY FIELD(goods_id, {$goodsId})";
  2867.         $tmp = (new SqlService())->Sql($query)
  2868.             ->FetchAll();
  2869.         return $tmp;
  2870.     }
  2871.     public function getCategoryData($mcId$ctId null)
  2872.     {
  2873.         if (empty($ctId)) {
  2874.             $query "SELECT * FROM main_category_table WHERE main_category_id = :mcId";
  2875.             $tmp = (new SqlService())->Sql($query)
  2876.                 ->Param('mcId'$mcId)
  2877.                 ->Fetch();
  2878.         } else {
  2879.             $query "SELECT * FROM main_category_table INNER JOIN category_table ON main_category_id = category_main_category WHERE main_category_id = :mcId AND category_id = :ctId";
  2880.             $tmp = (new SqlService())->Sql($query)
  2881.                 ->Param('mcId'$mcId)
  2882.                 ->Param('ctId'$ctId)
  2883.                 ->Fetch();
  2884.         }
  2885.         return $tmp;
  2886.     }
  2887.     public function getMainCategoryName($mcName)
  2888.     {
  2889.         return (new SqlService())
  2890.             ->Table('main_category_table')
  2891.             ->Join('category_group_table''T1.category_group_id = T.main_category_group''INNER')
  2892.             ->Join('category_table''T.main_category_id = T2.category_main_category''LEFT')
  2893.             ->Select("T.main_category_webname AS mc, T2.category_webname AS ct, T.main_category_id, T2.category_id
  2894.                     , T1.category_group_noshowdb, T1.category_group_only_main, T.main_category_group
  2895.                     , T.main_category_name, T2.category_name, T2.category_webname, T.main_bottomlink, T.main_pagebottom")
  2896.             ->Set('T.main_category_webname'$mcName)
  2897.             ->Find();
  2898.     }
  2899.     public function getSubCategoryName($mcId$ctName)
  2900.     {
  2901.         return (new SqlService())
  2902.             ->Table('main_category_table')
  2903.             ->Join('category_table''T.main_category_id = T1.category_main_category''INNER')
  2904.             ->Select("T.main_category_webname AS mc, T1.category_webname AS ct, T.main_category_id, T1.category_id")
  2905.             ->Set('T.main_category_id'$mcId)
  2906.             ->Set('T1.category_webname'$ctName)
  2907.             ->Find();
  2908.     }
  2909.     public function getMainCategoryData($id)
  2910.     {
  2911.         return (new SqlService())
  2912.             ->Table('main_category_table')
  2913.             ->Set('main_category_id'$id)
  2914.             ->Find();
  2915.     }
  2916.     public function _getOriginalCategory_Main($id)
  2917.     {
  2918.         $rs = (array)(new SqlService())
  2919.             ->Table('category_table')
  2920.             ->Set('category_main_category'$id)
  2921.             ->Select("category_id, category_category, category_main")
  2922.             ->FindAll();
  2923.         $all_category "";
  2924.         foreach ($rs as $row) {
  2925.             if ($all_category != ""$all_category .= ",";
  2926.             $all_category .= $this->_getOriginalCategory($row['category_id'], $row);
  2927.         }
  2928.         return $all_category;
  2929.     }
  2930.     public function _getOriginalCategory($id$tmpRow null)
  2931.     {
  2932.         if ($tmpRow === null) {
  2933.             $row = (new SqlService())
  2934.                 ->Table('category_table')
  2935.                 ->Set('category_id'$id)
  2936.                 ->Select("category_id, category_category, category_main")
  2937.                 ->Find();
  2938.         } else {
  2939.             $row $tmpRow;
  2940.         }
  2941.         if ($row) {
  2942.             //カテゴリが共有されている場合の処理
  2943.             if ($row['category_category'] != "") {
  2944.                 $all_category $row['category_category'];
  2945.             } elseif ($row['category_main'] != "") {
  2946.                 $strSQL "select coalesce( category_category, category_id ) as cid, category_main
  2947.                     from category_table
  2948.                     where category_main_category = " $row['category_main'] . " and category_main is null";
  2949.                 $tempRow = (new SqlService())->Sql($strSQL)->FetchAll();
  2950.                 foreach ($tempRow as $row) {
  2951.                     if ($all_category != ""$all_category .= ",";
  2952.                     $all_category .= $row['cid'];
  2953.                 }
  2954.             } else {
  2955.                 $all_category $id;
  2956.             }
  2957.         } else {
  2958.             $all_category $id;
  2959.         }
  2960.         return $all_category;
  2961.     }
  2962.     public function useUnItemOrder($mcId null$ctId null)
  2963.     {
  2964.         if (empty($mcId)) return false;
  2965.         $category_id $mcId;
  2966.         $is_parent 1;
  2967.         // 子カテの指定がある場合
  2968.         if (!empty($ctId) && strtolower($ctId) !== 'allitem') {
  2969.             $category_id $ctId;
  2970.             $is_parent 0;
  2971.         }
  2972.         $rows = (new SqlService())
  2973.             ->Table('uniform_next_category_map_table')
  2974.             ->Set('lm_category_id'$category_id)
  2975.             ->Set('is_parent'$is_parent)
  2976.             ->Set('use_un_order'1)
  2977.             ->Finds();
  2978.         return !empty($rows);
  2979.     }
  2980.     public function getDataBySql($sql)
  2981.     {
  2982.         return (new SqlService())->Sql($sql)->FetchAll();
  2983.     }
  2984.     public function getSubCategoryList($mainCategoryId)
  2985.     {
  2986.         //
  2987.         return CategoryWithRelated::getSubCategoryListByMainCategoryId($mainCategoryId);
  2988.     }
  2989.     public function getByCategoryWebName($siteType$webName null)
  2990.     {
  2991.         // $db = $this->getAdapter();
  2992.         // $sql = "SELECT upper_one_column_content FROM upper_column_table";
  2993.         // if ($webName) {
  2994.         //     $sql .= " LEFT JOIN main_category_table ON upper_column_table.target_category_id = main_category_table.main_category_id ";
  2995.         //     $sql .= " AND site_type = {$siteType} ";
  2996.         //     $sql .= " WHERE main_category_has_main_categories = 1 AND main_category_webname = '{$webName}' AND main_category_status = 1";
  2997.         // }
  2998.         // $result = $db->fetchRow($sql);
  2999.         // return $result;
  3000.         $query = (new SqlService())
  3001.             ->Table('upper_column_table')
  3002.             ->Select('upper_one_column_content');
  3003.         if ($webName) {
  3004.             $query->Join('main_category_table'"T.target_category_id = T1.main_category_id AND site_type = {$siteType}"'LEFT')
  3005.                 ->Set('T1.main_category_has_main_categories'1)
  3006.                 ->Set('T1.main_category_webname'$webName)
  3007.                 ->Set('T1.main_category_status'1);
  3008.         }
  3009.         return $query->Fetch();
  3010.     }
  3011.     /**
  3012.      * 商品のパンくずリストを取得する
  3013.      * TODO: 相関エンティティに移植
  3014.      * @param int $goodsId
  3015.      * @return array
  3016.      */
  3017.     public function getBreadCrumbsByGoodsId($goodsId)
  3018.     {
  3019.         //
  3020.         $breadCrumb = array();
  3021.         //
  3022.         $goods $this->ProductConverter->getGoodsById($goodsId);
  3023.         //
  3024.         $displayCategory $this->LM_displayCategory4($goodsId);
  3025.         $canonicalPankuzuMainCategory $displayCategory['canonicalPankuzuMainCategory'];
  3026.         //
  3027.         if (!empty($goods['goods_breadcrumb_category_name2']) && !empty($goods['goods_breadcrumb_category_url2'])) {
  3028.             // 800-375-3……UT商品にて、パンくずリストのすべての階層を登録できるようにする(ファイルのインポート・エクスポートに項目追加して編集できるようにする)
  3029.             $breadCrumb[] = array(
  3030.                 'href' => preg_replace('@([^/]+)$@''$1/'$goods['goods_breadcrumb_category_url2']),
  3031.                 'label' => $goods['goods_breadcrumb_category_name2']
  3032.             );
  3033.         } else if ($canonicalPankuzuMainCategory[0]['main_web_name'] != '') {
  3034.             $breadcrumbCategory '';
  3035.             $tempRow $this->getMainCategoryData($canonicalPankuzuMainCategory[0]['main_web_name']);
  3036.             if ($tempRow) {
  3037.                 if ($tempRow[0]['main_breadcrumb_category_name'] != '' && $tempRow[0]['main_breadcrumb_category_url'] != '') {
  3038.                     $breadCrumb[] = array(
  3039.                         'href' => preg_replace('@([^/]+)$@''$1/'$tempRow[0]['main_breadcrumb_category_url']),
  3040.                         'label' => $tempRow[0]['main_breadcrumb_category_name']
  3041.                     );
  3042.                 }
  3043.             }
  3044.         }
  3045.         if (!empty($goods['goods_breadcrumb_category_name3']) && !empty($goods['goods_breadcrumb_category_url3'])) {
  3046.             // 800-375-3……UT商品にて、パンくずリストのすべての階層を登録できるようにする(ファイルのインポート・エクスポートに項目追加して編集できるようにする)
  3047.             $breadCrumb[] = array(
  3048.                 'href' => preg_replace('@([^/]+)$@''$1/'$goods['goods_breadcrumb_category_url3']),
  3049.                 'label' => $goods['goods_breadcrumb_category_name3']
  3050.             );
  3051.         } else if (empty($goods['goods_breadcrumb_category_name2']) || empty($goods['goods_breadcrumb_category_url2'])) {
  3052.             // 配下カテゴリ
  3053.             if (!empty($canonicalPankuzuMainCategory[0]['main_main_id'])) {
  3054.                 $breadCrumb[] = array(
  3055.                     'href' => "/{$canonicalPankuzuMainCategory[0]['main_main_web_name']}/",
  3056.                     'label' => $canonicalPankuzuMainCategory[0]['main_main_name']
  3057.                 );
  3058.                 // 商品詳細の「子カテゴリ名1」が空の場合のみ、「商品が最も多く属する親カテ」をパンくずに表示。
  3059.                 $breadCrumb[] = array(
  3060.                     'href' => "/{$canonicalPankuzuMainCategory[0]['main_main_web_name']}/{$canonicalPankuzuMainCategory[0]['main_web_name']}/",
  3061.                     'label' => $canonicalPankuzuMainCategory[0]['main_name']
  3062.                 );
  3063.             } else {
  3064.                 // 商品詳細の「子カテゴリ名1」が空の場合のみ、「商品が最も多く属する親カテ」をパンくずに表示。
  3065.                 $breadCrumb[] = array(
  3066.                     'href' => "/{$canonicalPankuzuMainCategory[0]['main_web_name']}/",
  3067.                     'label' => $canonicalPankuzuMainCategory[0]['main_name']
  3068.                 );
  3069.             }
  3070.         }
  3071.         if ($goods['goods_breadcrumb_category_name'] != '' && $goods['goods_breadcrumb_category_url'] != '') {
  3072.             $breadCrumb[] = array(
  3073.                 'href' => preg_replace('@([^/]+)$@''$1/'$goods['goods_breadcrumb_category_url']),
  3074.                 'label' => $goods['goods_breadcrumb_category_name']
  3075.             );
  3076.         }
  3077.         if (!empty($goods['goods_breadcrumb_category_name4']) && !empty($goods['goods_breadcrumb_category_url4'])) {
  3078.             // 800-375-4……UT商品パンくず……「子カテゴリ名4」の追加
  3079.             $breadCrumb[] = array(
  3080.                 'href' => preg_replace('@([^/]+)$@''$1/'$goods['goods_breadcrumb_category_url4']),
  3081.                 'label' => $goods['goods_breadcrumb_category_name4']
  3082.             );
  3083.         }
  3084.         $itemId $goods['goods_canonical_hinban'] ?: $goods['goods_id'];
  3085.         $breadCrumb[] = array(
  3086.             'href' => "/item/{$itemId}.html",
  3087.             'label' => $goods['goods_name'],
  3088.         );
  3089.         return $breadCrumb;
  3090.     }
  3091.     public function getFollowUpByHashKey($hashKey)
  3092.     {
  3093.         $query "SELECT * FROM follow_up_list_table
  3094.                 INNER JOIN customer_table USING ( customer_id )
  3095.                 WHERE ful_hash_key = :hashKey";
  3096.         $result = (new SqlService())->Sql($query)
  3097.             ->Param('hashKey'$hashKey)
  3098.             ->Fetch();
  3099.         return $result;
  3100.     }
  3101.     public function saveReply($ful_id$replyOption)
  3102.     {
  3103.         $result = (new SqlService())
  3104.             ->Table('follow_up_list_table')
  3105.             ->Values([
  3106.                 'ful_reply_status' => 1,
  3107.                 'ful_reply_option' => $replyOption,
  3108.                 'ful_reply_date' => date('Y-m-d H:i:s'),
  3109.                 'ful_modified_at' => date('Y-m-d H:i:s'),
  3110.             ])
  3111.             ->Set('ful_id'$ful_id)
  3112.             ->Update();;
  3113.         return $result;
  3114.     }
  3115.     // 受注情報(お届け予定日、黄色の付箋)の更新
  3116.     public function updateOrder($ful_id$replyOption)
  3117.     {
  3118.         $result false;
  3119.         if (!is_numeric($ful_id)) {
  3120.             return false;
  3121.         }
  3122.         if (in_array($replyOption, [
  3123.             self::REPLY_OPTION_WAIT_ENTIRE,
  3124.             self::REPLY_OPTION_WAIT_SEQUENTIAL,
  3125.             self::REPLY_OPTION_CANCEL_DELAYED,
  3126.             self::REPLY_OPTION_CANCEL_ALL,
  3127.         ])) {
  3128.             $date date('Y-m-d');
  3129.             $comment "お客様返信済み";
  3130.             $ohMemo sprintf(self::MEMO_FORMATdate('n/j'strtotime($date)), $comment);
  3131.             $dbManager = new DbManager();
  3132.             $g_db $dbManager->get();
  3133.             $sql "UPDATE follow_up_list_table AS `ful`
  3134.                     INNER JOIN follow_up_detail_table AS `fud` USING ( ful_id )
  3135.                     INNER JOIN follow_up_summary_table AS `fus` USING ( fus_id )
  3136.                     INNER JOIN order_header_table AS `oh` USING ( oh_id )
  3137.                     SET
  3138.                         oh_send_schedule = DATE_FORMAT(fus_alternative_schedule, '%Y/%m/%d'),
  3139.                         oh_memo = CONCAT('" $ohMemo "', '\n\n', oh_memo)
  3140.                     WHERE
  3141.                         ful_id = " $ful_id;
  3142.             $g_db->exec($sql);
  3143.             $result true;
  3144.         }
  3145.         return $result;
  3146.     }
  3147.     public function getFollowUpDetailByFulId($fulId)
  3148.     {
  3149.         $query "SELECT oh_shubetsu, oh_id FROM follow_up_list_table
  3150.                 INNER JOIN follow_up_detail_table USING (ful_id)
  3151.                 INNER JOIN order_header_table USING (oh_id)
  3152.                 WHERE ful_id = :fulId";
  3153.         $result = (new SqlService())->Sql($query)
  3154.             ->Param('fulId'$fulId)
  3155.             ->FetchAll();
  3156.         return $result;
  3157.     }
  3158. }