ClassProcess.php 1.06 KB
<?php

namespace Plugin;

/**
 * 分类数据处理类
 */
class ClassProcess
{

    /**
     * 处理品类数据
     * @param $data
     * @return array 处理之后的品类数据
     */
    public static function getClassData($data)
    {
        $num = 1;
        $classes = array();

        foreach ($data as $k => $v){
            $oneClass = array('name'=>$k, 'ca'=>array());
            if($num === 1)
            {
                $oneClass['focus'] = true;
            }

            foreach ($v as $val) {
                $item = array();
                $item['name'] = $val['category_name'];
                foreach ($val['sub'] as $value) {
                    $subitem = array();
                    $subitem['name'] = $value['category_name'];
                    $subitem['url'] = $value['category_id'];
                
                    $item['sub'][] = $subitem;
                }
                
                $oneClass['ca'][] = $item;
            }

            $num++;
            $classes[] = $oneClass;
        }

        return $classes;
        
    }
}