<?php
namespace Customize\Service;
use Customize\Entity\CacheTrait;
use Lm\Service\Db\SqlService;
class DynamicConverterService
{
use CacheTrait;
public function getFbnrs($params, $siteType, $webName)
{
//
$cacheKey = md5(serialize(compact('params', 'siteType', 'webName')));
//
return $this->getCacheByKey($cacheKey, function () use ($params, $siteType, $webName){
//
log_info("[HOGE] (*'o')");
//
$result = [];
//
switch ($params['type']) {
case 'item':
$goodsId = $params['value'];
$itemMcWebNames = (array)(new SqlService())
->Table('goods_category_table')
->Select('T2.main_category_webname')
->Join('category_table', 'T1.category_id = T.gc_category', 'INNER')
->Join('main_category_table', 'T2.main_category_id = T1.category_main_category', 'INNER')
->Set('gc_goods', $goodsId)
->Set('T2.main_category_has_main_categories', 1)
->Set('T2.main_category_status', 1)
->OrderBy('char_length(T2.main_category_webname) DESC')
->FindAll();
foreach ($itemMcWebNames as $itemMcWebName) {
$itemFbnr = $this->getFbnrByCategoryWebName($siteType, $itemMcWebName['main_category_webname']);
$result[] = $itemFbnr;
}
break;
case 'main-category':
case 'category':
$itemFbnr = $this->getFbnrByCategoryWebName($siteType, $webName);
$result[] = $itemFbnr;
$main_category_webname = addslashes(stripslashes($webName));
$mcHasMainCategoryData = (new SqlService())
->Table("main_category_table")
->Select('*')
->Set('main_category_webname', $main_category_webname)
->Set('main_category_status', 1)
->Set('main_category_main_category', 'NOT NULL')
->Find();
$itemFbnr = $this->getFbnrByCategoryWebName($siteType, $mcHasMainCategoryData['main_category_main_category_webname'] ?? null);
$result[] = $itemFbnr;
break;
default:
break;
}
//
$sql = (new SqlService())
->Table('floating_banner_table')
->Select('fbnr_content, fbnr_content2')
->Set('fbnr_site_type', $siteType);
$result[] = $sql->Find();
//
return $result;
});
}
public function getFbnrByCategoryWebName($siteType, $webName) {
$itemFbnr = null;
if ($webName) {
$itemFbnr = (new SqlService())
->Select('fbnr_content, fbnr_content2, T1.main_category_main_category, T1.main_category_main_category_webname')
->Table('floating_banner_table')
->Join('main_category_table', 'T1.main_category_id = T.target_category', 'INNER')
->Set('fbnr_site_type', $siteType)
->Set('T1.main_category_has_main_categories', 1)
->Set('T1.main_category_webname', $webName)
->Find();
} else {
$itemFbnr = (new SqlService())
->Select('fbnr_content, fbnr_content2, T1.main_category_main_category, T1.main_category_main_category_webname')
->Table('floating_banner_table')
->Join('main_category_table', 'T1.main_category_id = T.target_category', 'INNER')
->Set('fbnr_site_type', $siteType)
->Set('T1.main_category_has_main_categories', 1)
->Set('T1.main_category_webname', $webName)
->Find();
}
return $itemFbnr;
}
}