NewSaleProcess.php 1.91 KB
<?php

namespace Plugin\DataProcess;

use Plugin\DataProcess\ListProcess;
use Plugin\Helpers;

/**
 * 新品到着、折扣专区数据处理类
 */
class NewSaleProcess
{

    /**
     * 处理新品到着、折扣专区数据
     * 
     * @param  array $products  接口传回的数据
     * @return array       处理之后的数据
     */
    public static function newSaleData($products)
    {
        $result = array();
        $noTab = true;
        $productsLi = array();
        $tabItem = array();

        foreach ($products as $single) {
            if (empty($single)) {
                continue;
            }

            // 处理Filter
            if(isset($single['filter'])) {
                $result['filter'] = ListProcess::getFilterData($single['filter']);
            }
            
            // 处理Tabs
            $noTab = true;
            if (isset($single['tabs']) && $noTab) {
                $result['tabs'] = array();
                foreach ($single['tabs'] as $key => $one) {
                    $tabItem = array();
                    $tabItem['title'] = $one;
                    $tabItem['dataId'] = $key;
                    if ($key === 1) {
                        $tabItem['focus'] = true;
                    }
                    $result['tabs'][] = $tabItem;
                }
                $noTab = false;
            }

            // 处理商品
            $productsLi = array();
            if (isset($single['product_list'])) {
                foreach ($single['product_list'] as $value) {
                    $productsLi['goods'][] = Helpers::formatProduct($value, true, false, false);
                }
            }

            // 对于第一个productsLi添加show字段
            if (!isset($result['goodsContainer'][0])) {
                $productsLi['show'] = true;
            }

            $result['goodsContainer'][] = $productsLi;
        }

        return $result;
    }

}