Blame view

yohobuy/m.yohobuy.com/application/modules/Guang/controllers/Index.php 10.1 KB
1 2 3 4 5
<?php

use Action\AbstractAction;
use LibModels\Wap\Guang\ListData;
use Plugin\Helpers;
hf authored
6 7
use Plugin\Cache;
use Configs\CacheConfig;
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

/**
 * 逛首页、列表页、编辑页
 */
class IndexController extends AbstractAction
{

    /**
     * 首页
     * 
     * @param int id 分类ID 0:最新,1:话题,2:搭配,3:潮人,4:潮品,5:小贴士
     * @param string gender '1,3'表示男,'2,3'表示女, 默认为所有
     */
    public function indexAction()
    {
        $this->setTitle('逛');
        $this->setNavHeader('逛', true, SITE_MAIN);

        $uid = $this->getUid();
        $udid = $this->getUdid();
hf authored
28
29
        $type = $this->get('id', 0);
hf authored
30
        $gender = $this->get('gender');
31 32
        if (is_string($gender)) {
            $gender = rawurldecode($gender);
hf authored
33 34
        } else {
            $gender = Helpers::getGenderByCookie();
35
        }
hf authored
36 37 38 39 40 41
//        // 设置侧边栏逛的默认选中状态
//        if ($gender === '1,3') {
//            $this->setNavSide('boys');
//        } elseif ($gender === '2,3') {
//            $this->setNavSide('girls');
//        } else {
hf authored
42
//            $this->setNavSide();
hf authored
43
//        }
44
45
        $this->_view->display('index', Guang\IndexModel::getArticle($gender, $type, $uid, $udid));
46 47 48 49 50 51 52 53 54 55 56 57 58
    }

