Home.php 5.31 KB
<?php
namespace Index;
use Configs\CacheConfig;
use Configs\ChannelConfig;
use Plugin\Helpers;
use Plugin\Cache;
use LibModels\Web\Home\IndexData;
use LibModels\Web\Product\SearchData;
/**
 * web首页模板数据模型
 * 
 * @name HomeModel
 * @package models
 * @copyright yoho.inc
 * @version 1.0 (2015-12-20 11:08:21)
 * @author whb <huanbao.wang@yoho.cn>
 */
class HomeModel
{
    /* COOKIE标识访问的是男生频道 */
    const COOKIE_NAME_BOYS = 'boys';
    /* COOKIE标识访问的是女生频道 */
    const COOKIE_NAME_GIRLS = 'girls';
    /* COOKIE标识访问的是潮童频道 */
    const COOKIE_NAME_KIDS = 'kids';
    /* COOKIE标识访问的是创意生活频道 */
    const COOKIE_NAME_LIFESTYLE = 'lifestyle';
    
    //男首首页
    const CODE_BOYS_CHANNEL = '';
    //女首首页
    const CODE_GIRLS_CHANNEL = 'a519ba44ef3a85cf3c05e405c6ba8e53';
    //潮童首页
    const CODE_KIDS_CHANNEL = 'a7741b94e8bb9d56d0d36e00c05956f7';
    //创意生活
    const CODE_LIFESTYLE_CHANNEL_1 = '380c38155fd8beee10913a3f5b462da6';
    const CODE_LIFESTYLE_CHANNEL_2 = '665f7c2fb9d037ee820766953ee34bf7';
    
    /**
     * 获取导航
     * 
     * @param string $channel
     * @return array
     */
    public static function getNavBars($channel = 'boys')
    {
        $data = IndexData::getNavData();
        if(empty($data)) {
            return array();
        }
        $menu = array();
        $item = array();
        foreach ($data['data'] as $val){
            $item = array (
                'name_cn'   => $val['sort_name'], //父级
                'name_en' => $val['sort_name_en'],
                'link'=> $val['sort_url'],
                'icon'=> $val['sort_ico'],
                'classname' => str_replace(' ', '', strtolower($val['sort_name_en'])) == $channel ? $channel : '',
                'index_main' => 0,
                'is_hot'=> $val['is_hot'] == 'Y' ? true:false,
                'is_new' => $val['is_new'] == 'Y' ? true:false,
                'subnav' => array(),
            );
            foreach($val['sub'] as $sub) { //二级
                $index_sub = 0;
                $subnav = array(
                    'name' => $sub['sort_name'],
                    'name_en'=> $sub['sort_name_en'],
                    'link'=> $sub['sort_url'],
                    'is_hot'=> $sub['is_hot'] == 'Y' ? true:false,
                    'is_new' => $sub['is_new'] == 'Y' ? true:false,
                    'thirdnav'=> array(),
                    'index_sub'=> $index_sub++ ,
                );
                if(isset($sub['sub']))
                {
                    foreach($sub['sub'] as $thirdsub) { //三级
                        $thirdnav = array(
                            'title' => $thirdsub['sort_name'],
                            'name_en'=> $thirdsub['sort_name_en'],
                            'link'=> $thirdsub['sort_url'],
                            'branditems'=> array(),
                        );
                        if(isset($thirdsub['sub'])){
                            foreach($thirdsub['sub'] as $fourthnav) { //四级
                                $thirdnav['branditems'][] = array(
                                    'brandname'=> $fourthnav['sort_name'],
                                    'link' => $fourthnav['sort_url'],
                                );
                            }
                        }
                        $subnav['thirdnav'][] = $thirdnav;
                    }
                }
                $item['subnav'][] = $subnav;
            }
            $menu[] = $item;
        }
        return $menu;
    }
    
    /**
     * 设置选择的频道保存到浏览器COOKIE
     *
     * @param string $cookie
     * @return void
     */
    public static function setSwitchToCookie($cookie)
    {
        setcookie('_Channel', $cookie, time() + 86400 * 300, '/', COOKIE_DOMAIN);
    }
    
    /**
     * 获取选择频道
     * 
     * @return string
     */
    public static function getSwitchChannel()
    {
        $channel = self::COOKIE_NAME_BOYS;
        if (empty($_COOKIE['_Channel'])) {
            self::setSwitchToCookie(self::COOKIE_NAME_BOYS);
        }
        else {
            $channel = $_COOKIE['_Channel'];
        }
        return $channel;
    }
    
    /**
     * 获取频道资源
     * 
     * @param string $content_code
     * @return array
     */
    public static function getChannelResource($content_code)
    {
        $data =  IndexData::getResourceData($content_code);
        //格式化数据
    }
    
    /**
     * 获取最新上架商品
     * 
     * @param string $channel
     * @return array
     */
    public static function getNewArrival($channel)
    {
        $result = array();
        $params = array(
            'order' => 's_t_desc',
            'shelve_time' => strtotime("-60 days").','.time()
        );
        //最新上架分类
        if(isset(ChannelConfig::$newArrivalSortList[$channel])) {
            $sortList = ChannelConfig::$newArrivalSortList[$channel];
            //获取分类列表获取商品信息
            $result = SearchData::getSearchDataBySort($params, $sortList);
            //格式化数据
        }
        return $result;
    }
}