|
|
<?php
|
|
|
namespace Index;
|
|
|
|
|
|
use Configs\CacheConfig;
|
|
|
use Configs\WebCacheConfig;
|
|
|
use Configs\ChannelConfig;
|
|
|
use WebPlugin\Helpers;
|
|
|
use WebPlugin\Cache;
|
...
|
...
|
@@ -58,17 +58,18 @@ class HomeModel |
|
|
*/
|
|
|
public static function getNavBars($channel = 'boys')
|
|
|
{
|
|
|
$menu = array();
|
|
|
$key = CacheConfig::KEY_WEB_HOME_NAVBAR_DATA.'_'.$channel;
|
|
|
$key = WebCacheConfig::KEY_WEB_HOME_NAVBAR_DATA . '_' . $channel;
|
|
|
$menu = Cache::get($key);
|
|
|
$data = array();
|
|
|
if(empty($menu)) {//数据缓存不存在
|
|
|
//数据缓存不存在
|
|
|
if(empty($menu)) {
|
|
|
$data = IndexData::getNavData();
|
|
|
|
|
|
//接口存在数据
|
|
|
if(!empty($data['data'])) {
|
|
|
$item = array();
|
|
|
$index_main = 0;
|
|
|
$subnav = array();
|
|
|
$thirdnav = array();
|
|
|
$indexMain = 0;
|
|
|
$indexSub = 0;
|
|
|
foreach ($data['data'] as $val) {
|
|
|
$item = array(
|
|
|
'name_cn' => $val['sort_name'], // 父级
|
...
|
...
|
@@ -76,13 +77,13 @@ class HomeModel |
|
|
'link' => $val['sort_url'],
|
|
|
'icon' => $val['sort_ico'],
|
|
|
'classname' => str_replace(' ', '', strtolower($val['sort_name_en'])) == $channel ? $channel : '',
|
|
|
'index_main' => $index_main ++,
|
|
|
'index_main' => $indexMain ++,
|
|
|
'content_code' => $val['content_code'],
|
|
|
'is_hot' => $val['is_hot'] == 'Y' ? true : false,
|
|
|
'is_new' => $val['is_new'] == 'Y' ? true : false,
|
|
|
// 'subnav' => array()
|
|
|
);
|
|
|
$index_sub = 0;
|
|
|
$indexSub = 0;
|
|
|
foreach ($val['sub'] as $sub) { // 二级
|
|
|
$subnav = array(
|
|
|
'name' => $sub['sort_name'],
|
...
|
...
|
@@ -92,9 +93,10 @@ class HomeModel |
|
|
'is_new' => $sub['is_new'] == 'Y' ? true : false,
|
|
|
'content_code' => $sub['content_code'],
|
|
|
// 'thirdnav' => array(),
|
|
|
'index_sub' => $index_sub ++
|
|
|
'index_sub' => $indexSub ++
|
|
|
);
|
|
|
if (isset($sub['sub'])) {
|
|
|
$thirdnav = array();
|
|
|
foreach ($sub['sub'] as $thirdsub) { // 三级
|
|
|
$thirdnav = array(
|
|
|
'title' => $thirdsub['sort_name'],
|
...
|
...
|
@@ -123,8 +125,9 @@ class HomeModel |
|
|
Cache::set($key, $menu, 3600);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//数据缓存和接口都空的,取二级数据
|
|
|
if(empty($menu) && empty($data)) {
|
|
|
if(empty($menu)) {
|
|
|
$menu = Cache::get($key,'slave');
|
|
|
}
|
|
|
|
...
|
...
|
@@ -176,25 +179,27 @@ class HomeModel |
|
|
/**
|
|
|
* 获取频道资源
|
|
|
*
|
|
|
* @param string $channel
|
|
|
* @param string $content_code
|
|
|
* @param string $channel 频道标识(boys,girls,kids,lifestyle)
|
|
|
* @param string $contentCode 资源码
|
|
|
* @return array
|
|
|
*/
|
|
|
public static function getChannelResource($channel, $content_code)
|
|
|
public static function getChannelResource($channel, $contentCode)
|
|
|
{
|
|
|
$key = CacheConfig::KEY_WEB_HOME_CHANNEL_DATA.'_'.$content_code;
|
|
|
$key = WebCacheConfig::KEY_WEB_HOME_CHANNEL_DATA . '_' . $contentCode;
|
|
|
$data = Cache::get($key);
|
|
|
$resource = array();
|
|
|
if(empty($data)) {
|
|
|
$resource = IndexData::getResourceData($content_code);
|
|
|
if(isset($resource['data']) && !empty($resource['data']) && $resource['code'] == 200) {
|
|
|
$resource = IndexData::getResourceData($contentCode);
|
|
|
if (isset($resource['data']) && !empty($resource['data']) && $resource['code'] == 200) {
|
|
|
//格式化数据
|
|
|
$data = ChannelProcess::getFormat($channel, $resource['data']);
|
|
|
Cache::set($key, $data, 3600);//设置master,slave
|
|
|
//设置master,slave
|
|
|
Cache::set($key, $data, 3600);
|
|
|
//清空变量
|
|
|
$resource = array();
|
|
|
}
|
|
|
}
|
|
|
//master没有数据,资源位没有数据, 取二层缓存
|
|
|
if(empty($data) && (empty($resource) || !isset($resource['data']))) {
|
|
|
if(empty($data)) {
|
|
|
$data = Cache::get($key, 'slave');
|
|
|
}
|
|
|
return $data;
|
...
|
...
|
|