Index.php 3.73 KB
<?php

use Action\AbstractAction;
use LibModels\Wap\Category\BrandData;
use LibModels\Wap\Category\ClassData;
use Plugin\DataProcess\ListProcess;
use Plugin\Helpers;

/**
 * 商品列表相关的控制器
 * 
 */
class IndexController extends AbstractAction
{

    /**
     * 品类商品列表页
     * 
     * @param  string $gender    "1,3"表示男, "2,3"表示女, "1,2,3"表示全部
     * @param  integer $brand    品牌Id
     * @param  integer $sort     品类查询sort参数
     * @param  integer $color    颜色Id
     * @param  integer $size     尺码Id
     * @param  string $price     价格
     * @param  string $p_d       折扣
     */
    public function indexAction()
    {
        // 过滤请求参数
        $condition = filter_input_array(INPUT_GET, array(
            'brand' => FILTER_VALIDATE_INT,
            'sort' => FILTER_VALIDATE_INT,
            'msort' => FILTER_VALIDATE_INT,
            'misort' => FILTER_VALIDATE_INT,
            'color' => FILTER_VALIDATE_INT,
            'size' => FILTER_VALIDATE_INT,
            'price' => FILTER_VALIDATE_INT,
            'discount' => FILTER_VALIDATE_INT,
            'gender' => FILTER_DEFAULT,
            'p_d' => FILTER_DEFAULT,), false);

        // 性别参数,不传则从COOKIE获取
        if (!isset($condition['gender'])) {
            $condition['gender'] = Helpers::getGenderByCookie();
        }

        // 品类名称参数, 不传则默认为全部
        $name = $this->get('sort_name');
        if (empty($name)) {
            $name = $this->get('title', '全部');
        }
        $this->setTitle($name);
        $this->setNavHeader($name, true, SITE_MAIN);

        $goodList = Product\ListModel::getClassData($condition);
        if (!empty($condition)) {
            $goodList = array_merge($goodList, $condition);
        }
        $this->_view->display('index', array(
            'goodListPage' => true,
            'goodList' => $goodList,
        ));
    }

    /**
     * 品牌商品列表页
     * 
     * @param  string $gender    "1,3"表示男, "2,3"表示女, "1,2,3"表示全部
     * @param  integer $sort     品类查询sort参数
     * @param  integer $color    颜色Id
     * @param  integer $size     尺码Id
     * @param  string $price     价格
     * @param  string $p_d       折扣
     */
    public function brandAction()
    {
        /* 品牌域名参数 @see Bootstrap.php */ 
        $domain = $this->param('named');
        if (empty($domain)) {
            $this->error();
        }

        /* 通过品牌域名找到对应的品牌ID */
        $domainList = Product\ListModel::getAllBrandDomains();
        $brandIds = array_keys($domainList, $domain);
        if (!isset($brandIds[0])) {
            $this->error();
        }
        // 当前的登录用户UID
        $uid = $this->getUid();
        
        /* 过滤请求参数 */
        $condition = filter_input_array(INPUT_GET, array(
            'sort' => FILTER_VALIDATE_INT,
            'msort' => FILTER_VALIDATE_INT,
            'misort' => FILTER_VALIDATE_INT,
            'color' => FILTER_VALIDATE_INT,
            'size' => FILTER_VALIDATE_INT,
            'price' => FILTER_VALIDATE_INT,
            'discount' => FILTER_VALIDATE_INT,
            'gender' => FILTER_DEFAULT,
            'p_d' => FILTER_DEFAULT,), false);
        $condition['brand'] = $brandIds[0];
        
        // 存标题信息
        $title = '';

        $data = Product\ListModel::getBrandData($condition, $brandIds[0], $uid, $title);
        if (!empty($condition)) {
            $data = array_merge($data, $condition);
        }
        $data['goodListPage'] = true;

        $this->setTitle($title);
        $this->setNavHeader($title, true, SITE_MAIN);

        $this->_view->display('index', $data);
    }

}