Blame view

yohobuy/m.yohobuy.com/application/modules/Product/controllers/Index.php 8.19 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
<?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(
28
            'brand' => FILTER_DEFAULT,
29
            'sort' => FILTER_DEFAULT,
hf authored
30 31
            'msort' => FILTER_DEFAULT,
            'misort' => FILTER_DEFAULT,
32 33 34 35 36
            'color' => FILTER_DEFAULT,
            'size' => FILTER_DEFAULT,
            'style' => FILTER_DEFAULT,
            'price' => FILTER_DEFAULT,
            'discount' => FILTER_DEFAULT,
37 38 39
            'gender' => FILTER_DEFAULT,
            'p_d' => FILTER_DEFAULT,), false);
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
        // 转义品牌
        if (isset($condition['brand'])) {
            $condition['brand'] = rawurldecode($condition['brand']);
        }
        // 转义分类
        if (isset($condition['sort'])) {
            $condition['sort'] = rawurldecode($condition['sort']);
        }
        // 转义一级分类
        if (isset($condition['msort'])) {
            $condition['msort'] = rawurldecode($condition['msort']);
        }
        // 转义二级分类
        if (isset($condition['misort'])) {
            $condition['misort'] = rawurldecode($condition['misort']);
        }
        // 转义颜色
        if (isset($condition['color'])) {
            $condition['color'] = rawurldecode($condition['color']);
        }
        // 转义尺码
        if (isset($condition['size'])) {
            $condition['size'] = rawurldecode($condition['size']);
        }
        // 转义风格
        if (isset($condition['style'])) {
            $condition['style'] = rawurldecode($condition['style']);
        }
        // 转义价格
        if (isset($condition['price'])) {
            $condition['price'] = rawurldecode($condition['price']);
        }
        // 转换折扣
        if (isset($condition['discount'])) {
            $condition['p_d'] = rawurldecode($condition['discount']);
        }
hf authored
76 77 78 79
        // 为了兼容现在运营在用的p_d
        if (isset($condition['p_d'])) {
            $condition['discount'] = rawurldecode($condition['p_d']);
        }
80 81 82
        // 性别参数,不传则从COOKIE获取
        if (!isset($condition['gender'])) {
            $condition['gender'] = Helpers::getGenderByCookie();
hf authored
83 84
        } else {
            $condition['gender'] = rawurldecode($condition['gender']);
85 86 87 88 89 90 91 92 93 94
        }

        // 品类名称参数, 不传则默认为全部
        $name = $this->get('sort_name');
        if (empty($name)) {
            $name = $this->get('title', '全部');
        }
        $this->setTitle($name);
        $this->setNavHeader($name, true, SITE_MAIN);
95 96 97 98
        if (!$condition) {
            $condition = array();
        }
        $goodList = $condition;
99 100
        $goodList['cartUrl'] = Helpers::url('/cart/index/index', null);
101 102 103 104
//        $goodList = Product\ListModel::getClassData($condition);
//        if (!empty($condition) && !empty($goodList)) {
//            $goodList = array_merge($goodList, $condition);
//        }
105 106
        $this->_view->display('index', array(
            'goodListPage' => true,
107
            'showDownloadApp' => true,
108 109
            'goodList' => $goodList,
            'pageFooter' => true,
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
        ));
    }

    /**
     * 品牌商品列表页
     * 
     * @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()
    {
125
        /* 品牌域名参数 @see Bootstrap.php */
126 127
        $domain = $this->param('named');
        if (empty($domain)) {
hf authored
128
            $this->go(SITE_MAIN);
129 130
        }
hf authored
131 132 133
        // 存标题信息
        $title = '';
        $brandLogo = Product\ListModel::getBrandLogoByDomain($domain, $title);
134
        $brandId = 0;
hf authored
135 136 137
        if ($brandLogo && isset($brandLogo['id'])) {
            $brandId = $brandLogo['id'];
        }
hf authored
138
hf authored
139 140 141 142 143 144 145
        /* 通过品牌域名找到对应的品牌ID */
