Blame view

yohobuy/m.yohobuy.com/application/modules/Product/controllers/Index.php 5.01 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
<?php

use Action\AbstractAction;
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,
29
            'sort' => FILTER_DEFAULT,
30 31 32 33 34 35 36 37 38 39 40 41
            '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();
hf authored
42 43
        } else {
            $condition['gender'] = rawurldecode($condition['gender']);
44 45 46 47 48 49 50 51 52 53
        }

        // 品类名称参数, 不传则默认为全部
        $name = $this->get('sort_name');
        if (empty($name)) {
            $name = $this->get('title', '全部');
        }
        $this->setTitle($name);
        $this->setNavHeader($name, true, SITE_MAIN);
54 55 56 57
        $goodList = array();
        $goodList['cartUrl'] = Helpers::url('/cart/index/index', null);
        $goodList += $condition;
58 59 60 61
//        $goodList = Product\ListModel::getClassData($condition);
//        if (!empty($condition) && !empty($goodList)) {
//            $goodList = array_merge($goodList, $condition);
//        }
62 63
        $this->_view->display('index', array(
            'goodListPage' => true,
64
            'showDownloadApp' => true,
65 66
            'goodList' => $goodList,
            'pageFooter' => true,
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
        ));
    }

    /**
     * 品牌商品列表页
     * 
     * @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()
    {
82
        /* 品牌域名参数 @see Bootstrap.php */
83 84
        $domain = $this->param('named');
        if (empty($domain)) {
hf authored
85
            $this->go(SITE_MAIN);
86 87 88 89 90
        }

        /* 通过品牌域名找到对应的品牌ID */
        $domainList = Product\ListModel::getAllBrandDomains();
        $brandIds = array_keys($domainList, $domain);
91 92 93
        $brandId = 0;
        if (isset($brandIds[0])) {
            $brandId = $brandIds[0];
94
        }
95
96 97
        // 当前的登录用户UID
        $uid = $this->getUid();
98 99 100 101 102 103 104
        // 存标题信息
        $title = '';

        /* 搜索框相关 */
        $from = $this->get('from');
        $query = $this->get('query');
105 106
        /* 过滤请求参数 */
        $condition = filter_input_array(INPUT_GET, array(
107
            'sort' => FILTER_DEFAULT,
108 109 110 111 112 113 114 115
            '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);
116 117
        $condition['brand'] = $brandId;
hf authored
118 119
        if (isset($condition['gender'])) {
            $condition['gender'] = rawurldecode($condition['gender']);
120 121
        } else {
            $condition['gender'] = Helpers::getGenderByCookie();
hf authored
122
        }
123
hf authored
124
        $data = array();
125
        $data['goodListPage'] = true;
126
        $data['showDownloadApp'] = true;
127 128
        // 从搜索页过来的,显示搜索框, 和进入品牌引导信息
        if ($from === 'search') {
129
            $data['goodList'] = array();
130
            $data['goodList']['brandWay'] = \Product\ListModel::getBrandLogoByIds($brandId, $title);
131 132
            $data['goodList']['search']['default'] = $query;
            $data['goodList']['search']['url'] = Helpers::url('', null, 'search');
133
        }
134 135
        // 品牌一览过来的展示品牌介绍和LOGO
        else {
136
            $data['brandHome'] = \Product\ListModel::getBrandIntro($brandId, $uid, $title);
137
            $data['goodList'] = array();
138
        }
139 140 141

        // 右下角的购物车链接
        $data['goodList']['cartUrl'] = Helpers::url('/cart/index/index', null);
142
        $data['goodList'] += $condition;
hf authored
143
        $data['pageFooter'] = true;
144
145 146 147
        if ($title === '') {
            $title = $domain;
        }
148 149 150 151 152 153 154
        $this->setTitle($title);
        $this->setNavHeader($title, true, SITE_MAIN);

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

}