Index.php 2.93 KB
<?php

namespace Guang;

use LibModels\Wap\Guang\ListData;
use Plugin\Helpers;

/**
 * 
 * @name IndexModel
 * @package models/Guang
 * @copyright yoho.inc
 * @version 1.0 (2015-10-27 11:31:49)
 * @author fei.hong <fei.hong@yoho.cn>
 */
class IndexModel
{

    /**
     * 获取逛首页分类内容列表
     * 
     * @param string $gender "1,3"表示男, "2,3"表示女
     * @param int channel APP客户端标识 1表示男,2:表示女,3:潮童,4:创意生活
     * @param int type 分类ID 0:最新,1:话题,2:搭配,3:潮人,4:潮品,5:小贴士
     * @param int $uid 用户ID
     * @param string $udid 客户端唯一标识
     * @param int $page 分页第几页, 默认第1页
     * @return array
     */
    public static function getArticleGroup($gender, $type, $uid, $udid, $page = 1)
    {
        // 逛首页的分类名称列表
        $category = ListData::category();
        $articleGroup = array();

        switch ($gender) {
            case '1,3': // 男
                $articleGroup = ListData::articleGroup($category['data'], '1,3', $uid, $udid, $page);
                break;
            case '2,3': // 女
                $articleGroup = ListData::articleGroup($category['data'], '2,3', $uid, $udid, $page);
                break;
            default: // 其它所有
                $articleGroup = ListData::articleGroup($category['data'], '1,2,3', $uid, $udid, $page);
                break;
        }

        $data = array();
        $build = array();

        // 模板中使用JS的标识
        $data['guangHome'] = true;

        // 顶部的分类列表
        foreach ($category['data'] as $value) {
            $build = array();
            $build['typeId'] = $value['id'];
            $build['type'] = $value['name'];
            $build['focus'] = ($value['id'] == $type);
            $data['navs'][] = $build;
        }

        $data['guang']['swiper'] = array();
        $data['guang']['infos'] = array();
        foreach ($articleGroup as $id => $value) {
            // 判断是否有内容
            if (empty($value['list'])) {
                continue;
            }

            // 轮番广告
            if ($id == 0) {
                $build = array();
                foreach ($value['list']['adlist'] as $banner) {
                    $build['url'] = Helpers::getFilterUrl($banner['url']);
                    $build['img'] = Helpers::getImageUrl($banner['src'], 830, 327);
                    $data['guang']['swiper'][] = $build;
                }
            }

            // 内容列表
            $build = array();
            $build['show'] = ($id == $type);
            foreach ($value['list']['artList'] as $article) {
                $build['info'][] = Helpers::formatArticle($article, true, false);
            }
            $data['guang']['infos'][] = $build;
        }

        // 分页需要参数
        $data['guang']['gender'] = $gender;

        $category = array();
        
        return $data;
    }

}