//        $domainList = Product\ListModel::getAllBrandDomains();
//        $brandIds = array_keys($domainList, $domain);
//        $brandId = 0;
//        if (isset($brandIds[0])) {
//            $brandId = $brandIds[0];
//        } 
146 147
        // 当前的登录用户UID
        $uid = $this->getUid();
148 149 150 151 152

        /* 搜索框相关 */
        $from = $this->get('from');
        $query = $this->get('query');
153 154
        /* 过滤请求参数 */
        $condition = filter_input_array(INPUT_GET, array(
155
            'sort' => FILTER_DEFAULT,
156 157 158 159 160 161 162
            'msort' => FILTER_DEFAULT,
            'misort' => FILTER_DEFAULT,
            'color' => FILTER_DEFAULT,
            'size' => FILTER_DEFAULT,
            'style' => FILTER_DEFAULT,
            'price' => FILTER_DEFAULT,
            'discount' => FILTER_DEFAULT,
163 164
            'gender' => FILTER_DEFAULT,
            'p_d' => FILTER_DEFAULT,), false);
165
        $condition['brand'] = $brandId;
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
        // 转义分类
        if (isset($condition['sort'])) {
            $condition['sort'] = rawurldecode($condition['sort']);
        }
        // 转义一级分类
        if (isset($condition['msort'])) {
            $condition['msort'] = rawurldecode($condition['msort']);
        }
        // 转义二级分类
        if (isset($condition['misort'])) {
            $condition['misort'] = rawurldecode($condition['misort']);
        }
        // 转义颜色
        if (isset($condition['color'])) {
            $condition['color'] = rawurldecode($condition['color']);
        }
        // 转义尺码
        if (isset($condition['size'])) {
            $condition['size'] = rawurldecode($condition['size']);
        }
        // 转义风格
        if (isset($condition['style'])) {
            $condition['style'] = rawurldecode($condition['style']);
        }
        // 转义价格
        if (isset($condition['price'])) {
            $condition['price'] = rawurldecode($condition['price']);
        }
        // 转换折扣
        if (isset($condition['discount'])) {
            $condition['p_d'] = rawurldecode($condition['discount']);
        }
hf authored
198 199 200 201
        // 为了兼容现在运营在用的p_d
        if (isset($condition['p_d'])) {
            $condition['discount'] = rawurldecode($condition['p_d']);
        }
202 203 204
        if ($brandId === 0) {
            $condition['query'] = $domain;
        }
205
hf authored
206 207
        if (isset($condition['gender'])) {
            $condition['gender'] = rawurldecode($condition['gender']);
208 209
        } else {
            $condition['gender'] = Helpers::getGenderByCookie();
hf authored
210
        }
211
hf authored
212
        $data = array();
213
        $data['goodListPage'] = true;
214
        $data['showDownloadApp'] = true;
215 216
        // 从搜索页过来的,显示搜索框, 和进入品牌引导信息
        if ($from === 'search') {
217
            $data['goodList'] = array();
hf authored
218 219
            //$data['goodList']['brandWay'] = \Product\ListModel::getBrandLogoByIds($brandId, $title);
            $data['goodList']['brandWay'] = $brandLogo;
220 221
            $data['goodList']['search']['default'] = $query;
            $data['goodList']['search']['url'] = Helpers::url('', null, 'search');
222
        }
223
        // 品牌一览过来的展示品牌介绍和LOGO
hf authored
224
        elseif ($brandId !== 0) {
225
            $data['brandHome'] = \Product\ListModel::getBrandIntro($brandId, $uid, $title);
226
            $data['goodList'] = array();
227
        }
228 229 230

        // 右下角的购物车链接
        $data['goodList']['cartUrl'] = Helpers::url('/cart/index/index', null);
231
        $data['goodList'] += $condition;
hf authored
232
        $data['pageFooter'] = true;
233
234 235 236
        if ($title === '') {
            $title = $domain;
        }
237 238 239 240 241 242 243
        $this->setTitle($title);
        $this->setNavHeader($title, true, SITE_MAIN);

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

}