PlusstarIndex.php 3.39 KB
<?php
namespace WebPlugin\DataProcess\Channel;
use WebPlugin\Images;
class PlusstarIndex extends AbstractChannel
{

    /**
     * 格式化数据
     *
     * @param array $resource
     * @return
     */
    public static function format($resources)
    {
        $singleGoods = array('name'=>'','list'=> array());
        $video = array('name'=> '','list'=> array());
        $news = array('name' =>'', 'pics'=> array('list' => array()),'txts'=> array('list'=> array()));
        $ads = array('list'=> array());
        $result = array();
        if(!empty($resources))
        {
            $len = count($resources) + 4 ;//4个是默认已经处理了
            foreach($resources as $key => $resource) {
                if($key == 4 && $resource['template_name'] == 'text') {//单品名称
                    $singleGoods['name'] = $resource['data']['text'];
                }
                if($key == 5 && $resource['template_name'] == 'floor') {//单品列表
                    foreach($resource['data'] as $pos => $val) {
                        $val['src'] = Images::getImageUrl($val['src'], 280, 374, 1);
                        $singleGoods['list'][] = array('href' => $val['url'],'name'=> $val['title'],'img' => $val['src']);
                    }
                    $result[$key] = array('singlegoods' => $singleGoods);
                }
                
                if($key == 6 && $resource['template_name'] == 'text') { //视频名称
                    $video['name'] = $resource['data']['text'];
                }
                
                if($key == 7 && $resource['template_name'] == 'floor') { //视频名称
                    foreach($resource['data'] as $pos => $val) {
                        $val['src'] = Images::getImageUrl($val['src'], 378, 241, 1);
                        $video['list'][] = array('href' => $val['url'],'name'=> $val['title'],'img' => $val['src']);
                    }
                    $result[$key] = array('video' => $video);
                }
                
                //倒数第三个
                if($key == ($len - 3) && $resource['template_name'] == 'text'){//资讯名称
                    $news['name'] = $resource['data']['text'];
                }
                
                //倒数第二个
                if($key == ($len - 2) && $resource['template_name'] == 'textNav') { //资讯banner
                    foreach($resource['data'] as $val) {
                        if(is_numeric($val['name'])) {
                            $id = $val['name'];
                            $news['pics']['list'][$id] = array('id' => $id,'href' => $val['url'], 'img'=>'','tips'=>'');
                        }
                    }
                    $result[$key] = array('news' => $news);
                }
                
                //最后一个
                if($key == ($len - 1) && $resource['template_name'] == 'textNav') {//小资讯
                    foreach($resource['data'] as $pos => $val) {
                        if(is_numeric($val['name'])) {
                            $id = $val['name'];
                            $ads['list'][$id] = array('id' => $id,'href' => $val['url'],'img'=>'',);
                        }
                    }
                    $result[$key] = array('ads' => $ads);
                }
            }
        }
        return $result;
    }
}