    /**
     * 列表页
     * 
     * @param string tag 标签名称
     * @param int yh_channel APP客户端标识 1表示男,2:表示女,3:潮童,4:创意生活
     */
    public function tagAction()
    {
        $tag = $this->get('query');
        $channel = $this->get('yh_channel');
59 60 61 62 63 64 65 66 67 68 69 70 71 72
        // 标识是不是APP客户端
        $isApp = is_numeric($channel);
        // APP访问时通过频道参数判断性别
        if ($isApp) {
            switch (intval($channel)) {
                case 1: // 男
                    $gender = '1,3';
                    break;
                case 2: // 女
                    $gender = '2,3';
                    break;
                default: // 所有
                    $gender = '1,2,3';
            }
73 74 75 76 77 78 79 80
            $uid = $this->get('uid');
            $udid = $this->get('udid');
            if ($uid) {
                $this->setSession('uid', $uid);
            }
            if ($udid) {
                $this->setSession('udid', $udid);
            }
81 82 83 84
        }
        // 从Cookie获取
        else {
            $gender = Helpers::getGenderByCookie();
hf authored
85
86 87 88
            $uid = $this->getUid();
            $udid = $this->getUdid();
89 90 91
            $this->setNavHeader($tag, true, SITE_MAIN);
        }
92
        // 标签聚合内容列表
93
        $article = ListData::article($gender, 0, $uid, $udid, 1, $tag);
94 95 96 97 98 99 100 101 102 103 104 105 106 107
        // 标签聚合内容不存在, 跳到错误页面
        if (empty($article['data']['list']['artList'])) {
            $this->error();
        }

        $this->setTitle($tag);

        $data = array();
        // 模板中使用JS的标识
        $data['guangList'] = true;

        // 构建资讯文章内容
        $build = array();
        foreach ($article['data']['list']['artList'] as $article) {
108
            $build[] = Helpers::formatArticle($article, true, $isApp, true, $uid);
109 110 111 112 113
        }
        $data['guang']['infos'] = $build;

        // 分页需要的参数
        $data['guang']['tag'] = $tag;
114 115
        $data['guang']['gender'] = $gender;
        $data['guang']['isApp'] = $isApp ? 1 : 0;
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131

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

    /**
     * 编辑页
     * 
     * @param int id 作者ID
     * @param int yh_channel APP客户端标识 1表示男,2:表示女,3:潮童,4:创意生活
     */
    public function editorAction()
    {
        $id = $this->get('id');
        $channel = $this->get('yh_channel');

        // 标识是不是APP客户端
132 133 134 135 136 137 138 139 140 141 142 143 144
        $isApp = is_numeric($channel);
        // APP访问时通过频道参数判断性别
        if ($isApp) {
            switch (intval($channel)) {
                case 1: // 男
                    $gender = '1,3';
                    break;
                case 2: // 女
                    $gender = '2,3';
                    break;
                default: // 所有
                    $gender = '1,2,3';
            }
145 146 147 148 149 150 151 152
            $uid = $this->get('uid');
            $udid = $this->get('udid');
            if ($uid) {
                $this->setSession('uid', $uid);
            }
            if ($udid) {
                $this->setSession('udid', $udid);
            }
153 154 155 156
        }
        // 从Cookie获取
        else {
            $gender = Helpers::getGenderByCookie();
hf authored
157
158 159 160
            $uid = $this->getUid();
            $udid = $this->getUdid();
161 162 163
            $this->setNavHeader('编辑简介', true, SITE_MAIN);
        }
hf authored
164 165 166 167 168 169 170
        // 获取作者信息
        $author = ListData::author($id);
        // 作者信息不存在,则跳到错误页面
        if (!isset($author['name'])) {
            $this->error();
        }
171
        $this->setTitle('编辑简介', false, '');
172
173 174 175 176 177
        $data = array();
        // 模板中使用JS的标识
        $data['guangList'] = true;

        // 作者信息
178 179 180 181 182
        $data['authorInfo'] = array();
        $data['authorInfo']['avatar'] = Helpers::getImageUrl($author['avatar'], 100, 100);
        $data['authorInfo']['name'] = $author['name'];
        $data['authorInfo']['info'] = $author['author_desc'];
        $data['authorInfo']['id'] = $id;
183 184

        // 标签聚合内容列表
185
        $article = ListData::article($gender, 0, $uid, $udid, 1, null, $id);
186 187 188 189
        // 构建资讯文章内容
        if (!empty($article['data']['list']['artList'])) {
            $build = array();
            foreach ($article['data']['list']['artList'] as $article) {
190
                $build[] = Helpers::formatArticle($article, true, $isApp, false, $uid);
191 192 193
            }
            $data['guang']['infos'] = $build;
        }
hf authored
194
195 196
        $data['guang']['gender'] = $gender;
        $data['guang']['isApp'] = $isApp ? 1 : 0;
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226

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

    /**
     * 逛列表页面的资讯分页
     * 
     * 逛首页、标签页、编辑页资讯列表
     * 
     * @param string tag 标签名称, 没有传空或不传
     * @param int type 逛首页的分类ID
     * @param int page 分页的页码
     * @param string gender "1,2,3"表示所有, "1,3"表示男, "2,3"表示女
     * @param int authorId 作者ID
     * @return html
     */
    public function pageAction()
    {
        do {
            /* 判断是不是AJAX请求 */
            if (!$this->isAjax()) {
                break;
            }

            /* 判断参数是否有效 */
            $tag = $this->get('tag');
            $sortId = $this->get('type', 0);
            $page = $this->get('page');
            $gender = $this->get('gender');
            $authorId = $this->get('authorId');
227
            $isApp = $this->get('isApp', false);
228 229 230 231 232 233 234 235 236 237 238 239
            $showAuthor = true;
            if (!empty($sortId) && !is_numeric($sortId)) {
                break;
            }
            if (!empty($page) && !is_numeric($page)) {
                break;
            }
            if (!empty($authorId) && is_numeric($authorId)) {
                $showAuthor = false;
            }

            /* 获取资讯文章列表 */
240 241 242 243 244 245 246
            if ($isApp) {
                $uid = $this->getSession('uid');
                $udid = $this->getSession('udid');
            } else {
                $uid = $this->getUid();
                $udid = $this->getUdid();
            }
247
            //$page = intval($page) + 1;
248 249 250 251 252 253 254 255 256
            $article = ListData::article($gender, $sortId, $uid, $udid, $page, $tag, $authorId);
            if (empty($article['data']['list']['artList'])) {
                break;
            }

            /* 构建资讯文章内容 */
            $data = array();
            $build = array();
            foreach ($article['data']['list']['artList'] as $article) {
257
                $build[] = Helpers::formatArticle($article, true, $isApp, $showAuthor, $uid);
258 259 260 261 262
            }
            $data['infos'] = $build;

        } while (false);
263 264 265 266 267
        if (isset($data)) {
            $this->_view->display('page', $data);
        } else {
            echo ' ';
        }
268
    }
hf authored
269 270 271 272 273 274
    
    /**
     * @todo 清缓存
     */
    public function clearAction()
    {
275 276 277 278 279
        $key = $this->get('key');
        if ($key !== '9646abcdef') {
            exit();
        }
        
hf authored
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
        $type = $this->get('type');
        switch (strval($type)) {
            case 'boys':
                Cache::delete(CacheConfig::KEY_ACTION_BOYS_INDEX);
                break;
            case 'girls':
                Cache::delete(CacheConfig::KEY_ACTION_GIRLS_INDEX);
                break;
            case 'kids':
                Cache::delete(CacheConfig::KEY_ACTION_KIDS_INDEX);
                break;
            case 'lifestyle':
                Cache::delete(CacheConfig::KEY_ACTION_LIFESTYLE_INDEX);
                break;
            case 'bgimg':
                Cache::delete(CacheConfig::KEY_ACTION_INDEX_INDEX);
                break;
hf authored
297 298 299 300 301 302
            case 'brands':
                Cache::delete('3206a153b0cebbd6e47be90c6ac41ee8');
                Cache::delete('1c6bb62c480aec413b247d6f21e9c23a');
                Cache::delete('60bb7899f49b3549dde438ac53526dea');
                Cache::delete('9085ba21ac3d4f849c977da37a290a23');
                break;
303 304 305 306 307 308 309 310 311 312 313 314
            case 'new':
                Cache::delete(CacheConfig::KEY_ACTION_PRODUCT_NEWSALE_INDEX . '3cf2c1be5217fbab6009ce83959e1e12');
                Cache::delete(CacheConfig::KEY_ACTION_PRODUCT_NEWSALE_INDEX . '1cf7f9f10e2a2670e73d05c568793ad9');
                Cache::delete(CacheConfig::KEY_ACTION_PRODUCT_NEWSALE_INDEX . '57457adececa6c748b29c90cad0ae940');
                Cache::delete(CacheConfig::KEY_ACTION_PRODUCT_NEWSALE_INDEX . '04953a61cbf1db426a681e55d496d2fe');
                break;
            case 'sale':
                Cache::delete(CacheConfig::KEY_ACTION_PRODUCT_NEWSALE_DISCOUNT . '153180b9a88c0b565848850c523bb637');
                Cache::delete(CacheConfig::KEY_ACTION_PRODUCT_NEWSALE_DISCOUNT . '0b2d133419a0f7c381306fd3522365e1');
                Cache::delete(CacheConfig::KEY_ACTION_PRODUCT_NEWSALE_DISCOUNT . 'de23648d28ee1e8a3f087a9dbac506f8');
                Cache::delete(CacheConfig::KEY_ACTION_PRODUCT_NEWSALE_DISCOUNT . '01269e498ff5b07756e0733ec0e88c75');
                break;
hf authored
315 316
        }
    }
317 318

}