StarClass.php 6.42 KB
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016-4-12
 * Time: 9:53
 */

namespace Guang;

use Plugin\Helpers;
use LibModels\Wap\Guang\StarClassData;
use Api\Yohobuy;

/**
 * Class TrendClassesroom
 * 星潮教室
 * @package Guang
 */
class StarClassModel
{

    //星潮教室首页
    public static function getStarClass($uid)
    {
        $result = array();
        $result['title'] = '星潮教室';
        $result['headTab'] = self::getHeadTab('index');

        //组装资源位获取星潮教室首页数据URL
        $contentCode = '8adc27fcf5676f356602889afcfd2a8e';
        $res['starClassIndex'] = StarClassData::getResourceDataUrl($contentCode);

        //组装获得每日签到数据接口URL
        $res['rankInfo'] = StarClassData::rankInfoDataUrl($uid);
//print_r($res['rankInfo']);exit;
        $data = Yohobuy::getMulti($res);
        print_r($data['starClassIndex']);
//        print_r($data);exit;
        //调用成功封装数据
        if (isset($data['starClassIndex']) && !empty($data['starClassIndex'])) {
            $starClassIndex = $data['starClassIndex'];
            $build = array();
            foreach ($starClassIndex as $value) {
                if (empty($value)) {
                    continue;
                }
                $fun = $value['template_name'];
                if (empty($value['data']) || !is_callable("self::$fun")) {
                    continue;
                }
                $build = self::$fun($value['data']);
                if (empty($build)) {
                    continue;
                }
                $result['resources'][] = $build;
            }
            $build = array();

        }

        return $result;
    }


    //星专题
    public static function getspecial()
    {
        $result = array();
        $result['title'] = '星潮教室';
        $result['headTab'] = self::getHeadTab('special');

        //组装资源位获取星潮教室首页数据URL
        $contentCode = '89cc20483ee2cbc8a716dcfe2b6c7603';
        $data = StarClassData::getResourceData($contentCode);
        if (isset($data['code']) && $data['code'] == 200) {
            $build = array();
            foreach ($data['data'] as $value) {
                if (empty($value)) {
                    continue;
                }
                $fun = $value['template_name'];
                if (empty($value['data']) || !is_callable("self::$fun")) {
                    continue;
                }
                $build = self::$fun($value['data']);
                if (empty($build)) {
                    continue;
                }
                $result['resources'][] = $build;
            }
            $build = array();
        }

        return $result;
    }


    /**
     * 星搭配
     */
    public static function getCollocation()
    {
        $result = array();
        $result['title'] = '星潮教室';
        $result['headTab'] = self::getHeadTab('collocation');


        return $result;
    }

    /**
     * 星搭配
     */
    public static function ajaxCollocation($page)
    {
        $data = StarClassData::collocationData($page);

        $result = array();
        $collocationList = array();
        if (isset($data['code']) && $data['code'] == 200 && !empty($data['data'])) {
            foreach ($data['data']['list']['artList'] as $key=>$value) {
                $collocationList[$key]['img'] = Helpers::getImageUrl($value['src'], 640, 240);
                $collocationList[$key]['url'] = $value['url'];
                $collocationList[$key]['title'] = $value['title'];
                $collocationList[$key]['content'] = $value['intro'];
                $collocationList[$key]['time'] = $value['publish_time'];
                $collocationList[$key]['seeNum'] = $value['views_num'];
                $collocationList[$key]['zanNum'] = $value['praise_num'];
                $collocationList[$key]['isLiked '] = $value['isPraise'];
                $collocationList[$key]['isCollected'] = $value['isFavor'];
            }
            $result['collocationList'] = $collocationList;
        }

        return $result;
    }

    //签到操作
    public static function sign($uid)
    {
        $data = StarClassData::sign($uid);
//print_r($data);
        $result = array();
        if (isset($data['code']) && $data['code'] == 200) {
            $result['signDay'];
            foreach ($data['data']['logs'] as $key=>$value) {
                $result['signDay'] .= date('N', $value['createTime']) . ',';
            }
            $result['intimacyNum'] = $data['data']['addNum'];
            $result['fanCharts'] = $data['data']['rankList'];
            foreach ($data['data']['rankList'] as $key=>$value) {
                $result['fanCharts'][$key]['num'] = intval($key)+1;
                $result['fanCharts'][$key]['img'] = Helpers::getImageUrl($value['avatar'], 640, 240);
                $result['fanCharts'][$key]['name'] = $value['username'];
                $result['fanCharts'][$key]['intimacyNum'] = $value['num'];
            }

        }

        return $result;
    }


    /**
     * 获取headTab
     */
    public static function getHeadTab($tab)
    {
        $result = array(
            array(
                'name' => '全部',
                'url' => Helpers::url('/guang/starclass/index'),
            ),
            array(
                'name' => '星专题',
                'url' => Helpers::url('/guang/starclass/special')
            ),
            array(
                'name' => '星搭配',
                'url' => Helpers::url('/guang/starclass/collocation')
            ),
            array(
                'name' => '星鲜事',
                'url' => Helpers::url('/guang/starclass/fresh')
            )
        );
        switch ($tab) {
            case 'index':
                $result[0]['cur'] = true;
                break;
            case 'special':
                $result[1]['cur'] = true;
                break;
            case 'collocation':
                $result[2]['cur'] = true;
                break;
            case 'fresh':
                $result[3]['cur'] = true;
                break;
            default:
                break;
        }

        return $result;
    }

    //single_name_image
    public static function single_name_image($data)
    {
        $result = array();

        $result['url'] = $data['url'];
        $result['img'] = $data['src'];
        $result['title'] = $data['title'];
        $result['subject'] = true;

        return $result;
    }

}