Common.php 1.92 KB
<?php
use Action\WebAction;
use Index\HomeModel;
use Plugin\Cache;
use Configs\CacheConfig;

class CommonController extends WebAction
{

    /**
     * 获取首页资源品牌
     */
    public function getIndexResourceBrandAction()
    {
        // 首页资源品牌,采用内存存储
        $type = $this->get('type');
        $data = array();
        if (! empty($type)) {
            $key = CacheConfig::KEY_INDEX_BRANDS_LIST_DATA . '_' . $type;
            // array('logoBrand'=>'','moreBrand'=>'')
            $data = Cache::get($key);
        }
        echo $this->echoJson($data);
    }

    /**
     * 新品上架 接口数据
     *
     * @param string channel 当前频道
     * @param int pageIndex 当前页数
     * @param int pageCount 一页显示个数
     */
    public function getNewArrivalAction()
    {
        $result = $data = array();
        do {
            /* 判断是不是AJAX请求 */
            if (! $this->isAjax()) {
                break;
            }
            $channels = array(
                HomeModel::COOKIE_NAME_BOYS,
                HomeModel::COOKIE_NAME_GIRLS,
                HomeModel::COOKIE_NAME_KIDS,
                HomeModel::COOKIE_NAME_LIFESTYLE
            );
            $channel = $this->post('type', '');
            $pageIndex = $this->post('pageIndex', 1);
            $pageCount = $this->post('pageCount', 8);
            if (! in_array($channel, $channels)) {
                break;
            } else {
                $data = HomeModel::getNewArrival($channel);
            }
            $result = array_slice($data, ($pageIndex - 1) * $pageCount, $pageCount);
            if (empty($result)) {
                break;
            }
            $result = array(
                'code' => 200,
                'commodity' => $result
            );
        } while (false);
        
        $this->echoJson($result);
    }
}