<?php
namespace Customize\Service;
use Customize\Converter\DynamicConverter;
use Eccube\Entity\ClassCategory;
use Lm\Engine\EC\Entity\GoodsExtended;
use Lm\Engine\EC\Entity\SkuWithPrice;
use Lm\Engine\SokujitsuHassou\SokujitsuHassou;
use Lm\Engine\EC\Entity\GoodsWithRelated;
use Lm\Entity\GoodsColor;
use Lm\Service\Cache\CacheService;
use Lm\Service\Db\SqlService;
class GoodsService extends LmAbstractService
{
const CFIMG_DOMAIN = "img0.land-mark.biz";
const TAX = 10;
const VENDING_LIST_FOLDER = 'files/goods/';
const VENDING_LIST_FILENAME = 'goods_vending_status_list.json';
/**
* @var LmHelper $LmHelper
*/
protected $LmHelper;
/**
* @var DynamicConverter $dynamicConverter
*/
protected $dynamicConverter;
public function __construct(CacheService $cacheService,
LmHelper $lmHelper,
DynamicConverter $dynamicConverter)
{
//
parent::__construct($cacheService);
//
$this->LmHelper = $lmHelper;
$this->dynamicConverter = $dynamicConverter;
}
public function getGoodsRoutingMap($from)
{
$sql = new SqlService();
$data = $sql->Table('goods_routing_map_table')
->Set('grm_from', $from)
->Find();
if (!empty($data)) {
return $data['grm_to'];
} else {
return false;
}
}
public function getGoodsRoutingByHinban($hinban)
{
$sql = new SqlService();
$data = $sql->Table('goods_routing_table')
->Set('gr_hinban', $hinban)
->Find();
if (!empty($data)) {
return $data['gr_goods'];
} else {
return false;
}
}
public function getGoodsSusoageById($goodsId)
{
$result = (new SqlService())
->Select('goods_susoage')
->Table('goods_table')
->Set('goods_id', $goodsId)
->Find();
if (empty($result)) {
return false;
}
return $result['goods_susoage'];
}
public function getGoodsSusoageByHinban($hinban)
{
$result = (new SqlService())
->Select('goods_susoage')
->Table('goods_table')
->Join('goods_routing_table', 'goods_id = gr_goods', 'INNER')
->Set('T1.gr_hinban', $hinban)
->Find();
if (empty($result)) {
return false;
}
return $result['goods_susoage'];
}
/**
* @param $id int
* @param bool $DlFlg 削除されたDATAを抽出しない
* @return array
*/
public function getGoodsById($id, $DlFlg = false)
{
return $this->getCached(function () use ($id, $DlFlg) {
$sql = new SqlService();
$sql->Table('goods_table')
->Set('goods_id', $id);
if ($DlFlg) {
$sql->Set('goods_ddate', null);
}
$data = $sql->Find();
if (!empty($data)) {
return $data;
} else {
return false;
}
});
}
/**
* @param bool $whichNoDeleted
* @param int|null $goodsStatus
* @param array $fields
* @return mixed
* @throws \ReflectionException
*/
public function getGoodsList($whichNoDeleted = false, $goodsStatus = null, array $fields = [])
{
return $this->getCached(function () use ($whichNoDeleted, $goodsStatus, $fields) {
//
$sql = (new SqlService())
->Table('goods_table')
->Order('goods_id')
;
;
//
if ($whichNoDeleted) {
$sql->Set('goods_ddate', null);
}
//
if ($goodsStatus !== null) {
$sql->Set('goods_status', $goodsStatus);
}
//
if (!empty($fields)) {
$sql->Select(implode(',', $fields));
}
//
return $sql->Finds() ?? [];
});
}
/**
* 指定されたJANコードIDの商品情報を取得する
*
* @param $janId = dtb_product_class.id
* @return array|null
*/
public function getGoodsByJanId($janId)
{
$result = (new SqlService())
->Select('T.*')
->Table('goods_table')
->Join('jancode_table', 'goods_id = jan_goods', 'INNER')
->Set('T1.jan_id', $janId)
->Find();
return $result;
}
/**
* 商品カラーIDより、商品情報を取得する
*
* @param int $gclId 商品カラーID (=dtb_product_class.class_category1 - $offset)
* @return mixed
* @throws \ReflectionException
*/
public function getGoodsByGclId($gclId)
{
return $this->getCached(function () use ($gclId) {
$data = (new SqlService())
->Select('T.*, T2.*')
->Table('goods_table')
->Join('goods_color_table', 'T.goods_id = T1.gcl_goods', 'INNER')
->Join('color_table', 'T2.color_id = T1.gcl_color_id', 'INNER')
->Set('T1.gcl_id', $gclId)
->Find();
if (!empty($data)) {
return $data;
} else {
return false;
}
});
}
/**
* 800-379……UT……商品ページの複製化
* 親カテに属する商品を検索
* @param string $goodsId
* @param string $mcWebName
* @param string $mcMcWebName
* @return array
* @author worker_g
*/
public function isBelongsToMc($goodsId, $mcWebName)
{
// TODO: null AS `category_id`
// TODO: null AS `category_webname`
$result = (new SqlService())
->Select('main_category_id, main_category_webname, T4.*')
->Table('main_category_table')
->Join('category_table', 'main_category_id = T1.category_main_category', 'INNER')
->Join('goods_category_table', 'T1.category_id = T2.gc_category', 'INNER')
->Join('goods_table', 'T3.goods_id = T2.gc_goods', 'INNER')
->Join('category_group_table', 'T4.category_group_id = T.main_category_group')
->Set('T3.goods_id', $goodsId)
->Set('main_category_webname', $mcWebName)
->Find()
?? (new SqlService())
->Select('main_category_id, main_category_webname, T3.*')
->Table('main_category_table')
->Join('goods_main_category_table', 'main_category_id = T1.gmc_main_category', 'INNER')
->Join('goods_table', 'T2.goods_id = T1.gmc_goods', 'INNER')
->Join('category_group_table', 'T3.category_group_id = T.main_category_group')
->Set('T2.goods_id', $goodsId)
->Set('main_category_webname', $mcWebName)
->Find();
return $result;
}
/**
* 800-379……UT……商品ページの複製化
* 親カテに属する商品を検索
* @param string $goodsId
* @param string $mcWebName
* @param string $mcMcWebName
* @return array
* @author worker_g
*/
public function isBelongsToMcMc($goodsId, $mcMcWebName, $mcWebName)
{
// TODO: null AS `category_id`
// TODO: null AS `category_webname`
// TODO: 親カテのみ
$result = (new SqlService())
->Select('main_category_id, main_category_webname, T4.*')
->Table('main_category_table')
->Join('category_table', 'main_category_id = T1.category_main_category', 'INNER')
->Join('goods_category_table', 'T1.category_id = T2.gc_category', 'INNER')
->Join('goods_table', 'T3.goods_id = T2.gc_goods', 'INNER')
->Join('category_group_table', 'T4.category_group_id = T.main_category_group')
->Set('T3.goods_id', $goodsId)
->Set('main_category_main_category_webname', $mcMcWebName)
->Set('main_category_webname', $mcWebName)
->Find();
return $result;
}
/**
* 800-379……UT……商品ページの複製化
* 子カテに属する商品を検索
* @param string $goodsId
* @param string $mcWebName
* @param string $ctWebName
* @return array
* @author worker_g
*/
public function isBelongsToMcCt($goodsId, $mcWebName, $ctWebName)
{
$result = (new SqlService())
->Select('main_category_id, main_category_webname, T1.category_id, T1.category_webname, T4.*')
->Table('main_category_table')
->Join('category_table', 'main_category_id = T1.category_main_category', 'INNER')
->Join('goods_category_table', 'T1.category_id = T2.gc_category', 'INNER')
->Join('goods_table', 'T3.goods_id = T2.gc_goods', 'INNER')
->Join('category_group_table', 'T4.category_group_id = T.main_category_group')
->Set('T3.goods_id', $goodsId)
->Set('main_category_webname', $mcWebName)
->Set('T1.category_webname', $ctWebName)
->Find();
return $result;
}
/**
* 800-379……UT……商品ページの複製化
* 子カテに属する商品を検索
* @param string $goodsId
* @param string $mcMcWebName
* @param string $mcWebName
* @param string $ctWebName
* @return array
* @author worker_g
*/
public function isBelongsToMcMcCt($goodsId, $mcMcWebName, $mcWebName, $ctWebName)
{
$result = (new SqlService())
->Select('main_category_id, main_category_webname, T1.category_id, T1.category_webname, T4.*')
->Table('main_category_table')
->Join('category_table', 'main_category_id = T1.category_main_category', 'INNER')
->Join('goods_category_table', 'T1.category_id = gc_category', 'INNER')
->Join('goods_table', 'T3.goods_id = T2.gc_goods', 'INNER')
->Join('category_group_table', 'T4.category_group_id = T.main_category_group')
->Set('T3.goods_id', $goodsId)
->Set('main_category_main_category_webname', $mcMcWebName)
->Set('main_category_webname', $mcWebName)
->Set('T1.category_webname', $ctWebName)
->Find();
return $result;
}
/**
* 型番取得(1件)
*
* @param string $goods_id 商品ID
* @return string
*/
public function getGoodsKataban1($goods_id)
{
$result = (new SqlService())
->Select('DISTINCT gpt.gp_kataban')
->Table('goods_price_table AS gpt')
->Where('gp_goods = ' . $goods_id)
->Find();
return (!empty($result)) ? $result['gp_kataban'] : '';
}
/**
* カラーリスト取得
*
* @param string $goods_id 商品ID
* @return string
*/
public function getGoodsColorList($goods_id)
{
$list = (new SqlService())
->Select('ct.color_rgb')
->Table('goods_color_table AS gct')
->Join('color_table AS ct', 'gct.gcl_color_id = ct.color_id', 'INNER')
->Where('gcl_goods = ' . $goods_id)
->Where('gcl_display_status = 1')
->OrderBy('CAST( color_name AS BINARY )')
->Finds();;
$ret = '';
foreach ($list ?? [] as $row) {
$ret .= '<div style="float: left; width: 10px; height: 10px; background-color: #' . str_replace("#", "", $row['color_rgb']) . '; border: 1px solid #EFEFEF;"></div>';
}
$ret = '<div style="margin-top: 15px;">' . $ret . '</div>';
return $ret;
}
/**
* 商品価格取得
* Note. 現行では1SQLとしているが、厳格なSQLではエラーとなるため、キャンペーン価格と通常価格で分けて取得
*
* @param string $goods_id 商品ID
* @return string
*/
public function getGoodsPrice($goods_id, $display_max = false)
{
$min = $max = 0;
// キャンペーン価格取得
$cols = array(
'MIN(cp_price) AS mi',
'MAX(cp_price) AS ma',
);
$result_cp = (new SqlService())
->Select(join(",", $cols))
->Table('campaign_price_table')
->Where('cp_start_datetime <= NOW()')
->Where('cp_end_datetime >= NOW()')
->Where('cp_del_flg = 0')
->Where('cp_gp = ' . $goods_id)
->Find();
if (!empty($result_cp)) {
$min = (int)$result_cp['mi'];
$max = (int)$result_cp['ma'];
}
// キャンペーン価格が無い場合は通常価格を検索
if ($min === 0 && $max === 0) {
$cols = array(
'MIN(gp_price2) AS mi',
'MAX(gp_price2) AS ma',
);
$result_gp = (new SqlService())
->Select(join(",", $cols))
->Table('goods_price_table')
->Where('(gp_display != 99 OR gp_display IS NULL)')
->Where('gp_goods = ' . $goods_id)
->Find();
if (!empty($result_gp)) {
// TODO: 税率設定
$min = round($result_gp['mi'] * (1 + self::TAX / 100));
$max = round($result_gp['ma'] * (1 + self::TAX / 100));
}
}
$ret = number_format($min);
if ($display_max) {
$ret .= ($min === $max) ? "円" : "円~" . number_format($max) . "円";
} else {
$ret .= ($min === $max) ? "円" : "円~";
}
return $ret;
}
/**
* 口コミ取得
*
* @param string $goods_id 商品ID
* @return string
*/
public function getGoodsAverage($goods_id)
{
// Note. cra_goods_id が PRIMARY のため、取得件数は1件
$result = (new SqlService())
->Select('cra_average_points')
->Table('customer_review_average_table')
->Where('cra_target_count >= 1')
->Where('cra_goods_id = ' . $goods_id)
->Find();
return (!empty($result)) ? (int)$result['cra_average_points'] : 0;
}
/**
* 口コミimgタグ取得
*
* @param string $average レビュー平均
* @return string
*/
public function getGoodsAverageImg($average)
{
$image_name = (int)($average * 2) / 2 * 10;
$ret = "<img class=\"searchpop_result_description_review_img\" alt=\"お客様からの口コミレビュー評価の星の数" . $average . "\" src=\"" . $this->LmHelper->getConfig('CFIMG_URL') . "/public_images/review/star_m" . $image_name . ".gif\">";
return $ret;
}
/**
* レビュー数取得
*
* @param string $goods_id 商品ID
* @return string
*/
public function getGoodsReviewCount($goods_id, $goods_status)
{
if ($goods_status != '1') {
return 0;
}
$result = (new SqlService())
->Table('customer_review_table')
->Where('cr_approval = 1')
->Where('cr_site_id = 0')
->Where('cr_goods_id = ' . $goods_id)
->Where('cr_main_category_id = 0')
->Count();
return (int)$result;
}
/**
* データ整形:商品検索
*
* @param array $list
* @return array
*/
public function formatItemList($list)
{
$formatRows = $list;
$formatRows['searchtext'] = $list['params']['searchtext'];
$formatRows['display_max'] = $list['params']['max_display_cnt'];
$formatRows['item'] = array();
if ($list['item']) {
foreach ($list['item'] as $idx => $row) {
$formatRows['item'][$idx] = $row;
$formatRows['item'][$idx]['tt_type'] = '1';
$formatRows['item'][$idx]['kataban'] = $this->getGoodsKataban1($row['goods_id']);
$formatRows['item'][$idx]['color'] = $this->getGoodsColorList($row['goods_id']);
$formatRows['item'][$idx]['price'] = $this->getGoodsPrice($row['goods_id']);
$formatRows['item'][$idx]['image'] = $this->LmHelper->getGoodsImageUrl($row['goods_id'], 'main_sum.webp');
// 口コミ
$formatRows['item'][$idx]['average'] = $this->getGoodsAverage($row['goods_id']);
$formatRows['item'][$idx]['average_img'] = $this->getGoodsAverageImg($formatRows['item'][$idx]['average']);
$formatRows['item'][$idx]['review'] = $this->getGoodsReviewCount($row['goods_id'], $row['goods_status']);
// ステータス
$formatRows['item'][$idx]['status'] = $row['goods_status'];
}
}
return $formatRows;
}
/**
* データ整形:カテゴリ検索
*
* @param array $list
* @return array
*/
public function formatCategoryList($list)
{
$formatRows = $list;
$formatRows['searchtext'] = $list['params']['searchtext'];
$formatRows['display_max'] = $list['params']['max_display_cnt'];
$formatRows['category_type'] = $list['params']['category_type'];
$formatRows['categories'] = array();
if ($list['categories']) {
foreach ($list['categories'] as $idx => $row) {
// ※現行通りにセットすると以下の通りとなる
$categoryInfo = null;
$row['categoryInfo'] = $categoryInfo;
$row['item_count'] = $row['goodscount'];
$formatRows['categories'][$idx] = $row;
}
}
return $formatRows;
}
/**
* データ整形:カラムリスト
*
* @param array $list
* @return array
*/
public function formatColumnList($list)
{
$formatRows = $list;
$formatRows['searchtext'] = $list['params']['searchtext'];
$formatRows['display_max'] = $list['params']['max_display_cnt'];
return $formatRows;
}
/**
* データ整形:商品リスト(カテゴリ検索)
*
* @param array $list
* @return array
*/
public function formatItemByCategoryList($list)
{
$formatRows = $list;
$formatRows['main_category_id'] = $list['params']['main_category_id'];
$formatRows['category_id'] = $list['params']['category_id'];
$formatRows['category_group_only_main'] = $list['params']['category_group_only_main'];
$formatRows['display_max'] = $list['params']['max_display_cnt'];
$formatRows['item'] = array();
if ($list['item']) {
foreach ($list['item'] as $idx => $row) {
$formatRows['item'][$idx] = $row;
$formatRows['item'][$idx]['tt_type'] = '1';
$formatRows['item'][$idx]['kataban'] = $this->getGoodsKataban1($row['goods_id']);
$formatRows['item'][$idx]['color'] = $this->getGoodsColorList($row['goods_id']);
$formatRows['item'][$idx]['price'] = $this->getGoodsPrice($row['goods_id']);
$formatRows['item'][$idx]['image'] = $this->LmHelper->getGoodsImageUrl($row['goods_id'], 'main_sum.jpg');
}
}
return $formatRows;
}
/**
* カテゴリ検索SQL取得(From句 ~ Where句)
* ※本SQLは複雑なためSQL文を直接編集する
*
* @param SqlService $sqlService
* @param string $keyword
* @param int $start
* @param int $limit
* @param bool $isSecret
* @return string
*/
protected static function getSqlSearchCategoryQuery(SqlService $sqlService, $keyword, $type, $isSecret)
{
// SQLパラメータ: キーワード
$sqlService->Params([
'keyword_exact' => $keyword,
'keyword_like' => "%{$keyword}%",
]);
// ブランド別かどうか
$main_category_group = "";
if ($type == 'normal') {
$main_category_group = " main_category_group NOT IN ( 6, 7, 8 )";
} else if ($type == 'brand') {
$main_category_group = " main_category_group = 6";
} else if ($type == 'description') {
$main_category_group = " main_category_group = 7";
} else if ($type == 'maker') {
$main_category_group = " main_category_group = 8";
}
if ($main_category_group) {
$main_category_group = "WHERE" . $main_category_group;
}
$sql = "
FROM (
SELECT
1 AS result_priority
, main_category_id
, NULL AS category_id
, main_category_name
, NULL AS category_name
, main_category_webname
, NULL AS category_webname
, main_category_group
, ((main_category_name = :keyword_exact) || (main_breadcrumb = :keyword_exact)) AS exact1
, LENGTH(main_category_name) AS exact2
, lppv_pageview
, goods_count
, main_category_main_category_webname
FROM (
SELECT
main_category_id
, main_category_name
, main_category_webname
, main_category_group
, main_breadcrumb
, main_category_pageviews AS lppv_pageview
, COUNT(DISTINCT goods_id) AS goods_count
, main_category_main_category_webname
FROM main_category_table
INNER JOIN category_group_table ON category_group_id = main_category_group AND category_group_only_main = 1
LEFT JOIN goods_main_category_table ON main_category_id = gmc_main_category
LEFT JOIN goods_table ON goods_id = gmc_goods AND goods_ddate IS NULL";
if (!$isSecret) {
$sql .= " AND goods_status = 1 ";
}
$sql .= " WHERE main_category_name collate utf8_unicode_ci LIKE :keyword_like
GROUP BY main_category_id
UNION ALL
SELECT
main_category_id
, main_category_name
, main_category_webname
, main_category_group
, main_breadcrumb
, main_category_pageviews AS lppv_pageview
, COUNT(DISTINCT goods_id) AS goods_count
, main_category_main_category_webname
FROM main_category_table
INNER JOIN category_group_table ON category_group_id = main_category_group AND category_group_only_main != 1
LEFT JOIN category_table ON main_category_id = category_main_category AND category_status = 1
LEFT JOIN goods_category_table ON category_id = gc_category
LEFT JOIN goods_table ON goods_id = gc_goods AND goods_ddate IS NULL";
if (!$isSecret) {
$sql .= " AND goods_status = 1 ";
}
$sql .= " WHERE category_is_hinban_link = 0 AND main_category_name collate utf8_unicode_ci LIKE :keyword_like
GROUP BY main_category_id
) AS mc
UNION
SELECT
result_priority
, main_category_id
, category_id
, main_category_name
, category_name
, main_category_webname
, category_webname
, main_category_group
, exact1
, exact2
, lppv_pageview
, goods_count
, main_category_main_category_webname
FROM (
SELECT
20 AS result_priority
, main_category_id
, category_id
, main_category_name
, category_name
, main_category_webname
, category_webname
, main_category_group
, 0 AS exact1
, category_pageviews AS lppv_pageview
, LENGTH(main_category_name) AS exact2
, COUNT(DISTINCT goods_id) AS goods_count
, main_category_main_category_webname
FROM main_category_table
INNER JOIN category_table ON main_category_id = category_main_category AND category_status = 1
INNER JOIN goods_category_table ON category_id = gc_category
INNER JOIN goods_table ON goods_id = gc_goods AND goods_ddate IS NULL";
if (!$isSecret) {
$sql .= " AND goods_status = 1 ";
}
$sql .= " WHERE category_is_hinban_link = 0 AND category_name collate utf8_unicode_ci LIKE :keyword_like
GROUP BY category_id
) AS ct
) AS ct_summary
INNER JOIN category_group_table ON category_group_id = ct_summary.main_category_group
$main_category_group
";
return $sql;
}
/**
* カテゴリ検索SQL取得
* ※本SQLは複雑なためSQL文を直接編集する
*
* @param $SqlService $sqlService
* @param string $keyword
* @param int $start
* @param int $limit
* @param bool $isSecret
* @return string
*/
protected static function getSqlSearchCategoryList(SqlService $sqlService, $keyword, $type, $start, $limit, $isSecret)
{
$sql = self::getSqlSearchCategoryQuery($sqlService, $keyword, $type, $isSecret);
$sql = "
SELECT
ct_summary.main_category_id
, ct_summary.category_id AS category_id
, ct_summary.main_category_name
, ct_summary.category_name AS category_name
, ct_summary.main_category_webname
, ct_summary.category_webname AS category_webname
, ct_summary.main_category_group
, category_group_only_main
, IfNull(ct_summary.goods_count, 0) AS goodscount
, main_category_main_category_webname " . $sql . "
ORDER BY exact1 DESC, lppv_pageview DESC, goodscount DESC , exact2 ASC, result_priority ASC
LIMIT " . intval($start). "," . intval($limit);
return $sql;
}
/**
* カテゴリ検索SQL(count)取得
* ※本SQLは複雑なためSQL文を直接編集する
*
* @param SqlService $sqlService
* @param string $keyword
* @param int $start
* @param bool $isSecret
*/
protected static function getSqlSearchCategoryCount(SqlService $sqlService, $keyword, $type, $isSecret)
{
$sql = self::getSqlSearchCategoryQuery($sqlService, $keyword, $type, $isSecret);
$sql = "SELECT COUNT(*) AS CNT FROM ( SELECT 'X' " . $sql . ") AS XXX";
return $sql;
}
/**
* カテゴリ検索SQL取得(From句 ~ Where句)
* ※本SQLは複雑なためSQL文を直接編集する
*
* @param int $main_category_id
* @param int $category_id
* @param bool $isSecret
* @return string
*/
protected static function getSqlSearchItemByMainCategoryIdQuery($main_category_id, $category_id, $isSecret)
{
$mc_genre_text_map = array(
'222' => '事務服', // jimufuku
);
$where_goods_status = "";
if (!$isSecret) {
$where_goods_status = ' AND goods_status = 1 ';
}
$where = "";
if (isset($mc_genre_text_map[$main_category_id])) {
$where = "
UNION
SELECT
goods_id
, goods_name
FROM goods_table
WHERE goods_genre_text = '{$mc_genre_text_map[$main_category_id]}'
AND goods_ddate IS NULL
{$where_goods_status}";
}
$sql = "
FROM (
SELECT
goods_id
, goods_name
FROM main_category_table
INNER JOIN goods_main_category_table
ON main_category_id = gmc_main_category
INNER JOIN goods_table
ON goods_id = gmc_goods
WHERE goods_ddate IS NULL
AND main_category_id = {$main_category_id}
{$where_goods_status}
{$where}
) AS goods
LEFT JOIN rank_table ON goods_id = rank_goods
";
return $sql;
}
/**
* メインカテゴリID⇒商品検索SQL(list)取得
* ※本SQLは複雑なためSQL文を直接編集する
*
* @param int $main_category_id
* @param int $category_id
* @param int $limit
* @param bool $isSecret
* @return string
*/
protected static function getSqlSearchItemListByMainCategoryId($main_category_id, $category_id, $limit, $isSecret)
{
$sqls = array(
"SELECT goods_id, goods_name",
self::getSqlSearchItemByMainCategoryIdQuery($main_category_id, $category_id, $isSecret),
"ORDER BY rank_money DESC",
"LIMIT 0, $limit",
);
return join(" ", $sqls);
}
/**
* メインカテゴリID⇒商品検索SQL(count)取得
* ※本SQLは複雑なためSQL文を直接編集する
*
* @param int $main_category_id
* @param int $category_id
* @param bool $isSecret
*/
protected static function getSqlSearchItemCountByMainCategoryId($main_category_id, $category_id, $isSecret)
{
$sqls = array(
"SELECT COUNT(*) AS CNT FROM ( SELECT 'X' ",
self::getSqlSearchItemByMainCategoryIdQuery($main_category_id, $category_id, $isSecret),
") AS XXX",
);
return join(" ", $sqls);
}
/**
* 指定されたキーワードにて商品一覧を検索する
*
* @param array $params
* @return array|null
*/
public function searchItemListByKeyword($params)
{
$list = array();
$list['params'] = $params;
// SQLパラメータ
$bind = [];
// SQLパラメータ: キーワード検索
$keywords = [];
// キーワード検索
$sqlKeywords = "SELECT goods_id FROM search_goods_keywords WHERE 1";
foreach ($params['keywords'] as $index => $keyword) {
//
$keywords[$placeholder = "keyword{$index}"] = "%{$keyword}%";
//
$sqlKeywords .= " AND fulltext_keywords LIKE :{$placeholder}";
}
// シークレットモード
if (LmHelper::isSecret()) {
$sqlKeywords .= " AND sgk_goods_status = 1";
}
if (!empty($keywords)) {
$bind = array_merge($bind, $keywords);
}
// ソート順
if ($params['order_type'] == "1") { // 安い順
$order = "rt.lowest_price ASC";
} elseif ($params['order_type'] == "3") { // 高い順
$order = "rt.lowest_price DESC";
} else { // 品番順
$order = "rt.rank_money DESC";
}
// 商品テーブルを照会
$cols = array('gt.goods_id', 'gt.goods_name', 'gt.goods_status', 'gt.goods_main_kataban AS gp_kataban', 'rt.rank_money', 'rt.lowest_price');
$sql = new SqlService();
$sql->Table('goods_table AS gt')
->Join("rank_table AS rt", "gt.goods_id = rt.rank_goods", 'LEFT')
->Where("goods_id IN (" . $sqlKeywords . ")")
->Where("goods_ddate IS NULL");
// SQLパラメータ
if (!empty($bind)) {
$sql->Params($bind);
}
$list['item_count'] = (clone $sql)->Count();
$list['item'] = $sql->Table('goods_table AS gt')
->Select(join(",", $cols))
->GroupBy('gt.goods_id')
->OrderBy($order)
->Limit($params['start'] . ', ' . $params['max_display_cnt'])
->Finds();
//->Finds(2, true);
// リスト整形
return $this->formatItemList($list);
}
/**
* 指定されたキーワードにてカテゴリ一覧を検索する
*
* @param array $params
* @return array|null
*/
public function searchCategoryListByKeyword($params)
{
$list = array();
$list['params'] = $params;
// キーワードは最初の1件のみ使用
$keyword = $params['keywords'][0];
$isSecret = LmHelper::isSecret();
// SQL取得
$sql1 = new SqlService();
$sql2 = new SqlService();
$sqlList = self::getSqlSearchCategoryList($sql1, $keyword, $params['category_type'], $params['start'], $params['max_display_cnt'], $isSecret);
$sqlCount = self::getSqlSearchCategoryCount($sql2, $keyword, $params['category_type'], $isSecret);
// カテゴリ検索
$list['categories'] = $sql1->Sql($sqlList)->FetchAll();
$list['category_count'] = $sql2->Sql($sqlCount)->Fetch();
$list['category_count'] = isset($list['category_count']['CNT']) ? $list['category_count']['CNT'] : 0;
// リスト整形
return $this->formatCategoryList($list);
}
/**
* 指定されたキーワードにてコラム一覧を検索する
*
* @param string $keyword
* @param int $limit
* @return array|null
*/
public function searchColumnListByKeyword($params)
{
$list = array();
$list['params'] = $params;
// SQLパラメータ
$bind = [];
// SQLパラメータ: キーワード検索
$keywords = [];
// キーワード検索
$where_column1 = array();
$where_column2 = array();
foreach ($params['keywords'] as $index => $keyword) {
//
$keywords[$placeholder = "keyword{$index}"] = "%{$keyword}%";
//
$where_column1[] = "`column_name` LIKE :{$placeholder}";
$where_column2[] = "`column_keyword_tag` LIKE :{$placeholder}";
}
if (!empty($keywords)) {
$bind = array_merge($bind, $keywords);
}
// コラムテーブルを照会
$cols = array('c.column_name', 'c.column_title_tag', 'c.column_webname', 'mc.main_category_webname', 'ct.category_webname');
$sql = new SqlService();
// SQLパラメータ
if (!empty($bind)) {
$sql->Params($bind);
}
$sql->Table('column_table AS c')
->Select(join(",", $cols))
->Join("main_category_table AS mc", "c.column_main_category = mc.main_category_id", 'LEFT')
->Join("category_table AS ct", "c.column_target_category = ct.category_id", 'LEFT')
->Where("c.column_status = 1")
->Limit('0, ' . intval($params['max_display_cnt']));
if ($where_column1 && $where_column2) {
$sql->Where(join(" OR ", $where_column1) . " OR " . join(" OR ", $where_column2));
}
$list['columns'] = $sql->Finds();
// リスト整形
return $this->formatColumnList($list);
}
/**
* 指定されたカテゴリID属する商品一覧を検索する
*
* @param int $mainCategoryId
* @param int $limit
* @return array|null
*/
public function searchItemListByMainCategoryId($params)
{
$list = array();
$list['params'] = $params;
$sql = new SqlService();
$isSecret = LmHelper::isSecret();
// カテゴリ情報の取得
$result = $sql->Table('main_category_table AS mct')
->Select('mct.main_category_id, mct.main_category_name, mct.main_category_webname, ct.category_id, ct.category_name, ct.category_webname')
->Join("category_table AS ct", "mct.main_category_id = ct.category_main_category", 'LEFT')
->Where('mct.main_category_id = ' . $params['main_category_id']);
if ($params['category_id']) {
$sql->Where("ct.category_id = " . $params['category_id']);
}
$result = $sql->Find();
$list += $result;
// カテゴリテーブル/商品テーブルを照会
if (!$params['category_group_only_main']) {
// not OnlyMain
$cols = array('gt.goods_id', 'gt.goods_canonical_hinban', 'gt.goods_name');
// SQL取得
$sql->Table('main_category_table AS mct')
->Join("category_table AS ct", "mct.main_category_id = ct.category_main_category", 'INNER')
->Join("goods_category_table AS gct", "ct.category_id = gct.gc_category", 'INNER')
->Join("goods_table AS gt", "gt.goods_id = gct.gc_goods", 'INNER')
->Join("rank_table AS rt", "gt.goods_id = rt.rank_goods", 'LEFT')
->Where("gt.goods_ddate IS NULL")
->Where("mct.main_category_id = " . $params['main_category_id']);
if (!$isSecret) {
$sql->Where("gt.goods_status = 1");
}
if ($params['category_id']) {
$sql->Where("ct.category_id = " . $params['category_id']);
}
$list['item_count'] = (clone $sql)->Count(0, 'DISTINCT(gt.goods_id)');
$list['item'] = $sql->Select(join(",", $cols))
->GroupBy("gt.goods_id, gt.goods_name")
->OrderBy("rt.rank_money DESC")
->Limit('0, ' . $params['max_display_cnt'])
->Finds(0, true);
} else {
// OnlyMain
// SQL取得
$sqlList = self::getSqlSearchItemListByMainCategoryId($params['main_category_id'], $params['category_id'], $params['max_display_cnt'], $isSecret);
$sqlCount = self::getSqlSearchItemCountByMainCategoryId($params['main_category_id'], $params['category_id'], $isSecret);
// SQL実行
$list['item'] = $sql->Sql($sqlList)->FetchAll(0, true);
$list['item_count'] = $sql->Sql($sqlCount)->Fetch();
$list['item_count'] = isset($list['item_count']['CNT']) ? $list['item_count']['CNT'] : 0;
}
// リスト整形
return $this->formatItemByCategoryList($list);
}
/**
* TODO: 型番を検索を検索する
*
* @param int $goods_id
* @return array|null
*/
public function getGoodsKataban($goods_id)
{
// $strSql = "SELECT FROM goods_price_table WHERE gp_goods = " . $goods_id . " AND NOT(gp_display <=> 99) LIMIT 0,3";
$result = (array)(new SqlService())
->Table('goods_price_table')
->Sql('SELECT DISTINCT gp_kataban')
->Set('gp_goods', $goods_id)
->Set('gp_display', 99, '!=')
->Limit(3)
->FindAll();
return $result;
}
/**
* TODO: 即日発送の可否
*
* @return array|null
*/
public function getGoodsSameDayShipping($goods_id = NULL, $is_matrix = NULL, $jan_id = NULL, $gp_id = NULL, $gcl_id = NULL, $amount = NULL, $date = NULL)
{
return (new SokujitsuHassou())
->check($goods_id, $is_matrix, $jan_id, $gcl_id, $gp_id, $date, $amount);
}
/**
* 入荷予定日の計算
*
* @param int $goodsId
* @param bool $isMatrix
* @param int $janId
* @param int $gpId
* @param int $gclId
* @param string $datetime
* @return array|false|null
* @return array|false|string|null
*/
public function getGoodsStockDate($goodsId = NULL, $isMatrix = NULL, $janId = NULL, $gpId = NULL, $gclId = NULL, $datetime = NULL)
{
return (new \Lm\Engine\Zaiko\NyuukaYoteibi())
->calculate($goodsId, $isMatrix, $janId, $gpId, $gclId, $datetime)
;
}
/**
* @param null|int $goodsId
* @param null|bool $isMatrix
* @param null|int $janId
* @param null|int $gpId
* @param null|int $gclId
* @param null|string $datetime
* @return array|bool
*/
public function getGoodsReservation($goodsId = null, $isMatrix = null, $janId = null, $gpId = null, $gclId = null, $datetime = null)
{
return (new \Lm\Engine\Zaiko\Yoyaku())
->check2($goodsId, $isMatrix, $janId, $gpId, $gclId, $datetime)
;
}
/**
* 単一SKUの在庫数取得(バリデーション用)
*
* @param int $jan_id (=dtb_product_class.id)
* @return mixed|null 0 ・・・ 在庫なし
* 0以上 ・・・ 在庫あり
* null ・・・ 無限(入荷予定)
* @throws \Exception
*/
public function getValidationStock(int $jan_id)
{
$stockInfo = $this->getGoodsStock(null, false, $jan_id);
$stock = $stockInfo['stock_total'];
return $stock;
}
/**
* モジュール……在庫数
*
* @param int|NULL $goods_id
* @param bool $is_matrix
* @param int|NULL $jan_id
* @param int|NULL $gp_id
* @param int|NULL $gcl_id
* @param string|NULL $date
* @return array|mixed
* @throws \Exception
*/
public function getGoodsStock(int $goods_id = NULL, bool $is_matrix = false, int $jan_id = NULL, int $gp_id = NULL, int $gcl_id = NULL, string $date = NULL)
{
return $this->getCached(function () use ($goods_id, $is_matrix, $jan_id, $gp_id, $gcl_id, $date) {
//
return GoodsWithRelated::getStockById($goods_id, $is_matrix, $jan_id, $gp_id, $gcl_id, $date);
});
}
// 売れ筋カラー取得
public function getSellingColorSql($goods_id, $goods_count)
{
$limit = (int)($goods_count / 5);
$strSql = "SELECT * FROM (
SELECT *
FROM `selling_color_count_table`
WHERE `scc_goods_id` = " . $goods_id . "
ORDER BY `scc_amount` desc
) as data
limit " . $limit;
$temp_list = (new SqlService())
->Sql($strSql)
->FetchAll();
$selling_list = array();
foreach ((array)$temp_list as $selling) {
$selling_list[$selling['scc_gcl']] = $selling;
}
return $selling_list;
}
// 商品色
public function getGoodsColorSelectSql($goods_id)
{
//
return $this->getCached(function () use ($goods_id) {
$strSql = "SELECT
*
FROM (
SELECT
gcl_id
, gcl_display
, color_id
, color_display
, color_name
, color_rgb
FROM goods_table
LEFT JOIN goods_color_table ON goods_id = gcl_goods AND gcl_display_status = 1
LEFT JOIN color_table ON color_id = gcl_color_id
WHERE goods_id = {$goods_id}
) AS `goods`
ORDER BY
gcl_display
, color_display
, CAST( color_name AS binary )";
$data = (new SqlService())
->Sql($strSql)
->FetchAll();
if (is_null($data)) {
return false;
}
$tmpRow = 0;
$color_array = array();
foreach ($data as $row) {
$tmpRow++;
$color_array[$tmpRow - 1]['gcl_id'] = $row['gcl_id'];
$color_array[$tmpRow - 1]['color_name'] = $row['color_name'];
$color_array[$tmpRow - 1]['color_rgb'] = $row['color_rgb'];
}
return $color_array;
});
}
// 商品サイズ
public function getGoodsSizeListById($goods_id)
{
//
return $this->getCached(function () use ($goods_id) {
$strSql = "SELECT *,
(CASE WHEN cp_price IS NOT NULL AND cp_price > 0 THEN cp_price ELSE ROUND(gp_price2 * (1+ 10/100)) END) as gp_price
FROM goods_price_table
INNER JOIN size_table ON gp_size_id = size_id
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
WHERE gp_goods = {$goods_id}
AND ( gp_display IS NULL OR ( gp_display IS NOT NULL AND gp_display != 99 ) )
ORDER BY gp_display,size_display";
$data = ((array)((new SqlService())
->Sql($strSql)
->FetchAll()));
$tmpArray1 = [];
$tmpArray2 = [];
foreach ($data as $row) {
$tmpArray1[$row['gp_id']] = $row['size_name'];
$tmpArray2[$row['gp_id']]['gp_price'] = $row['gp_price'];
}
// サイズ名で並び替え
$tmpRow = 0;
$size_array = array();
foreach ($tmpArray1 as $key => $val) {
$tmpRow++;
$size_array[$tmpRow - 1]['gp_id'] = $key;
$size_array[$tmpRow - 1]['size_name'] = $val;
$size_array[$tmpRow - 1]['gp_price'] = $tmpArray2[$key]['gp_price'];
}
return $size_array;
});
}
/**
* 商品規格1(=商品カラー)より、商品サイズ一覧(在庫情報含む)を取得する
*
* @param ClassCategory $classCategory1
* @return mixed
* @throws \ReflectionException
*/
public function getGoodsSizeListWithStockInfoByClassCategory1(ClassCategory $classCategory1)
{
//
return $this->getCached(function () use ($classCategory1) {
$classCategoryId = $classCategory1->getId();
$classCategoryNameId = $classCategory1->getClassName()->getId();
$dbConvertConfig = $this->LmHelper->getConfig('DbConvert');
$AddIdNum = (int)$dbConvertConfig['ProductClassCategory']['offset'][$classCategoryNameId];
$gclId = $classCategoryId - $AddIdNum;
return $this->getGoodsSizeListWithStockInfoByGclId($gclId);
});
}
/**
* 商品カラーIDより、商品サイズ一覧(在庫情報含む)を取得する
*
* @param int $gclId 商品カラーID (=dtb_product_class.class_category1 - $offset)
* @return mixed
* @throws \ReflectionException
*/
public function getGoodsSizeListWithStockInfoByGclId($gclId)
{
//
return $this->getCached(function () use ($gclId) {
//
$sizeList = [];
//
$goodsId = (new GoodsColor($gclId))->getGoods()->getGoodsId();
//
$skuList = array_filter(SkuWithPrice::getInstanceList($goodsId), function ($sku) use ($gclId) {
//
return $sku->getGclId() === (int)$gclId;
});
//
$sokujitsuHassouList = $this->getGoodsSameDayShipping($goodsId, true);
//
foreach ($skuList as $sku) {
//
$gpId = $sku->getGpId();
//
if (!isset($sizeList[$gpId])) {
//
$sizeList[$gpId] = [
'gp_id' => $gpId,
'size_name' => $sku->getSizeName(),
'gp_price' => $sku->getPriceInTax(),
'disabled' => 0,
];
}
//
if ($sku->isNoDisplay()) {
$sizeList[$gpId]['size_name'] = "{$sizeList[$gpId]['size_name']} - 購入不可";
$sizeList[$gpId]['disabled'] = 1; // 無効フラグ = 「1: 無効」
} else if ($sku->getIsYoyakuAvailable() || $sku->getIsBichikuYoyakuAvailable()) {
//
$sizeList[$gpId]['size_name'] = "{$sizeList[$gpId]['size_name']} - 予約";
} else if ($sokujitsuHassouList[$gclId][$gpId] > SokujitsuHassou::FLG_NONE) {
//
$sizeList[$gpId]['size_name'] = "{$sizeList[$gpId]['size_name']} - 即日発送";
} else if (!is_numeric($sku->getStockTotal())) {
// 在庫あり(「*」)
// no operation.
} else if ($sku->getStockTotal() > 0) {
// 在庫あり
// no operation.
} else {
$sizeList[$gpId]['size_name'] = "{$sizeList[$gpId]['size_name']} - 在庫切れ";
$sizeList[$gpId]['disabled'] = 1; // 無効フラグ = 「1: 無効」
}
}
//
return $sizeList;
});
}
/**
* 商品に対応する加工種別の取得
*
* @param int $id
* @return false|int
*/
public static function getEnableEstimateTypeById($id)
{
//
return (new GoodsExtended($id))
->getAvailableEstimateType() ?: false
;
}
/**
* 指定されたJANコードID(=商品規格ID)リスト中、加工可能(裾上げ)商品を含むか否かを返す
*
* @param int[] $janIdList
* @return bool
*/
public static function isSusoageExistInJanIdList($janIdList)
{
//
return (bool)(array_filter($janIdList, function ($janId) {
//
return (GoodsExtended::createByJanId($janId))->isSusoageAvailable();
}));
}
/**
* 指定されたJANコードID(=商品規格ID)リスト中、加工可能(裾上げ以外)商品を含むか否かを返す
*
* @param int[] $janIdList
* @return bool
*/
public static function isNairePrintExistInJanIdList($janIdList)
{
//
return (bool)(array_filter($janIdList, function ($janId) {
//
return (GoodsExtended::createByJanId($janId))->isNairePrintAvailable();
}));
}
/**
* 指定されたJANコードID(=商品規格ID)リスト中、加工可能(共栄)商品を含むか否かを返す
*
* @param int[] $janIdList
* @return bool
*/
public static function isKyoueiExistInJanIdList($janIdList)
{
//
return (bool)(array_filter($janIdList, function ($janId) {
//
return (GoodsExtended::createByJanId($janId))->isKyouei();
}));
}
/**
* 指定されたJANコードID(=商品規格ID)リスト中、加工可能(共栄以外)商品を含むか否かを返す
*
* @param int[] $janIdList
* @return bool
*/
public static function isNairePrintWithKyoueiExistInJanIdList($janIdList)
{
//
return (bool)(array_filter($janIdList, function ($janId) {
//
return ($goods = GoodsExtended::createByJanId($janId))
&& $goods->isNairePrintWithKyoueiAvailable()
;
}));
}
/**
* @param int[] $janIdList
* @return bool
*/
public static function isNairePrintWithoutKyoueiExistInJanIdList($janIdList)
{
//
return (bool)(array_filter($janIdList, function ($janId) {
//
return ($goods = GoodsExtended::createByJanId($janId))
&& $goods->isNairePrintWithoutKyoueiAvailable()
;
}));
}
/**
* JANコードID(=商品規格ID)より、SKU情報を取得する
*
* @param int $janId JANコードID(=`dtb_product_class`.`id`).
* @return mixed
* @throws \ReflectionException
*/
public function getSkuInfoByJanId($janId)
{
return $this->getCached(function () use ($janId) {
return (new SqlService())
->Select('T1.gcl_id, T2.gp_id, T.*')
->Table('jancode_table')
->Join('goods_color_table', 'T1.gcl_id = T.jan_color', 'INNER')
->Join('goods_price_table', 'T2.gp_id = T.jan_price', 'INNER')
->Set('jan_id', $janId)
->Find();
});
}
/**
* @param $lmOrderId
* @return array|null
*/
public function getSkuListByOrderId($lmOrderId)
{
//
$result = (new SqlService())
->Select('T.oh_shubetsu, T3.jan_id, T2.ogl_amount')
->Table('order_header_table')
->Join('order_list_table', 'T.oh_id = T1.ol_oh')
->Join('order_goods_list_table', 'T.oh_id = ogl_oh AND T1.ol_id = T2.ogl_ol')
->Join('jancode_table', 'T3.jan_goods = T1.ol_goods AND T3.jan_color = T2.ogl_gcl AND T3.jan_price = T2.ogl_gp')
->Set('T.oh_id', $lmOrderId)
->Set('T3.jan_ddate', 'NULL')
->FindAll();
//
return $result;
}
/**
* @param $goodsIds
* @return array|null
*/
public function getGoodsListByIds($goodsIds, $data, $an_v)
{
$sql = "SELECT
goods_id
, goods_canonical_hinban
, goods_icon1
, goods_icon2
, goods_icon3
, goods_icon4
, goods_icon5
, goods_maker_uresuji
, gcl.rgb_list
, gp1.gp_kataban
, gp2.mi
, gp2.min_teika_intax as gp_teika
, gi0.gi_id AS gi0_id
FROM
goods_table
LEFT JOIN (
SELECT gcl_goods AS goods_id, GROUP_CONCAT(color_rgb ORDER BY CAST( color_name AS BINARY ) SEPARATOR ',') AS rgb_list
FROM
goods_color_table
INNER JOIN
color_table ON gcl_color_id = color_id
WHERE gcl_goods IN ({$goodsIds}) AND gcl_display_status = 1
GROUP BY gcl_goods
) AS gcl using (goods_id)
LEFT JOIN (
SELECT gp_goods AS goods_id, gp_kataban
FROM goods_price_table
INNER JOIN (
SELECT MIN(gp_id) AS gp_id
FROM goods_price_table
WHERE gp_goods IN ({$goodsIds})
GROUP BY gp_goods
) gp_min using (gp_id)
WHERE gp_goods IN ({$goodsIds})
) AS gp1 using (goods_id)
LEFT JOIN (
SELECT gp_goods AS goods_id,
(CASE WHEN cp_price IS NOT NULL AND cp_price > 0 THEN MIN(cp_price/1.10) ELSE MIN(gp_price2) END) as mi,
MIN(gp_teika) as min_teika_intax
FROM goods_price_table
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
WHERE gp_goods IN ({$goodsIds}) AND (gp_display != 99 OR gp_display IS NULL)
GROUP BY gp_goods
) AS gp2 using (goods_id)
LEFT JOIN (
SELECT gi_goods AS goods_id, MAX(gi_id) AS gi_id
FROM goods_image_table
WHERE gi_goods IN ({$goodsIds}) AND gi_display = 0
GROUP BY gi_goods
) AS gi0 using (goods_id)
WHERE goods_id IN ({$goodsIds})";
$tempGoodsList = ((array)((new SqlService())
->Sql($sql)
->FetchAll()));
$goodsList = array();
foreach ($tempGoodsList as $goods) {
$goodsList[$goods['goods_id']] = $goods;
}
for ($i = 1; $i <= count($data['item']); $i++) {
$data['item'][$an_v[$i - 1]]['goods_canonical_hinban'] = $goodsList[$data['item'][$an_v[$i - 1]]['goods_id']]['goods_canonical_hinban'];
$data['item'][$an_v[$i - 1]]['gi0_id'] = $goodsList[$data['item'][$an_v[$i - 1]]['goods_id']]['gi0_id'];
$data['item'][$an_v[$i - 1]]['color_list'] = array();
foreach (explode(',', $goodsList[$data['item'][$an_v[$i - 1]]['goods_id']]['rgb_list']) as $colorCount => $rgb) {
$data['item'][$an_v[$i - 1]]['color_list'][] = $rgb == '' ? '#111111' : '#'.$rgb;
}
$data['item'][$an_v[$i - 1]]['color_count'] = $colorCount + 1;
$data['item'][$an_v[$i - 1]]['price'] = $goodsList[$data['item'][$an_v[$i - 1]]['goods_id']]['mi'];
$data['item'][$an_v[$i - 1]]['teika'] =
isset($goodsList[$data['item'][$an_v[$i - 1]]['goods_id']]['gp_teika']) && !empty($goodsList[$data['item'][$an_v[$i - 1]]['goods_id']]['gp_teika']) ? $goodsList[$data['item'][$an_v[$i - 1]]['goods_id']]['gp_teika'] : null;
$data['item'][$an_v[$i - 1]]['goods_maker_uresuji'] = $goodsList[$data['item'][$an_v[$i - 1]]['goods_id']]['goods_maker_uresuji'];
}
return $data['item'];
}
/**
* @param boolean $createNewFlg
* @return array|null
*/
public function getGoodsVendingStatusMap($createNewFlg = false) {
$filename = self::VENDING_LIST_FOLDER . self::VENDING_LIST_FILENAME;
$goodsVendingStatusList = [];
if ($createNewFlg) {
$goodsVendingStatusList = $this->createGoodsVendingFile();
} else {
if (file_exists($filename)) {
$json = file_get_contents($filename);
$goodsVendingStatusList = json_decode($json, true);
} else {
$goodsVendingStatusList = $this->createGoodsVendingFile();
}
}
$vendingStatusMap = [];
if ($goodsVendingStatusList) {
foreach ($goodsVendingStatusList as $row) {
$vendingStatusMap[(int)$row['goods_id']] = (int)$row['goods_vending_status'];
}
}
return $vendingStatusMap;
}
protected function createGoodsVendingFile () {
$filename = self::VENDING_LIST_FOLDER . self::VENDING_LIST_FILENAME;
$goodsVendingStatusList = $this->dynamicConverter->getGoodsVendingStatusList();
$encoded = json_encode($goodsVendingStatusList);
mkdir(self::VENDING_LIST_FOLDER, 0777, true);
file_put_contents($filename, $encoded);
return $goodsVendingStatusList;
}
}